Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
4 type="text/css"?>
5 <window title="NPAPI Private Mode Tests"
6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
7 <script type="application/javascript"
8 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
9 <script type="application/javascript"
10 src="chrome://mochikit/content/chrome-harness.js" />
11 <script type="application/javascript" src="utils.js"></script>
12 <script type="application/javascript">
13 setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
14 </script>
15 <body xmlns="http://www.w3.org/1999/xhtml" onload="runTests()">
16 <embed id="plugin1" type="application/x-test" width="200" height="200"></embed>
17 <embed id="plugin2" type="application/x-test" width="200" height="200"></embed>
18 </body>
19 <script class="testbody" type="application/javascript">
20 <![CDATA[
21 SimpleTest.waitForExplicitFinish();
23 const Cc = Components.classes;
24 const Ci = Components.interfaces;
26 function runTests() {
27 // Allow all cookies, then run the actual tests
28 SpecialPowers.pushPrefEnv({"set": [["network.cookie.cookieBehavior", 0]]}, runTestsCallback);
29 }
31 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
32 Components.utils.import("resource://gre/modules/Services.jsm");
34 function whenDelayedStartupFinished(aWindow, aCallback) {
35 Services.obs.addObserver(function observer(aSubject, aTopic) {
36 if (aWindow == aSubject) {
37 Services.obs.removeObserver(observer, aTopic);
38 SimpleTest.executeSoon(aCallback);
39 }
40 }, "browser-delayed-startup-finished", false);
41 }
43 function runTestsCallback() {
44 var pluginElement1 = document.getElementById("plugin1");
45 var pluginElement2 = document.getElementById("plugin2");
47 var state1 = false;
48 var state2 = false;
49 var exceptionThrown = false;
51 try {
52 state1 = pluginElement1.queryPrivateModeState();
53 state2 = pluginElement2.queryPrivateModeState();
54 } catch (e) {
55 exceptionThrown = true;
56 }
57 is(exceptionThrown, false, "Exception thrown getting private mode state.");
58 is(state1, false, "Browser returned incorrect private mode state.");
59 is(state2, false, "Browser returned incorrect private mode state.");
61 pluginElement1.setCookie("foo");
62 is(pluginElement1.getCookie(), "foo", "Cookie was set and retrieved correctly in public mode.");
64 // open a window with private mode and get the references of the elements.
65 var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
66 .getInterface(Ci.nsIWebNavigation)
67 .QueryInterface(Ci.nsIDocShellTreeItem)
68 .rootTreeItem
69 .QueryInterface(Ci.nsIInterfaceRequestor)
70 .getInterface(Ci.nsIDOMWindow);
71 var contentPage = getRootDirectory(window.location.href) + "privatemode_perwindowpb.xul";
73 function testOnWindow(aIsPrivate, aCallback) {
74 var win = mainWindow.OpenBrowserWindow({private: aIsPrivate});
75 whenDelayedStartupFinished(win, function () {
76 win.addEventListener("DOMContentLoaded", function onInnerLoad() {
77 if (win.content.location.href == "about:privatebrowsing") {
78 win.gBrowser.loadURI(contentPage);
79 return;
80 }
81 win.removeEventListener("DOMContentLoaded", onInnerLoad, true);
82 win.gBrowser.selectedBrowser.focus();
83 SimpleTest.executeSoon(function() { aCallback(win); });
84 }, true);
85 SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); });
86 });
87 }
89 testOnWindow(true, function(aWin) {
90 pluginElement1 = aWin.gBrowser.contentDocument.getElementById("plugin1");
91 pluginElement2 = aWin.gBrowser.contentDocument.getElementById("plugin2");
93 var officialState1, officialState2;
94 try {
95 officialState1 = pluginElement1.queryPrivateModeState();
96 officialState2 = pluginElement2.queryPrivateModeState();
97 } catch (e) {
98 exceptionThrown = true;
99 }
100 is(exceptionThrown, false, "Exception thrown getting private mode state.");
101 is(officialState1, true, "Querying private mode reported incorrectly");
102 is(officialState2, true, "Querying private mode reported incorrectly");
104 // It would be nice to assert that we don't see the public cookie in private mode,
105 // but the NPAPI complains when the resulting string is empty.
106 // is(pluginElement1.getCookie(), "", "Public cookie was not retrieved in private mode.");
107 pluginElement1.setCookie("bar");
108 is(pluginElement1.getCookie(), "bar", "Cookie was set and retrieved correctly in private mode.");
110 aWin.close();
112 pluginElement1 = document.getElementById("plugin1");
113 is(pluginElement1.getCookie(), "foo", "Private cookie was not retrieved in public mode.");
115 SimpleTest.finish();
116 });
117 }
118 ]]>
119 </script>
120 </window>