зеркало из https://github.com/mozilla/pjs.git
Bug 597244: refactor and simplify PopupNotifications event callbacks, r=dolske, a=blocking-b7+
--HG-- extra : rebase_source : b4422707ee3a090110a0a3a16a8af88303d2716a
This commit is contained in:
Родитель
669e945bef
Коммит
16695917f9
|
@ -144,8 +144,18 @@ function basicNotification() {
|
|||
}
|
||||
];
|
||||
this.options = {
|
||||
dismissalCallback: function() {
|
||||
self.dismissalCallbackTriggered = true;
|
||||
eventCallback: function (eventName) {
|
||||
switch (eventName) {
|
||||
case "dismissed":
|
||||
self.dismissalCallbackTriggered = true;
|
||||
break;
|
||||
case "shown":
|
||||
self.shownCallbackTriggered = true;
|
||||
break;
|
||||
case "removed":
|
||||
self.removedCallbackTriggered = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
this.addOptions = function(options) {
|
||||
|
@ -194,8 +204,9 @@ var tests = [
|
|||
dismissNotification(popup);
|
||||
},
|
||||
onHidden: function (popup) {
|
||||
ok(this.notifyObj.dismissalCallbackTriggered, "dismissal handler triggered");
|
||||
ok(this.notifyObj.dismissalCallbackTriggered, "dismissal callback triggered");
|
||||
this.notification.remove();
|
||||
ok(this.notifyObj.removedCallbackTriggered, "removed callback triggered");
|
||||
}
|
||||
},
|
||||
// test opening a notification for a background browser
|
||||
|
@ -210,7 +221,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");
|
||||
ok(!wrongBrowserNotificationObject.dismissalCallbackTriggered, "dismissal callback wasn't called");
|
||||
}
|
||||
},
|
||||
// now select that browser and test to see that the notification appeared
|
||||
|
@ -229,9 +240,10 @@ var tests = [
|
|||
},
|
||||
onHidden: function (popup) {
|
||||
// actually remove the notification to prevent it from reappearing
|
||||
ok(!wrongBrowserNotificationObject.dismissalCallbackTriggered, "dismissal handler wasn't called");
|
||||
ok(!wrongBrowserNotificationObject.dismissalCallbackTriggered, "dismissal callback wasn't called");
|
||||
wrongBrowserNotification.remove();
|
||||
ok(!wrongBrowserNotificationObject.dismissalCallbackTriggered, "dismissal handler wasn't called after remove()");
|
||||
ok(!wrongBrowserNotificationObject.dismissalCallbackTriggered, "dismissal callback wasn't called after remove()");
|
||||
ok(wrongBrowserNotificationObject.removedCallbackTriggered, "removed callback triggered");
|
||||
wrongBrowserNotification = null;
|
||||
}
|
||||
},
|
||||
|
@ -284,11 +296,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.testNotif1.dismissalCallbackTriggered, "dismissal callback #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");
|
||||
ok(!this.testNotif2.dismissalCallbackTriggered, "dismissal callback #2 wasn't called");
|
||||
}
|
||||
},
|
||||
// Test notification without mainAction
|
||||
|
@ -326,6 +338,7 @@ var tests = [
|
|||
onHidden: function (popup) {
|
||||
// Remove the first notification
|
||||
this.firstNotification.remove();
|
||||
ok(this.notifyObj.removedCallbackTriggered, "removed callback triggered");
|
||||
}
|
||||
},
|
||||
// Test optional params
|
||||
|
@ -340,7 +353,9 @@ var tests = [
|
|||
dismissNotification(popup);
|
||||
},
|
||||
onHidden: function (popup) {
|
||||
ok(this.notifyObj.dismissalCallbackTriggered, "dismissal callback triggered");
|
||||
this.notification.remove();
|
||||
ok(this.notifyObj.removedCallbackTriggered, "removed callback triggered");
|
||||
}
|
||||
},
|
||||
// Test that icons appear
|
||||
|
@ -490,8 +505,10 @@ function showNotification(notifyObj) {
|
|||
|
||||
function checkPopup(popup, notificationObj) {
|
||||
info("[Test #" + gTestIndex + "] checking popup");
|
||||
let notifications = popup.childNodes;
|
||||
|
||||
ok(notificationObj.shownCallbackTriggered, "shown callback was triggered");
|
||||
|
||||
let notifications = popup.childNodes;
|
||||
is(notifications.length, 1, "only one notification displayed");
|
||||
let notification = notifications[0];
|
||||
let icon = document.getAnonymousElementByAttribute(notification, "class", "popup-notification-icon");
|
||||
|
|
|
@ -189,10 +189,18 @@ 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).
|
||||
* eventCallback:
|
||||
* Callback to be invoked when the notification changes
|
||||
* state. The callback's first argument is a string
|
||||
* identifying the state change:
|
||||
* "dismissed": notification has been dismissed by the
|
||||
* user (e.g. by clicking away or switching
|
||||
* tabs)
|
||||
* "removed": notification has been removed (due to
|
||||
* location change or user action)
|
||||
* "shown": notification has been shown (this can be fired
|
||||
* multiple times as notifications are dismissed
|
||||
* and re-shown)
|
||||
* 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.
|
||||
|
@ -316,6 +324,7 @@ PopupNotifications.prototype = {
|
|||
|
||||
// remove the notification
|
||||
notifications.splice(index, 1);
|
||||
this._fireCallback(notification, "removed");
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -385,6 +394,9 @@ PopupNotifications.prototype = {
|
|||
this._currentAnchorElement = anchorElement;
|
||||
|
||||
this.panel.openPopup(anchorElement, position);
|
||||
notificationsToShow.forEach(function (n) {
|
||||
this._fireCallback(n, "shown");
|
||||
}, this);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -461,6 +473,11 @@ PopupNotifications.prototype = {
|
|||
this._update(anchor);
|
||||
},
|
||||
|
||||
_fireCallback: function PopupNotifications_fireCallback(n, event) {
|
||||
if (n.options.eventCallback)
|
||||
n.options.eventCallback.call(n, event);
|
||||
},
|
||||
|
||||
_onPopupHidden: function PopupNotifications_onPopupHidden(event) {
|
||||
if (event.target != this.panel || this._ignoreDismissal)
|
||||
return;
|
||||
|
@ -469,8 +486,7 @@ PopupNotifications.prototype = {
|
|||
Array.forEach(this.panel.childNodes, function (nEl) {
|
||||
let notificationObj = nEl.notification;
|
||||
notificationObj.dismissed = true;
|
||||
if (notificationObj.options.dismissalCallback)
|
||||
notificationObj.options.dismissalCallback.call();
|
||||
this._fireCallback(notificationObj, "dismissed");
|
||||
}, this);
|
||||
|
||||
this._update();
|
||||
|
|
Загрузка…
Ссылка в новой задаче