diff --git a/browser/base/content/test/popupNotifications/browser_popupNotification_5.js b/browser/base/content/test/popupNotifications/browser_popupNotification_5.js index 83c0aebe6e02..cf1914d86f11 100644 --- a/browser/base/content/test/popupNotifications/browser_popupNotification_5.js +++ b/browser/base/content/test/popupNotifications/browser_popupNotification_5.js @@ -271,4 +271,49 @@ var tests = [ }, 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(); + } + }, ]; diff --git a/toolkit/modules/PopupNotifications.jsm b/toolkit/modules/PopupNotifications.jsm index dd575522db43..65abc452fd00 100644 --- a/toolkit/modules/PopupNotifications.jsm +++ b/toolkit/modules/PopupNotifications.jsm @@ -620,16 +620,18 @@ PopupNotifications.prototype = { /** * 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 && @@ -712,7 +714,7 @@ PopupNotifications.prototype = { 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);