Bug 1690390, change appendNotification to take a smaller number of arguments: the string type value, a dictionary containing the notification details, and the button list, r=mstriemer

Differential Revision: https://phabricator.services.mozilla.com/D107755
This commit is contained in:
Neil Deakin 2021-09-16 19:11:17 +00:00
Родитель c18dd9edcd
Коммит 82501df9f7
26 изменённых файлов: 328 добавлений и 298 удалений

Просмотреть файл

@ -254,10 +254,12 @@ class DecoderDoctorParent extends JSWindowActorParent {
}
box.appendNotification(
title,
notificationId,
"", // This uses the info icon as specified below.
box.PRIORITY_INFO_LOW,
{
label: title,
image: "", // This uses the info icon as specified below.
priority: box.PRIORITY_INFO_LOW,
},
buttons
);
} else if (formatsInPref) {

Просмотреть файл

@ -170,10 +170,12 @@ class EncryptedMediaParent extends JSWindowActorParent {
let iconURL = "chrome://browser/skin/drm-icon.svg";
notificationBox.appendNotification(
notificationMessage,
notificationId,
iconURL,
notificationBox.PRIORITY_INFO_HIGH,
{
label: notificationMessage,
image: iconURL,
priority: notificationBox.PRIORITY_INFO_HIGH,
},
buttons
);
}

Просмотреть файл

@ -189,10 +189,12 @@ class PluginParent extends JSWindowActorParent {
[report.pluginName]
);
notification = notificationBox.appendNotification(
messageString,
"plugin-crashed",
iconURL,
priority,
{
label: messageString,
image: iconURL,
priority,
},
buttons
);

Просмотреть файл

@ -317,12 +317,13 @@ var CaptivePortalWatcher = {
};
gNotificationBox.appendNotification(
message,
this.PORTAL_NOTIFICATION_VALUE,
"",
gNotificationBox.PRIORITY_INFO_MEDIUM,
buttons,
closeHandler
{
label: message,
priority: gNotificationBox.PRIORITY_INFO_MEDIUM,
eventCallback: closeHandler,
},
buttons
);
Services.telemetry.recordEvent(

Просмотреть файл

@ -72,19 +72,20 @@ var gDataNotificationInfoBar = {
this._log.info("Creating data reporting policy notification.");
gNotificationBox.appendNotification(
message,
this._DATA_REPORTING_NOTIFICATION,
null,
gNotificationBox.PRIORITY_INFO_HIGH,
buttons,
event => {
if (event == "removed") {
Services.obs.notifyObservers(
null,
"datareporting:notify-data-policy:close"
);
}
}
{
label: message,
priority: gNotificationBox.PRIORITY_INFO_HIGH,
eventCallback: event => {
if (event == "removed") {
Services.obs.notifyObservers(
null,
"datareporting:notify-data-policy:close"
);
}
},
},
buttons
);
// It is important to defer calling onUserNotifyComplete() until we're
// actually sure the notification was displayed. If we ever called

Просмотреть файл

@ -972,10 +972,11 @@ const gStoragePressureObserver = {
messageFragment.appendChild(message);
gNotificationBox.appendNotification(
messageFragment,
NOTIFICATION_VALUE,
null,
gNotificationBox.PRIORITY_WARNING_HIGH,
{
label: messageFragment,
priority: gNotificationBox.PRIORITY_WARNING_HIGH,
},
buttons
);
@ -1056,10 +1057,12 @@ var gPopupBlockerObserver = {
const priority = notificationBox.PRIORITY_INFO_MEDIUM;
notificationBox.appendNotification(
message,
"popup-blocked",
"chrome://browser/skin/notification-icons/popup.svg",
priority,
{
label: message,
image: "chrome://browser/skin/notification-icons/popup.svg",
priority,
},
buttons
);
}
@ -1370,10 +1373,11 @@ var gKeywordURIFixup = {
},
];
let notification = notificationBox.appendNotification(
message,
"keyword-uri-fixup",
null,
notificationBox.PRIORITY_INFO_HIGH,
{
label: message,
priority: notificationBox.PRIORITY_INFO_HIGH,
},
buttons
);
notification.persistence = 1;
@ -9074,10 +9078,12 @@ const SafeBrowsingNotificationBox = {
}
let notification = notificationBox.appendNotification(
title,
value,
"chrome://global/skin/icons/blocked.svg",
notificationBox.PRIORITY_CRITICAL_HIGH,
{
label: title,
image: "chrome://global/skin/icons/blocked.svg",
priority: notificationBox.PRIORITY_CRITICAL_HIGH,
},
buttons
);
// Persist the notification until the user removes so it

Просмотреть файл

@ -5528,10 +5528,12 @@
];
notificationBox.appendNotification(
message,
"refresh-blocked",
"chrome://browser/skin/notification-icons/popup.svg",
notificationBox.PRIORITY_INFO_MEDIUM,
{
label: message,
image: "chrome://browser/skin/notification-icons/popup.svg",
priority: notificationBox.PRIORITY_INFO_MEDIUM,
},
buttons
);
}

Просмотреть файл

@ -6,7 +6,7 @@
async function addNotification(box, label, value, priorityName) {
let added = BrowserTestUtils.waitForNotificationInNotificationBox(box, value);
let priority = gNotificationBox[`PRIORITY_${priorityName}_MEDIUM`];
let notification = box.appendNotification(label, value, null, priority);
let notification = box.appendNotification(value, { label, priority });
await added;
return notification;
}

Просмотреть файл

@ -34,13 +34,10 @@ function assertNotificationBoxShown(reason, browser) {
function createNotification({ browser, label, value, priority }) {
let notificationBox = gBrowser.getNotificationBox(browser);
let notification = notificationBox.appendNotification(
let notification = notificationBox.appendNotification(value, {
label,
value,
null,
notificationBox[priority],
[]
);
priority: notificationBox[priority],
});
return notification;
}

Просмотреть файл

@ -1565,10 +1565,12 @@ BrowserGlue.prototype = {
];
win.gNotificationBox.appendNotification(
message,
"reset-profile-notification",
"chrome://global/skin/icons/help.svg",
win.gNotificationBox.PRIORITY_INFO_LOW,
{
label: message,
image: "chrome://global/skin/icons/question-64.png",
priority: win.gNotificationBox.PRIORITY_INFO_LOW,
},
buttons
);
},
@ -1597,10 +1599,11 @@ BrowserGlue.prototype = {
];
win.gNotificationBox.appendNotification(
message,
"unsigned-addons-disabled",
"",
win.gNotificationBox.PRIORITY_WARNING_MEDIUM,
{
label: message,
priority: win.gNotificationBox.PRIORITY_WARNING_MEDIUM,
},
buttons
);
},
@ -3255,7 +3258,6 @@ BrowserGlue.prototype = {
var placesBundle = Services.strings.createBundle(
"chrome://browser/locale/places/places.properties"
);
var title = placesBundle.GetStringFromName("lockPrompt.title");
var text = placesBundle.formatStringFromName("lockPrompt.text", [
applicationName,
]);
@ -3265,10 +3267,11 @@ BrowserGlue.prototype = {
var notifyBox = win.gBrowser.getNotificationBox();
var notification = notifyBox.appendNotification(
text,
title,
null,
notifyBox.PRIORITY_CRITICAL_MEDIUM,
"places-locked",
{
label: text,
priority: win.gNotificationBox.PRIORITY_CRITICAL_MEDIUM,
},
buttons
);
notification.persistence = -1; // Until user closes it
@ -4315,10 +4318,11 @@ BrowserGlue.prototype = {
// XXXndeakin is this notification still relevant?
win.gNotificationBox.appendNotification(
message,
"flash-hang",
null,
win.gNotificationBox.PRIORITY_INFO_MEDIUM,
{
label: message,
priority: win.gNotificationBox.PRIORITY_INFO_MEDIUM,
},
buttons
);
},

Просмотреть файл

@ -691,10 +691,12 @@ var AboutLogins = {
}
notification = notificationBox.appendNotification(
messageFragment,
id,
iconURL,
notificationBox[priority],
{
label: messageFragment,
image: iconURL,
priority: notificationBox[priority],
},
buttons
);
}

Просмотреть файл

@ -53,12 +53,14 @@ class InfoBarNotification {
: notificationContainer.PRIORITY_INFO_MEDIUM);
this.notification = notificationContainer.appendNotification(
this.formatMessageConfig(doc, content.text),
this.message.id,
content.icon || "chrome://branding/content/icon64.png",
priority,
content.buttons.map(b => this.formatButtonConfig(b)),
this.infobarCallback
{
label: this.formatMessageConfig(doc, content.text),
image: content.icon || "chrome://branding/content/icon64.png",
priority,
eventCallback: this.infobarCallback,
},
content.buttons.map(b => this.formatButtonConfig(b))
);
this.addImpression();

Просмотреть файл

@ -164,10 +164,12 @@ WebProtocolHandlerRegistrar.prototype = {
};
let notificationBox = browser.getTabBrowser().getNotificationBox(browser);
notificationBox.appendNotification(
message,
notificationValue,
notificationIcon,
notificationBox.PRIORITY_INFO_LOW,
{
label: message,
image: notificationIcon,
priority: notificationBox.PRIORITY_INFO_LOW,
},
[addButton]
);
},

Просмотреть файл

@ -302,15 +302,10 @@ class TranslationParent extends JSWindowActorParent {
showTranslationInfoBar() {
let notificationBox = this.notificationBox;
let notif = notificationBox.appendNotification(
"",
"translation",
null,
notificationBox.PRIORITY_INFO_HIGH,
null,
null,
"translation-notification"
);
let notif = notificationBox.appendNotification("translation", {
priority: notificationBox.PRIORITY_INFO_HIGH,
notificationIs: "translation-notification",
});
notif.init(this);
return notif;
}

Просмотреть файл

@ -478,15 +478,10 @@ add_task(async function pickingTipDoesNotDisableOtherKinds() {
add_task(async function notification() {
await BrowserTestUtils.withNewTab("about:blank", async () => {
let box = gBrowser.getNotificationBox();
let note = box.appendNotification(
"Test",
"urlbar-test",
null,
box.PRIORITY_INFO_HIGH,
null,
null,
null
);
let note = box.appendNotification("urlbar-test", {
label: "Test",
priority: box.PRIORITY_INFO_HIGH,
});
// Give it a big persistence so it doesn't go away on page load.
note.persistence = 100;
await withDNSRedirect("www.google.com", "/", async url => {

Просмотреть файл

@ -303,13 +303,12 @@ class TranslationBrowserChromeUi {
const notificationBox = this.notificationBox;
const chromeWin = this.browser.ownerGlobal;
const notif = notificationBox.appendNotification(
"",
"translation",
null,
notificationBox.PRIORITY_INFO_HIGH,
null,
null,
`translation-notification-${chromeWin.now}`,
{
label: "",
priority: notificationBox.PRIORITY_INFO_HIGH,
is: `translation-notification-${chromeWin.now}`,
}
);
notif.init(this.translationBrowserChromeUiNotificationManager);
this.translationBrowserChromeUiNotificationManager.infobarDisplayed(

Просмотреть файл

@ -52,7 +52,6 @@ detailsPane.itemsCountLabel=One item;#1 items
# LOCALIZATION NOTE (lockPrompt.text)
# %S will be replaced with the application name.
lockPrompt.title=Browser Startup Error
lockPrompt.text=The bookmarks and history system will not be functional because one of %Ss files is in use by another application. Some security software can cause this problem.
# LOCALIZATION NOTE (cmd.deleteSinglePage.accesskey,

Просмотреть файл

@ -433,35 +433,37 @@ var TabCrashHandler = {
);
notification = notificationBox.appendNotification(
messageFragment,
value,
TABCRASHED_ICON_URI,
notificationBox.PRIORITY_INFO_MEDIUM,
buttons,
eventName => {
if (eventName == "disconnected") {
removeTelemetryFn();
{
label: messageFragment,
image: TABCRASHED_ICON_URI,
priority: notificationBox.PRIORITY_INFO_MEDIUM,
eventCallback: eventName => {
if (eventName == "disconnected") {
removeTelemetryFn();
let existingItem = this.notificationsMap.get(childID);
if (existingItem) {
let idx = existingItem.indexOf(notification);
if (idx >= 0) {
existingItem.splice(idx, 1);
let existingItem = this.notificationsMap.get(childID);
if (existingItem) {
let idx = existingItem.indexOf(notification);
if (idx >= 0) {
existingItem.splice(idx, 1);
}
if (!existingItem.length) {
this.notificationsMap.delete(childID);
}
}
} else if (eventName == "dismissed") {
if (dumpID) {
CrashSubmit.ignore(dumpID);
this.childMap.delete(childID);
}
if (!existingItem.length) {
this.notificationsMap.delete(childID);
}
closeAllNotifications();
}
} else if (eventName == "dismissed") {
if (dumpID) {
CrashSubmit.ignore(dumpID);
this.childMap.delete(childID);
}
closeAllNotifications();
}
}
},
},
buttons
);
let existingItem = this.notificationsMap.get(childID);
@ -1154,12 +1156,14 @@ var UnsubmittedCrashHandler = {
);
return chromeWin.gNotificationBox.appendNotification(
message,
notificationID,
TABCRASHED_ICON_URI,
chromeWin.gNotificationBox.PRIORITY_INFO_HIGH,
buttons,
eventCallback
{
label: message,
image: TABCRASHED_ICON_URI,
priority: chromeWin.gNotificationBox.PRIORITY_INFO_HIGH,
eventCallback,
},
buttons
);
},

Просмотреть файл

@ -570,16 +570,18 @@ var ProcessHangMonitor = {
win.gNotificationBox
.appendNotification(
message,
"process-hang",
"chrome://browser/content/aboutRobots-icon.png",
win.gNotificationBox.PRIORITY_INFO_HIGH,
buttons,
event => {
if (event == "dismissed") {
ProcessHangMonitor.waitLonger(win);
}
}
{
label: message,
image: "chrome://browser/content/aboutRobots-icon.png",
priority: win.gNotificationBox.PRIORITY_INFO_HIGH,
eventCallback: event => {
if (event == "dismissed") {
ProcessHangMonitor.waitLonger(win);
}
},
},
buttons
)
.setAttribute("notification-tag", notificationTag);
},

Просмотреть файл

@ -54,7 +54,7 @@ async function showNotification(
priority = nbox.PRIORITY_INFO_MEDIUM;
}
nbox.appendNotification(msg, value, null, priority, []);
nbox.appendNotification(value, { label: msg, priority });
}
exports.showNotification = showNotification;

Просмотреть файл

@ -173,17 +173,19 @@ var Heartbeat = class {
this.notificationBox = this.chromeWindow.gNotificationBox;
this.notice = this.notificationBox.appendNotification(
this.options.message,
"heartbeat-" + this.options.flowId,
"resource://normandy/skin/shared/heartbeat-icon.svg",
this.notificationBox.PRIORITY_SYSTEM,
this.buttons,
eventType => {
if (eventType !== "removed") {
return;
}
this.maybeNotifyHeartbeat("NotificationClosed");
}
{
label: this.options.message,
image: "resource://normandy/skin/shared/heartbeat-icon.svg",
priority: this.notificationBox.PRIORITY_SYSTEM,
eventCallback: eventType => {
if (eventType !== "removed") {
return;
}
this.maybeNotifyHeartbeat("NotificationClosed");
},
},
this.buttons
);
this.notice.classList.add("heartbeat");
this.notice.messageText.classList.add("heartbeat");

Просмотреть файл

@ -329,19 +329,20 @@ class PdfjsParent extends JSWindowActorParent {
},
];
notificationBox.appendNotification(
data.message,
"pdfjs-fallback",
null,
notificationBox.PRIORITY_INFO_MEDIUM,
buttons,
function eventsCallback(eventType) {
// Currently there is only one event "removed" but if there are any other
// added in the future we still only care about removed at the moment.
if (eventType !== "removed") {
return;
}
sendMessage(false);
}
{
label: data.message,
priority: notificationBox.PRIORITY_INFO_MEDIUM,
eventCallback: eventType => {
// Currently there is only one event "removed" but if there are any other
// added in the future we still only care about removed at the moment.
if (eventType !== "removed") {
return;
}
sendMessage(false);
},
},
buttons
);
}
}

Просмотреть файл

@ -35,10 +35,8 @@ function test() {
});
is(gNotificationBox.allNotifications.length, 0, "There should be no initial notifications");
gNotificationBox.appendNotification("Test notification",
"notification1", null,
gNotificationBox.PRIORITY_INFO_LOW,
null);
gNotificationBox.appendNotification("notification1",
{ label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
is(gNotificationBox.allNotifications.length, 1, "Notification exists while animating in");
let notification = gNotificationBox.getNotificationWithValue("notification1");
ok(notification, "Notification should exist while animating in");
@ -62,10 +60,8 @@ function test1() {
// Tests that a notification that is animating in gets removed immediately
function test2() {
let notification = gNotificationBox.appendNotification("Test notification",
"notification2", null,
gNotificationBox.PRIORITY_INFO_LOW,
null);
let notification = gNotificationBox.appendNotification("notification2",
{ label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
gNotificationBox.removeNotification(notification);
notification = gNotificationBox.getNotificationWithValue("notification2");
ok(!notification, "Test 2 showed notification was still present");
@ -79,14 +75,10 @@ function test2() {
// Tests that a background notification goes away immediately
function test3() {
let notification = gNotificationBox.appendNotification("Test notification",
"notification3", null,
gNotificationBox.PRIORITY_INFO_LOW,
null);
let notification2 = gNotificationBox.appendNotification("Test notification",
"notification4", null,
gNotificationBox.PRIORITY_INFO_LOW,
null);
let notification = gNotificationBox.appendNotification("notification3",
{ label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
let notification2 = gNotificationBox.appendNotification("notification4",
{ label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
is(gNotificationBox.allNotifications.length, 2, "Test 3 should show 2 notifications present");
gNotificationBox.removeNotification(notification);
is(gNotificationBox.allNotifications.length, 1, "Test 3 should show 1 notifications present");
@ -105,14 +97,10 @@ function test3() {
// Tests that a foreground notification hiding a background one goes away
function test4() {
let notification = gNotificationBox.appendNotification("Test notification",
"notification5", null,
gNotificationBox.PRIORITY_INFO_LOW,
null);
let notification2 = gNotificationBox.appendNotification("Test notification",
"notification6", null,
gNotificationBox.PRIORITY_INFO_LOW,
null);
let notification = gNotificationBox.appendNotification("notification5",
{ label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
let notification2 = gNotificationBox.appendNotification("notification6",
{ label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
gNotificationBox.removeNotification(notification2);
notification2 = gNotificationBox.getNotificationWithValue("notification6");
ok(!notification2, "Test 4 showed notification2 was still present");
@ -131,14 +119,10 @@ function test4() {
// Tests that removeAllNotifications gets rid of everything
function test5() {
let notification = gNotificationBox.appendNotification("Test notification",
"notification7", null,
gNotificationBox.PRIORITY_INFO_LOW,
null);
let notification2 = gNotificationBox.appendNotification("Test notification",
"notification8", null,
gNotificationBox.PRIORITY_INFO_LOW,
null);
let notification = gNotificationBox.appendNotification("notification7",
{ label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
let notification2 = gNotificationBox.appendNotification("notification8",
{ label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
gNotificationBox.removeAllNotifications();
notification = gNotificationBox.getNotificationWithValue("notification7");
notification2 = gNotificationBox.getNotificationWithValue("notification8");
@ -147,10 +131,8 @@ function test5() {
ok(!gNotificationBox.currentNotification, "Test 5 said there was still a current notification");
is(gNotificationBox.allNotifications.length, 0, "Test 5 should show 0 notifications present");
gNotificationBox.appendNotification("Test notification",
"notification9", null,
gNotificationBox.PRIORITY_INFO_LOW,
null);
gNotificationBox.appendNotification("notification9",
{ label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
// Wait for the notificaton to finish displaying
completeAnimation(test6);
@ -165,10 +147,8 @@ function test6() {
ok(!gNotificationBox.currentNotification, "Test 6 shouldn't be any current notification");
is(gNotificationBox.allNotifications.length, 0, "Test 6 allNotifications.length should be 0");
notification = gNotificationBox.appendNotification("Test notification",
"notification10", null,
gNotificationBox.PRIORITY_INFO_LOW,
null);
notification = gNotificationBox.appendNotification("notification10",
{ label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
is(notification, gNotificationBox.currentNotification, "Test 6 should have made the current notification");
gNotificationBox.removeNotification(notification);

Просмотреть файл

@ -28,10 +28,8 @@ function test() {
is(gNotificationBox.allNotifications.length, 0, "There should be no initial notifications");
gNotificationBox.appendNotification("Test notification",
"notification1", null,
gNotificationBox.PRIORITY_INFO_LOW,
null);
gNotificationBox.appendNotification("notification1",
{ label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
is(gNotificationBox.allNotifications.length, 1, "Notification exists");
is(gNotificationBox._animating, false, "Notification shouldn't be animating");

Просмотреть файл

@ -126,8 +126,11 @@ var tests =
{
test(nb, ntf) {
// append a new notification
ntf = nb.appendNotification("Notification", "note", "happy.png",
nb.PRIORITY_INFO_LOW, testtag_notificationbox_buttons);
ntf = nb.appendNotification("note", {
label: "Notification",
image: "happy.png",
priority: nb.PRIORITY_INFO_LOW,
}, testtag_notificationbox_buttons);
SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append notification");
return ntf;
},
@ -158,10 +161,12 @@ var tests =
{
test(nb, ntf) {
// append a new notification, but now with an event callback
ntf = nb.appendNotification("Notification", "note", "happy.png",
nb.PRIORITY_INFO_LOW,
testtag_notificationbox_buttons,
notification_eventCallback);
ntf = nb.appendNotification("note", {
label: "Notification",
image: "happy.png",
priority: nb.PRIORITY_INFO_LOW,
eventCallback: notification_eventCallback,
}, testtag_notificationbox_buttons);
SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append notification with callback");
return ntf;
},
@ -185,15 +190,20 @@ var tests =
},
{
test(nb, ntf) {
ntf = nb.appendNotification("Notification", "note", "happy.png",
nb.PRIORITY_INFO_LOW,
testtag_notificationbox_buttons,
notification_eventCallback);
SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append notification with callback");
ntf = nb.appendNotification("note", {
label: "Notification",
image: "happy.png",
priority: nb.PRIORITY_INFO_MEDIUM,
eventCallback: notification_eventCallback,
}, testtag_notificationbox_buttons);
SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append notification with object");
return ntf;
},
result(nb, ntf) {
testtag_notificationbox_State(nb, "append with callback", ntf, 1);
testtag_notificationbox_State(nb, "append using object", ntf, 1);
testtag_notification_State(nb, ntf, "append object", "Notification", "note",
"happy.png", nb.PRIORITY_INFO_MEDIUM);
return ntf;
}
},
@ -214,14 +224,14 @@ var tests =
},
{
test(nb, ntf) {
ntf = nb.appendNotification(
"Notification", "note", "happy.png",
nb.PRIORITY_WARNING_LOW,
[{
ntf = nb.appendNotification("note", {
label: "Notification",
image: "happy.png",
priority: nb.PRIORITY_WARNING_LOW,
eventCallback: notification_eventCallback,
}, [{
label: "Button",
}]
);
}]);
return ntf;
},
result(nb, ntf) {
@ -241,8 +251,11 @@ var tests =
switch (idx) {
case 1:
// append a new notification
ntf = nb.appendNotification("Notification", "note", "happy.png",
nb.PRIORITY_INFO_LOW, testtag_notificationbox_buttons);
ntf = nb.appendNotification("note", {
label: "Notification",
image: "happy.png",
priority: nb.PRIORITY_INFO_LOW,
}, testtag_notificationbox_buttons);
SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append notification");
// Test persistence
@ -286,8 +299,11 @@ var tests =
{
test(nb, ntf) {
// append another notification
ntf = nb.appendNotification("Notification", "note", "happy.png",
nb.PRIORITY_INFO_MEDIUM, testtag_notificationbox_buttons);
ntf = nb.appendNotification("note", {
label: "Notification",
image: "happy.png",
priority: nb.PRIORITY_INFO_MEDIUM,
}, testtag_notificationbox_buttons);
SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append notification again");
return ntf;
},
@ -311,8 +327,11 @@ var tests =
},
{
test(nb, ntf) {
ntf = nb.appendNotification("Notification", "note", "happy.png",
nb.PRIORITY_INFO_HIGH, testtag_notificationbox_buttons);
ntf = nb.appendNotification("note", {
label: "Notification",
image: "happy.png",
priority: nb.PRIORITY_INFO_HIGH,
}, testtag_notificationbox_buttons);
return ntf;
},
result(nb, ntf) {
@ -325,10 +344,12 @@ var tests =
},
{
test(nb, ntf) {
ntf = nb.appendNotification("Notification", "note", "happy.png",
nb.PRIORITY_INFO_LOW,
testtag_notificationbox_links,
notification_eventCallback);
ntf = nb.appendNotification("note", {
label: "Notification",
image: "happy.png",
priority: nb.PRIORITY_INFO_LOW,
eventCallback: notification_eventCallback,
}, testtag_notificationbox_links);
SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append link notification with callback");
return ntf;
},
@ -350,8 +371,12 @@ var tests =
{
test(nb, ntf) {
// append a new notification
ntf = nb.appendNotification("Notification", "note", "happy.png",
nb.PRIORITY_INFO_LOW, testtag_notificationbox_buttons_nopopup);
ntf = nb.appendNotification("note", {
label: "Notification",
image: "happy.png",
priority: nb.PRIORITY_INFO_LOW,
eventCallback: notification_eventCallback,
}, testtag_notificationbox_supportpage);
return ntf;
},
result(nb, ntf) {
@ -374,10 +399,12 @@ var tests =
},
{
test(nb, ntf) {
ntf = nb.appendNotification("Notification", "note", "happy.png",
nb.PRIORITY_INFO_LOW,
testtag_notificationbox_supportpage,
notification_eventCallback);
ntf = nb.appendNotification("note", {
label: "Notification",
image: "happy.png",
priority: nb.PRIORITY_INFO_LOW,
eventCallback: notification_eventCallback,
}, testtag_notificationbox_supportpage);
SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append support page notification");
return ntf;
},
@ -400,16 +427,18 @@ var tests =
{
test(nb, unused) {
// add a number of notifications and check that they are added in order
nb.appendNotification("Four", "4", null, nb.PRIORITY_INFO_HIGH, testtag_notificationbox_buttons);
nb.appendNotification("Seven", "7", null, nb.PRIORITY_WARNING_HIGH, testtag_notificationbox_buttons);
nb.appendNotification("Two", "2", null, nb.PRIORITY_INFO_LOW, null);
nb.appendNotification("Eight", "8", null, nb.PRIORITY_CRITICAL_LOW, null);
nb.appendNotification("Five", "5", null, nb.PRIORITY_WARNING_LOW, null);
nb.appendNotification("Six", "6", null, nb.PRIORITY_WARNING_HIGH, null);
nb.appendNotification("One", "1", null, nb.PRIORITY_INFO_LOW, null);
nb.appendNotification("Nine", "9", null, nb.PRIORITY_CRITICAL_MEDIUM, null);
var ntf = nb.appendNotification("Ten", "10", null, nb.PRIORITY_CRITICAL_HIGH, null);
nb.appendNotification("Three", "3", null, nb.PRIORITY_INFO_MEDIUM, null);
nb.appendNotification("4", { label: "Four", priority: nb.PRIORITY_INFO_HIGH },
testtag_notificationbox_buttons);
nb.appendNotification("7", { label: "Seven", priority: nb.PRIORITY_WARNING_HIGH },
testtag_notificationbox_buttons);
nb.appendNotification("2", { label: "Two", priority: nb.PRIORITY_INFO_LOW });
nb.appendNotification("8", { label: "Eight", priority: nb.PRIORITY_CRITICAL_LOW });
nb.appendNotification("5", { label: "Five", priority: nb.PRIORITY_WARNING_LOW });
nb.appendNotification("6", { label: "Six", priority: nb.PRIORITY_WARNING_LOW });
nb.appendNotification("1", { label: "One", priority: nb.PRIORITY_INFO_LOW });
nb.appendNotification("9", { label: "Nine", priority: nb.PRIORITY_CRITICAL_MEDIUM });
let ntf = nb.appendNotification("10", { label: "Ten", priority: nb.PRIORITY_CRITICAL_HIGH });
nb.appendNotification("3", { label: "Three", priority: nb.PRIORITY_INFO_MEDIUM });
return ntf;
},
result(nb, ntf) {
@ -445,13 +474,13 @@ var tests =
test(nb, ntf) {
var exh = false;
try {
nb.appendNotification("no", "no", "no", -1, null);
nb.appendNotification("no", { label: "no", priority: 0 });
} catch (ex) { exh = true; }
SimpleTest.is(exh, true, "appendNotification priority too low");
exh = false;
try {
nb.appendNotification("no", "no", "no", 11, null);
nb.appendNotification("no", { label: "no", priority: 11 });
} catch (ex) { exh = true; }
SimpleTest.is(exh, true, "appendNotification priority too high");
@ -464,8 +493,11 @@ var tests =
var appendPriorityTests = [
{
test(nb, priority) {
var ntf = nb.appendNotification("Notification", "note", "happy.png",
priority, testtag_notificationbox_buttons);
let ntf = nb.appendNotification("note", {
label: "Notification",
image: "happy.png",
priority,
}, testtag_notificationbox_buttons);
SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append notification " + priority);
return [ntf, priority];
},
@ -481,8 +513,11 @@ var appendPriorityTests = [
},
result(nb, priority) {
if (priority == nb.PRIORITY_CRITICAL_HIGH) {
let ntf = nb.appendNotification("Notification", "note", "happy.png",
nb.PRIORITY_INFO_LOW, testtag_notificationbox_buttons);
let ntf = nb.appendNotification("note", {
label: "Notification",
image: "happy.png",
priority: nb.PRIORITY_INFO_LOW,
}, testtag_notificationbox_buttons);
setTimeout(checkPopupTest, 50, nb, ntf);
}
else {

Просмотреть файл

@ -79,19 +79,28 @@
* Creates a <notification> element and shows it. The calling code can modify
* the element synchronously to add features to the notification.
*
* @param aLabel
* The main message text, or a DocumentFragment containing elements to
* add as children of the notification's main <description> element.
* @param aValue
* String identifier of the notification.
* @param aImage
* URL of the icon image to display. If not specified, a default icon
* based on the priority will be shown.
* @param aPriority
* aType
* String identifier that can uniquely identify the type of the notification.
* aNotification
* Object that contains any of the following properties, where only the
* priority must be specified:
* priority
* One of the PRIORITY_ constants. These determine the appearance of
* the notification based on severity (using the "type" attribute), and
* only the notification with the highest priority is displayed.
* @param aButtons
* label
* The main message text, or a DocumentFragment containing elements to
* add as children of the notification's main <description> element.
* eventCallback
* This may be called with the "removed", "dismissed" or "disconnected"
* parameter:
* removed - notification has been removed
* dismissed - user dismissed notification
* disconnected - notification removed in any way
* notificationIs
* Defines a Custom Element name to use as the "is" value on creation.
* This allows subclassing the created element.
* aButtons
* Array of objects defining action buttons:
* {
* label:
@ -121,39 +130,24 @@
* Defines a Custom Element name to use as the "is" value on
* button creation.
* }
* @param aEventCallback
* This may be called with the "removed", "dismissed" or "disconnected"
* parameter:
* removed - notification has been removed
* dismissed - user dismissed notification
* disconnected - notification removed in any way
* @param aNotificationIs
* Defines a Custom Element name to use as the "is" value on creation.
* This allows subclassing the created element.
*
* @return The <notification> element that is shown.
*/
appendNotification(
aLabel,
aValue,
aImage,
aPriority,
aButtons,
aEventCallback,
aNotificationIs
) {
appendNotification(aType, aNotification, aButtons) {
if (
aPriority < this.PRIORITY_SYSTEM ||
aPriority > this.PRIORITY_CRITICAL_HIGH
aNotification.priority < this.PRIORITY_SYSTEM ||
aNotification.priority > this.PRIORITY_CRITICAL_HIGH
) {
throw new Error("Invalid notification priority " + aPriority);
throw new Error(
"Invalid notification priority " + aNotification.priority
);
}
MozXULElement.insertFTLIfNeeded("toolkit/global/notification.ftl");
// Create the Custom Element and connect it to the document immediately.
var newitem;
if (!aNotificationIs) {
if (!aNotification.notificationIs) {
if (!customElements.get("notification-message")) {
// There's some weird timing stuff when this element is created at
// script load time, we don't need it until now anyway so be lazy.
@ -164,7 +158,9 @@
} else {
newitem = document.createXULElement(
"notification",
aNotificationIs ? { is: aNotificationIs } : {}
aNotification.notificationIs
? { is: aNotification.notificationIs }
: {}
);
}
@ -179,30 +175,31 @@
if (newitem.messageText) {
// Can't use instanceof in case this was created from a different document:
if (
aLabel &&
typeof aLabel == "object" &&
aLabel.nodeType &&
aLabel.nodeType == aLabel.DOCUMENT_FRAGMENT_NODE
aNotification.label &&
typeof aNotification.label == "object" &&
aNotification.label.nodeType &&
aNotification.label.nodeType ==
aNotification.label.DOCUMENT_FRAGMENT_NODE
) {
newitem.messageText.appendChild(aLabel);
newitem.messageText.appendChild(aNotification.label);
} else {
newitem.messageText.textContent = aLabel;
newitem.messageText.textContent = aNotification.label;
}
}
newitem.setAttribute("value", aValue);
newitem.setAttribute("value", aType);
newitem.eventCallback = aEventCallback;
newitem.eventCallback = aNotification.eventCallback;
if (aButtons) {
newitem.setButtons(aButtons);
}
newitem.priority = aPriority;
if (aPriority == this.PRIORITY_SYSTEM) {
newitem.priority = aNotification.priority;
if (aNotification.priority == this.PRIORITY_SYSTEM) {
newitem.setAttribute("type", "system");
} else if (aPriority >= this.PRIORITY_CRITICAL_LOW) {
} else if (aNotification.priority >= this.PRIORITY_CRITICAL_LOW) {
newitem.setAttribute("type", "critical");
} else if (aPriority <= this.PRIORITY_INFO_HIGH) {
} else if (aNotification.priority <= this.PRIORITY_INFO_HIGH) {
newitem.setAttribute("type", "info");
} else {
newitem.setAttribute("type", "warning");