diff --git a/browser/components/privatebrowsing/test/browser/perwindow/Makefile.in b/browser/components/privatebrowsing/test/browser/perwindow/Makefile.in index 363dd7593a7c..89bd0da5b0c6 100644 --- a/browser/components/privatebrowsing/test/browser/perwindow/Makefile.in +++ b/browser/components/privatebrowsing/test/browser/perwindow/Makefile.in @@ -29,8 +29,10 @@ MOCHITEST_BROWSER_FILES = \ browser_privatebrowsing_localStorage_page2.html \ browser_privatebrowsing_opendir.js \ browser_privatebrowsing_openlocation.js \ + browser_privatebrowsing_popupblocker.js \ browser_privatebrowsing_theming.js \ browser_privatebrowsing_zoomrestore.js \ + popup.html \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_popupblocker.js b/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_popupblocker.js new file mode 100644 index 000000000000..46be6b85eb4d --- /dev/null +++ b/browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_popupblocker.js @@ -0,0 +1,86 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This test makes sure that private browsing mode disables the remember option +// for the popup blocker menu. +function test() { + // initialization + waitForExplicitFinish(); + + let testURI = "http://mochi.test:8888/browser/browser/components/privatebrowsing/test/browser/perwindow/popup.html"; + let windowsToClose = []; + let oldPopupPolicy = gPrefService.getBoolPref("dom.disable_open_during_load"); + gPrefService.setBoolPref("dom.disable_open_during_load", true); + + function testPopupBlockerMenuItem(aExpectedDisabled, aWindow, aCallback) { + + aWindow.gBrowser.addEventListener("DOMUpdatePageReport", function() { + aWindow.gBrowser.removeEventListener("DOMUpdatePageReport", arguments.callee, false); + + executeSoon(function() { + let notification = aWindow.gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"); + ok(notification, "The notification box should be displayed"); + + function checkMenuItem(callback) { + dump("CMI: in\n"); + aWindow.document.addEventListener("popupshown", function(event) { + dump("CMI: popupshown\n"); + aWindow.document.removeEventListener("popupshown", arguments.callee, false); + + if (aExpectedDisabled) + is(aWindow.document.getElementById("blockedPopupAllowSite").getAttribute("disabled"), "true", + "The allow popups menu item should be disabled"); + + event.originalTarget.hidePopup(); + dump("CMI: calling back\n"); + callback(); + dump("CMI: called back\n"); + }, false); + dump("CMI: out\n"); + } + + checkMenuItem(function() { + aCallback(); + }); + notification.querySelector("button").doCommand(); + }); + + }, false); + + aWindow.gBrowser.selectedBrowser.loadURI(testURI); + } + + function finishTest() { + // cleanup + gPrefService.setBoolPref("dom.disable_open_during_load", oldPopupPolicy); + finish(); + }; + + function testOnWindow(options, callback) { + let win = OpenBrowserWindow(options); + win.addEventListener("load", function onLoad() { + win.removeEventListener("load", onLoad, false); + windowsToClose.push(win); + executeSoon(function() callback(win)); + }, false); + }; + + registerCleanupFunction(function() { + windowsToClose.forEach(function(win) { + win.close(); + }); + }); + + testOnWindow({}, function(win) { + testPopupBlockerMenuItem(false, win, + testOnWindow({private: true}, function(win) { + testPopupBlockerMenuItem(true, win, + testOnWindow({}, function(win) { + testPopupBlockerMenuItem(false, win, finishTest); + }) + ); + }) + ); + }); +} diff --git a/browser/components/privatebrowsing/test/browser/perwindow/popup.html b/browser/components/privatebrowsing/test/browser/perwindow/popup.html new file mode 100644 index 000000000000..333a303469ee --- /dev/null +++ b/browser/components/privatebrowsing/test/browser/perwindow/popup.html @@ -0,0 +1,11 @@ + + + + Page creating a popup + + + + +