diff --git a/remote/shared/RecommendedPreferences.sys.mjs b/remote/shared/RecommendedPreferences.sys.mjs index 0ebee8e41c8d..990c12153113 100644 --- a/remote/shared/RecommendedPreferences.sys.mjs +++ b/remote/shared/RecommendedPreferences.sys.mjs @@ -145,9 +145,6 @@ const COMMON_PREFERENCES = new Map([ // Do not redirect user when a milstone upgrade of Firefox is detected ["browser.startup.homepage_override.mstone", "ignore"], - // Unload the previously selected tab immediately - ["browser.tabs.remote.unloadDelayMs", 0], - // Don't unload tabs when available memory is running low ["browser.tabs.unloadOnLowMemory", false], diff --git a/remote/test/puppeteer/test/TestExpectations.json b/remote/test/puppeteer/test/TestExpectations.json index 5baac3bfc870..f19c2f72e0a1 100644 --- a/remote/test/puppeteer/test/TestExpectations.json +++ b/remote/test/puppeteer/test/TestExpectations.json @@ -885,7 +885,7 @@ { "testIdPattern": "[page.spec] Page Page.bringToFront should work", "platforms": ["darwin", "linux", "win32"], - "parameters": ["chrome", "webDriverBiDi"], + "parameters": ["webDriverBiDi"], "expectations": ["FAIL"] }, { diff --git a/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs b/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs index 4e93a285705e..bc600e89cdf2 100644 --- a/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs +++ b/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs @@ -232,25 +232,11 @@ class BrowsingContextModule extends Module { ); } - const targetTab = lazy.TabManager.getTabForBrowsingContext(context); - const targetWindow = lazy.TabManager.getWindowForTab(targetTab); - const selectedTab = lazy.TabManager.getTabBrowser(targetWindow).selectedTab; + const tab = lazy.TabManager.getTabForBrowsingContext(context); + const window = lazy.TabManager.getWindowForTab(tab); - const activated = [ - lazy.windowManager.focusWindow(targetWindow), - lazy.TabManager.selectTab(targetTab), - ]; - - if (targetTab !== selectedTab) { - // We need to wait until the "document.visibilityState" of the currently - // selected tab in the target window is marked as "hidden". - const selectedBrowser = lazy.TabManager.getBrowserForTab(selectedTab); - activated.push( - this.#waitForVisibilityChange(selectedBrowser.browsingContext) - ); - } - - await Promise.all(activated); + await lazy.windowManager.focusWindow(window); + await lazy.TabManager.selectTab(tab); } /** @@ -561,39 +547,17 @@ class BrowsingContextModule extends Module { ); } - // 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 promises = []; - - if (!background) { - // 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". - 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); + const tab = await lazy.TabManager.addTab({ + focus: !background, + referenceTab, + userContextId: userContext, + }); browser = lazy.TabManager.getBrowserForTab(tab); } @@ -1954,21 +1918,6 @@ 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 */ diff --git a/remote/webdriver-bidi/modules/windowglobal/browsingContext.sys.mjs b/remote/webdriver-bidi/modules/windowglobal/browsingContext.sys.mjs index adf821601dcf..8421445d2ce4 100644 --- a/remote/webdriver-bidi/modules/windowglobal/browsingContext.sys.mjs +++ b/remote/webdriver-bidi/modules/windowglobal/browsingContext.sys.mjs @@ -17,7 +17,6 @@ ChromeUtils.defineESModuleGetters(lazy, { "chrome://remote/content/webdriver-bidi/modules/root/browsingContext.sys.mjs", OriginType: "chrome://remote/content/webdriver-bidi/modules/root/browsingContext.sys.mjs", - PollPromise: "chrome://remote/content/shared/Sync.sys.mjs", }); const DOCUMENT_FRAGMENT_NODE = 11; @@ -357,29 +356,6 @@ class BrowsingContextModule extends WindowGlobalBiDiModule { }); } - /** - * Waits until the visibility state of the document has the expected value. - * - * @param {object} options - * @param {number} options.value - * Expected value of the visibility state. - * - * @returns {Promise} - * Promise that resolves when the visibility state has the expected value. - */ - async _awaitVisibilityState(options) { - const { value } = options; - const win = this.messageHandler.window; - - await lazy.PollPromise((resolve, reject) => { - if (win.document.visibilityState === value) { - resolve(); - } else { - reject(); - } - }); - } - _getBaseURL() { return this.messageHandler.window.document.baseURI; } diff --git a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/__init__.py b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/__init__.py index 51b3c64b42d3..dbacac8cf897 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/__init__.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/__init__.py @@ -53,13 +53,6 @@ def assert_browsing_context( assert info["userContext"] == user_context -async def assert_document_status(bidi_session, context, visible, focused): - state = "visible" if visible else "hidden" - - assert await get_visibility_state(bidi_session, context) == state - assert await get_document_focus(bidi_session, context) is focused - - def assert_navigation_info(event, expected_navigation_info): recursive_compare( { diff --git a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/activate/__init__.py b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/activate/__init__.py index 86f9ace3ee2d..5d0b52a5ac44 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/activate/__init__.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/activate/__init__.py @@ -3,7 +3,7 @@ from typing import Any, Mapping from webdriver.bidi.modules.script import ContextTarget -async def is_element_focused(bidi_session, context: Mapping[str, Any], selector: str) -> bool: +async def is_selector_focused(bidi_session, context: Mapping[str, Any], selector: str) -> bool: result = await bidi_session.script.call_function( function_declaration="""(selector) => { return document.querySelector(selector) === document.activeElement; @@ -13,5 +13,4 @@ async def is_element_focused(bidi_session, context: Mapping[str, Any], selector: ], target=ContextTarget(context["context"]), await_promise=False) - return result["value"] diff --git a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/activate/activate.py b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/activate/activate.py index 8f782be2b3a4..0abbbbac38e3 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/activate/activate.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/activate/activate.py @@ -1,62 +1,95 @@ import pytest from webdriver.bidi.modules.script import ContextTarget -from . import is_element_focused -from .. import assert_document_status +from . import is_selector_focused +from .. import get_document_focus, get_visibility_state pytestmark = pytest.mark.asyncio -@pytest.mark.parametrize("type_hint", ["tab", "window"]) -async def test_switch_between_contexts(bidi_session, top_context, type_hint): - is_window = type_hint == "window" - - new_context = await bidi_session.browsing_context.create(type_hint=type_hint) +async def test_activate(bidi_session, new_tab, top_context): + assert await get_document_focus(bidi_session, top_context) is False await bidi_session.browsing_context.activate(context=top_context["context"]) - await assert_document_status(bidi_session, top_context, True, True) - await assert_document_status(bidi_session, new_context, is_window, False) - await bidi_session.browsing_context.activate(context=new_context["context"]) - await assert_document_status(bidi_session, top_context, is_window, False) - await assert_document_status(bidi_session, new_context, True, True) + assert await get_visibility_state(bidi_session, top_context) == 'visible' + assert await get_document_focus(bidi_session, top_context) is True -async def test_keeps_element_focused(bidi_session, inline, new_tab, top_context): - await bidi_session.browsing_context.navigate( - context=new_tab["context"], - url=inline(""), - wait="complete") +async def test_deactivates_other_contexts(bidi_session, new_tab, top_context): + await bidi_session.browsing_context.activate(context=top_context["context"]) + + assert await get_visibility_state(bidi_session, top_context) == 'visible' + assert await get_document_focus(bidi_session, top_context) is True + + assert await get_document_focus(bidi_session, new_tab) is False + + await bidi_session.browsing_context.activate(context=new_tab["context"]) + + assert await get_document_focus(bidi_session, top_context) is False + + assert await get_visibility_state(bidi_session, new_tab) == 'visible' + assert await get_document_focus(bidi_session, new_tab) is True + + +async def test_keeps_focused_area(bidi_session, inline, new_tab, top_context): + await bidi_session.browsing_context.activate(context=new_tab["context"]) + assert await get_visibility_state(bidi_session, new_tab) == 'visible' + assert await get_document_focus(bidi_session, new_tab) is True + + await bidi_session.browsing_context.navigate(context=new_tab["context"], + url=inline(""), + wait="complete") await bidi_session.script.evaluate( expression="""document.querySelector("input").focus()""", target=ContextTarget(new_tab["context"]), await_promise=False) - assert await is_element_focused(bidi_session, new_tab, "input") + assert await is_selector_focused(bidi_session, new_tab, "input") await bidi_session.browsing_context.activate(context=top_context["context"]) - assert await is_element_focused(bidi_session, new_tab, "input") + assert await get_document_focus(bidi_session, new_tab) is False + assert await is_selector_focused(bidi_session, new_tab, "input") await bidi_session.browsing_context.activate(context=new_tab["context"]) - assert await is_element_focused(bidi_session, new_tab, "input") + assert await get_visibility_state(bidi_session, new_tab) == 'visible' + assert await get_document_focus(bidi_session, new_tab) is True + assert await is_selector_focused(bidi_session, new_tab, "input") -async def test_multiple_activation(bidi_session, inline, new_tab): - await bidi_session.browsing_context.navigate( - context=new_tab["context"], - url=inline( - ""), - wait="complete") +async def test_double_activation(bidi_session, inline, new_tab): + await bidi_session.browsing_context.activate(context=new_tab["context"]) + assert await get_visibility_state(bidi_session, new_tab) == 'visible' + assert await get_document_focus(bidi_session, new_tab) is True - await assert_document_status(bidi_session, new_tab, True, True) - assert await is_element_focused(bidi_session, new_tab, "input") + await bidi_session.browsing_context.navigate(context=new_tab["context"], + url=inline(""), + wait="complete") + assert await is_selector_focused(bidi_session, new_tab, "input") await bidi_session.browsing_context.activate(context=new_tab["context"]) - await assert_document_status(bidi_session, new_tab, True, True) - assert await is_element_focused(bidi_session, new_tab, "input") + assert await get_visibility_state(bidi_session, new_tab) == 'visible' + assert await get_document_focus(bidi_session, new_tab) is True + assert await is_selector_focused(bidi_session, new_tab, "input") # Activate again. await bidi_session.browsing_context.activate(context=new_tab["context"]) - await assert_document_status(bidi_session, new_tab, True, True) - assert await is_element_focused(bidi_session, new_tab, "input") + assert await get_visibility_state(bidi_session, new_tab) == 'visible' + assert await get_document_focus(bidi_session, new_tab) is True + assert await is_selector_focused(bidi_session, new_tab, "input") + + +async def test_activate_window(bidi_session): + new_window_1 = await bidi_session.browsing_context.create(type_hint="window") + new_window_2 = await bidi_session.browsing_context.create(type_hint="window") + + assert await get_visibility_state(bidi_session, new_window_2) == 'visible' + assert await get_document_focus(bidi_session, new_window_2) is True + + assert await get_document_focus(bidi_session, new_window_1) is False + + await bidi_session.browsing_context.activate(context=new_window_1["context"]) + + assert await get_visibility_state(bidi_session, new_window_1) == 'visible' + assert await get_document_focus(bidi_session, new_window_1) is True diff --git a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/create/type.py b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/create/type.py index 543420a9ecd3..55ce7b44282a 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/create/type.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/create/type.py @@ -1,27 +1,19 @@ import pytest +from .. import assert_browsing_context from webdriver.bidi.modules.script import ContextTarget -from .. import assert_browsing_context, assert_document_status - pytestmark = pytest.mark.asyncio -@pytest.mark.parametrize("type_hint", ["tab", "window"]) -async def test_type(bidi_session, top_context, type_hint): - is_window = type_hint == "window" - +@pytest.mark.parametrize("value", ["tab", "window"]) +async def test_type(bidi_session, value): contexts = await bidi_session.browsing_context.get_tree(max_depth=0) assert len(contexts) == 1 - await assert_document_status(bidi_session, top_context, True, True) - - new_context = await bidi_session.browsing_context.create(type_hint=type_hint) + new_context = await bidi_session.browsing_context.create(type_hint=value) assert contexts[0]["context"] != new_context["context"] - await assert_document_status(bidi_session, new_context, True, True) - await assert_document_status(bidi_session, top_context, is_window, False) - # Check there is an additional browsing context contexts = await bidi_session.browsing_context.get_tree(max_depth=0) assert len(contexts) == 2