Bug 1325841 - fix hiding popup icon when navigating the browser, r?felipe
MozReview-Commit-ID: AXBgxwb3Jt
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -568,17 +568,17 @@ var gPopupBlockerObserver = {
handleEvent(aEvent) {
if (aEvent.originalTarget != gBrowser.selectedBrowser)
return;
if (!this._reportButton)
this._reportButton = document.getElementById("page-report-button");
if (!gBrowser.selectedBrowser.blockedPopups ||
- gBrowser.selectedBrowser.blockedPopups.count == 0) {
+ !gBrowser.selectedBrowser.blockedPopups.length) {
// Hide the icon in the location bar (if the location bar exists)
this._reportButton.hidden = true;
// Hide the notification box (if it's visible).
let notificationBox = gBrowser.getNotificationBox();
let notification = notificationBox.getNotificationWithValue("popup-blocked");
if (notification) {
notificationBox.removeNotification(notification, false);
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -54,17 +54,16 @@ support-files =
healthreport_testRemoteCommands.html
moz.png
navigating_window_with_download.html
offlineQuotaNotification.cacheManifest
offlineQuotaNotification.html
page_style_sample.html
pinning_headers.sjs
ssl_error_reports.sjs
- popup_blocker.html
print_postdata.sjs
searchSuggestionEngine.sjs
searchSuggestionEngine.xml
searchSuggestionEngine2.xml
subtst_contextmenu.html
subtst_contextmenu_input.html
subtst_contextmenu_xul.xul
test_bug462673.html
@@ -433,21 +432,16 @@ support-files = test_offline_gzip.html g
[browser_permissions.js]
support-files =
permissions.html
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_pinnedTabs.js]
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_plainTextLinks.js]
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
-[browser_popupUI.js]
-# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
-[browser_popup_blocker.js]
-skip-if = (os == 'linux') || (e10s && debug) # Frequent bug 1081925 and bug 1125520 failures
-# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_printpreview.js]
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_private_browsing_window.js]
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_private_no_prompt.js]
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
[browser_purgehistory_clears_sh.js]
# DO NOT ADD MORE TESTS HERE. USE A TOPICAL DIRECTORY INSTEAD.
--- a/browser/base/content/test/general/head.js
+++ b/browser/base/content/test/general/head.js
@@ -183,32 +183,16 @@ function setTestPluginEnabledState(newEn
var plugin = getTestPlugin(pluginName);
var oldEnabledState = plugin.enabledState;
plugin.enabledState = newEnabledState;
SimpleTest.registerCleanupFunction(function() {
getTestPlugin(pluginName).enabledState = oldEnabledState;
});
}
-// after a test is done using the plugin doorhanger, we should just clear
-// any permissions that may have crept in
-function clearAllPluginPermissions() {
- clearAllPermissionsByPrefix("plugin");
-}
-
-function clearAllPermissionsByPrefix(aPrefix) {
- let perms = Services.perms.enumerator;
- while (perms.hasMoreElements()) {
- let perm = perms.getNext();
- if (perm.type.startsWith(aPrefix)) {
- Services.perms.removePermission(perm);
- }
- }
-}
-
function pushPrefs(...aPrefs) {
let deferred = Promise.defer();
SpecialPowers.pushPrefEnv({"set": aPrefs}, deferred.resolve);
return deferred.promise;
}
function updateBlocklist(aCallback) {
var blocklistNotifier = Cc["@mozilla.org/extensions/blocklist;1"]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/popups/browser.ini
@@ -0,0 +1,4 @@
+[browser_popupUI.js]
+[browser_popup_blocker.js]
+support-files = popup_blocker.html
+skip-if = (os == 'linux') || (e10s && debug) # Frequent bug 1081925 and bug 1125520 failures
rename from browser/base/content/test/general/browser_popupUI.js
rename to browser/base/content/test/popups/browser_popupUI.js
rename from browser/base/content/test/general/browser_popup_blocker.js
rename to browser/base/content/test/popups/browser_popup_blocker.js
--- a/browser/base/content/test/general/browser_popup_blocker.js
+++ b/browser/base/content/test/popups/browser_popup_blocker.js
@@ -1,71 +1,96 @@
/* 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/. */
-const baseURL = "http://example.com/browser/browser/base/content/test/general/";
+const baseURL = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "http://example.com");
-function test() {
- waitForExplicitFinish();
- Task.spawn(function* () {
- // Enable the popup blocker.
- yield pushPrefs(["dom.disable_open_during_load", true]);
+function clearAllPermissionsByPrefix(aPrefix) {
+ let perms = Services.perms.enumerator;
+ while (perms.hasMoreElements()) {
+ let perm = perms.getNext();
+ if (perm.type.startsWith(aPrefix)) {
+ Services.perms.removePermission(perm);
+ }
+ }
+}
- // Open the test page.
- let tab = gBrowser.loadOneTab(baseURL + "popup_blocker.html", { inBackground: false });
- yield promiseTabLoaded(tab);
+add_task(function* test_opening_blocked_popups() {
+ // Enable the popup blocker.
+ yield SpecialPowers.pushPrefEnv({set: [["dom.disable_open_during_load", true]]});
+
+ // Open the test page.
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, baseURL + "popup_blocker.html");
- // Wait for the popup-blocked notification.
- let notification;
- yield promiseWaitForCondition(() =>
- notification = gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"));
+ // Wait for the popup-blocked notification.
+ let notification;
+ yield BrowserTestUtils.waitForCondition(() =>
+ notification = gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"));
- // Show the menu.
- let popupShown = promiseWaitForEvent(window, "popupshown");
- let popupFilled = BrowserTestUtils.waitForMessage(gBrowser.selectedBrowser.messageManager,
- "PopupBlocking:ReplyGetBlockedPopupList");
- notification.querySelector("button").doCommand();
- let popup_event = yield popupShown;
- let menu = popup_event.target;
- is(menu.id, "blockedPopupOptions", "Blocked popup menu shown");
+ // Show the menu.
+ let popupShown = BrowserTestUtils.waitForEvent(window, "popupshown");
+ let popupFilled = BrowserTestUtils.waitForMessage(gBrowser.selectedBrowser.messageManager,
+ "PopupBlocking:ReplyGetBlockedPopupList");
+ notification.querySelector("button").doCommand();
+ let popup_event = yield popupShown;
+ let menu = popup_event.target;
+ is(menu.id, "blockedPopupOptions", "Blocked popup menu shown");
- yield popupFilled;
- // The menu is filled on the same message that we waited for, so let's ensure that it
- // had a chance of running before this test code.
- yield new Promise(resolve => executeSoon(resolve));
+ yield popupFilled;
+ // The menu is filled on the same message that we waited for, so let's ensure that it
+ // had a chance of running before this test code.
+ yield new Promise(resolve => executeSoon(resolve));
+
+ // Check the menu contents.
+ let sep = menu.querySelector("menuseparator");
+ let popupCount = 0;
+ for (let i = sep.nextElementSibling; i; i = i.nextElementSibling) {
+ popupCount++;
+ }
+ is(popupCount, 2, "Two popups were blocked");
- // Check the menu contents.
- let sep = menu.querySelector("menuseparator");
- let popupCount = 0;
- for (let i = sep.nextElementSibling; i; i = i.nextElementSibling) {
- popupCount++;
- }
- is(popupCount, 2, "Two popups were blocked");
+ // Pressing "allow" should open all blocked popups.
+ let popupTabs = [];
+ function onTabOpen(event) {
+ popupTabs.push(event.target);
+ }
+ gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen);
- // Pressing "allow" should open all blocked popups.
- let popupTabs = [];
- function onTabOpen(event) {
- popupTabs.push(event.target);
- }
- gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen);
+ // Press the button.
+ let allow = menu.querySelector("[observes='blockedPopupAllowSite']");
+ allow.doCommand();
+ yield BrowserTestUtils.waitForCondition(() =>
+ popupTabs.length == 2 &&
+ popupTabs.every(aTab => aTab.linkedBrowser.currentURI.spec != "about:blank"));
+
+ gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen);
+
+ is(popupTabs[0].linkedBrowser.currentURI.spec, "data:text/plain;charset=utf-8,a", "Popup a");
+ is(popupTabs[1].linkedBrowser.currentURI.spec, "data:text/plain;charset=utf-8,b", "Popup b");
- // Press the button.
- let allow = menu.querySelector("[observes='blockedPopupAllowSite']");
- allow.doCommand();
- yield promiseWaitForCondition(() =>
- popupTabs.length == 2 &&
- popupTabs.every(aTab => aTab.linkedBrowser.currentURI.spec != "about:blank"));
+ // Clean up.
+ gBrowser.removeTab(tab);
+ for (let popup of popupTabs) {
+ gBrowser.removeTab(popup);
+ }
+ clearAllPermissionsByPrefix("popup");
+ // Ensure the menu closes.
+ menu.hidePopup();
+});
- gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen);
+add_task(function* check_icon_hides() {
+ // Enable the popup blocker.
+ yield SpecialPowers.pushPrefEnv({set: [["dom.disable_open_during_load", true]]});
- is(popupTabs[0].linkedBrowser.currentURI.spec, "data:text/plain;charset=utf-8,a", "Popup a");
- is(popupTabs[1].linkedBrowser.currentURI.spec, "data:text/plain;charset=utf-8,b", "Popup b");
+ let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, baseURL + "popup_blocker.html");
+
+ let button = document.getElementById("page-report-button");
+ yield BrowserTestUtils.waitForCondition(() =>
+ gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"));
+ ok(!button.hidden, "Button should be visible");
- // Clean up.
- gBrowser.removeTab(tab);
- for (let popup of popupTabs) {
- gBrowser.removeTab(popup);
- }
- clearAllPermissionsByPrefix("popup");
- finish();
- });
-}
+ let otherPageLoaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+ openLinkIn(baseURL, "current", {});
+ yield otherPageLoaded;
+ ok(button.hidden, "Button should have hidden again after another page loaded.");
+ yield BrowserTestUtils.removeTab(tab);
+});
rename from browser/base/content/test/general/popup_blocker.html
rename to browser/base/content/test/popups/popup_blocker.html
--- a/browser/base/moz.build
+++ b/browser/base/moz.build
@@ -18,16 +18,17 @@ BROWSER_CHROME_MANIFESTS += [
'content/test/alerts/browser.ini',
'content/test/captivePortal/browser.ini',
'content/test/forms/browser.ini',
'content/test/general/browser.ini',
'content/test/newtab/browser.ini',
'content/test/pageinfo/browser.ini',
'content/test/plugins/browser.ini',
'content/test/popupNotifications/browser.ini',
+ 'content/test/popups/browser.ini',
'content/test/referrer/browser.ini',
'content/test/siteIdentity/browser.ini',
'content/test/social/browser.ini',
'content/test/static/browser.ini',
'content/test/tabcrashed/browser.ini',
'content/test/tabPrompts/browser.ini',
'content/test/tabs/browser.ini',
'content/test/urlbar/browser.ini',