dom/plugins/test/mochitest/test_privatemode_perwindowpb.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial