Bug 1233350 - Fix TypeError in notifications.getAll(). r=kmag
This also adds some tests for the method.
This commit is contained in:
@@ -124,7 +124,7 @@ extensions.registerPrivilegedAPI("notifications", (extension, context) => {
|
||||
|
||||
getAll: function(callback) {
|
||||
let notifications = notificationsMap.get(extension);
|
||||
notifications = notifications.map(notification => notification.id);
|
||||
notifications = Array.from(notifications, notification => notification.id);
|
||||
runSafe(context, callback, notifications);
|
||||
},
|
||||
|
||||
|
||||
@@ -45,6 +45,74 @@ add_task(function* test_notifications() {
|
||||
info("extension unloaded successfully");
|
||||
});
|
||||
|
||||
add_task(function* test_notifications_empty_getAll() {
|
||||
function backgroundScript() {
|
||||
browser.test.log("running background script");
|
||||
|
||||
browser.notifications.getAll(notifications => {
|
||||
browser.test.assertTrue(Array.isArray(notifications),
|
||||
"getAll() returned an array");
|
||||
browser.test.assertEq(notifications.length, 0, "the array was empty");
|
||||
browser.test.notifyPass("getAll empty");
|
||||
});
|
||||
}
|
||||
|
||||
let extensionData = {
|
||||
manifest: {
|
||||
permissions: ["notifications"]
|
||||
},
|
||||
background: "(" + backgroundScript.toString() + ")()"
|
||||
};
|
||||
|
||||
let extension = ExtensionTestUtils.loadExtension(extensionData);
|
||||
info("load complete");
|
||||
yield extension.startup();
|
||||
info("startup complete");
|
||||
yield extension.awaitFinish("getAll empty");
|
||||
info("test complete");
|
||||
yield extension.unload();
|
||||
info("extension unloaded successfully");
|
||||
});
|
||||
|
||||
add_task(function* test_notifications_populated_getAll() {
|
||||
function backgroundScript() {
|
||||
browser.test.log("running background script");
|
||||
|
||||
var opts = {title: "Testing Notification", message: "Carry on"};
|
||||
browser.notifications.create("p1", opts, () => {
|
||||
browser.notifications.create("p2", opts, () => {
|
||||
browser.notifications.getAll(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.notifyPass("getAll populated");
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
let extensionData = {
|
||||
manifest: {
|
||||
permissions: ["notifications"]
|
||||
},
|
||||
background: "(" + backgroundScript.toString() + ")()"
|
||||
};
|
||||
|
||||
let extension = ExtensionTestUtils.loadExtension(extensionData);
|
||||
info("load complete");
|
||||
yield extension.startup();
|
||||
info("startup complete");
|
||||
yield extension.awaitFinish("getAll populated");
|
||||
info("test complete");
|
||||
yield extension.unload();
|
||||
info("extension unloaded successfully");
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user