Bug 1254359 - notifications.getAll() result is not Chrome-compatible, r?kmag
MozReview-Commit-ID: EIeIZquJaIN
--- a/toolkit/components/extensions/ext-notifications.js
+++ b/toolkit/components/extensions/ext-notifications.js
@@ -106,17 +106,20 @@ extensions.registerSchemaAPI("notificati
if (notifications.has(notificationId)) {
notifications.get(notificationId).clear();
return Promise.resolve(true);
}
return Promise.resolve(false);
},
getAll: function() {
- let result = Array.from(notificationsMap.get(extension).keys());
+ let result = {};
+ notificationsMap.get(extension).forEach((value, key) => {
+ result[key] = value.options;
+ });
return Promise.resolve(result);
},
onClosed: new EventManager(context, "notifications.onClosed", fire => {
let listener = notification => {
// FIXME: Support the byUser argument.
fire(notification.id, true);
};
--- a/toolkit/components/extensions/schemas/notifications.json
+++ b/toolkit/components/extensions/schemas/notifications.json
@@ -272,21 +272,18 @@
"async": "callback",
"parameters": [
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "notifications",
- "type": "array",
- "description": "The set of notification_ids currently in the system.",
- "items": {
- "type": "string"
- }
+ "type": "object",
+ "description": "The set of notifications currently in the system."
}
]
}
]
},
{
"name": "getPermissionLevel",
"unsupported": true,
--- a/toolkit/components/extensions/test/mochitest/test_ext_notifications.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_notifications.html
@@ -108,19 +108,18 @@ add_task(function* test_notification_cle
is(x, true, "got correct boolean from notifications.clear");
yield extension.awaitFinish();
yield extension.unload();
});
add_task(function* test_notifications_empty_getAll() {
function backgroundScript() {
browser.notifications.getAll().then(notifications => {
- browser.test.assertTrue(Array.isArray(notifications),
- "getAll() returned an array");
- browser.test.assertEq(notifications.length, 0, "the array was empty");
+ browser.test.assertEq("object", typeof notifications, "getAll() returned an object");
+ browser.test.assertEq(0, Object.keys(notifications).length, "the object has no properties");
browser.test.notifyPass("getAll empty");
});
}
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["notifications"],
},
@@ -139,24 +138,27 @@ add_task(function* test_notifications_po
message: "Carry on",
};
browser.notifications.create("p1", opts).then(() => {
return browser.notifications.create("p2", opts);
}).then(() => {
return browser.notifications.getAll();
}).then(notifications => {
- browser.test.assertTrue(Array.isArray(notifications),
- "getAll() returned an array");
- browser.test.assertEq(notifications.length, 2,
- "the array contained two notification ids");
- browser.test.assertTrue(notifications.includes("p1"),
- "the array contains the first notification");
- browser.test.assertTrue(notifications.includes("p2"),
- "the array contains the second notification");
+ browser.test.assertEq("object", typeof notifications, "getAll() returned an object");
+ browser.test.assertEq(2, Object.keys(notifications).length, "the object has 2 properties");
+ for (let notificationId of ["p1", "p2"]) {
+ for (let key of Object.keys(opts)) {
+ browser.test.assertEq(
+ opts[key],
+ notifications[notificationId][key],
+ `the notification has the expected value for option: ${key}`
+ );
+ }
+ }
browser.test.notifyPass("getAll populated");
});
}
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["notifications"],
},