From 330e587de860c7760cad78bfa6b0b8e40d0b2e62 Mon Sep 17 00:00:00 2001 From: Bill McCloskey Date: Thu, 24 Sep 2015 12:34:45 -0700 Subject: [PATCH] Bug 1207911 - [webext] Fix races in webextension tests (r=gabor) --- .../components/extensions/test/browser/browser_ext_simple.js | 3 +-- .../extensions/test/browser/browser_ext_tabs_update.js | 3 +-- .../extensions/test/browser/browser_ext_windows_update.js | 5 ++--- .../extensions/test/mochitest/test_ext_contentscript.html | 5 +++-- .../extensions/test/mochitest/test_ext_generate.html | 3 +-- .../extensions/test/mochitest/test_ext_simple.html | 3 +-- .../extensions/test/mochitest/test_ext_storage.html | 4 +--- .../extensions/test/mochitest/test_ext_webrequest.html | 3 +-- 8 files changed, 11 insertions(+), 18 deletions(-) diff --git a/browser/components/extensions/test/browser/browser_ext_simple.js b/browser/components/extensions/test/browser/browser_ext_simple.js index 86df641b7336..713ebc8f30e5 100644 --- a/browser/components/extensions/test/browser/browser_ext_simple.js +++ b/browser/components/extensions/test/browser/browser_ext_simple.js @@ -10,8 +10,7 @@ add_task(function* test_simple() { add_task(function* test_background() { let extension = ExtensionTestUtils.loadExtension("background"); info("load complete"); - yield extension.startup(); - let x = yield extension.awaitMessage("running"); + let [, x] = yield Promise.all([extension.startup(), extension.awaitMessage("running")]); is(x, 1, "got correct value from extension"); info("startup complete"); extension.sendMessage(10, 20); diff --git a/browser/components/extensions/test/browser/browser_ext_tabs_update.js b/browser/components/extensions/test/browser/browser_ext_tabs_update.js index f52e7d1745c0..bde32c69fa14 100644 --- a/browser/components/extensions/test/browser/browser_ext_tabs_update.js +++ b/browser/components/extensions/test/browser/browser_ext_tabs_update.js @@ -30,8 +30,7 @@ add_task(function* () { }, }); - yield extension.startup(); - yield extension.awaitMessage("check"); + yield Promise.all([extension.startup(), extension.awaitMessage("check")]); ok(gBrowser.selectedTab == tab2, "correct tab selected"); diff --git a/browser/components/extensions/test/browser/browser_ext_windows_update.js b/browser/components/extensions/test/browser/browser_ext_windows_update.js index eb70e2c33568..e5e57c12af0b 100644 --- a/browser/components/extensions/test/browser/browser_ext_windows_update.js +++ b/browser/components/extensions/test/browser/browser_ext_windows_update.js @@ -40,12 +40,11 @@ add_task(function* () { }, }); - yield extension.startup(); - yield extension.awaitMessage("check"); + yield Promise.all([extension.startup(), extension.awaitMessage("check")]); yield promiseWaitForFocus(window1); yield extension.unload(); yield BrowserTestUtils.closeWindow(window2); -}); \ No newline at end of file +}); diff --git a/toolkit/components/extensions/test/mochitest/test_ext_contentscript.html b/toolkit/components/extensions/test/mochitest/test_ext_contentscript.html index a8fa5eccb536..18a474787e6a 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_contentscript.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_contentscript.html @@ -16,8 +16,6 @@ add_task(function* test_contentscript() { let extension = ExtensionTestUtils.loadExtension("content_script"); - yield extension.startup(); - info("extension loaded"); let loadingCount = 0; let interactiveCount = 0; @@ -31,6 +29,9 @@ add_task(function* test_contentscript() let chromeNamespacePromise = extension.awaitMessage("chrome-namespace-ok"); + yield extension.startup(); + info("extension loaded"); + let win = window.open("file_sample.html"); yield Promise.all([waitForLoad(win), completePromise, chromeNamespacePromise]); diff --git a/toolkit/components/extensions/test/mochitest/test_ext_generate.html b/toolkit/components/extensions/test/mochitest/test_ext_generate.html index 976030bb9e89..f4501a2f33e7 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_generate.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_generate.html @@ -32,8 +32,7 @@ let extensionData = { add_task(function* test_background() { let extension = ExtensionTestUtils.loadExtension(extensionData); info("load complete"); - yield extension.startup(); - let x = yield extension.awaitMessage("running"); + let [, x] = yield Promise.all([extension.startup(), extension.awaitMessage("running")]); is(x, 1, "got correct value from extension"); info("startup complete"); extension.sendMessage(10, 20); diff --git a/toolkit/components/extensions/test/mochitest/test_ext_simple.html b/toolkit/components/extensions/test/mochitest/test_ext_simple.html index 90cf84968fb7..bf85fe925cf7 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_simple.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_simple.html @@ -24,8 +24,7 @@ add_task(function* test_simple() { add_task(function* test_background() { let extension = ExtensionTestUtils.loadExtension("background"); info("load complete"); - yield extension.startup(); - let x = yield extension.awaitMessage("running"); + let [, x] = yield Promise.all([extension.startup(), extension.awaitMessage("running")]); is(x, 1, "got correct value from extension"); info("startup complete"); extension.sendMessage(10, 20); diff --git a/toolkit/components/extensions/test/mochitest/test_ext_storage.html b/toolkit/components/extensions/test/mochitest/test_ext_storage.html index 0b2f2a112f1e..180758489777 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_storage.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_storage.html @@ -156,9 +156,7 @@ let extensionData = { add_task(function* test_contentscript() { let extension = ExtensionTestUtils.loadExtension(extensionData); - yield extension.startup(); - info("extension loaded"); - yield extension.awaitMessage("invalidate"); + yield Promise.all([extension.startup(), extension.awaitMessage("invalidate")]); SpecialPowers.invalidateExtensionStorageCache(); extension.sendMessage("invalidated"); yield extension.awaitFinish("storage"); diff --git a/toolkit/components/extensions/test/mochitest/test_ext_webrequest.html b/toolkit/components/extensions/test/mochitest/test_ext_webrequest.html index c1feb2ee36c7..cd8b1d02a402 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_webrequest.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_webrequest.html @@ -77,8 +77,7 @@ function compareLists(list1, list2, kind) function* test_once() { let extension = ExtensionTestUtils.loadExtension("webrequest"); - yield extension.startup(); - yield extension.awaitMessage("ready"); + yield Promise.all([extension.startup(), extension.awaitMessage("ready")]); info("webrequest extension loaded"); yield new Promise(resolve => { setTimeout(resolve, 0); });