Bug 1330609 - Hide the correct persistent popup notification on close. r=past

MozReview-Commit-ID: 23e8uKsz4tm

--HG--
extra : rebase_source : 778fa23fc246bce77f47a74ab7843468e35db7fa
This commit is contained in:
Johann Hofmann 2017-01-17 16:23:41 +01:00
parent 42e1871519
commit 42092fd6c2
2 changed files with 52 additions and 5 deletions

View File

@ -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();
}
},
];

View File

@ -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);