Bug 1173801 - Correctly wait for both focus and the delayed startup to finish when opening a new window in private browsing tests. r=mconley, a=test-only
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 21 Jul 2015 21:29:36 -0400
changeset 275398 bc2ec0c02d768c0a9fdb765d5972fa24bd4bda28
parent 275397 527271c3a4bc19af9a4542ccb3c98e902f97a667
child 275399 4bd34b79aa114c25573911b240927f85afeaf61a
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley, test-only
bugs1173801
milestone40.0
Bug 1173801 - Correctly wait for both focus and the delayed startup to finish when opening a new window in private browsing tests. r=mconley, a=test-only
browser/components/privatebrowsing/test/browser/head.js
--- a/browser/components/privatebrowsing/test/browser/head.js
+++ b/browser/components/privatebrowsing/test/browser/head.js
@@ -2,44 +2,21 @@
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 let {PromiseUtils} = Cu.import("resource://gre/modules/PromiseUtils.jsm", {});
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
   "resource://testing-common/PlacesTestUtils.jsm");
 
 function whenNewWindowLoaded(aOptions, aCallback) {
   let win = OpenBrowserWindow(aOptions);
-  let gotLoad = false;
-  let gotActivate = Services.focus.activeWindow == win;
-
-  function maybeRunCallback() {
-    if (gotLoad && gotActivate) {
-      executeSoon(function() { aCallback(win); });
-    }
-  }
-
-  if (!gotActivate) {
-    win.addEventListener("activate", function onActivate() {
-      info("Got activate.");
-      win.removeEventListener("activate", onActivate, false);
-      gotActivate = true;
-      maybeRunCallback();
-    }, false);
-  } else {
-    info("Was activated.");
-  }
-
-  Services.obs.addObserver(function observer(aSubject, aTopic) {
-    if (win == aSubject) {
-      info("Delayed startup finished");
-      Services.obs.removeObserver(observer, aTopic);
-      gotLoad = true;
-      maybeRunCallback();
-    }
-  }, "browser-delayed-startup-finished", false);
+  let focused = SimpleTest.promiseFocus(win);
+  let startupFinished = TestUtils.topicObserved("browser-delayed-startup-finished",
+                                                subject => subject == win).then(() => win);
+  Promise.all([focused, startupFinished])
+    .then(results => executeSoon(() => aCallback(results[1])));
 
   return win;
 }
 
 function openWindow(aParent, aOptions, a3) {
   let { Promise: { defer } } = Components.utils.import("resource://gre/modules/Promise.jsm", {});
   let { promise, resolve } = defer();