2015-02-18 14:52:00 +03:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
|
2017-01-24 17:24:04 +03:00
|
|
|
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
|
2015-02-18 14:52:00 +03:00
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480
|
|
|
|
-->
|
|
|
|
<window title="Mozilla Bug 1123480"
|
|
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
|
|
onload="RunTest();">
|
|
|
|
<title>nsTransferable PBM Overflow Selection Test</title>
|
|
|
|
<script type="application/javascript"
|
|
|
|
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
|
|
|
|
|
|
|
|
<script type="application/javascript">
|
|
|
|
<![CDATA[
|
2017-09-27 01:26:07 +03:00
|
|
|
// Boilerplate constructs
|
|
|
|
var SmallDataset = 100000; // Hundred thousand bytes
|
2017-09-21 15:17:27 +03:00
|
|
|
|
2017-09-27 01:26:07 +03:00
|
|
|
// Create 1 Mo of sample garbage text
|
|
|
|
var Ipsum = ""; // Select text from this
|
|
|
|
for (var Iter = 0; Iter < SmallDataset; Iter++) {
|
|
|
|
Ipsum += Math.random().toString(36) + ' ';
|
2015-02-18 14:52:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function RunTest() {
|
2017-09-27 01:26:07 +03:00
|
|
|
// Construct a nsIFile object for access to file methods
|
|
|
|
Components.utils.import("resource://gre/modules/FileUtils.jsm");
|
|
|
|
var clipboardFile = FileUtils.getFile("TmpD", ["clipboardcache"]);
|
2015-02-18 14:52:00 +03:00
|
|
|
|
|
|
|
// Sanitize environment
|
2017-09-27 01:26:07 +03:00
|
|
|
if (clipboardFile.exists()) {
|
|
|
|
clipboardFile.remove(false);
|
|
|
|
}
|
|
|
|
ok(!clipboardFile.exists(), "failed to presanitize the environment");
|
2015-02-18 14:52:00 +03:00
|
|
|
|
|
|
|
// Overflow a nsTransferable region by using the clipboard helper
|
2017-09-27 01:26:07 +03:00
|
|
|
const gClipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
|
2015-02-18 14:52:00 +03:00
|
|
|
gClipboardHelper.copyString(Ipsum);
|
|
|
|
|
|
|
|
// Disabled private browsing mode should cache large selections to disk
|
2017-09-27 01:26:07 +03:00
|
|
|
ok(clipboardFile.exists(), "correctly saved memory by caching to disk");
|
2015-02-18 14:52:00 +03:00
|
|
|
|
|
|
|
// Sanitize environment again
|
2017-09-27 01:26:07 +03:00
|
|
|
if (clipboardFile.exists()) {
|
|
|
|
clipboardFile.remove(false);
|
|
|
|
}
|
|
|
|
ok(!clipboardFile.exists(), "failed to postsanitize the environment");
|
2015-02-18 14:52:00 +03:00
|
|
|
|
|
|
|
// Repeat procedure of plain text selection with private browsing enabled
|
|
|
|
Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
|
|
|
|
var Winpriv = window.open("about:blank", "_blank", "chrome, width=500, height=200, private");
|
|
|
|
ok(Winpriv, "failed to open private window");
|
|
|
|
ok(PrivateBrowsingUtils.isContentWindowPrivate(Winpriv), "correctly used a private window context");
|
|
|
|
|
|
|
|
// Select plaintext in private channel
|
|
|
|
Components.utils.import('resource://gre/modules/Services.jsm');
|
|
|
|
const nsTransferable = Components.Constructor("@mozilla.org/widget/transferable;1", "nsITransferable");
|
|
|
|
const nsSupportsString = Components.Constructor("@mozilla.org/supports-string;1", "nsISupportsString");
|
|
|
|
var Loadctx = PrivateBrowsingUtils.privacyContextFromWindow(Winpriv);
|
|
|
|
var Transfer = nsTransferable();
|
|
|
|
var Suppstr = nsSupportsString();
|
|
|
|
Suppstr.data = Ipsum;
|
|
|
|
Transfer.init(Loadctx);
|
|
|
|
Transfer.addDataFlavor("text/plain");
|
|
|
|
Transfer.setTransferData("text/plain", Suppstr, Ipsum.length);
|
|
|
|
Services.clipboard.setData(Transfer, null, Services.clipboard.kGlobalClipboard);
|
|
|
|
|
|
|
|
// Enabled private browsing mode should not cache any selection to disk
|
2017-09-27 01:26:07 +03:00
|
|
|
ok(!clipboardFile.exists(), "did not violate private browsing mode");
|
2015-02-18 14:52:00 +03:00
|
|
|
}
|
|
|
|
]]>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- test results are displayed in the html:body -->
|
|
|
|
<body xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1123480"
|
|
|
|
target="_blank">Mozilla Bug 1123480</a>
|
|
|
|
</body>
|
|
|
|
</window>
|