Bug 1220929 - Harden browser_crashedTabs.js against races. r?felipe draft
authorMike Conley <mconley@mozilla.com>
Tue, 03 Nov 2015 17:19:38 -0500
changeset 307989 a5026872e5912dd79984ad58f07cc8fd3345f092
parent 307988 034ec51164f37d2c3714ef16e649143f42854f48
child 307990 0b9af5a9e2210d8ca53e3c61ce0e9920bff78605
push id7421
push usermconley@mozilla.com
push dateWed, 11 Nov 2015 04:06:00 +0000
reviewersfelipe
bugs1220929
milestone45.0a1
Bug 1220929 - Harden browser_crashedTabs.js against races. r?felipe
browser/components/sessionstore/test/browser_crashedTabs.js
--- a/browser/components/sessionstore/test/browser_crashedTabs.js
+++ b/browser/components/sessionstore/test/browser_crashedTabs.js
@@ -97,16 +97,33 @@ function promiseHistoryLength(browser, l
       }
     });
 
     mm.loadFrameScript("data:,(" + frame_script.toString() + ")();", false);
   });
 }
 
 /**
+ * Returns a Promise that resolves when a browser has fired the
+ * AboutTabCrashedReady event.
+ *
+ * @param browser
+ *        The remote <xul:browser> that will fire the event.
+ * @return Promise
+ */
+function promiseTabCrashedReady(browser) {
+  return new Promise((resolve) => {
+    browser.addEventListener("AboutTabCrashedReady", function ready(e) {
+      browser.removeEventListener("AboutTabCrashedReady", ready, false, true);
+      resolve();
+    }, false, true);
+  });
+}
+
+/**
  * Checks that if a tab crashes, that information about the tab crashed
  * page does not get added to the tab history.
  */
 add_task(function test_crash_page_not_in_history() {
   let newTab = gBrowser.addTab();
   gBrowser.selectedTab = newTab;
   let browser = newTab.linkedBrowser;
   ok(browser.isRemoteBrowser, "Should be a remote browser");
@@ -369,18 +386,23 @@ add_task(function* test_hide_restore_all
   ok(restoreOneButton.classList.contains("primary"), "Restore Tab button should have the primary class");
 
   let newTab2 = gBrowser.addTab();
   gBrowser.selectedTab = newTab;
 
   browser.loadURI(PAGE_2);
   yield promiseBrowserLoaded(browser);
 
+  // We'll need to make sure the second tab's browser has finished
+  // sending its AboutTabCrashedReady event before we know for
+  // sure whether or not we're showing the right Restore buttons.
+  let otherBrowserReady = promiseTabCrashedReady(newTab2.linkedBrowser);
   // Crash the tab
   yield BrowserTestUtils.crashBrowser(browser);
+  yield otherBrowserReady;
 
   doc = browser.contentDocument;
   restoreAllButton = doc.getElementById("restoreAll");
   restoreOneButton = doc.getElementById("restoreTab");
 
   ok(!restoreAllButton.hasAttribute("hidden"), "Restore All button should not be hidden");
   ok(!(restoreOneButton.classList.contains("primary")), "Restore Tab button should not have the primary class");