Bug 1595678 - browser.experiments.urlbar.isBrowserShowingNotification should not treat app menu badges as notifications. r=mak
authorDrew Willcoxon <adw@mozilla.com>
Wed, 13 Nov 2019 22:50:50 +0000
changeset 501849 7ace5357440ad37e7608a301bf37b6c2b53dd6b4
parent 501848 f0968dabe1ff713ae3f28861dae1ca6524aafd80
child 501850 4cf8f3f89042f4622a349e2fd75a849155ffa75b
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1595678
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1595678 - browser.experiments.urlbar.isBrowserShowingNotification should not treat app menu badges as notifications. r=mak This also updates each test task to make sure the function returns false after each notification is dismissed. Differential Revision: https://phabricator.services.mozilla.com/D52915
browser/components/urlbar/tests/ext/api.js
browser/components/urlbar/tests/ext/browser/browser_ext_urlbar_isBrowserShowingNotification.js
--- a/browser/components/urlbar/tests/ext/api.js
+++ b/browser/components/urlbar/tests/ext/api.js
@@ -13,25 +13,33 @@ XPCOMUtils.defineLazyModuleGetters(this,
 this.experiments_urlbar = class extends ExtensionAPI {
   getAPI() {
     return {
       experiments: {
         urlbar: {
           isBrowserShowingNotification() {
             let window = BrowserWindowTracker.getTopWindow();
 
-            // urlbar view, app menu notification, notification box (info bar)
+            // urlbar view and notification box (info bar)
             if (
               window.gURLBar.view.isOpen ||
-              AppMenuNotifications.activeNotification ||
               window.gBrowser.getNotificationBox().currentNotification
             ) {
               return true;
             }
 
+            // app menu notification doorhanger
+            if (
+              AppMenuNotifications.activeNotification &&
+              !AppMenuNotifications.activeNotification.dismissed &&
+              !AppMenuNotifications.activeNotification.options.badgeOnly
+            ) {
+              return true;
+            }
+
             // tracking protection and identity box doorhangers
             if (
               ["tracking-protection-icon-container", "identity-box"].some(
                 id =>
                   window.document.getElementById(id).getAttribute("open") ==
                   "true"
               )
             ) {
--- a/browser/components/urlbar/tests/ext/browser/browser_ext_urlbar_isBrowserShowingNotification.js
+++ b/browser/components/urlbar/tests/ext/browser/browser_ext_urlbar_isBrowserShowingNotification.js
@@ -10,91 +10,116 @@
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   AppMenuNotifications: "resource://gre/modules/AppMenuNotifications.jsm",
 });
 
 // isBrowserShowingNotification should return false when there are no
 // notifications.
 add_task(async function noNotifications() {
+  // First, hide notifications that are currently showing.
+
+  // Escape closes many doorhangers and panels: tracking protection, site
+  // identity, page action panels, toolbar button panels.
+  EventUtils.synthesizeKey("KEY_Escape");
+
+  // urlbar view
+  await UrlbarTestUtils.promisePopupClose(window);
+
+  // notification box (info bar)
+  window.gBrowser.getNotificationBox().removeAllNotifications(true);
+
+  // app menu notification doorhanger
+  if (AppMenuNotifications.activeNotification) {
+    AppMenuNotifications.dismissNotification(
+      AppMenuNotifications.activeNotification.id
+    );
+  }
+
   await checkExtension(false);
 });
 
 // isBrowserShowingNotification should return true when the urlbar view is open.
 add_task(async function urlbarView() {
   await UrlbarTestUtils.promiseAutocompleteResultPopup({
     window,
     value: "test",
     waitForFocus,
   });
   await checkExtension(true);
   await UrlbarTestUtils.promisePopupClose(window);
+  await checkExtension(false);
 });
 
 // isBrowserShowingNotification should return true when the tracking protection
 // doorhanger is showing.
 add_task(async function trackingProtection() {
   await BrowserTestUtils.withNewTab("http://example.com/", async () => {
     let panel = document.getElementById("protections-popup");
     document.getElementById("tracking-protection-icon-container").click();
     await BrowserTestUtils.waitForPopupEvent(panel, "shown");
 
     await checkExtension(true);
 
     EventUtils.synthesizeKey("KEY_Escape");
     await BrowserTestUtils.waitForPopupEvent(panel, "hidden");
+
+    await checkExtension(false);
   });
 });
 
 // isBrowserShowingNotification should return true when the site identity
 // doorhanger is showing.
 add_task(async function siteIdentity() {
   await BrowserTestUtils.withNewTab("http://example.com/", async () => {
     let panel = document.getElementById("identity-popup");
     document.getElementById("identity-box").click();
     await BrowserTestUtils.waitForPopupEvent(panel, "shown");
 
     await checkExtension(true);
 
     EventUtils.synthesizeKey("KEY_Escape");
     await BrowserTestUtils.waitForPopupEvent(panel, "hidden");
+
+    await checkExtension(false);
   });
 });
 
 // isBrowserShowingNotification should return true when a notification box (info
 // bar) is showing.
 add_task(async function notificationBox() {
   let box = gBrowser.getNotificationBox();
   let note = box.appendNotification(
     "Test",
     "urlbar-test",
     null,
     box.PRIORITY_INFO_HIGH,
     null,
     null,
     null
   );
-
   await checkExtension(true);
-
   box.removeNotification(note, true);
+  await checkExtension(false);
 });
 
 // isBrowserShowingNotification should return true when a page action panel is
 // showing.
 add_task(async function pageActionPanel() {
   await BrowserTestUtils.withNewTab("http://example.com/", async () => {
     let panel = document.getElementById("pageActionPanel");
     document.getElementById("pageActionButton").click();
     await BrowserTestUtils.waitForPopupEvent(panel, "shown");
 
     await checkExtension(true);
 
     EventUtils.synthesizeKey("KEY_Escape");
     await BrowserTestUtils.waitForPopupEvent(panel, "hidden");
+
+    await checkExtension(false);
   });
 });
 
 // isBrowserShowingNotification should return true when a toolbar button panel
 // is showing.
 add_task(async function toolbarButtonPanel() {
   document.getElementById("library-button").click();
 
@@ -105,31 +130,40 @@ add_task(async function toolbarButtonPan
   });
 
   await checkExtension(true);
 
   EventUtils.synthesizeKey("KEY_Escape");
   await TestUtils.waitForCondition(() => {
     return !document.getElementById("customizationui-widget-panel");
   });
+
+  await checkExtension(false);
 });
 
 // isBrowserShowingNotification should return true when an app menu notification
 // is showing.
 add_task(async function appMenuNotification() {
   AppMenuNotifications.showNotification("update-manual", {
     callback: () => {},
   });
   let panel = document.getElementById("appMenu-notification-popup");
   await BrowserTestUtils.waitForPopupEvent(panel, "shown");
 
   await checkExtension(true);
 
   AppMenuNotifications.dismissNotification("update-manual");
   await BrowserTestUtils.waitForPopupEvent(panel, "hidden");
+
+  await checkExtension(false);
+
+  // The notification remains in AppMenuNotifications and the badge remains on
+  // the button even though the panel was dismissed, so remove it for good now
+  // so it doesn't interfere with other tests.
+  AppMenuNotifications.removeNotification("update-manual");
 });
 
 async function checkExtension(expectedShowing) {
   let ext = await loadExtension(async () => {
     let showing = await browser.experiments.urlbar.isBrowserShowingNotification();
     browser.test.sendMessage("showing", showing);
   });
   let showing = await ext.awaitMessage("showing");