summaryrefslogtreecommitdiffstats
path: root/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
commit40a355a42d4a9444dc753c04c6608dade2f06a23 (patch)
tree871fc667d2de662f171103ce5ec067014ef85e61 /remote/webdriver-bidi/modules/root/browsingContext.sys.mjs
parentAdding upstream version 124.0.1. (diff)
downloadfirefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz
firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/webdriver-bidi/modules/root/browsingContext.sys.mjs')
-rw-r--r--remote/webdriver-bidi/modules/root/browsingContext.sys.mjs80
1 files changed, 68 insertions, 12 deletions
diff --git a/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs b/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs
index bc600e89cd..f2a5d5e645 100644
--- a/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs
+++ b/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs
@@ -232,11 +232,27 @@ class BrowsingContextModule extends Module {
);
}
- const tab = lazy.TabManager.getTabForBrowsingContext(context);
- const window = lazy.TabManager.getWindowForTab(tab);
+ const targetTab = lazy.TabManager.getTabForBrowsingContext(context);
+ const targetWindow = lazy.TabManager.getWindowForTab(targetTab);
+ const selectedTab = lazy.TabManager.getTabBrowser(targetWindow).selectedTab;
+
+ const activated = [
+ lazy.windowManager.focusWindow(targetWindow),
+ lazy.TabManager.selectTab(targetTab),
+ ];
- await lazy.windowManager.focusWindow(window);
- await lazy.TabManager.selectTab(tab);
+ if (targetTab !== selectedTab && !lazy.AppInfo.isAndroid) {
+ // We need to wait until the "document.visibilityState" of the currently
+ // selected tab in the target window is marked as "hidden".
+ //
+ // Bug 1884142: It's not supported on Android for the TestRunner package.
+ const selectedBrowser = lazy.TabManager.getBrowserForTab(selectedTab);
+ activated.push(
+ this.#waitForVisibilityChange(selectedBrowser.browsingContext)
+ );
+ }
+
+ await Promise.all(activated);
}
/**
@@ -532,33 +548,58 @@ class BrowsingContextModule extends Module {
const type = lazy.AppInfo.isAndroid ? "tab" : typeHint;
switch (type) {
- case "window":
+ case "window": {
const newWindow = await lazy.windowManager.openBrowserWindow({
focus: !background,
userContextId: userContext,
});
browser = lazy.TabManager.getTabBrowser(newWindow).selectedBrowser;
break;
-
- case "tab":
+ }
+ case "tab": {
if (!lazy.TabManager.supportsTabs()) {
throw new lazy.error.UnsupportedOperationError(
`browsingContext.create with type "tab" not supported in ${lazy.AppInfo.name}`
);
}
+ // The window to open the new tab in.
+ let window = Services.wm.getMostRecentWindow(null);
+
let referenceTab;
if (referenceContext !== null) {
referenceTab =
lazy.TabManager.getTabForBrowsingContext(referenceContext);
+ window = lazy.TabManager.getWindowForTab(referenceTab);
}
- const tab = await lazy.TabManager.addTab({
- focus: !background,
- referenceTab,
- userContextId: userContext,
- });
+ const promises = [];
+
+ if (!background && !lazy.AppInfo.isAndroid) {
+ // When opening a new foreground tab we need to wait until the
+ // "document.visibilityState" of the currently selected tab in this
+ // window is marked as "hidden".
+ //
+ // Bug 1884142: It's not supported on Android for the TestRunner package.
+ const selectedTab = lazy.TabManager.getTabBrowser(window).selectedTab;
+ promises.push(
+ this.#waitForVisibilityChange(
+ lazy.TabManager.getBrowserForTab(selectedTab).browsingContext
+ )
+ );
+ }
+
+ promises.unshift(
+ lazy.TabManager.addTab({
+ focus: !background,
+ referenceTab,
+ userContextId: userContext,
+ })
+ );
+
+ const [tab] = await Promise.all(promises);
browser = lazy.TabManager.getBrowserForTab(tab);
+ }
}
await lazy.waitForInitialNavigationCompleted(
@@ -1918,6 +1959,21 @@ class BrowsingContextModule extends Module {
}
}
+ #waitForVisibilityChange(browsingContext) {
+ return this.messageHandler.forwardCommand({
+ moduleName: "browsingContext",
+ commandName: "_awaitVisibilityState",
+ destination: {
+ type: lazy.WindowGlobalMessageHandler.type,
+ id: browsingContext.id,
+ },
+ params: {
+ value: "hidden",
+ },
+ retryOnAbort: true,
+ });
+ }
+
/**
* Internal commands
*/