diff --git a/accessible/tests/browser/events/browser_test_textcaret.js b/accessible/tests/browser/events/browser_test_textcaret.js index 8fb3f08925f7..a468dc0227b0 100644 --- a/accessible/tests/browser/events/browser_test_textcaret.js +++ b/accessible/tests/browser/events/browser_test_textcaret.js @@ -14,27 +14,28 @@ function caretMoveChecker(target, 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 ] ]); diff --git a/browser/base/content/browser-captivePortal.js b/browser/base/content/browser-captivePortal.js index b8bfca9cc05b..6de93c7f127d 100644 --- a/browser/base/content/browser-captivePortal.js +++ b/browser/base/content/browser-captivePortal.js @@ -113,12 +113,6 @@ var CaptivePortalWatcher = { } 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 @@ -142,12 +136,6 @@ var CaptivePortalWatcher = { } 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; diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index a8dd2cc3b731..eadab288e793 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -4290,19 +4290,6 @@ function toOpenWindowByType(inType, uri, features) { 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); diff --git a/browser/base/content/test/captivePortal/head.js b/browser/base/content/test/captivePortal/head.js index dab6cb1ce037..58a23c9770b0 100644 --- a/browser/base/content/test/captivePortal/head.js +++ b/browser/base/content/test/captivePortal/head.js @@ -20,13 +20,22 @@ async function setupPrefsAndRecentWindowBehavior() { // 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"); }); } diff --git a/browser/base/content/test/forms/browser_selectpopup.js b/browser/base/content/test/forms/browser_selectpopup.js index 12c14502b1f4..2adeb54d3848 100644 --- a/browser/base/content/test/forms/browser_selectpopup.js +++ b/browser/base/content/test/forms/browser_selectpopup.js @@ -590,24 +590,18 @@ add_task(async function test_large_popup() { // 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) { diff --git a/browser/base/content/test/plugins/browser_private_clicktoplay.js b/browser/base/content/test/plugins/browser_private_clicktoplay.js index f7b9fcfcccc4..b94d441bffaf 100644 --- a/browser/base/content/test/plugins/browser_private_clicktoplay.js +++ b/browser/base/content/test/plugins/browser_private_clicktoplay.js @@ -26,8 +26,7 @@ let createPrivateWindow = async function createPrivateWindow(url) { 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() { diff --git a/browser/base/content/test/sidebar/browser_sidebar_adopt.js b/browser/base/content/test/sidebar/browser_sidebar_adopt.js index c007c82b759a..93ffa5f7dcd1 100644 --- a/browser/base/content/test/sidebar/browser_sidebar_adopt.js +++ b/browser/base/content/test/sidebar/browser_sidebar_adopt.js @@ -19,11 +19,11 @@ add_task(async function testAdoptedTwoWindows() { // 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); @@ -46,7 +46,7 @@ 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"); diff --git a/browser/components/customizableui/test/browser_sidebar_toggle.js b/browser/components/customizableui/test/browser_sidebar_toggle.js index 163bfc38af49..18136102eab3 100644 --- a/browser/components/customizableui/test/browser_sidebar_toggle.js +++ b/browser/components/customizableui/test/browser_sidebar_toggle.js @@ -42,7 +42,7 @@ add_task(async function() { 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); diff --git a/browser/components/extensions/test/browser/browser_ext_sidebarAction_windows.js b/browser/components/extensions/test/browser/browser_ext_sidebarAction_windows.js index 5d6fe2629caf..4cc9a257f27b 100644 --- a/browser/components/extensions/test/browser/browser_ext_sidebarAction_windows.js +++ b/browser/components/extensions/test/browser/browser_ext_sidebarAction_windows.js @@ -48,7 +48,7 @@ add_task(async function sidebar_windows() { // 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"); diff --git a/browser/components/sessionstore/test/browser_394759_perwindowpb.js b/browser/components/sessionstore/test/browser_394759_perwindowpb.js index c58f6477ed2c..d03357e969ee 100644 --- a/browser/components/sessionstore/test/browser_394759_perwindowpb.js +++ b/browser/components/sessionstore/test/browser_394759_perwindowpb.js @@ -17,7 +17,8 @@ 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); diff --git a/dom/tests/browser/browser_bug1236512.js b/dom/tests/browser/browser_bug1236512.js index 939092a847bf..ba46d9d81c52 100644 --- a/dom/tests/browser/browser_bug1236512.js +++ b/dom/tests/browser/browser_bug1236512.js @@ -43,16 +43,12 @@ async function waitContentVisibilityChange(aIsHidden, aBrowser) { */ 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}`); diff --git a/layout/style/test/mochitest.ini b/layout/style/test/mochitest.ini index 94751d9907b6..32d74b419ec4 100644 --- a/layout/style/test/mochitest.ini +++ b/layout/style/test/mochitest.ini @@ -373,3 +373,4 @@ skip-if = toolkit == 'android' # TIMED_OUT for android [test_mql_event_listener_leaks.html] [test_non_matching_sheet_media.html] [test_use_counters.html] +skip-if = !nightly_build diff --git a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm index 7a5b0cff8018..94df22dceb2b 100644 --- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm +++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm @@ -25,9 +25,6 @@ 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( @@ -704,19 +701,61 @@ var BrowserTestUtils = { }, /** - * 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; } - let win = currentWin.OpenBrowserWindow(options); + + if (options.private) { + features += ",private"; + } + + if (options.width) { + features += ",width=" + options.width; + } + if (options.height) { + features += ",height=" + options.height; + } + + 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