Bug 1486824 - change BrowserTestUtils to just call OpenBrowserWindow so it does the same thing as opening a window normally, r=mconley,nhnt11

Differential Revision: https://phabricator.services.mozilla.com/D4466

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Gijs Kruitbosch 2018-08-29 17:58:25 +00:00
Родитель a82f668e23
Коммит a8e2b8e702
12 изменённых файлов: 74 добавлений и 88 удалений

Просмотреть файл

@ -14,28 +14,27 @@ function caretMoveChecker(target, caretOffset) {
}
async function checkURLBarCaretEvents() {
let url = "about:mozilla";
const kURL = "about:mozilla";
let newWin = await BrowserTestUtils.openNewBrowserWindow();
newWin.gBrowser.selectedBrowser.loadURI(kURL);
let onDocLoad = waitForEvent(
await waitForEvent(
EVENT_DOCUMENT_LOAD_COMPLETE,
event => {
try {
return event.accessible.QueryInterface(nsIAccessibleDocument).URL == url;
return event.accessible.QueryInterface(nsIAccessibleDocument).URL == kURL;
} catch (e) {
return false;
}
}
);
let [ newWin ] = await Promise.all([
BrowserTestUtils.openNewBrowserWindow({ url }),
onDocLoad
]);
info("Loaded " + kURL);
let urlbarInputEl = newWin.document.getElementById("urlbar").inputField;
let urlbarInput = getAccessible(urlbarInputEl, [ nsIAccessibleText ]);
let onCaretMove = waitForEvents([
[ EVENT_TEXT_CARET_MOVED, caretMoveChecker(urlbarInput, url.length) ],
[ EVENT_TEXT_CARET_MOVED, caretMoveChecker(urlbarInput, kURL.length) ],
[ EVENT_FOCUS, urlbarInput ]
]);

Просмотреть файл

@ -113,6 +113,12 @@ 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
@ -136,6 +142,12 @@ 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;

Просмотреть файл

@ -4281,6 +4281,19 @@ 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);

Просмотреть файл

@ -20,22 +20,13 @@ 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 from BrowserWindowTracker.getTopWindow in an attempt to
// mask its presence.
// exclude it using an attribute to mask its presence.
window.CaptivePortalWatcher.uninit();
let getTopWindowCopy = BrowserWindowTracker.getTopWindow;
let defaultWindow = window;
BrowserWindowTracker.getTopWindow = () => {
let win = getTopWindowCopy();
if (win == defaultWindow) {
return null;
}
return win;
};
window.document.documentElement.setAttribute("ignorecaptiveportal", "true");
registerCleanupFunction(function cleanUp() {
BrowserWindowTracker.getTopWindow = getTopWindowCopy;
window.CaptivePortalWatcher.init();
window.document.documentElement.removeAttribute("ignorecaptiveportal");
});
}

Просмотреть файл

@ -590,18 +590,24 @@ 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({ width: 400, height: 400 });
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;
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) {

Просмотреть файл

@ -26,7 +26,8 @@ let createPrivateWindow = async function createPrivateWindow(url) {
gPrivateBrowser = gPrivateWindow.getBrowser().selectedBrowser;
BrowserTestUtils.loadURI(gPrivateBrowser, url);
await BrowserTestUtils.browserLoaded(gPrivateBrowser);
await BrowserTestUtils.browserLoaded(gPrivateBrowser, false, url);
info("loaded " + url);
};
add_task(async function test() {

Просмотреть файл

@ -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({opener: window});
let win1 = await BrowserTestUtils.openNewBrowserWindow();
await win1.SidebarUI.show("viewBookmarksSidebar");
await BrowserTestUtils.closeWindow(win1);
let win2 = await BrowserTestUtils.openNewBrowserWindow({opener: window});
let win2 = await BrowserTestUtils.openNewBrowserWindow();
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({opener: window});
BrowserTestUtils.openNewBrowserWindow();
let win = await promiseNewWindow;
let adoptedShown = BrowserTestUtils.waitForEvent(win, "SidebarShown");

Просмотреть файл

@ -42,7 +42,7 @@ add_task(async function() {
is(SidebarUI.currentID, "viewHistorySidebar", "Selected sidebar remembered");
await hideSidebar();
let otherWin = await BrowserTestUtils.openNewBrowserWindow({opener: window});
let otherWin = await BrowserTestUtils.openNewBrowserWindow();
await showSidebar(otherWin);
is(otherWin.SidebarUI.currentID, "viewHistorySidebar", "Selected sidebar remembered across windows");
await hideSidebar(otherWin);

Просмотреть файл

@ -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({opener: window});
let win = await BrowserTestUtils.openNewBrowserWindow();
await secondSidebar;
ok(!win.document.getElementById("sidebar-box").hidden, "sidebar box is visible in second window");

Просмотреть файл

@ -17,8 +17,7 @@ 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);
await Promise.resolve();
await promiseBrowserLoaded(win.gBrowser.selectedBrowser, true, aTest.url);
// Mark the window with some unique data to be restored later on.
ss.setWindowValue(win, aTest.key, aTest.value);
await TabStateFlusher.flushWindow(win);

Просмотреть файл

@ -43,12 +43,16 @@ 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 winTest = await BrowserTestUtils.openNewBrowserWindow({ width: 500,
height: 500,
left: 200,
top: 200 });
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 browserTest = winTest.gBrowser;
info(`loading test page: ${testPageURL}`);

Просмотреть файл

@ -25,6 +25,9 @@ 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(
@ -700,61 +703,19 @@ var BrowserTestUtils = {
},
/**
* @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
* }
* 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.
*
* @return {Promise}
* Resolves with the new window once it is loaded.
*/
async openNewBrowserWindow(options = {}) {
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 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.");
}
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);
let win = currentWin.OpenBrowserWindow(options);
// Wait for browser-delayed-startup-finished notification, it indicates
// that the window has loaded completely and is ready to be used for