From 3d87d2a1d15b59f91861cb30e98720710f7cbdf1 Mon Sep 17 00:00:00 2001 From: "Mario Alvarado [:marioalv]" Date: Wed, 14 Nov 2012 04:21:30 -0600 Subject: [PATCH] Bug 806694 - Port browser_privatebrowsing_popupblocker.js to the new per-window PB APIs; r=ehsan --HG-- rename : browser/components/privatebrowsing/test/browser/global/browser_privatebrowsing_popupblocker.js => browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_popupblocker.js rename : browser/components/privatebrowsing/test/browser/global/popup.html => browser/components/privatebrowsing/test/browser/perwindow/popup.html extra : rebase_source : 637f2cc15fb5dd31a960b40bd9683b7ae7017853 --- .../test/browser/perwindow/Makefile.in | 2 + .../browser_privatebrowsing_popupblocker.js | 86 +++++++++++++++++++ .../test/browser/perwindow/popup.html | 11 +++ 3 files changed, 99 insertions(+) create mode 100644 browser/components/privatebrowsing/test/browser/perwindow/browser_privatebrowsing_popupblocker.js create mode 100644 browser/components/privatebrowsing/test/browser/perwindow/popup.html diff --git a/browser/components/privatebrowsing/test/browser/perwindow/Makefile.in b/browser/components/privatebrowsing/test/browser/perwindow/Makefile.in index 363dd7593a7..89bd0da5b0c 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 00000000000..46be6b85eb4 --- /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 00000000000..333a303469e --- /dev/null +++ b/browser/components/privatebrowsing/test/browser/perwindow/popup.html @@ -0,0 +1,11 @@ + + + + Page creating a popup + + + + +