commit be62884d661cc13cba783c7dd3f0b0bde748454e
parent c520a9586aaeeb63a4d63977e30f96654f969a32
Author: agoloman <agoloman@mozilla.com>
Date: Wed, 24 Dec 2025 13:17:47 +0200
Revert "Bug 1891028 - [remote] Wait for "browser-delayed-startup-finished" when opening a new browser window. r=Sasha" for causing wpt failures.
This reverts commit b20d5047f4186c827d9617043661895454991039.
Diffstat:
4 files changed, 49 insertions(+), 141 deletions(-)
diff --git a/remote/marionette/driver.sys.mjs b/remote/marionette/driver.sys.mjs
@@ -678,9 +678,8 @@ GeckoDriver.prototype.newSession = async function (cmd) {
lazy.logger.debug(`Waiting for initial application window`);
await lazy.Marionette.browserStartupFinished;
- // This call includes a fallback to "mail:3pane" as well.
- const appWin = Services.wm.getMostRecentBrowserWindow();
- await lazy.windowManager.waitForChromeWindowLoaded(appWin);
+ const appWin =
+ await lazy.windowManager.waitForInitialApplicationWindowLoaded();
if (lazy.MarionettePrefs.clickToStart) {
Services.prompt.alert(
diff --git a/remote/shared/WindowManager.sys.mjs b/remote/shared/WindowManager.sys.mjs
@@ -2,8 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
-
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
@@ -339,12 +337,8 @@ class WindowManager {
* @param {string=} options.userContextId
* The id of the user context which should own the initial tab of the new
* window.
- *
- * @returns {Promise<ChromeWindow>}
+ * @returns {Promise}
* A promise resolving to the newly created chrome window.
- *
- * @throws {UnsupportedOperationError}
- * When opening a new browser window is not supported.
*/
async openBrowserWindow(options = {}) {
let {
@@ -397,10 +391,7 @@ class WindowManager {
await this.focusWindow(openerWindow);
}
- const chromeWindow = browser.ownerGlobal;
- await this.waitForChromeWindowLoaded(chromeWindow);
-
- return chromeWindow;
+ return browser.ownerGlobal;
}
default:
@@ -479,32 +470,38 @@ class WindowManager {
}
/**
- * Wait until the browser window is initialized and loaded.
- *
- * @param {ChromeWindow} window
- * The chrome window to check for completed loading.
+ * Wait until the initial application window has been opened and loaded.
*
- * @returns {Promise}
- * A promise that resolves when the chrome window finished loading.
+ * @returns {Promise<WindowProxy>}
+ * A promise that resolved to the application window.
*/
- async waitForChromeWindowLoaded(window) {
- const loaded =
- window.document.readyState === "complete" &&
- !window.document.isUncommittedInitialDocument;
+ waitForInitialApplicationWindowLoaded() {
+ return new lazy.TimedPromise(
+ async resolve => {
+ // This call includes a fallback to "mail:3pane" as well.
+ const win = Services.wm.getMostRecentBrowserWindow();
+
+ const windowLoaded = lazy.waitForObserverTopic(
+ "browser-delayed-startup-finished",
+ {
+ checkFn: subject => (win !== null ? subject == win : true),
+ }
+ );
- if (!loaded) {
- await new lazy.EventPromise(window, "load");
- }
+ // The current window has already been finished loading.
+ if (win && win.document.readyState == "complete") {
+ resolve(win);
+ return;
+ }
- if (
- window.document.documentURI === AppConstants.BROWSER_CHROME_URL &&
- !(window.gBrowserInit && window.gBrowserInit.delayedStartupFinished)
- ) {
- // If it's a browser window wait for it to be fully initialized.
- await lazy.waitForObserverTopic("browser-delayed-startup-finished", {
- checkFn: subject => subject === window,
- });
- }
+ // Wait for the next browser/mail window to open and finished loading.
+ const { subject } = await windowLoaded;
+ resolve(subject);
+ },
+ {
+ errorMessage: "No applicable application window found",
+ }
+ );
}
#setChromeWindowForBrowsingContext(context) {
diff --git a/remote/shared/test/browser/browser_WindowManager.js b/remote/shared/test/browser/browser_WindowManager.js
@@ -328,96 +328,3 @@ add_task(async function test_getWindowById() {
windowManager.destroy();
}
});
-
-add_task(async function test_waitForChromeWindowLoaded_newBrowserWindow() {
- const win = Services.ww.openWindow(
- null,
- AppConstants.BROWSER_CHROME_URL,
- "_blank",
- "chrome,all,dialog=no",
- null
- );
-
- try {
- ok(
- !win.gBrowserInit?.delayedStartupFinished,
- "Browser window not finished delayed startup"
- );
-
- await windowManager.waitForChromeWindowLoaded(win);
-
- ok(
- win.gBrowserInit.delayedStartupFinished,
- "Browser window finished delayed startup"
- );
- is(
- win.document.readyState,
- "complete",
- "Window document is in complete state"
- );
- ok(
- !win.document.isUncommittedInitialDocument,
- "Window document is not an uncommitted initial document"
- );
- } finally {
- await BrowserTestUtils.closeWindow(win);
- }
-});
-
-add_task(async function test_waitForChromeWindowLoaded_alreadyLoadedWindow() {
- const win = await BrowserTestUtils.openNewBrowserWindow();
-
- try {
- ok(
- win.gBrowserInit.delayedStartupFinished,
- "Browser window is already fully loaded"
- );
-
- await windowManager.waitForChromeWindowLoaded(win);
-
- is(
- win.document.readyState,
- "complete",
- "Window document is in complete state"
- );
- ok(
- !win.document.isUncommittedInitialDocument,
- "Window document is not an uncommitted initial document"
- );
- } finally {
- await BrowserTestUtils.closeWindow(win);
- }
-});
-
-add_task(
- async function test_waitForChromeWindowLoaded_nonBrowserChromeWindow() {
- const win = Services.ww.openWindow(
- gBrowser.ownerGlobal,
- "chrome://browser/content/pageinfo/pageInfo.xhtml",
- "_blank",
- "chrome,dialog=no,all",
- null
- );
-
- try {
- await windowManager.waitForChromeWindowLoaded(win);
-
- isnot(
- win.document.documentURI,
- AppConstants.BROWSER_CHROME_URL,
- "Window is not a browser window"
- );
- is(
- win.document.readyState,
- "complete",
- "Window document is in complete state"
- );
- ok(
- !win.document.isUncommittedInitialDocument,
- "Window document is not an uncommitted initial document"
- );
- } finally {
- await BrowserTestUtils.closeWindow(win);
- }
- }
-);
diff --git a/testing/marionette/harness/marionette_harness/runner/mixins/window_manager.py b/testing/marionette/harness/marionette_harness/runner/mixins/window_manager.py
@@ -96,22 +96,27 @@ class WindowManagerMixin(object):
const { NavigableManager } = ChromeUtils.importESModule(
"chrome://remote/content/shared/NavigableManager.sys.mjs"
);
- const { windowManager } = ChromeUtils.importESModule(
- "chrome://remote/content/shared/WindowManager.sys.mjs"
- );
- const browsingContext =
- NavigableManager.getBrowsingContextById(handle);
- const window =
- windowManager.getChromeWindowForBrowsingContext(browsingContext);
+ const isLoaded = window =>
+ window?.document.readyState === "complete" &&
+ !window?.document.isUncommittedInitialDocument;
- (async function() {
- if (window) {
- await windowManager.waitForChromeWindowLoaded(window);
- }
+ const browsingContext = NavigableManager.getBrowsingContextById(handle);
+ const targetWindow = browsingContext?.window;
+ if (isLoaded(targetWindow)) {
resolve();
- })();
+ } else {
+ const onLoad = () => {
+ if (isLoaded(targetWindow)) {
+ targetWindow.removeEventListener("load", onLoad);
+ resolve();
+ } else {
+ dump(`** Target window not loaded yet. Waiting for the next "load" event\n`);
+ }
+ };
+ targetWindow.addEventListener("load", onLoad);
+ }
""",
script_args=[handle],
)