Backed out changeset 96b5a88ac004 (bug 1486824) for causing frequent failures e.g: browser/components/privatebrowsing/test/browser/browser_privatebrowsing_about.js a=backout
authorMargareta Eliza Balazs <ebalazs@mozilla.com>
Fri, 31 Aug 2018 12:17:27 +0300
changeset 482517 63d2134f95878cabfb89c7849a1baad2ef139fd0
parent 482503 02f33375bc170cc26faeb9284f11d74f653565ea
child 482523 bc7c9760b7d1db79ff9eaefbe17b871a6a50ea65
push id232
push userfmarier@mozilla.com
push dateWed, 05 Sep 2018 20:45:54 +0000
reviewersbackout
bugs1486824
milestone63.0a1
backs out96b5a88ac0041a1bd382a731749e1fca9aa911ed
Backed out changeset 96b5a88ac004 (bug 1486824) for causing frequent failures e.g: browser/components/privatebrowsing/test/browser/browser_privatebrowsing_about.js a=backout
accessible/tests/browser/events/browser_test_textcaret.js
browser/base/content/browser-captivePortal.js
browser/base/content/browser.js
browser/base/content/test/captivePortal/head.js
browser/base/content/test/forms/browser_selectpopup.js
browser/base/content/test/plugins/browser_private_clicktoplay.js
browser/base/content/test/sidebar/browser_sidebar_adopt.js
browser/components/customizableui/test/browser_editcontrols_update.js
browser/components/customizableui/test/browser_sidebar_toggle.js
browser/components/extensions/test/browser/browser_ext_sidebarAction_windows.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_about.js
browser/components/sessionstore/test/browser_394759_perwindowpb.js
dom/tests/browser/browser_bug1236512.js
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
--- a/accessible/tests/browser/events/browser_test_textcaret.js
+++ b/accessible/tests/browser/events/browser_test_textcaret.js
@@ -9,37 +9,38 @@
 function caretMoveChecker(target, caretOffset) {
   return function(event) {
     let cmEvent = event.QueryInterface(nsIAccessibleCaretMoveEvent);
     return cmEvent.accessible == getAccessible(target) && cmEvent.caretOffset == caretOffset;
   };
 }
 
 async function checkURLBarCaretEvents() {
-  const kURL = "about:mozilla";
-  let newWin = await BrowserTestUtils.openNewBrowserWindow();
-  newWin.gBrowser.selectedBrowser.loadURI(kURL);
+  let url = "about:mozilla";
 
-  await waitForEvent(
+  let onDocLoad = waitForEvent(
     EVENT_DOCUMENT_LOAD_COMPLETE,
     event => {
       try {
-        return event.accessible.QueryInterface(nsIAccessibleDocument).URL == kURL;
+        return event.accessible.QueryInterface(nsIAccessibleDocument).URL == url;
       } catch (e) {
         return false;
       }
     }
   );
-  info("Loaded " + kURL);
+  let [ newWin ] = await Promise.all([
+    BrowserTestUtils.openNewBrowserWindow({ url }),
+    onDocLoad
+  ]);
 
   let urlbarInputEl = newWin.document.getElementById("urlbar").inputField;
   let urlbarInput = getAccessible(urlbarInputEl, [ nsIAccessibleText ]);
 
   let onCaretMove = waitForEvents([
-    [ EVENT_TEXT_CARET_MOVED, caretMoveChecker(urlbarInput, kURL.length) ],
+    [ EVENT_TEXT_CARET_MOVED, caretMoveChecker(urlbarInput, url.length) ],
     [ EVENT_FOCUS, urlbarInput ]
   ]);
 
   urlbarInput.caretOffset = -1;
   await onCaretMove;
   ok(true, "Caret move in URL bar #1");
 
   onCaretMove = waitForEvent(
--- a/browser/base/content/browser-captivePortal.js
+++ b/browser/base/content/browser-captivePortal.js
@@ -108,22 +108,16 @@ var CaptivePortalWatcher = {
   },
 
   _captivePortalDetected() {
     if (this._delayedCaptivePortalDetectedInProgress) {
       return;
     }
 
     let win = BrowserWindowTracker.getTopWindow();
-    // Used by tests: ignore the main test window in order to enable testing of
-    // the case where we have no open windows.
-    if (win && win.document.documentElement.getAttribute("ignorecaptiveportal")) {
-      win = null;
-    }
-
     // If no browser window has focus, open and show the tab when we regain focus.
     // This is so that if a different application was focused, when the user
     // (re-)focuses a browser window, we open the tab immediately in that window
     // so they can log in before continuing to browse.
     if (win != Services.ww.activeWindow) {
       this._delayedCaptivePortalDetectedInProgress = true;
       Services.obs.addObserver(this, "xul-window-visible");
     }
@@ -137,22 +131,16 @@ var CaptivePortalWatcher = {
    * the tab if needed after a short delay to allow the recheck to complete.
    */
   _delayedCaptivePortalDetected() {
     if (!this._delayedCaptivePortalDetectedInProgress) {
       return;
     }
 
     let win = BrowserWindowTracker.getTopWindow();
-    // Used by tests: ignore the main test window in order to enable testing of
-    // the case where we have no open windows.
-    if (win && win.document.documentElement.getAttribute("ignorecaptiveportal")) {
-      win = null;
-    }
-
     if (win != Services.ww.activeWindow) {
       // The window that got focused was not a browser window.
       return;
     }
     Services.obs.removeObserver(this, "xul-window-visible");
     this._delayedCaptivePortalDetectedInProgress = false;
 
     if (win != window) {
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -4287,29 +4287,16 @@ function toOpenWindowByType(inType, uri,
   if (topWindow)
     topWindow.focus();
   else if (features)
     window.open(uri, "_blank", features);
   else
     window.open(uri, "_blank", "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar");
 }
 
-/**
- * Open a new browser window.
- *
- * @param {Object} options
- *        {
- *          private: A boolean indicating if the window should be
- *                   private
- *          remote:  A boolean indicating if the window should run
- *                   remote browser tabs or not. If omitted, the window
- *                   will choose the profile default state.
- *        }
- * @return a reference to the new window.
- */
 function OpenBrowserWindow(options) {
   var telemetryObj = {};
   TelemetryStopwatch.start("FX_NEW_WINDOW_MS", telemetryObj);
 
   var handler = Cc["@mozilla.org/browser/clh;1"]
                   .getService(Ci.nsIBrowserHandler);
   var defaultArgs = handler.defaultArgs;
   var wintype = document.documentElement.getAttribute("windowtype");
--- a/browser/base/content/test/captivePortal/head.js
+++ b/browser/base/content/test/captivePortal/head.js
@@ -15,23 +15,32 @@ const PORTAL_NOTIFICATION_VALUE = "capti
 async function setupPrefsAndRecentWindowBehavior() {
   await SpecialPowers.pushPrefEnv({
     set: [["captivedetect.canonicalURL", CANONICAL_URL],
           ["captivedetect.canonicalContent", CANONICAL_CONTENT]],
   });
   // We need to test behavior when a portal is detected when there is no browser
   // window, but we can't close the default window opened by the test harness.
   // Instead, we deactivate CaptivePortalWatcher in the default window and
-  // exclude it using an attribute to mask its presence.
+  // exclude it from BrowserWindowTracker.getTopWindow in an attempt to
+  // mask its presence.
   window.CaptivePortalWatcher.uninit();
-  window.document.documentElement.setAttribute("ignorecaptiveportal", "true");
+  let getTopWindowCopy = BrowserWindowTracker.getTopWindow;
+  let defaultWindow = window;
+  BrowserWindowTracker.getTopWindow = () => {
+    let win = getTopWindowCopy();
+    if (win == defaultWindow) {
+      return null;
+    }
+    return win;
+  };
 
   registerCleanupFunction(function cleanUp() {
+    BrowserWindowTracker.getTopWindow = getTopWindowCopy;
     window.CaptivePortalWatcher.init();
-    window.document.documentElement.removeAttribute("ignorecaptiveportal");
   });
 }
 
 async function portalDetected() {
   Services.obs.notifyObservers(null, "captive-portal-login");
   await BrowserTestUtils.waitForCondition(() => {
     return cps.state == cps.LOCKED_PORTAL;
   }, "Waiting for Captive Portal Service to update state after portal detected.");
--- a/browser/base/content/test/forms/browser_selectpopup.js
+++ b/browser/base/content/test/forms/browser_selectpopup.js
@@ -585,34 +585,28 @@ add_task(async function test_large_popup
 
   await performLargePopupTests(window);
 
   BrowserTestUtils.removeTab(tab);
 });
 
 // This test checks the same as the previous test but in a new smaller window.
 add_task(async function test_large_popup_in_small_window() {
-  let newWin = await BrowserTestUtils.openNewBrowserWindow();
-
-  let resizePromise = BrowserTestUtils.waitForEvent(newWin, "resize", false, e => {
-    return newWin.innerHeight <= 400 && newWin.innerWidth <= 400;
-  });
-  newWin.resizeTo(400, 400);
-  await resizePromise;
+  let newwin = await BrowserTestUtils.openNewBrowserWindow({ width: 400, height: 400 });
 
   const pageUrl = "data:text/html," + escape(PAGECONTENT_SMALL);
-  let browserLoadedPromise = BrowserTestUtils.browserLoaded(newWin.gBrowser.selectedBrowser);
-  await BrowserTestUtils.loadURI(newWin.gBrowser.selectedBrowser, pageUrl);
+  let browserLoadedPromise = BrowserTestUtils.browserLoaded(newwin.gBrowser.selectedBrowser);
+  await BrowserTestUtils.loadURI(newwin.gBrowser.selectedBrowser, pageUrl);
   await browserLoadedPromise;
 
-  newWin.gBrowser.selectedBrowser.focus();
+  newwin.gBrowser.selectedBrowser.focus();
 
-  await performLargePopupTests(newWin);
+  await performLargePopupTests(newwin);
 
-  await BrowserTestUtils.closeWindow(newWin);
+  await BrowserTestUtils.closeWindow(newwin);
 });
 
 async function performSelectSearchTests(win) {
   let browser = win.gBrowser.selectedBrowser;
   await ContentTask.spawn(browser, null, async function() {
     let doc = content.document;
     let select = doc.getElementById("one");
 
--- a/browser/base/content/test/plugins/browser_private_clicktoplay.js
+++ b/browser/base/content/test/plugins/browser_private_clicktoplay.js
@@ -21,18 +21,17 @@ function finishTest() {
 }
 
 let createPrivateWindow = async function createPrivateWindow(url) {
   gPrivateWindow = await BrowserTestUtils.openNewBrowserWindow({private: true});
   ok(!!gPrivateWindow, "should have created a private window.");
   gPrivateBrowser = gPrivateWindow.getBrowser().selectedBrowser;
 
   BrowserTestUtils.loadURI(gPrivateBrowser, url);
-  await BrowserTestUtils.browserLoaded(gPrivateBrowser, false, url);
-  info("loaded " + url);
+  await BrowserTestUtils.browserLoaded(gPrivateBrowser);
 };
 
 add_task(async function test() {
   registerCleanupFunction(function() {
     clearAllPluginPermissions();
     getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_ENABLED;
     getTestPlugin("Second Test Plug-in").enabledState = Ci.nsIPluginTag.STATE_ENABLED;
   });
--- a/browser/base/content/test/sidebar/browser_sidebar_adopt.js
+++ b/browser/base/content/test/sidebar/browser_sidebar_adopt.js
@@ -14,21 +14,21 @@ function failIfSidebarFocusedFires() {
 }
 
 add_task(async function testAdoptedTwoWindows() {
   // First open a new window, show the sidebar in that window, and close it.
   // Then, open another new window and confirm that the sidebar is closed since it is
   // being adopted from the main window which doesn't have a shown sidebar. See Bug 1407737.
   info("Ensure that sidebar state is adopted only from the opener");
 
-  let win1 = await BrowserTestUtils.openNewBrowserWindow();
+  let win1 = await BrowserTestUtils.openNewBrowserWindow({opener: window});
   await win1.SidebarUI.show("viewBookmarksSidebar");
   await BrowserTestUtils.closeWindow(win1);
 
-  let win2 = await BrowserTestUtils.openNewBrowserWindow();
+  let win2 = await BrowserTestUtils.openNewBrowserWindow({opener: window});
   ok(!win2.document.getElementById("sidebar-button").hasAttribute("checked"), "Sidebar button isn't checked");
   ok(!win2.SidebarUI.isOpen, "Sidebar is closed");
   await BrowserTestUtils.closeWindow(win2);
 });
 
 add_task(async function testEventsReceivedInMainWindow() {
   info("Opening the sidebar and expecting both SidebarShown and SidebarFocused events");
 
@@ -41,17 +41,17 @@ add_task(async function testEventsReceiv
 
   ok(true, "SidebarShown and SidebarFocused events fired on a new window");
 });
 
 add_task(async function testEventReceivedInNewWindow() {
   info("Opening a new window and expecting the SidebarFocused event to not fire");
 
   let promiseNewWindow = BrowserTestUtils.waitForNewWindow();
-  BrowserTestUtils.openNewBrowserWindow();
+  BrowserTestUtils.openNewBrowserWindow({opener: window});
   let win = await promiseNewWindow;
 
   let adoptedShown = BrowserTestUtils.waitForEvent(win, "SidebarShown");
   win.addEventListener("SidebarFocused", failIfSidebarFocusedFires);
 
   registerCleanupFunction(async function() {
     win.removeEventListener("SidebarFocused", failIfSidebarFocusedFires);
     await BrowserTestUtils.closeWindow(win);
--- a/browser/components/customizableui/test/browser_editcontrols_update.js
+++ b/browser/components/customizableui/test/browser_editcontrols_update.js
@@ -197,21 +197,16 @@ add_task(async function finish() {
 
 // Test updating in the initial state when the edit-controls are on the panel but
 // have not yet been created. This needs to be done in a new window to ensure that
 // other tests haven't opened the panel.
 add_task(async function test_initial_state() {
   let testWindow = await BrowserTestUtils.openNewBrowserWindow();
   await SimpleTest.promiseFocus(testWindow);
 
-  // For focusing the URL bar to have an effect, we need to ensure the URL bar isn't
-  // initially focused:
-  testWindow.gBrowser.selectedTab.focus();
-  await TestUtils.waitForCondition(() => !testWindow.gURLBar.focused);
-
   let overridePromise = expectCommandUpdate(isMac, testWindow);
 
   testWindow.gURLBar.focus();
   testWindow.gURLBar.value = "test";
 
   await overridePromise;
 
   // Commands won't update when no edit UI is present. They default to being
--- a/browser/components/customizableui/test/browser_sidebar_toggle.js
+++ b/browser/components/customizableui/test/browser_sidebar_toggle.js
@@ -37,15 +37,15 @@ add_task(async function() {
   is(SidebarUI.currentID, "viewBookmarksSidebar", "Default sidebar selected");
   await SidebarUI.show("viewHistorySidebar");
 
   await hideSidebar();
   await showSidebar();
   is(SidebarUI.currentID, "viewHistorySidebar", "Selected sidebar remembered");
 
   await hideSidebar();
-  let otherWin = await BrowserTestUtils.openNewBrowserWindow();
+  let otherWin = await BrowserTestUtils.openNewBrowserWindow({opener: window});
   await showSidebar(otherWin);
   is(otherWin.SidebarUI.currentID, "viewHistorySidebar", "Selected sidebar remembered across windows");
   await hideSidebar(otherWin);
 
   await BrowserTestUtils.closeWindow(otherWin);
 });
--- a/browser/components/extensions/test/browser/browser_ext_sidebarAction_windows.js
+++ b/browser/components/extensions/test/browser/browser_ext_sidebarAction_windows.js
@@ -43,17 +43,17 @@ add_task(async function sidebar_windows(
   ok(elements.length > 0, "have a menuitem");
   let style = elements[0].getAttribute("style");
   ok(style.includes("webextension-menuitem-image"), "this menu has style");
 
   let secondSidebar = extension.awaitMessage("sidebar");
 
   // SidebarUI relies on window.opener being set, which is normal behavior when
   // using menu or key commands to open a new browser window.
-  let win = await BrowserTestUtils.openNewBrowserWindow();
+  let win = await BrowserTestUtils.openNewBrowserWindow({opener: window});
 
   await secondSidebar;
   ok(!win.document.getElementById("sidebar-box").hidden, "sidebar box is visible in second window");
   // Check that the menuitem has our image styling.
   elements = win.document.getElementsByClassName("webextension-menuitem");
   ok(elements.length > 0, "have a menuitem");
   style = elements[0].getAttribute("style");
   ok(style.includes("webextension-menuitem-image"), "this menu has style");
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_about.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_about.js
@@ -8,17 +8,17 @@ const CB_UI_ENABLED_PREF = "browser.cont
 
 /**
  * Opens a new private window and loads "about:privatebrowsing" there.
  */
 async function openAboutPrivateBrowsing() {
   let win = await BrowserTestUtils.openNewBrowserWindow({ private: true });
   let tab = win.gBrowser.selectedBrowser;
   tab.loadURI("about:privatebrowsing");
-  await BrowserTestUtils.browserLoaded(tab, false, "about:privatebrowsing");
+  await BrowserTestUtils.browserLoaded(tab);
   return { win, tab };
 }
 
 /**
  * Clicks the given link and checks this opens a new tab with the given URI.
  */
 async function testLinkOpensTab({ win, tab, elementId, expectedUrl }) {
   let newTabPromise = BrowserTestUtils.waitForNewTab(win.gBrowser, expectedUrl);
--- a/browser/components/sessionstore/test/browser_394759_perwindowpb.js
+++ b/browser/components/sessionstore/test/browser_394759_perwindowpb.js
@@ -12,17 +12,18 @@ const TESTS = [
     key: "bug 394759 PB",
     value: "uniq" + r() },
 ];
 
 function promiseTestOpenCloseWindow(aIsPrivate, aTest) {
   return (async function() {
     let win = await BrowserTestUtils.openNewBrowserWindow({ "private": aIsPrivate });
     win.gBrowser.selectedBrowser.loadURI(aTest.url);
-    await promiseBrowserLoaded(win.gBrowser.selectedBrowser, true, aTest.url);
+    await promiseBrowserLoaded(win.gBrowser.selectedBrowser);
+    await Promise.resolve();
     // Mark the window with some unique data to be restored later on.
     ss.setWindowValue(win, aTest.key, aTest.value);
     await TabStateFlusher.flushWindow(win);
     // Close.
     await BrowserTestUtils.closeWindow(win);
   })();
 }
 
--- a/dom/tests/browser/browser_bug1236512.js
+++ b/dom/tests/browser/browser_bug1236512.js
@@ -38,26 +38,22 @@ async function waitContentVisibilityChan
 /**
  * This test is to test the visibility state will change to "hidden" when browser
  * window is fully covered by another non-translucent application. Note that we
  * only support this on Mac for now, other platforms don't support reporting
  * occlusion state.
  */
 add_task(async function() {
   info("creating test window");
-  let winTest = await BrowserTestUtils.openNewBrowserWindow();
   // Specify the width, height, left and top, so that the new window can be
   // fully covered by "window".
-  let resizePromise = BrowserTestUtils.waitForEvent(winTest, "resize", false, e => {
-    return winTest.innerHeight <= 500 && winTest.innerWidth <= 500;
-  });
-  winTest.moveTo(200, 200);
-  winTest.resizeTo(500, 500);
-  await resizePromise;
-
+  let winTest = await BrowserTestUtils.openNewBrowserWindow({ width: 500,
+                                                              height: 500,
+                                                              left: 200,
+                                                              top: 200 });
   let browserTest = winTest.gBrowser;
 
   info(`loading test page: ${testPageURL}`);
   browserTest.selectedBrowser.loadURI(testPageURL);
   await BrowserTestUtils.browserLoaded(browserTest.selectedBrowser);
 
   info("test init visibility state");
   await testContentVisibilityState(false /* isHidden */, browserTest);
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -20,19 +20,16 @@ var EXPORTED_SYMBOLS = [
 ];
 
 ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://testing-common/TestUtils.jsm");
 ChromeUtils.import("resource://testing-common/ContentTask.jsm");
 
-ChromeUtils.defineModuleGetter(this, "BrowserWindowTracker",
-  "resource:///modules/BrowserWindowTracker.jsm");
-
 Services
   .mm
   .loadFrameScript(
     "chrome://mochikit/content/tests/BrowserTestUtils/content-utils.js", true);
 
 ChromeUtils.defineModuleGetter(this, "E10SUtils",
   "resource://gre/modules/E10SUtils.jsm");
 
@@ -699,29 +696,71 @@ var BrowserTestUtils = {
           resolve(subject.QueryInterface(Ci.nsIDOMWindow));
         }
       }
       Services.ww.registerNotification(observer);
     });
   },
 
   /**
-   * Open a new browser window from an existing one.
-   * This relies on OpenBrowserWindow in browser.js, and waits for the window
-   * to be completely loaded before resolving.
-   *
+   * @param {Object} options
+   *        {
+   *          private: A boolean indicating if the window should be
+   *                   private
+   *          remote:  A boolean indicating if the window should run
+   *                   remote browser tabs or not. If omitted, the window
+   *                   will choose the profile default state.
+   *          width: Desired width of window
+   *          height: Desired height of window
+   *        }
    * @return {Promise}
    *         Resolves with the new window once it is loaded.
    */
   async openNewBrowserWindow(options = {}) {
-    let currentWin = BrowserWindowTracker.getTopWindow({private: false});
-    if (!currentWin) {
-      throw new Error("Can't open a new browser window from this helper if no non-private window is open.");
+    let argString = Cc["@mozilla.org/supports-string;1"].
+                    createInstance(Ci.nsISupportsString);
+    argString.data = "";
+    let features = "chrome,dialog=no,all";
+    let opener = null;
+
+    if (options.opener) {
+      opener = options.opener;
+    }
+
+    if (options.private) {
+      features += ",private";
+    }
+
+    if (options.width) {
+      features += ",width=" + options.width;
+    }
+    if (options.height) {
+      features += ",height=" + options.height;
     }
-    let win = currentWin.OpenBrowserWindow(options);
+
+    if (options.left) {
+      features += ",left=" + options.left;
+    }
+
+    if (options.top) {
+      features += ",top=" + options.top;
+    }
+
+    if (options.hasOwnProperty("remote")) {
+      let remoteState = options.remote ? "remote" : "non-remote";
+      features += `,${remoteState}`;
+    }
+
+    if (options.url) {
+      argString.data = options.url;
+    }
+
+    let win = Services.ww.openWindow(
+      opener, AppConstants.BROWSER_CHROME_URL, "_blank",
+      features, argString);
 
     // Wait for browser-delayed-startup-finished notification, it indicates
     // that the window has loaded completely and is ready to be used for
     // testing.
     let startupPromise =
       TestUtils.topicObserved("browser-delayed-startup-finished",
                               subject => subject == win).then(() => win);