commit ce61ed0fc59347e8329d06ffe190515cf330b31e parent d47322285bb162314fd29e81a6b67581e20ec6d9 Author: Alexandra Borovova <aborovova@mozilla.com> Date: Fri, 31 Oct 2025 16:29:53 +0000 Bug 1997556 - [wdspec] Add a test for setting locale and timezone override at the same time. r=jdescottes Differential Revision: https://phabricator.services.mozilla.com/D270851 Diffstat:
8 files changed, 253 insertions(+), 210 deletions(-)
diff --git a/testing/web-platform/meta/webdriver/tests/bidi/emulation/combined/multiple_emulations.py.ini b/testing/web-platform/meta/webdriver/tests/bidi/emulation/combined/multiple_emulations.py.ini @@ -0,0 +1,5 @@ +[multiple_emulations.py] + [test_locale_and_timezone_for_user_context] + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1877953 + expected: + if os == "android": FAIL diff --git a/testing/web-platform/mozilla/tests/webdriver/bidi/emulation/set_locale_override/contexts.py b/testing/web-platform/mozilla/tests/webdriver/bidi/emulation/set_locale_override/contexts.py @@ -2,7 +2,7 @@ import pytest pytestmark = pytest.mark.asyncio -pytest_plugins = "tests.bidi.emulation.set_locale_override.conftest" +pytest_plugins = "tests.bidi.emulation.conftest" @pytest.mark.capabilities( diff --git a/testing/web-platform/mozilla/tests/webdriver/bidi/emulation/set_timezone_override/contexts.py b/testing/web-platform/mozilla/tests/webdriver/bidi/emulation/set_timezone_override/contexts.py @@ -2,7 +2,7 @@ import pytest pytestmark = pytest.mark.asyncio -pytest_plugins = "tests.bidi.emulation.set_timezone_override.conftest" +pytest_plugins = "tests.bidi.emulation.conftest" @pytest.mark.capabilities( diff --git a/testing/web-platform/tests/webdriver/tests/bidi/emulation/combined/__init__.py b/testing/web-platform/tests/webdriver/tests/bidi/emulation/combined/__init__.py diff --git a/testing/web-platform/tests/webdriver/tests/bidi/emulation/combined/multiple_emulations.py b/testing/web-platform/tests/webdriver/tests/bidi/emulation/combined/multiple_emulations.py @@ -0,0 +1,39 @@ +import pytest + +pytestmark = pytest.mark.asyncio + + +async def test_locale_and_timezone_for_user_context( + bidi_session, + create_user_context, + new_tab, + some_locale, + assert_locale_against_default, + assert_locale_against_value, + get_current_timezone, + default_timezone, + some_timezone, +): + user_context = await create_user_context() + + await assert_locale_against_default(new_tab) + assert await get_current_timezone(new_tab) == default_timezone + + # Set locale override. + await bidi_session.emulation.set_locale_override( + user_contexts=[user_context], locale=some_locale + ) + + # Set timezone override. + await bidi_session.emulation.set_timezone_override( + user_contexts=[user_context], timezone=some_timezone + ) + + # Create a new context in the user context. + context_in_user_context = await bidi_session.browsing_context.create( + user_context=user_context, type_hint="tab" + ) + + # Assert the locale and timezone is emulated in a new browsing context of the user context. + await assert_locale_against_value(some_locale, context_in_user_context) + assert await get_current_timezone(context_in_user_context) == some_timezone diff --git a/testing/web-platform/tests/webdriver/tests/bidi/emulation/conftest.py b/testing/web-platform/tests/webdriver/tests/bidi/emulation/conftest.py @@ -0,0 +1,207 @@ +import pytest +import pytest_asyncio + +from webdriver.bidi.modules.script import ContextTarget + +LOCALES = ["de-DE", "es-ES", "fr-FR", "it-IT"] +TIMEZONES = ["Asia/Yekaterinburg", "Europe/Berlin", "America/New_York", "Asia/Tokyo"] + + +@pytest_asyncio.fixture +async def get_current_locale(bidi_session): + async def get_current_locale(context, sandbox=None): + result = await bidi_session.script.evaluate( + expression="new Intl.DateTimeFormat().resolvedOptions().locale", + target=ContextTarget(context["context"], sandbox=sandbox), + await_promise=False, + ) + + return result["value"] + + return get_current_locale + + +@pytest_asyncio.fixture +async def default_locale(get_current_locale, top_context): + """ + Returns default locale. + """ + return await get_current_locale(top_context) + + +@pytest.fixture +def some_locale(default_locale): + """ + Returns some locale which is not equal to `default_locale`. + """ + for locale in LOCALES: + if locale != default_locale: + return locale + + raise Exception( + f"Unexpectedly could not find locale different from the default {default_locale}" + ) + + +@pytest.fixture +def another_locale(default_locale, some_locale): + """ + Returns some another locale which is not equal to `default_locale` nor to + `some_locale`. + """ + for locale in LOCALES: + if locale != default_locale and locale != some_locale: + return locale + + raise Exception( + f"Unexpectedly could not find locale different from the default {default_locale} and {some_locale}" + ) + + +@pytest_asyncio.fixture +async def get_current_navigator_language(bidi_session): + async def get_current_navigator_language(context, sandbox=None): + result = await bidi_session.script.evaluate( + expression="navigator.language", + target=ContextTarget(context["context"], sandbox=sandbox), + await_promise=False, + ) + + return result["value"] + + return get_current_navigator_language + + +@pytest_asyncio.fixture +async def default_navigator_language(get_current_navigator_language, top_context): + """Returns default navigator.language value.""" + return await get_current_navigator_language(top_context) + + +@pytest_asyncio.fixture +async def get_current_navigator_languages(bidi_session): + async def get_current_navigator_languages(context, sandbox=None): + result = await bidi_session.script.evaluate( + expression="navigator.languages", + target=ContextTarget(context["context"], sandbox=sandbox), + await_promise=False, + ) + + return [item["value"] for item in result["value"]] + + return get_current_navigator_languages + + +@pytest_asyncio.fixture +async def default_navigator_languages(get_current_navigator_languages, top_context): + """Returns default navigator.languages value.""" + return await get_current_navigator_languages(top_context) + + +@pytest_asyncio.fixture +async def assert_locale_against_default( + top_context, + get_current_locale, + get_current_navigator_language, + get_current_navigator_languages, + default_locale, + default_navigator_language, + default_navigator_languages, +): + """ + Assert JS locale and navigator.language/s against default values. + + Note: it's possible to have slightly different values between JS locale and + navigator.language/s, that's why we have to retrieve the default values + for each API. + """ + + async def assert_locale_against_default(context, sandbox_name=None): + assert ( + context != top_context + ), "Provided context should be different from top_context" + + assert await get_current_locale(context, sandbox_name) == default_locale + assert ( + await get_current_navigator_language(context, sandbox_name) + == default_navigator_language + ) + assert ( + await get_current_navigator_languages(context, sandbox_name) + == default_navigator_languages + ) + + return assert_locale_against_default + + +@pytest_asyncio.fixture +async def assert_locale_against_value( + top_context, + get_current_locale, + get_current_navigator_language, + get_current_navigator_languages, +): + """ + Assert JS locale and navigator.language/s against provided value + """ + + async def assert_locale_against_value(value, context, sandbox_name=None): + assert ( + context != top_context + ), "Provided context should be different from top_context" + + assert await get_current_locale(context, sandbox_name) == value + assert await get_current_navigator_language(context, sandbox_name) == value + assert await get_current_navigator_languages(context, sandbox_name) == [value] + + return assert_locale_against_value + + +@pytest_asyncio.fixture +async def get_current_timezone(bidi_session): + async def get_current_timezone(context, sandbox=None): + result = await bidi_session.script.evaluate( + expression="Intl.DateTimeFormat().resolvedOptions().timeZone", + target=ContextTarget(context["context"], sandbox=sandbox), + await_promise=False, + ) + return result["value"] + + return get_current_timezone + + +@pytest_asyncio.fixture +async def default_timezone(get_current_timezone, top_context): + """ + Returns default timezone. + """ + return await get_current_timezone(top_context) + + +@pytest.fixture +def some_timezone(default_timezone): + """ + Returns some timezone which is not equal to `default_timezone`. + """ + for timezone in TIMEZONES: + if timezone != default_timezone: + return timezone + + raise Exception( + f"Unexpectedly could not find timezone different from the default {default_timezone}" + ) + + +@pytest.fixture +def another_timezone(default_timezone, some_timezone): + """ + Returns some another timezone which is not equal to `default_timezone` nor to + `some_timezone`. + """ + for timezone in TIMEZONES: + if timezone != default_timezone and timezone != some_timezone: + return timezone + + raise Exception( + f"Unexpectedly could not find timezone different from the default {default_timezone} and {some_timezone}" + ) diff --git a/testing/web-platform/tests/webdriver/tests/bidi/emulation/set_locale_override/conftest.py b/testing/web-platform/tests/webdriver/tests/bidi/emulation/set_locale_override/conftest.py @@ -1,156 +0,0 @@ -import pytest -import pytest_asyncio - -from webdriver.bidi.modules.script import ContextTarget - -LOCALES = ["de-DE", "es-ES", "fr-FR", "it-IT"] - - -@pytest_asyncio.fixture -async def get_current_locale(bidi_session): - async def get_current_locale(context, sandbox=None): - result = await bidi_session.script.evaluate( - expression="new Intl.DateTimeFormat().resolvedOptions().locale", - target=ContextTarget(context["context"], sandbox=sandbox), - await_promise=False, - ) - - return result["value"] - - return get_current_locale - - -@pytest_asyncio.fixture -async def default_locale(get_current_locale, top_context): - """ - Returns default locale. - """ - return await get_current_locale(top_context) - - -@pytest.fixture -def some_locale(default_locale): - """ - Returns some locale which is not equal to `default_locale`. - """ - for locale in LOCALES: - if locale != default_locale: - return locale - - raise Exception( - f"Unexpectedly could not find locale different from the default {default_locale}" - ) - - -@pytest.fixture -def another_locale(default_locale, some_locale): - """ - Returns some another locale which is not equal to `default_locale` nor to - `some_locale`. - """ - for locale in LOCALES: - if locale != default_locale and locale != some_locale: - return locale - - raise Exception( - f"Unexpectedly could not find locale different from the default {default_locale} and {some_locale}" - ) - - -@pytest_asyncio.fixture -async def get_current_navigator_language(bidi_session): - async def get_current_navigator_language(context, sandbox=None): - result = await bidi_session.script.evaluate( - expression="navigator.language", - target=ContextTarget(context["context"], sandbox=sandbox), - await_promise=False, - ) - - return result["value"] - - return get_current_navigator_language - - -@pytest_asyncio.fixture -async def default_navigator_language(get_current_navigator_language, top_context): - """Returns default navigator.language value.""" - return await get_current_navigator_language(top_context) - - -@pytest_asyncio.fixture -async def get_current_navigator_languages(bidi_session): - async def get_current_navigator_languages(context, sandbox=None): - result = await bidi_session.script.evaluate( - expression="navigator.languages", - target=ContextTarget(context["context"], sandbox=sandbox), - await_promise=False, - ) - - return [item["value"] for item in result["value"]] - - return get_current_navigator_languages - - -@pytest_asyncio.fixture -async def default_navigator_languages(get_current_navigator_languages, top_context): - """Returns default navigator.languages value.""" - return await get_current_navigator_languages(top_context) - - -@pytest_asyncio.fixture -async def assert_locale_against_default( - top_context, - get_current_locale, - get_current_navigator_language, - get_current_navigator_languages, - default_locale, - default_navigator_language, - default_navigator_languages, -): - """ - Assert JS locale and navigator.language/s against default values. - - Note: it's possible to have slightly different values between JS locale and - navigator.language/s, that's why we have to retrieve the default values - for each API. - """ - - async def assert_locale_against_default(context, sandbox_name=None): - assert ( - context != top_context - ), "Provided context should be different from top_context" - - assert await get_current_locale(context, sandbox_name) == default_locale - assert ( - await get_current_navigator_language(context, sandbox_name) - == default_navigator_language - ) - assert ( - await get_current_navigator_languages(context, sandbox_name) - == default_navigator_languages - ) - - return assert_locale_against_default - - -@pytest_asyncio.fixture -async def assert_locale_against_value( - top_context, - get_current_locale, - get_current_navigator_language, - get_current_navigator_languages, -): - """ - Assert JS locale and navigator.language/s against provided value - """ - - async def assert_locale_against_value(value, context, sandbox_name=None): - assert ( - context != top_context - ), "Provided context should be different from top_context" - - assert await get_current_locale(context, sandbox_name) == value - assert await get_current_navigator_language(context, sandbox_name) == value - assert await get_current_navigator_languages(context, sandbox_name) == [value] - - return assert_locale_against_value diff --git a/testing/web-platform/tests/webdriver/tests/bidi/emulation/set_timezone_override/conftest.py b/testing/web-platform/tests/webdriver/tests/bidi/emulation/set_timezone_override/conftest.py @@ -3,58 +3,6 @@ import pytest_asyncio from webdriver.bidi.modules.script import ContextTarget -TIMEZONES = [ - "Asia/Yekaterinburg", "Europe/Berlin", "America/New_York", "Asia/Tokyo" -] - - -@pytest_asyncio.fixture -async def get_current_timezone(bidi_session): - async def get_current_timezone(context, sandbox=None): - result = await bidi_session.script.evaluate( - expression="Intl.DateTimeFormat().resolvedOptions().timeZone", - target=ContextTarget(context["context"], sandbox=sandbox), - await_promise=False, - ) - return result["value"] - - return get_current_timezone - - -@pytest_asyncio.fixture -async def default_timezone(get_current_timezone, top_context): - """ - Returns default timezone. - """ - return await get_current_timezone(top_context) - - -@pytest.fixture -def some_timezone(default_timezone): - """ - Returns some timezone which is not equal to `default_timezone`. - """ - for timezone in TIMEZONES: - if timezone != default_timezone: - return timezone - - raise Exception( - f"Unexpectedly could not find timezone different from the default {default_timezone}") - - -@pytest.fixture -def another_timezone(default_timezone, some_timezone): - """ - Returns some another timezone which is not equal to `default_timezone` nor to - `some_timezone`. - """ - for timezone in TIMEZONES: - if timezone != default_timezone and timezone != some_timezone: - return timezone - - raise Exception( - f"Unexpectedly could not find timezone different from the default {default_timezone} and {some_timezone}") - @pytest_asyncio.fixture async def get_timezone_offset(bidi_session):