Bug 1490819 - wait for windows to be active in browser_BrowserWindowTracker.js, r=dao
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 13 Sep 2018 08:21:51 +0000
changeset 436128 da39be9798ad66987d684506b69a249f1257d55e
parent 436127 0d8eb8a0c2b4ad081ffad8ecf172b82d16c38d01
child 436129 355b50b3aa6b07892c5300f746ac86cf82a1aeef
push id34630
push usernerli@mozilla.com
push dateThu, 13 Sep 2018 21:58:06 +0000
treeherdermozilla-central@71736f1f0f3e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1490819
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1490819 - wait for windows to be active in browser_BrowserWindowTracker.js, r=dao Differential Revision: https://phabricator.services.mozilla.com/D5707
browser/modules/test/browser/browser_BrowserWindowTracker.js
--- a/browser/modules/test/browser/browser_BrowserWindowTracker.js
+++ b/browser/modules/test/browser/browser_BrowserWindowTracker.js
@@ -1,19 +1,28 @@
 "use strict";
 
 ChromeUtils.import("resource:///modules/BrowserWindowTracker.jsm");
 ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 
 const TEST_WINDOW = window;
 
+function windowActivated(win) {
+  if (Services.ww.activeWindow == win) {
+    return Promise.resolve();
+  }
+  return BrowserTestUtils.waitForEvent(win, "activate");
+}
+
 async function withOpenWindows(amount, cont) {
   let windows = [];
   for (let i = 0; i < amount; ++i) {
-    windows.push(await BrowserTestUtils.openNewBrowserWindow());
+    let win = await BrowserTestUtils.openNewBrowserWindow();
+    await windowActivated(win);
+    windows.push(win);
   }
   await cont(windows);
   await Promise.all(windows.map(window => BrowserTestUtils.closeWindow(window)));
 }
 
 add_task(async function test_getTopWindow() {
   await withOpenWindows(5, async function(windows) {
     // Without options passed in.
@@ -62,16 +71,17 @@ add_task(async function test_getTopWindo
     Assert.equal(window, windows[expectedMostRecentIndex],
       "Window focused before the private window should be the most recent one.");
     let popupWindowPromise = BrowserTestUtils.waitForNewWindow();
     ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
       let features = "location=no, personalbar=no, toolbar=no, scrollbars=no, menubar=no, status=no";
       content.window.open("about:blank", "_blank", features);
     });
     let popupWindow = await popupWindowPromise;
+    await windowActivated(popupWindow);
     window = BrowserWindowTracker.getTopWindow({ allowPopups: true });
     Assert.equal(window, popupWindow,
       "The popup window should be the most recent one, when requested.");
     window = BrowserWindowTracker.getTopWindow({ allowPopups: false });
     Assert.equal(window, windows[expectedMostRecentIndex],
       "Window focused before the popup window should be the most recent one.");
     popupWindow.close();
   });