Bug 1167896 - attempt to fix intermittent failures in browser_tabs_close_beforeunload.js, rs=test-only,a=test-only
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 16 Mar 2016 19:31:53 +0000
changeset 323514 9153cfa4fc87d8a044c1cfbafad9352b41869519
parent 323513 6d030cb1d2ab43b99cc2b5b585d9acbdf6fc9e35
child 323515 292b1d932cf667526f32cf0c4f1e0f02b0c27bca
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstest-only, test-only
bugs1167896
milestone47.0a2
Bug 1167896 - attempt to fix intermittent failures in browser_tabs_close_beforeunload.js, rs=test-only,a=test-only MozReview-Commit-ID: HYoRGdy12qk
browser/base/content/test/general/browser_tabs_close_beforeunload.js
--- a/browser/base/content/test/general/browser_tabs_close_beforeunload.js
+++ b/browser/base/content/test/general/browser_tabs_close_beforeunload.js
@@ -1,36 +1,40 @@
 "use strict";
 
+SimpleTest.requestCompleteLog();
+
 SpecialPowers.pushPrefEnv({"set": [["dom.require_user_interaction_for_beforeunload", false]]});
 
 const FIRST_TAB = getRootDirectory(gTestPath) + "close_beforeunload_opens_second_tab.html";
 const SECOND_TAB = getRootDirectory(gTestPath) + "close_beforeunload.html";
 
 add_task(function*() {
+  info("Opening first tab");
   let firstTab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, FIRST_TAB);
-  let newTabPromise = waitForNewTabEvent(gBrowser);
-  ContentTask.spawn(firstTab.linkedBrowser, "", function*() {
+  let secondTabLoadedPromise;
+  let secondTab;
+  let tabOpened = new Promise(resolve => {
+    info("Adding tabopen listener");
+    gBrowser.tabContainer.addEventListener("TabOpen", function tabOpenListener(e) {
+      info("Got tabopen, removing listener and waiting for load");
+      gBrowser.tabContainer.removeEventListener("TabOpen", tabOpenListener, false, false);
+      secondTab = e.target;
+      secondTabLoadedPromise = BrowserTestUtils.browserLoaded(secondTab.linkedBrowser, false, SECOND_TAB);
+      resolve();
+    }, false, false);
+  });
+  info("Opening second tab using a click");
+  yield ContentTask.spawn(firstTab.linkedBrowser, "", function*() {
     content.document.getElementsByTagName("a")[0].click();
   });
-  let tabOpenEvent = yield newTabPromise;
-  let secondTab = tabOpenEvent.target;
-  yield ContentTask.spawn(secondTab.linkedBrowser, SECOND_TAB, function*(expectedURL) {
-    if (content.window.location.href == expectedURL &&
-        content.document.readyState === "complete") {
-      return Promise.resolve();
-    }
-    return new Promise(function(resolve, reject) {
-      content.window.addEventListener("load", function() {
-        if (content.window.location.href == expectedURL) {
-          resolve();
-        }
-      }, false);
-    });
-  });
+  info("Waiting for the second tab to be opened");
+  yield tabOpened;
+  info("Waiting for the load in that tab to finish");
+  yield secondTabLoadedPromise;
 
   let closeBtn = document.getAnonymousElementByAttribute(secondTab, "anonid", "close-button");
   let closePromise = BrowserTestUtils.removeTab(secondTab, {dontRemove: true});
   info("closing second tab (which will self-close in beforeunload)");
   closeBtn.click();
   ok(secondTab.closing, "Second tab should be marked as closing synchronously.");
   yield closePromise;
   ok(secondTab.closing, "Second tab should still be marked as closing");