Bug 1287007 - Fix timing issue in browser_ext_windows_create_tabId.js r=billm
authorRob Wu <rob@robwu.nl>
Fri, 21 Oct 2016 01:35:03 +0200
changeset 428734 c0a8fecacb46f22d16205470dfdeb5e6aea815f8
parent 428733 f10221d238ac3f5bb4e0f2a00591291d4ee4cee9
child 428735 08efaee1d568cea9e70c86a7eca49c3c53553ed8
push id33405
push userbcampen@mozilla.com
push dateMon, 24 Oct 2016 15:32:53 +0000
reviewersbillm
bugs1287007
milestone52.0a1
Bug 1287007 - Fix timing issue in browser_ext_windows_create_tabId.js r=billm When tabs.onUpdated is called before the promise of windows.create resolves, the test fails. This test failure was observed on almost every try run with non-e10s, and sometimes (rarely) with e10s. MozReview-Commit-ID: 3znCP1uAUSB
browser/components/extensions/test/browser/browser_ext_windows_create_tabId.js
--- a/browser/components/extensions/test/browser/browser_ext_windows_create_tabId.js
+++ b/browser/components/extensions/test/browser/browser_ext_windows_create_tabId.js
@@ -108,28 +108,29 @@ add_task(function* testWindowCreate() {
         error => {
           browser.test.assertTrue(/Invalid tab ID: 0/.test(error.message),
                                   "Create call failed as expected");
         }
       );
     }).then(() => {
       browser.test.log("Try to create a window with two URLs");
 
-      return browser.windows.create({url: ["http://example.com/", "http://example.org/"]});
-    }).then(window => {
+      return Promise.all([
+        // tabs.onUpdated can be invoked between the call of windows.create and
+        // the invocation of its callback/promise, so set up the listeners
+        // before creating the window.
+        promiseTabUpdated("http://example.com/"),
+        promiseTabUpdated("http://example.org/"),
+        browser.windows.create({url: ["http://example.com/", "http://example.org/"]}),
+      ]);
+    }).then(([, , window]) => {
       browser.test.assertEq(2, window.tabs.length, "2 tabs were opened in new window");
       browser.test.assertEq("about:blank", window.tabs[0].url, "about:blank, page not loaded yet");
       browser.test.assertEq("about:blank", window.tabs[1].url, "about:blank, page not loaded yet");
 
-      return Promise.all([
-        promiseTabUpdated("http://example.com/"),
-        promiseTabUpdated("http://example.org/"),
-        Promise.resolve(window),
-      ]);
-    }).then(([, , window]) => {
       return browser.windows.get(window.id, {populate: true});
     }).then(window => {
       browser.test.assertEq(2, window.tabs.length, "2 tabs were opened in new window");
       browser.test.assertEq("http://example.com/", window.tabs[0].url, "Correct URL was loaded in tab 1");
       browser.test.assertEq("http://example.org/", window.tabs[1].url, "Correct URL was loaded in tab 2");
       return browser.windows.remove(window.id);
     }).then(() => {
       browser.test.notifyPass("window-create");