Bug 942229 - Intermittent browser_cmd_screenshot.js. r=jwalker, a=test-only
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Wed, 11 Dec 2013 22:36:24 +0200
changeset 156858 b9b2a1c652da90c11458000e0cac9db55a50854f
parent 156857 eae60e7c551d02a1bcb55e24c585dce6bd1f5ee8
child 156859 3bf027b4f17047e9de3455b11c05fce60ac1369e
push id360
push userryanvm@gmail.com
push dateThu, 12 Dec 2013 16:15:53 +0000
reviewersjwalker, test-only
bugs942229
milestone26.0
Bug 942229 - Intermittent browser_cmd_screenshot.js. r=jwalker, a=test-only
browser/devtools/commandline/test/browser_cmd_screenshot.js
browser/devtools/commandline/test/head.js
--- a/browser/devtools/commandline/test/browser_cmd_screenshot.js
+++ b/browser/devtools/commandline/test/browser_cmd_screenshot.js
@@ -165,31 +165,27 @@ function addTabWithToolbarRunTests(win) 
 }
 
 function addWindow(windowOptions, callback) {
   waitForExplicitFinish();
   let deferred = promise.defer();
 
   let win = OpenBrowserWindow(windowOptions);
 
-  let onLoad = function() {
-    win.removeEventListener("load", onLoad, false);
-
+  whenDelayedStartupFinished(win, function() {
     // Would like to get rid of this executeSoon, but without it the url
     // (TEST_URI) provided in addTabWithToolbarRunTests hasn't loaded
     executeSoon(function() {
       try {
         let reply = callback(win);
         promise.resolve(reply).then(function() {
           win.close();
           deferred.resolve();
         });
       }
       catch (ex) {
         deferred.reject(ex);
       }
     });
-  };
-
-  win.addEventListener("load", onLoad, false);
+  });
 
   return deferred.promise;
 }
--- a/browser/devtools/commandline/test/head.js
+++ b/browser/devtools/commandline/test/head.js
@@ -5,16 +5,25 @@
 const TEST_BASE_HTTP = "http://example.com/browser/browser/devtools/commandline/test/";
 const TEST_BASE_HTTPS = "https://example.com/browser/browser/devtools/commandline/test/";
 
 // Import the GCLI test helper
 let testDir = gTestPath.substr(0, gTestPath.lastIndexOf("/"));
 Services.scriptloader.loadSubScript(testDir + "/helpers.js", this);
 Services.scriptloader.loadSubScript(testDir + "/mockCommands.js", this);
 
+function whenDelayedStartupFinished(aWindow, aCallback) {
+  Services.obs.addObserver(function observer(aSubject, aTopic) {
+    if (aWindow == aSubject) {
+      Services.obs.removeObserver(observer, aTopic);
+      executeSoon(aCallback);
+    }
+  }, "browser-delayed-startup-finished", false);
+}
+
 /**
  * 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)