Bug 806723 - Port plugin test_privatemode.xul to the new per-tab PB APIs r=jdm a=test-only
--- a/dom/plugins/test/mochitest/Makefile.in
+++ b/dom/plugins/test/mochitest/Makefile.in
@@ -103,16 +103,21 @@ MOCHITEST_CHROME_FILES = \
test_bug479979.xul \
test_refresh_navigator_plugins.html \
$(NULL)
ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
MOCHITEST_CHROME_FILES += \
test_privatemode.xul \
$(NULL)
+else
+MOCHITEST_CHROME_FILES += \
+ privatemode_perwindowpb.xul \
+ test_privatemode_perwindowpb.xul \
+ $(NULL)
endif
ifneq ($(MOZ_WIDGET_TOOLKIT),cocoa)
MOCHITEST_FILES += \
test_instance_re-parent-windowed.html \
test_visibility.html \
$(NULL)
new file mode 100644
--- /dev/null
+++ b/dom/plugins/test/mochitest/privatemode_perwindowpb.xul
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
+ type="text/css"?>
+<window title="NPAPI Private Mode Tests"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <title>NPAPI Private Mode Tests</title>
+<body xmlns="http://www.w3.org/1999/xhtml">
+<embed id="plugin1" type="application/x-test" width="200" height="200"></embed>
+<embed id="plugin2" type="application/x-test" width="200" height="200"></embed>
+</body>
+</window>
copy from dom/plugins/test/mochitest/test_privatemode.xul
copy to dom/plugins/test/mochitest/test_privatemode_perwindowpb.xul
--- a/dom/plugins/test/mochitest/test_privatemode.xul
+++ b/dom/plugins/test/mochitest/test_privatemode_perwindowpb.xul
@@ -11,27 +11,20 @@
<body xmlns="http://www.w3.org/1999/xhtml" onload="runTests()">
<embed id="plugin1" type="application/x-test" width="200" height="200"></embed>
<embed id="plugin2" type="application/x-test" width="200" height="200"></embed>
</body>
<script class="testbody" type="application/javascript">
<![CDATA[
SimpleTest.waitForExplicitFinish();
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
function runTests() {
- // don't run these tests if we can't get ahold of the private browsing service
- var privateBrowsing = null;
- try {
- privateBrowsing = Components.classes["@mozilla.org/privatebrowsing;1"].getService(Components.interfaces.nsIPrivateBrowsingService);
- } catch (e) {
- ok(true, "no Private Browsing service");
- SimpleTest.finish();
- return;
- }
-
var pluginElement1 = document.getElementById("plugin1");
var pluginElement2 = document.getElementById("plugin2");
var state1 = false;
var state2 = false;
var exceptionThrown = false;
try {
@@ -42,57 +35,66 @@ function runTests() {
}
is(exceptionThrown, false, "Exception thrown getting private mode state.");
is(state1, false, "Browser returned incorrect private mode state.");
is(state2, false, "Browser returned incorrect private mode state.");
pluginElement1.setCookie("foo");
is(pluginElement1.getCookie(), "foo", "Cookie was set and retrieved correctly in public mode.");
- // change private mode pref
- var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
- var keepCurrentSession;
- try {
- keepCurrentSession = prefs.getBoolPref("browser.privatebrowsing.keep_current_session");
- } catch (e) {
- keepCurrentSession = false
+ // open a window with private mode and get the references of the elements.
+ var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIWebNavigation)
+ .QueryInterface(Ci.nsIDocShellTreeItem)
+ .rootTreeItem
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindow);
+ var contentPage = "chrome://mochitests/content/chrome/dom/plugins/test/privatemode_perwindowpb.xul";
+
+ function testOnWindow(aIsPrivate, aCallback) {
+ var win = mainWindow.OpenBrowserWindow({private: aIsPrivate});
+ win.addEventListener("load", function onLoad() {
+ win.removeEventListener("load", onLoad, false);
+ win.addEventListener("DOMContentLoaded", function onInnerLoad() {
+ if (win.content.location.href == "about:privatebrowsing") {
+ win.gBrowser.loadURI(contentPage);
+ return;
+ }
+ win.removeEventListener("DOMContentLoaded", onInnerLoad, true);
+ win.gBrowser.selectedBrowser.focus();
+ SimpleTest.executeSoon(function() { aCallback(win); });
+ }, true);
+ SimpleTest.executeSoon(function() { win.gBrowser.loadURI(contentPage); });
+ }, true);
}
- prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true);
- privateBrowsing.privateBrowsingEnabled = true;
-
- try {
- state1 = pluginElement1.lastReportedPrivateModeState();
- state2 = pluginElement2.lastReportedPrivateModeState();
- } catch (e) {
- exceptionThrown = true;
- }
- is(exceptionThrown, false, "Exception thrown getting private mode state.");
- is(state1, true, "Private mode state reported incorrectly.");
- is(state2, true, "Private mode state reported incorrectly.");
- var officialState1, officialState2;
- try {
- officialState1 = pluginElement1.queryPrivateModeState();
- officialState2 = pluginElement2.queryPrivateModeState();
- } catch (e) {
- exceptionThrown = true;
- }
- is(exceptionThrown, false, "Exception thrown getting private mode state.");
- is(officialState1, state1, "Private mode reported and queried is inconsistent.");
- is(officialState2, state2, "Private mode reported and queried is inconsistent.");
+ testOnWindow(true, function(aWin) {
+ pluginElement1 = aWin.gBrowser.contentDocument.getElementById("plugin1");
+ pluginElement2 = aWin.gBrowser.contentDocument.getElementById("plugin2");
- // It would be nice to assert that we don't see the public cookie in private mode,
- // but the NPAPI complains when the resulting string is empty.
- // is(pluginElement1.getCookie(), "", "Public cookie was not retrieved in private mode.");
- pluginElement1.setCookie("bar");
- is(pluginElement1.getCookie(), "bar", "Cookie was set and retrieved correctly in private mode.");
+ var officialState1, officialState2;
+ try {
+ officialState1 = pluginElement1.queryPrivateModeState();
+ officialState2 = pluginElement2.queryPrivateModeState();
+ } catch (e) {
+ exceptionThrown = true;
+ }
+ is(exceptionThrown, false, "Exception thrown getting private mode state.");
+ is(officialState1, true, "Querying private mode reported incorrectly");
+ is(officialState2, true, "Querying private mode reported incorrectly");
- // reset preference states
- privateBrowsing.privateBrowsingEnabled = false;
- prefs.setBoolPref("browser.privatebrowsing.keep_current_session", keepCurrentSession);
+ // It would be nice to assert that we don't see the public cookie in private mode,
+ // but the NPAPI complains when the resulting string is empty.
+ // is(pluginElement1.getCookie(), "", "Public cookie was not retrieved in private mode.");
+ pluginElement1.setCookie("bar");
+ is(pluginElement1.getCookie(), "bar", "Cookie was set and retrieved correctly in private mode.");
- is(pluginElement1.getCookie(), "foo", "Private cookie was not retrieved in public mode.");
+ aWin.close();
- SimpleTest.finish();
+ pluginElement1 = document.getElementById("plugin1");
+ is(pluginElement1.getCookie(), "foo", "Private cookie was not retrieved in public mode.");
+
+ SimpleTest.finish();
+ });
}
]]>
</script>
</window>