--- a/toolkit/components/extensions/test/mochitest/test_ext_notifications.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_notifications.html
@@ -7,87 +7,137 @@
<script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="text/javascript">
"use strict";
-add_task(function* test_notifications() {
+add_task(function* test_notification() {
function backgroundScript() {
- browser.test.log("running background script");
+ let opts = {
+ type: "basic",
+ title: "Testing Notification",
+ message: "Carry on",
+ };
+
+ browser.notifications.create("", opts).then(id => {
+ browser.test.sendMessage("running", id);
+ browser.test.notifyPass("background test passed");
+ });
+ }
+ let extension = ExtensionTestUtils.loadExtension({
+ manifest: {
+ permissions: ["notifications"],
+ },
+ background: `(${backgroundScript})()`,
+ });
+ yield extension.startup();
+ let x = yield extension.awaitMessage("running");
+ is(x, "0", "got correct id from notifications.create");
+ yield extension.awaitFinish();
+ yield extension.unload();
+});
+
+add_task(function* test_notification_on_closed() {
+ function backgroundScript() {
let opts = {
type: "basic",
title: "Testing Notification",
message: "Carry on",
};
- // Test an unimplemented listener.
- browser.notifications.onClicked.addListener(function() {});
+ // Test onClosed listener.
+ browser.notifications.onClosed.addListener(id => {
+ browser.test.sendMessage("closed", id);
+ browser.test.notifyPass("background test passed");
+ });
browser.notifications.create("5", opts).then(id => {
+ return browser.notifications.create("5", opts);
+ }).then(id => {
browser.test.sendMessage("running", id);
+ });
+ }
+
+ let extension = ExtensionTestUtils.loadExtension({
+ manifest: {
+ permissions: ["notifications"],
+ },
+ background: `(${backgroundScript})()`,
+ });
+ yield extension.startup();
+ let x = yield extension.awaitMessage("closed");
+ is(x, "5", "got correct id from onClosed listener");
+ x = yield extension.awaitMessage("running");
+ is(x, "5", "got correct id from notifications.create");
+ yield extension.awaitFinish();
+ yield extension.unload();
+});
+
+add_task(function* test_notification_clear() {
+ function backgroundScript() {
+ let opts = {
+ type: "basic",
+ title: "Testing Notification",
+ message: "Carry on",
+ };
+
+ browser.notifications.onClosed.addListener(id => {
+ browser.test.sendMessage("closed", id);
+ });
+
+ browser.notifications.create("99", opts).then(id => {
+ return browser.notifications.clear(id);
+ }).then(wasCleared => {
+ browser.test.sendMessage("cleared", wasCleared);
browser.test.notifyPass("background test passed");
});
}
- let extensionData = {
+ let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["notifications"],
},
- background: "(" + backgroundScript.toString() + ")()",
- };
-
- let extension = ExtensionTestUtils.loadExtension(extensionData);
- info("load complete");
+ background: `(${backgroundScript})()`,
+ });
yield extension.startup();
- info("startup complete");
- let x = yield extension.awaitMessage("running");
- is(x, "5", "got correct value from extension");
+ let x = yield extension.awaitMessage("closed");
+ is(x, "99", "got correct id from onClosed listener");
+ x = yield extension.awaitMessage("cleared");
+ is(x, true, "got correct boolean from notifications.clear");
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().then(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 = {
+ let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["notifications"],
},
- background: "(" + backgroundScript.toString() + ")()",
- };
-
- let extension = ExtensionTestUtils.loadExtension(extensionData);
- info("load complete");
+ background: `(${backgroundScript})()`,
+ });
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");
-
let opts = {
type: "basic",
title: "Testing Notification",
message: "Carry on",
};
browser.notifications.create("p1", opts).then(() => {
return browser.notifications.create("p2", opts);
@@ -101,29 +151,23 @@ add_task(function* test_notifications_po
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 = {
+ let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["notifications"],
},
- background: "(" + backgroundScript.toString() + ")()",
- };
-
- let extension = ExtensionTestUtils.loadExtension(extensionData);
- info("load complete");
+ background: `(${backgroundScript})()`,
+ });
yield extension.startup();
- info("startup complete");
yield extension.awaitFinish("getAll populated");
- info("test complete");
yield extension.unload();
- info("extension unloaded successfully");
});
</script>
</body>
</html>