Bug 1233350 - Fix TypeError in notifications.getAll(). r?kmag
This also adds some tests for the method.
--- a/toolkit/components/extensions/ext-notifications.js
+++ b/toolkit/components/extensions/ext-notifications.js
@@ -119,17 +119,17 @@ extensions.registerPrivilegedAPI("notifi
if (callback) {
runSafe(context, callback, cleared);
}
},
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);
},
onClosed: new EventManager(context, "notifications.onClosed", fire => {
let listener = notification => {
// FIXME: Support the byUser argument.
fire(notification.id, true);
};
--- a/toolkit/components/extensions/test/mochitest/test_ext_notifications.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_notifications.html
@@ -40,12 +40,80 @@ add_task(function* test_notifications()
let x = yield extension.awaitMessage("running");
is(x, "5", "got correct value from extension");
yield extension.awaitFinish();
info("test complete");
yield extension.unload();
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>
</html>