Bug 590794 - Add dismissalAction callback argument to PopupNotifications.show(). r+a=gavin

This commit is contained in:
Sylvain Pasche 2010-09-13 12:44:27 +02:00
parent bd5da08257
commit 166801f966
2 changed files with 29 additions and 7 deletions

View File

@ -20,6 +20,7 @@
*
* Contributor(s):
* Gavin Sharp <gavin@gavinsharp.com>
* Sylvain Pasche <sylvain.pasche@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -142,6 +143,15 @@ function basicNotification() {
}
}
];
this.options = {
dismissalCallback: function() {
self.dismissalCallbackTriggered = true;
}
};
this.addOptions = function(options) {
for (let [name, value] in Iterator(options))
self.options[name] = value;
}
}
var wrongBrowserNotificationObject = new basicNotification();
@ -184,6 +194,7 @@ var tests = [
dismissNotification(popup);
},
onHidden: function (popup) {
ok(this.notifyObj.dismissalCallbackTriggered, "dismissal handler triggered");
this.notification.remove();
}
},
@ -199,6 +210,7 @@ var tests = [
is(PopupNotifications.isPanelOpen, false, "panel isn't open");
ok(!wrongBrowserNotificationObject.mainActionClicked, "main action wasn't clicked");
ok(!wrongBrowserNotificationObject.secondaryActionClicked, "secondary action wasn't clicked");
ok(!wrongBrowserNotificationObject.dismissalCallbackTriggered, "dismissal handler wasn't called");
}
},
// now select that browser and test to see that the notification appeared
@ -217,7 +229,9 @@ var tests = [
},
onHidden: function (popup) {
// actually remove the notification to prevent it from reappearing
ok(!wrongBrowserNotificationObject.dismissalCallbackTriggered, "dismissal handler wasn't called");
wrongBrowserNotification.remove();
ok(!wrongBrowserNotificationObject.dismissalCallbackTriggered, "dismissal handler wasn't called after remove()");
wrongBrowserNotification = null;
}
},
@ -270,9 +284,11 @@ var tests = [
onHidden: function (popup) {
ok(this.testNotif1.mainActionClicked, "main action #1 was clicked");
ok(!this.testNotif1.secondaryActionClicked, "secondary action #1 wasn't clicked");
ok(!this.testNotif1.dismissalCallbackTriggered, "dismissal handler #1 wasn't called");
ok(!this.testNotif2.mainActionClicked, "main action #2 wasn't clicked");
ok(this.testNotif2.secondaryActionClicked, "secondary action #2 was clicked");
ok(!this.testNotif2.dismissalCallbackTriggered, "dismissal handler #2 wasn't called");
}
},
// Test notification without mainAction
@ -354,9 +370,9 @@ var tests = [
let self = this;
loadURI("http://example.com/", function() {
self.notifyObj = new basicNotification();
self.notifyObj.options = {
self.notifyObj.addOptions({
persistence: 2
};
});
self.notification = showNotification(self.notifyObj);
});
},
@ -391,9 +407,9 @@ var tests = [
loadURI("http://example.com/", function() {
self.notifyObj = new basicNotification();
// Set a timeout of 10 minutes that should never be hit
self.notifyObj.options = {
self.notifyObj.addOptions({
timeout: Date.now() + 600000
};
});
self.notification = showNotification(self.notifyObj);
});
},
@ -433,7 +449,7 @@ var tests = [
// The notification should open up on the box
this.notifyObj = new basicNotification();
this.notifyObj.anchorID = this.box.id = "nested-box";
this.notifyObj.options = {dismissed: true};
this.notifyObj.addOptions({dismissed: true});
this.notification = showNotification(this.notifyObj);
EventUtils.synthesizeMouse(button, 1, 1, {});
@ -452,7 +468,7 @@ var tests = [
run: function() {
let notifyObj = new basicNotification();
notifyObj.anchorID = "geo-notification-icon";
notifyObj.options = {neverShow: true};
notifyObj.addOptions({neverShow: true});
showNotification(notifyObj);
},
updateNotShowing: function() {

View File

@ -189,6 +189,10 @@ PopupNotifications.prototype = {
* dismissed: Whether the notification should be added as a dismissed
* notification. Dismissed notifications can be activated
* by clicking on their anchorElement.
* dismissalCallback:
* Callback to be invoked when the notification is
* dismissed (i.e. the user clicks away without activating
* either the mainAction or a secondaryAction).
* neverShow: Indicate that no popup should be shown for this
* notification. Useful for just showing the anchor icon.
* @returns the Notification object corresponding to the added notification.
@ -461,10 +465,12 @@ PopupNotifications.prototype = {
if (event.target != this.panel || this._ignoreDismissal)
return;
// Mark notifications as dismissed
// Mark notifications as dismissed and call dismissal callbacks
Array.forEach(this.panel.childNodes, function (nEl) {
let notificationObj = nEl.notification;
notificationObj.dismissed = true;
if (notificationObj.options.dismissalCallback)
notificationObj.options.dismissalCallback.call();
}, this);
this._update();