Bug 1325841 - fix hiding popup icon when navigating the browser, r=Felipe, a=jcristau
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 21 Mar 2017 15:57:42 +0000
changeset 395535 39cc9278d2fab01442a3349169f0f86805a152e9
parent 395534 e67a8a737afa6ef13386bc152bb6e8dec62a4b8f
child 395536 eff9e30b6f7528ef8af39ac526f7eb00d9b1eab7
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe, jcristau
bugs1325841
milestone54.0a2
Bug 1325841 - fix hiding popup icon when navigating the browser, r=Felipe, a=jcristau MozReview-Commit-ID: AXBgxwb3Jt
browser/base/content/browser.js
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_popupUI.js
browser/base/content/test/general/browser_popup_blocker.js
browser/base/content/test/general/head.js
browser/base/content/test/general/popup_blocker.html
browser/base/content/test/popups/browser.ini
browser/base/content/test/popups/browser_popupUI.js
browser/base/content/test/popups/browser_popup_blocker.js
browser/base/content/test/popups/popup_blocker.html
browser/base/moz.build
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -569,17 +569,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
@@ -49,17 +49,16 @@ support-files =
   moz.png
   navigating_window_with_download.html
   offlineQuotaNotification.cacheManifest
   offlineQuotaNotification.html
   page_style_sample.html
   parsingTestHelpers.jsm
   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
@@ -290,19 +289,16 @@ support-files =
 skip-if = debug # no point in running on both opt and debug, and will likely intermittently timeout on debug
 [browser_parsable_script.js]
 skip-if = asan || (os == 'linux' && !debug && (bits == 32)) # disabled on asan because of timeouts, and bug 1172468 for the linux 32-bit pgo issue.
 [browser_permissions.js]
 support-files =
   permissions.html
 [browser_pinnedTabs.js]
 [browser_plainTextLinks.js]
-[browser_popupUI.js]
-[browser_popup_blocker.js]
-skip-if = (os == 'linux') || (e10s && debug) # Frequent bug 1081925 and bug 1125520 failures
 [browser_printpreview.js]
 [browser_private_browsing_window.js]
 [browser_private_no_prompt.js]
 [browser_purgehistory_clears_sh.js]
 [browser_PageMetaData_pushstate.js]
 [browser_refreshBlocker.js]
 support-files =
   refresh_header.sjs
--- 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
@@ -17,16 +17,17 @@ MOCHITEST_CHROME_MANIFESTS += [
 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/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/tabcrashed/browser.ini',
     'content/test/tabPrompts/browser.ini',
     'content/test/tabs/browser.ini',
     'content/test/urlbar/browser.ini',
     'content/test/webextensions/browser.ini',