Bug 1266134 - Fix tab load event waiting in browser_cmd_csscoverage_startstop.js. r=jryans
MozReview-Commit-ID: FHqi163FjBq
--- a/devtools/client/commandline/test/browser_cmd_csscoverage_startstop.js
+++ b/devtools/client/commandline/test/browser_cmd_csscoverage_startstop.js
@@ -32,27 +32,28 @@ add_task(function* () {
/**
* Visit all the pages in the test
*/
function* navigate(usage, options) {
yield usage.start(options.chromeWindow, options.target);
ok(usage.isRunning(), "csscoverage is running");
- let load1Promise = helpers.listenOnce(options.browser, "load", true);
+ let load1Promise = waitForTabLoad(options.browser);
yield helpers.navigate(PAGE_1, options);
// Wait for the test pages to auto-cycle
yield load1Promise;
- is(options.window.location.href, PAGE_1, "page 1 loaded");
+ is(options.browser.currentURI.spec, PAGE_1, "page 1 loaded");
// Page 2 is a frame in page 1. JS in the page navigates to page 3.
- yield helpers.listenOnce(options.browser, "load", true);
- is(options.window.location.href, PAGE_3, "page 3 loaded");
+
+ yield waitForTabLoad(options.browser);
+ is(options.browser.currentURI.spec, PAGE_3, "page 3 loaded");
let toolboxReady = gDevTools.once("toolbox-ready");
yield usage.stop();
ok(!usage.isRunning(), "csscoverage not is running");
yield toolboxReady;
--- a/devtools/client/commandline/test/head.js
+++ b/devtools/client/commandline/test/head.js
@@ -23,16 +23,31 @@ function whenDelayedStartupFinished(aWin
Services.obs.addObserver(function observer(aSubject, aTopic) {
if (aWindow == aSubject) {
Services.obs.removeObserver(observer, aTopic);
executeSoon(aCallback);
}
}, "browser-delayed-startup-finished", false);
}
+var waitForTabLoad = function (browser) {
+ return ContentTask.spawn(browser, null, function* () {
+ yield new Promise(done => {
+ let listener = function (event) {
+ // Only consider top document load to ignore iframes
+ if (event.target == content.document) {
+ removeEventListener("load", listener, true);
+ done();
+ }
+ };
+ addEventListener("load", listener, true);
+ });
+ });
+}
+
/**
* Force GC on shutdown, because it seems that GCLI can outrun the garbage
* collector in some situations, which causes test failures in later tests
* Bug 774619 is an example.
*/
registerCleanupFunction(function tearDown() {
window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)