Bug 1330609 - Hide the correct persistent popup notification on close. r=past draft
authorJohann Hofmann <jhofmann@mozilla.com>
Tue, 17 Jan 2017 16:23:41 +0100
changeset 462482 778fa23fc246bce77f47a74ab7843468e35db7fa
parent 462402 3e275d37a06236981bff399b7d7aa0646be3fee7
child 542410 22566b336a36c5538988ddd1e9cfcc7111594cff
push id41769
push userbmo:jhofmann@mozilla.com
push dateTue, 17 Jan 2017 15:24:18 +0000
reviewerspast
bugs1330609
milestone53.0a1
Bug 1330609 - Hide the correct persistent popup notification on close. r=past MozReview-Commit-ID: 23e8uKsz4tm
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
@@ -266,9 +266,54 @@ var tests = [
       is(notification2.id, this.notifyObj3.id + "-notification", "id 2 matches");
 
       this.notification1.remove();
       this.notification2.remove();
       this.notification3.remove();
     },
     onHidden(popup) { }
   },
+  // Test that on closebutton click, only the persistent notification
+  // that contained the closebutton loses its persistent status.
+  { id: "Test#10",
+    run() {
+      this.notifyObj1 = new BasicNotification(this.id);
+      this.notifyObj1.id += "_1";
+      this.notifyObj1.anchorID = "geo-notification-icon";
+      this.notifyObj1.options.persistent = true;
+      this.notifyObj1.options.hideClose = false;
+      this.notification1 = showNotification(this.notifyObj1);
+
+      this.notifyObj2 = new BasicNotification(this.id);
+      this.notifyObj2.id += "_2";
+      this.notifyObj2.anchorID = "geo-notification-icon";
+      this.notifyObj2.options.persistent = true;
+      this.notifyObj2.options.hideClose = false;
+      this.notification2 = showNotification(this.notifyObj2);
+
+      this.notifyObj3 = new BasicNotification(this.id);
+      this.notifyObj3.id += "_3";
+      this.notifyObj3.anchorID = "geo-notification-icon";
+      this.notifyObj3.options.persistent = true;
+      this.notifyObj3.options.hideClose = false;
+      this.notification3 = showNotification(this.notifyObj3);
+
+      PopupNotifications._update();
+    },
+    onShown(popup) {
+      let notifications = popup.childNodes;
+      is(notifications.length, 3, "three notifications displayed");
+      EventUtils.synthesizeMouseAtCenter(notifications[1].closebutton, {});
+    },
+    onHidden(popup) {
+      let notifications = popup.childNodes;
+      is(notifications.length, 2, "two notifications displayed");
+
+      ok(this.notification1.options.persistent, "notification 1 is persistent");
+      ok(!this.notification2.options.persistent, "notification 2 is not persistent");
+      ok(this.notification3.options.persistent, "notification 3 is persistent");
+
+      this.notification1.remove();
+      this.notification2.remove();
+      this.notification3.remove();
+    }
+  },
 ];
--- a/toolkit/modules/PopupNotifications.jsm
+++ b/toolkit/modules/PopupNotifications.jsm
@@ -615,26 +615,28 @@ PopupNotifications.prototype = {
     // remove the notification
     notifications.splice(index, 1);
     this._fireCallback(notification, NOTIFICATION_EVENT_REMOVED);
   },
 
   /**
    * Dismisses the notification without removing it.
    */
-  _dismiss: function PopupNotifications_dismiss(telemetryReason) {
+  _dismiss: function PopupNotifications_dismiss(event, telemetryReason) {
     if (telemetryReason) {
       this.nextDismissReason = telemetryReason;
     }
 
     // An explicitly dismissed persistent notification effectively becomes
     // non-persistent.
-    if (this.panel.firstChild &&
-        telemetryReason == TELEMETRY_STAT_DISMISSAL_CLOSE_BUTTON) {
-      this.panel.firstChild.notification.options.persistent = false;
+    if (event && telemetryReason == TELEMETRY_STAT_DISMISSAL_CLOSE_BUTTON) {
+      let notificationEl = getNotificationFromElement(event.target);
+      if (notificationEl) {
+        notificationEl.notification.options.persistent = false;
+      }
     }
 
     let browser = this.panel.firstChild &&
                   this.panel.firstChild.notification.browser;
     this.panel.hidePopup();
     if (browser)
       browser.focus();
   },
@@ -707,17 +709,17 @@ PopupNotifications.prototype = {
       if (popupnotification)
         gNotificationParents.set(popupnotification, popupnotification.parentNode);
       else
         popupnotification = doc.createElementNS(XUL_NS, "popupnotification");
 
       popupnotification.setAttribute("label", n.message);
       popupnotification.setAttribute("id", popupnotificationID);
       popupnotification.setAttribute("popupid", n.id);
-      popupnotification.setAttribute("closebuttoncommand", `PopupNotifications._dismiss(${TELEMETRY_STAT_DISMISSAL_CLOSE_BUTTON});`);
+      popupnotification.setAttribute("closebuttoncommand", `PopupNotifications._dismiss(event, ${TELEMETRY_STAT_DISMISSAL_CLOSE_BUTTON});`);
       if (n.mainAction) {
         popupnotification.setAttribute("buttonlabel", n.mainAction.label);
         popupnotification.setAttribute("buttonaccesskey", n.mainAction.accessKey);
         popupnotification.setAttribute("buttoncommand", "PopupNotifications._onButtonEvent(event, 'buttoncommand');");
         popupnotification.setAttribute("dropmarkerpopupshown", "PopupNotifications._onButtonEvent(event, 'dropmarkerpopupshown');");
         popupnotification.setAttribute("learnmoreclick", "PopupNotifications._onButtonEvent(event, 'learnmoreclick');");
         popupnotification.setAttribute("menucommand", "PopupNotifications._onMenuCommand(event);");
       } else {