Bug 1325223 - Focusing the window shouldn't trigger the showing/shown events again on persistent notifications that were never dismissed, r=past.
authorFlorian Quèze <florian@queze.net>
Fri, 20 Jan 2017 23:37:48 +0100
changeset 377791 98c3bfd85ae321add710899c3203498b9ec60ec6
parent 377790 2301f25d15957f24d36b68103b1b4e9786344392
child 377792 4bfa82216639a496a20b05319d0c001ce1892e5f
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs1325223
milestone53.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 1325223 - Focusing the window shouldn't trigger the showing/shown events again on persistent notifications that were never dismissed, r=past.
browser/base/content/test/popupNotifications/browser_popupNotification_5.js
toolkit/modules/PopupNotifications.jsm
--- a/browser/base/content/test/popupNotifications/browser_popupNotification_5.js
+++ b/browser/base/content/test/popupNotifications/browser_popupNotification_5.js
@@ -174,41 +174,55 @@ var tests = [
     }
   },
   // Test that persistent panels are still open after switching to another
   // window and back.
   { id: "Test#7",
     *run() {
       this.oldSelectedTab = gBrowser.selectedTab;
       yield BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com/");
+      let firstTab = gBrowser.selectedTab;
+
+      yield BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com/");
 
       let shown = waitForNotificationPanel();
       let notifyObj = new BasicNotification(this.id);
       notifyObj.options.persistent = true;
       this.notification = showNotification(notifyObj);
       yield shown;
 
-      ok(notifyObj.shownCallbackTriggered, "Should have triggered the shown callback");
+      ok(notifyObj.shownCallbackTriggered, "Should have triggered the shown event");
+      ok(notifyObj.showingCallbackTriggered, "Should have triggered the showing event");
+      // Reset to false so that we can ensure these are not fired a second time.
+      notifyObj.shownCallbackTriggered = false;
+      notifyObj.showingCallbackTriggered = false;
 
-      yield BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com/");
       let promiseWin = BrowserTestUtils.waitForNewWindow();
-      gBrowser.replaceTabWithWindow(gBrowser.selectedTab);
+      gBrowser.replaceTabWithWindow(firstTab);
       let win = yield promiseWin;
 
       let anchor = win.document.getElementById("default-notification-icon");
       win.PopupNotifications._reshowNotifications(anchor);
       ok(win.PopupNotifications.panel.childNodes.length == 0,
          "no notification displayed in new window");
 
       yield BrowserTestUtils.closeWindow(win);
       yield waitForWindowReadyForPopupNotifications(window);
 
       let id = PopupNotifications.panel.firstChild.getAttribute("popupid");
       ok(id.endsWith("Test#7"), "Should have found the notification from Test7");
-      ok(PopupNotifications.isPanelOpen, "Should have shown the popup again after getting back to the window");
+      ok(PopupNotifications.isPanelOpen,
+         "Should have kept the popup on the first window");
+      ok(!notifyObj.dismissalCallbackTriggered,
+         "Should not have triggered a dismissed event");
+      ok(!notifyObj.shownCallbackTriggered,
+         "Should not have triggered a second shown event");
+      ok(!notifyObj.showingCallbackTriggered,
+         "Should not have triggered a second showing event");
+
       this.notification.remove();
       gBrowser.removeTab(gBrowser.selectedTab);
       gBrowser.selectedTab = this.oldSelectedTab;
 
       goNext();
     }
   },
   // Test that only the first persistent notification is shown on update
--- a/toolkit/modules/PopupNotifications.jsm
+++ b/toolkit/modules/PopupNotifications.jsm
@@ -560,16 +560,18 @@ PopupNotifications.prototype = {
   },
 
   handleEvent(aEvent) {
     switch (aEvent.type) {
       case "popuphidden":
         this._onPopupHidden(aEvent);
         break;
       case "activate":
+        if (this.isPanelOpen)
+          break;
       case "TabSelect":
         let self = this;
         // This is where we could detect if the panel is dismissed if the page
         // was switched. Unfortunately, the user usually has clicked elsewhere
         // at this point so this value only gets recorded for programmatic
         // reasons, like the "Learn More" link being clicked and resulting in a
         // tab switch.
         this.nextDismissReason = TELEMETRY_STAT_DISMISSAL_LEAVE_PAGE;