Bug 1220929 - Harden browser_crashedTabs.js against races. r?felipe
--- 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");