Bug 1335057 - Fix intermittent bug1058164.js test timed out by conditionally waiting. r=mconley, a=test-only
authorEd Lee <edilee@mozilla.com>
Thu, 10 Aug 2017 10:41:19 -0700
changeset 421116 be09ce5ce9b5ef166d4903c3a998f99b36f0fdd8
parent 421115 6493182684c42104593d181c641eb0fb855331cd
child 421117 2592fec1032484952cb8da4c5ab333f484958872
push id7606
push userryanvm@gmail.com
push dateFri, 11 Aug 2017 20:45:35 +0000
treeherdermozilla-beta@6ea7b3eb8990 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley, test-only
bugs1335057, 1058164
milestone56.0
Bug 1335057 - Fix intermittent bug1058164.js test timed out by conditionally waiting. r=mconley, a=test-only MozReview-Commit-ID: LRhV0IbHt5b
dom/base/test/browser_bug1058164.js
--- a/dom/base/test/browser_bug1058164.js
+++ b/dom/base/test/browser_bug1058164.js
@@ -77,27 +77,23 @@ add_task(async function test_swap_framel
 
   // Now let's send the browser back to the original window
 
   // First, create a new, empty browser tab to replace the window with
   let newTab = BrowserTestUtils.addTab(gBrowser);
   gBrowser.selectedTab = newTab;
   let emptyBrowser = newTab.linkedBrowser;
 
-  // Wait for that initial browser to show its pageshow event so that we
-  // don't confuse it with the other expected events. Note that we can't
-  // use BrowserTestUtils.waitForEvent here because we're using the
-  // e10s add-on shims in the e10s-case. I'm doing this because I couldn't
-  // find a way of sending down a frame script to the newly opened windows
-  // and tabs fast enough to attach the event handlers before they were
-  // fired.
-  await new Promise((resolve) => {
-    emptyBrowser.addEventListener("pageshow", function() {
-      resolve();
-    }, {once: true});
+  // Wait for that initial browser to show its pageshow event if it hasn't
+  // happened so that we don't confuse it with the other expected events.
+  await ContentTask.spawn(emptyBrowser, {}, async() => {
+    if (content.document.visibilityState === "hidden") {
+      info("waiting for hidden emptyBrowser to pageshow");
+      await ContentTaskUtils.waitForEvent(content, "pageshow");
+    }
   });
 
   // The empty tab we just added show now fire a pagehide as its replaced,
   // and a pageshow once the swap is finished.
   let emptyBrowserPromise =
     prepareForVisibilityEvents(emptyBrowser, ["pagehide", "pageshow"]);
 
   gBrowser.swapBrowsersAndCloseOther(newTab, newWindow.gBrowser.selectedTab);