forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_bug462106_perwindow.xul
136 lines (118 loc) · 4.25 KB
/
test_bug462106_perwindow.xul
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=462106
-->
<window title="Mozilla Bug 462106"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="initAndRunTests()">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
</body>
<!-- test code goes here -->
<script class="testbody" type="application/javascript">
<![CDATA[
/** Test for Bug 462106 **/
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
function copy(str, doc) {
if (!doc) {
doc = document;
}
Cc["@mozilla.org/widget/clipboardhelper;1"].
getService(Ci.nsIClipboardHelper).
copyString(str, doc);
}
function getLoadContext() {
return window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsILoadContext);
}
function paste() {
let trans = Cc["@mozilla.org/widget/transferable;1"].
createInstance(Ci.nsITransferable);
trans.init(getLoadContext());
trans.addDataFlavor("text/unicode");
let clip = Cc["@mozilla.org/widget/clipboard;1"].
getService(Ci.nsIClipboard);
clip.getData(trans, Ci.nsIClipboard.kGlobalClipboard);
let str = {}, length = {};
try {
trans.getTransferData("text/unicode", str, length);
} catch (e) {
str = null;
}
if (str) {
str = str.value.QueryInterface(Ci.nsISupportsString);
if (str)
str = str.data.substring(0, length.value / 2);
}
return str;
}
function whenDelayedStartupFinished(aWindow, aCallback) {
Services.obs.addObserver(function observer(aSubject, aTopic) {
if (aWindow == aSubject) {
Services.obs.removeObserver(observer, aTopic);
setTimeout(aCallback, 0);
}
}, "browser-delayed-startup-finished", false);
}
function testOnWindow(options, callback) {
var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
let win = mainWindow.OpenBrowserWindow(options);
whenDelayedStartupFinished(win, function() {
callback(win);
});
};
function initAndRunTests() {
SimpleTest.waitForExplicitFinish();
const data = "random number: " + Math.random();
copy(data);
is(data, paste(), "Data successfully copied before entering the private browsing mode");
testOnWindow({private: true}, function (aPrivateWindow) {
aPrivateWindow.close();
// the data should still be on the clipboard because it was copied before
// entering the private browsing mode
is(data, paste(), "Copied data persisted after leaving the private browsing mode");
const data2 = "another random number: " + Math.random();
testOnWindow({private: true}, function (aPrivateWindow) {
copy(data2, aPrivateWindow.document); // copy the data inside the private browsing mode
function insidePBPaste() {
if (data2 != paste()) {
setTimeout(insidePBPaste, 100);
return;
}
// the data should be on the clipboard inside the private browsing mode
is(data2, paste(), "Data successfully copied inside the private browsing mode");
aPrivateWindow.close();
function afterClose() {
if (data2 == paste()) {
setTimeout(afterClose, 100);
return;
}
// the data should no longer be on the clipboard at this stage
isnot(data2, paste(), "Data no longer available after leaving the private browsing mode");
SimpleTest.finish();
}
afterClose();
}
insidePBPaste();
});
});
}
]]>
</script>
</window>