commit b45d8304247695bcef6ce4b9014650a75eaadc51
parent b888cdb879bd83e8cf76635b6fead87851165697
Author: Alexandra Borovova <aborovova@mozilla.com>
Date: Tue, 11 Nov 2025 14:31:27 +0000
Bug 1995691 - [wdspec] Add checks for overriding "Accept-Language" header with "emulation.setLocaleOverride". r=whimboo
Differential Revision: https://phabricator.services.mozilla.com/D270816
Diffstat:
7 files changed, 81 insertions(+), 46 deletions(-)
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
@@ -15,7 +15,7 @@ pytest_plugins = "tests.bidi.emulation.conftest"
}
)
async def test_locale_override_isolated_in_browsing_context(
- bidi_session, get_current_locale, some_locale, another_locale
+ bidi_session, another_locale, assert_locale_against_value, some_locale
):
context_in_process_1 = await bidi_session.browsing_context.create(type_hint="tab")
@@ -31,5 +31,5 @@ async def test_locale_override_isolated_in_browsing_context(
)
# Make sure that the locale override didn't override inappropriate context.
- assert await get_current_locale(context_in_process_1) == some_locale
- assert await get_current_locale(context_in_process_2) == another_locale
+ await assert_locale_against_value(some_locale, context_in_process_1)
+ await assert_locale_against_value(another_locale, context_in_process_2)
diff --git a/testing/web-platform/tests/webdriver/tests/bidi/emulation/conftest.py b/testing/web-platform/tests/webdriver/tests/bidi/emulation/conftest.py
@@ -99,14 +99,46 @@ async def default_navigator_languages(get_current_navigator_languages, top_conte
@pytest_asyncio.fixture
+async def default_accept_language(bidi_session, get_fetch_headers, top_context, url):
+ """
+ Returns default value of `Accept-Language` header.
+ """
+ await bidi_session.browsing_context.navigate(
+ context=top_context["context"],
+ url=url("/webdriver/tests/bidi/browsing_context/support/empty.html"),
+ wait="complete"
+ )
+ headers = await get_fetch_headers(top_context)
+ return headers["accept-language"][0] if "accept-language" in headers else None
+
+
+@pytest_asyncio.fixture
+async def assert_accept_language(bidi_session, assert_header_present, url):
+ """
+ Assert value of `Accept-Language` header.
+ """
+ async def assert_accept_language(context, value, sandbox_name=None):
+ await bidi_session.browsing_context.navigate(
+ context=context["context"],
+ url=url("/webdriver/tests/bidi/browsing_context/support/empty.html"),
+ wait="complete"
+ )
+ await assert_header_present(context, "accept-language", value, sandbox_name)
+
+ return assert_accept_language
+
+
+@pytest_asyncio.fixture
async def assert_locale_against_default(
top_context,
- get_current_locale,
- get_current_navigator_language,
- get_current_navigator_languages,
+ assert_accept_language,
default_locale,
default_navigator_language,
default_navigator_languages,
+ default_accept_language,
+ get_current_locale,
+ get_current_navigator_language,
+ get_current_navigator_languages,
):
"""
Assert JS locale and navigator.language/s against default values.
@@ -130,6 +162,7 @@ async def assert_locale_against_default(
await get_current_navigator_languages(context, sandbox_name)
== default_navigator_languages
)
+ await assert_accept_language(context, default_accept_language, sandbox_name)
return assert_locale_against_default
@@ -137,6 +170,7 @@ async def assert_locale_against_default(
@pytest_asyncio.fixture
async def assert_locale_against_value(
top_context,
+ assert_accept_language,
get_current_locale,
get_current_navigator_language,
get_current_navigator_languages,
@@ -153,6 +187,7 @@ async def assert_locale_against_value(
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]
+ await assert_accept_language(context, value)
return assert_locale_against_value
diff --git a/testing/web-platform/tests/webdriver/tests/bidi/emulation/set_locale_override/contexts.py b/testing/web-platform/tests/webdriver/tests/bidi/emulation/set_locale_override/contexts.py
@@ -6,9 +6,9 @@ pytestmark = pytest.mark.asyncio
async def test_contexts(
bidi_session,
new_tab,
- some_locale,
assert_locale_against_default,
assert_locale_against_value,
+ some_locale,
):
new_context = await bidi_session.browsing_context.create(type_hint="tab")
@@ -34,8 +34,8 @@ async def test_contexts(
async def test_multiple_contexts(
bidi_session,
new_tab,
- assert_locale_against_value,
assert_locale_against_default,
+ assert_locale_against_value,
some_locale,
):
new_context = await bidi_session.browsing_context.create(type_hint="tab")
@@ -63,11 +63,11 @@ async def test_multiple_contexts(
async def test_iframe(
bidi_session,
new_tab,
- some_locale,
- domain,
inline,
another_locale,
assert_locale_against_value,
+ some_locale,
+ domain,
):
# Set locale override.
await bidi_session.emulation.set_locale_override(
@@ -123,8 +123,8 @@ async def test_locale_override_applies_to_existing_sandbox(
bidi_session,
new_tab,
another_locale,
- assert_locale_against_value,
assert_locale_against_default,
+ assert_locale_against_value,
):
sandbox_name = "test"
diff --git a/testing/web-platform/tests/webdriver/tests/bidi/emulation/set_locale_override/locale.py b/testing/web-platform/tests/webdriver/tests/bidi/emulation/set_locale_override/locale.py
@@ -6,10 +6,10 @@ pytestmark = pytest.mark.asyncio
async def test_locale_set_override_and_reset(
bidi_session,
new_tab,
- some_locale,
another_locale,
assert_locale_against_default,
assert_locale_against_value,
+ some_locale,
):
await assert_locale_against_default(new_tab)
diff --git a/testing/web-platform/tests/webdriver/tests/bidi/emulation/set_locale_override/user_contexts.py b/testing/web-platform/tests/webdriver/tests/bidi/emulation/set_locale_override/user_contexts.py
@@ -7,9 +7,9 @@ async def test_user_contexts(
bidi_session,
create_user_context,
new_tab,
- some_locale,
assert_locale_against_default,
assert_locale_against_value,
+ some_locale,
):
user_context = await create_user_context()
context_in_user_context = await bidi_session.browsing_context.create(
@@ -41,9 +41,9 @@ async def test_set_to_default_user_context(
bidi_session,
new_tab,
create_user_context,
- some_locale,
assert_locale_against_default,
assert_locale_against_value,
+ some_locale,
):
user_context = await create_user_context()
context_in_user_context = await bidi_session.browsing_context.create(
@@ -76,8 +76,8 @@ async def test_set_to_default_user_context(
async def test_set_to_multiple_user_contexts(
bidi_session,
create_user_context,
- some_locale,
assert_locale_against_value,
+ some_locale,
):
user_context_1 = await create_user_context()
context_in_user_context_1 = await bidi_session.browsing_context.create(
@@ -98,10 +98,10 @@ async def test_set_to_multiple_user_contexts(
async def test_set_to_user_context_and_then_to_context(
bidi_session,
create_user_context,
- some_locale,
another_locale,
assert_locale_against_default,
assert_locale_against_value,
+ some_locale,
):
user_context = await create_user_context()
context_in_user_context_1 = await bidi_session.browsing_context.create(
@@ -155,10 +155,10 @@ async def test_set_to_user_context_and_then_to_context(
async def test_set_to_context_and_then_to_user_context(
bidi_session,
create_user_context,
- some_locale,
another_locale,
assert_locale_against_default,
assert_locale_against_value,
+ some_locale,
):
user_context = await create_user_context()
context_in_user_context_1 = await bidi_session.browsing_context.create(
diff --git a/testing/web-platform/tests/webdriver/tests/bidi/network/set_extra_headers/conftest.py b/testing/web-platform/tests/webdriver/tests/bidi/network/set_extra_headers/conftest.py
@@ -62,21 +62,6 @@ async def get_navigation_headers(bidi_session, url):
return get_navigation_headers
-@pytest_asyncio.fixture
-async def get_fetch_headers(bidi_session, url):
- async def get_fetch_headers(context):
- echo_link = url("webdriver/tests/support/http_handlers/headers_echo.py")
- result = await bidi_session.script.evaluate(
- expression=f"fetch('{echo_link}').then(r => r.text())",
- target=ContextTarget(context["context"]),
- await_promise=True,
- )
-
- return (json.JSONDecoder().decode(result["value"]))["headers"]
-
- return get_fetch_headers
-
-
@pytest_asyncio.fixture(params=["fetch", "navigation"])
def get_headers_methods_invariant(request, get_fetch_headers,
get_navigation_headers):
@@ -88,18 +73,6 @@ def get_headers_methods_invariant(request, get_fetch_headers,
@pytest_asyncio.fixture
-def assert_header_present(get_fetch_headers):
- async def assert_header_present(context, header_name, header_value):
- actual_headers = await get_fetch_headers(context)
- assert header_name in actual_headers, \
- f"header '{header_name}' should be present"
- assert [header_value] == actual_headers[header_name], \
- f"header '{header_name}' should have value '{header_value}'"
-
- return assert_header_present
-
-
-@pytest_asyncio.fixture
def assert_header_not_present(get_fetch_headers):
async def assert_header_not_present(context, header_name):
actual_headers = await get_fetch_headers(context)
diff --git a/testing/web-platform/tests/webdriver/tests/support/fixtures_bidi.py b/testing/web-platform/tests/webdriver/tests/support/fixtures_bidi.py
@@ -644,6 +644,7 @@ def fetch(bidi_session, top_context, configuration):
post_data=None,
context=top_context,
timeout_in_seconds=3,
+ sandbox_name=None
):
if method is None:
method = "GET" if post_data is None else "POST"
@@ -683,7 +684,7 @@ def fetch(bidi_session, top_context, configuration):
# Wait for fetch() to resolve a response and for response.text() to
# resolve as well to make sure the request/response is completed when
# the helper returns.
- await bidi_session.script.evaluate(
+ return await bidi_session.script.evaluate(
expression=f"""
{{
const controller = new AbortController();
@@ -695,7 +696,7 @@ def fetch(bidi_session, top_context, configuration):
signal: controller.signal,
}}).then(response => response.text());
}}""",
- target=ContextTarget(context["context"]),
+ target=ContextTarget(context["context"], sandbox=sandbox_name),
await_promise=True,
)
@@ -1152,3 +1153,29 @@ async def assert_file_dialog_not_canceled(bidi_session, inline, top_context,
cancel_event_future.cancel()
yield assert_file_dialog_not_canceled
+
+
+@pytest_asyncio.fixture
+async def get_fetch_headers(url, fetch):
+ async def get_fetch_headers(context, sandbox_name=None):
+ result = await fetch(
+ url=url("webdriver/tests/support/http_handlers/headers_echo.py"),
+ context=context,
+ sandbox_name=sandbox_name
+ )
+
+ return (json.JSONDecoder().decode(result["value"]))["headers"]
+
+ return get_fetch_headers
+
+
+@pytest_asyncio.fixture
+async def assert_header_present(get_fetch_headers):
+ async def assert_header_present(context, header_name, header_value, sandbox_name=None):
+ actual_headers = await get_fetch_headers(context, sandbox_name)
+ assert header_name in actual_headers, \
+ f"header '{header_name}' should be present"
+ assert [header_value] == actual_headers[header_name], \
+ f"header '{header_name}' should have value '{header_value}'"
+
+ return assert_header_present