Bug 1335057 - Fix intermittent bug1058164.js test timed out by conditionally waiting. r=mconley draft
authorEd Lee <edilee@mozilla.com>
Thu, 10 Aug 2017 10:41:19 -0700
changeset 644252 8e4e02bb47ec8ee9e798568395b75d51af4f485b
parent 642916 1d042bcb2632ea6a38fa08dbe21a6e8a0ee46961
child 725549 aa44a08db4d45544221cbfb089a1bffe26b46e19
push id73369
push userbmo:edilee@mozilla.com
push dateThu, 10 Aug 2017 18:41:58 +0000
reviewersmconley
bugs1335057, 1058164
milestone57.0a1
Bug 1335057 - Fix intermittent bug1058164.js test timed out by conditionally waiting. r=mconley 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);