Bug 1396362 - Fix intermittent test_ext_notifications.html, r?mixedpuppy
MozReview-Commit-ID: 67LDQuEvDZI
--- a/toolkit/components/extensions/test/mochitest/test_ext_notifications.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_notifications.html
@@ -41,53 +41,59 @@ add_task(async function test_notificatio
await extension.startup();
let x = await extension.awaitMessage("running");
is(x, "0", "got correct id from notifications.create");
await extension.awaitFinish();
await extension.unload();
});
add_task(async function test_notification_events() {
- async function background() {
+ function background() {
let opts = {
type: "basic",
title: "Testing Notification",
message: "Carry on",
};
+ let createdId = "98";
+
// Test an ignored listener.
browser.notifications.onButtonClicked.addListener(function() {});
// We cannot test onClicked listener without a mock
// but we can attempt to add a 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.onShown.addListener(async function listener(id) {
+ browser.notifications.onShown.removeListener(listener);
+ browser.test.assertEq(createdId, id, "onShown received the expected id.");
+ let newId = await browser.notifications.create(id, opts);
+ browser.test.assertEq(createdId, newId, "create returned the expected id.");
+ browser.test.sendMessage("created");
});
- await browser.notifications.create("5", opts);
- let id = await browser.notifications.create("5", opts);
- browser.test.sendMessage("running", id);
+ // Test onClosed listener.
+ browser.notifications.onClosed.addListener(function listener(id) {
+ browser.notifications.onClosed.removeListener(listener);
+ browser.test.assertEq(createdId, id, "onClosed received the expected id.");
+ browser.test.sendMessage("closed");
+ });
+
+ browser.notifications.create(createdId, opts);
}
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["notifications"],
},
background,
});
await extension.startup();
- let x = await extension.awaitMessage("closed");
- is(x, "5", "got correct id from onClosed listener");
- x = await extension.awaitMessage("running");
- is(x, "5", "got correct id from notifications.create");
- await extension.awaitFinish();
+ await extension.awaitMessage("closed");
+ await extension.awaitMessage("created");
await extension.unload();
});
add_task(async function test_notification_clear() {
function background() {
let opts = {
type: "basic",
title: "Testing Notification",