Bug 1207911 - [webext] Fix races in webextension tests (r=gabor)
authorBill McCloskey <billm@mozilla.com>
Thu, 24 Sep 2015 12:34:45 -0700
changeset 264573 5f823efe3e6dcf7440ee1e5298fbff26f54d7f9d
parent 264572 3966bfa6a7ad0a565a5e98b0aecf126949c62ff3
child 264574 3c826002cabf4930cf13d4fa9c3bf7d9ea03e70f
push id65676
push userwmccloskey@mozilla.com
push dateSun, 27 Sep 2015 19:30:32 +0000
treeherdermozilla-inbound@5f823efe3e6d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor
bugs1207911
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1207911 - [webext] Fix races in webextension tests (r=gabor)
browser/components/extensions/test/browser/browser_ext_simple.js
browser/components/extensions/test/browser/browser_ext_tabs_update.js
browser/components/extensions/test/browser/browser_ext_windows_update.js
toolkit/components/extensions/test/mochitest/test_ext_contentscript.html
toolkit/components/extensions/test/mochitest/test_ext_generate.html
toolkit/components/extensions/test/mochitest/test_ext_simple.html
toolkit/components/extensions/test/mochitest/test_ext_storage.html
toolkit/components/extensions/test/mochitest/test_ext_webrequest.html
--- a/browser/components/extensions/test/browser/browser_ext_simple.js
+++ b/browser/components/extensions/test/browser/browser_ext_simple.js
@@ -5,18 +5,17 @@ add_task(function* test_simple() {
   info("startup complete");
   yield extension.unload();
   info("extension unloaded successfully");
 });
 
 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);
   yield extension.awaitFinish();
   info("test complete");
   yield extension.unload();
   info("extension unloaded successfully");
 });
--- a/browser/components/extensions/test/browser/browser_ext_tabs_update.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_update.js
@@ -25,18 +25,17 @@ add_task(function* () {
 
         browser.tabs.update(tabs[1].id, {active: true}, function() {
           browser.test.sendMessage("check");
         });
       });
     },
   });
 
-  yield extension.startup();
-  yield extension.awaitMessage("check");
+  yield Promise.all([extension.startup(), extension.awaitMessage("check")]);
 
   ok(gBrowser.selectedTab == tab2, "correct tab selected");
 
   yield extension.unload();
 
   yield BrowserTestUtils.removeTab(tab1);
   yield BrowserTestUtils.removeTab(tab2);
 });
--- a/browser/components/extensions/test/browser/browser_ext_windows_update.js
+++ b/browser/components/extensions/test/browser/browser_ext_windows_update.js
@@ -35,17 +35,16 @@ add_task(function* () {
         browser.windows.update(wins[0].id, {focused: true}, function() {
           browser.test.sendMessage("check");
         });
 
       });
     },
   });
 
-  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
+});
--- a/toolkit/components/extensions/test/mochitest/test_ext_contentscript.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_contentscript.html
@@ -11,31 +11,32 @@
 <body>
 
 <script type="application/javascript;version=1.8">
 "use strict";
 
 add_task(function* test_contentscript()
 {
   let extension = ExtensionTestUtils.loadExtension("content_script");
-  yield extension.startup();
-  info("extension loaded");
 
   let loadingCount = 0;
   let interactiveCount = 0;
   let completeCount = 0;
   extension.onMessage("script-run-loading", () => { loadingCount++; });
   extension.onMessage("script-run-interactive", () => { interactiveCount++; });
 
   let completePromise = new Promise(resolve => {
     extension.onMessage("script-run-complete", () => { completeCount++; resolve(); });
   });
 
   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]);
   info("test page loaded");
 
   win.close();
 
   is(loadingCount, 1, "document_start script ran exactly once");
--- a/toolkit/components/extensions/test/mochitest/test_ext_generate.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_generate.html
@@ -27,18 +27,17 @@ function backgroundScript() {
 
 let extensionData = {
   background: "(" + backgroundScript.toString() + ")()"
 };
 
 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);
   yield extension.awaitFinish();
   info("test complete");
   yield extension.unload();
   info("extension unloaded successfully");
 });
--- a/toolkit/components/extensions/test/mochitest/test_ext_simple.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_simple.html
@@ -19,18 +19,17 @@ add_task(function* test_simple() {
   info("startup complete");
   yield extension.unload();
   info("extension unloaded successfully");
 });
 
 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);
   yield extension.awaitFinish();
   info("test complete");
   yield extension.unload();
   info("extension unloaded successfully");
 });
--- a/toolkit/components/extensions/test/mochitest/test_ext_storage.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_storage.html
@@ -151,19 +151,17 @@ let extensionData = {
   background: "(" + backgroundScript.toString() + ")()",
   manifest: {
     permissions: ["storage"]
   },
 };
 
 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");
   yield extension.unload();
   info("extension unloaded");
 });
 
 </script>
--- a/toolkit/components/extensions/test/mochitest/test_ext_webrequest.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_webrequest.html
@@ -72,18 +72,17 @@ function compareLists(list1, list2, kind
   list2.sort();
   removeDupes(list2);
   is(String(list1), String(list2), `${kind} URLs correct`);
 }
 
 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); });
 
   let win = window.open();
 
   // Clear the image cache, since it gets in the way otherwise.
   var imgTools = SpecialPowers.Cc["@mozilla.org/image/tools;1"].getService(SpecialPowers.Ci.imgITools);