Bug 825723 - Popup notification anchor disappears when a notification with the same ID is re-added in a background tab. r=gavin
authorDão Gottwald <dao@mozilla.com>
Fri, 08 Mar 2013 18:22:29 +0100
changeset 124226 e25ca1ca1f17090a78dcb2fa4426bfe1978e77ba
parent 124225 2f4e44ec0b9aa987940def320004a9b12d8a0f24
child 124227 917070d58a1701379ca6dfc9f82dc8ac4ac751cc
push id24302
push userdgottwald@mozilla.com
push dateFri, 08 Mar 2013 17:22:46 +0000
treeherdermozilla-inbound@e25ca1ca1f17 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs825723
milestone22.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 825723 - Popup notification anchor disappears when a notification with the same ID is re-added in a background tab. r=gavin
browser/base/content/test/browser_popupNotification.js
toolkit/content/PopupNotifications.jsm
--- a/browser/base/content/test/browser_popupNotification.js
+++ b/browser/base/content/test/browser_popupNotification.js
@@ -722,40 +722,78 @@ var tests = [
     onHidden: function (popup) {
       ok(this.notifyObj.mainActionClicked, "mainAction was clicked after the delay");
       ok(!this.notifyObj.dismissalCallbackTriggered, "dismissal callback was not triggered");
       PopupNotifications.buttonDelay = PREF_SECURITY_DELAY_INITIAL;
     },
   },
   { // Test #25 - location change in background tab removes notification
     run: function () {
-      this.oldSelectedTab = gBrowser.selectedTab;
-      this.newTab = gBrowser.addTab("about:blank");
-      gBrowser.selectedTab = this.newTab;
+      let oldSelectedTab = gBrowser.selectedTab;
+      let newTab = gBrowser.addTab("about:blank");
+      gBrowser.selectedTab = newTab;
 
       loadURI("http://example.com/", function() {
-        gBrowser.selectedTab = this.oldSelectedTab;
-        let browser = gBrowser.getBrowserForTab(this.newTab);
+        gBrowser.selectedTab = oldSelectedTab;
+        let browser = gBrowser.getBrowserForTab(newTab);
 
-        this.notifyObj = new basicNotification();
-        this.notifyObj.browser = browser;
-        this.notifyObj.options.eventCallback = function (eventName) {
+        let notifyObj = new basicNotification();
+        notifyObj.browser = browser;
+        notifyObj.options.eventCallback = function (eventName) {
           if (eventName == "removed") {
             ok(true, "Notification removed in background tab after reloading");
             executeSoon(function () {
-              gBrowser.removeTab(this.newTab);
+              gBrowser.removeTab(newTab);
               goNext();
-            }.bind(this));
+            });
           }
-        }.bind(this);
-        this.notification = showNotification(this.notifyObj);
+        };
+        showNotification(notifyObj);
         executeSoon(function () {
           browser.reload();
         });
-      }.bind(this));
+      });
+    }
+  },
+  { // Test #26 -  Popup notification anchor shouldn't disappear when a notification with the same ID is re-added in a background tab
+    run: function () {
+      loadURI("http://example.com/", function () {
+        let originalTab = gBrowser.selectedTab;
+        let bgTab = gBrowser.addTab("about:blank");
+        gBrowser.selectedTab = bgTab;
+        loadURI("http://example.com/", function () {
+          let anchor = document.createElement("box");
+          anchor.id = "test26-anchor";
+          anchor.className = "notification-anchor-icon";
+          PopupNotifications.iconBox.appendChild(anchor);
+
+          gBrowser.selectedTab = originalTab;
+
+          let fgNotifyObj = new basicNotification();
+          fgNotifyObj.anchorID = anchor.id;
+          fgNotifyObj.options.dismissed = true;
+          let fgNotification = showNotification(fgNotifyObj);
+
+          let bgNotifyObj = new basicNotification();
+          bgNotifyObj.anchorID = anchor.id;
+          bgNotifyObj.browser = gBrowser.getBrowserForTab(bgTab);
+          // show the notification in the background tab ...
+          let bgNotification = showNotification(bgNotifyObj);
+          // ... and re-show it
+          bgNotification = showNotification(bgNotifyObj);
+
+          ok(fgNotification.id, "notification has id");
+          is(fgNotification.id, bgNotification.id, "notification ids are the same");
+          is(anchor.getAttribute("showing"), "true", "anchor still showing");
+
+          fgNotification.remove();
+          gBrowser.removeTab(bgTab);
+          goNext();
+        });
+      });
     }
   }
 ];
 
 function showNotification(notifyObj) {
   return PopupNotifications.show(notifyObj.browser,
                                  notifyObj.id,
                                  notifyObj.message,
--- a/toolkit/content/PopupNotifications.jsm
+++ b/toolkit/content/PopupNotifications.jsm
@@ -322,17 +322,17 @@ PopupNotifications.prototype = {
   },
 
   /**
    * Removes a Notification.
    * @param notification
    *        The Notification object to remove.
    */
   remove: function PopupNotifications_remove(notification) {
-    let isCurrent = this._currentNotifications.indexOf(notification) != -1;
+    let isCurrent = notification.browser == this.tabbrowser.selectedBrowser;
     this._remove(notification);
 
     // update the panel, if needed
     if (isCurrent)
       this._update();
   },
 
   handleEvent: function (aEvent) {
@@ -376,17 +376,18 @@ PopupNotifications.prototype = {
     let notifications = this._getNotificationsForBrowser(notification.browser);
     if (!notifications)
       return;
 
     var index = notifications.indexOf(notification);
     if (index == -1)
       return;
 
-    notification.anchorElement.removeAttribute(ICON_ATTRIBUTE_SHOWING);
+    if (notification.browser == this.tabbrowser.selectedBrowser)
+      notification.anchorElement.removeAttribute(ICON_ATTRIBUTE_SHOWING);
 
     // remove the notification
     notifications.splice(index, 1);
     this._fireCallback(notification, NOTIFICATION_EVENT_REMOVED);
   },
 
   /**
    * Dismisses the notification without removing it.