Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions webdriver/tests/bidi/emulation/set_locale_override/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,23 @@ def another_locale(default_locale, some_locale):
raise Exception(
f"Unexpectedly could not find locale different from the default {default_locale} and {some_locale}"
)


@pytest_asyncio.fixture
async def default_accept_language(get_fetch_headers, top_context):
"""
Returns default value of `Accept-Language` header.
"""
headers = await get_fetch_headers(top_context)
return headers["Accept-Language"] if "Accept-Language" in headers else None


@pytest_asyncio.fixture
async def assert_accept_language(assert_header_present):
"""
Assert value of `Accept-Language` header.
"""
async def assert_accept_language(context, value):
await assert_header_present(context, "Accept-Language", value)

return assert_accept_language
7 changes: 6 additions & 1 deletion webdriver/tests/bidi/emulation/set_locale_override/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@


async def test_locale_set_override_and_reset(bidi_session, top_context,
get_current_locale, default_locale, some_locale, another_locale):
get_current_locale, default_locale, some_locale, another_locale,
assert_accept_language, default_accept_language):
assert await get_current_locale(top_context) == default_locale
await assert_accept_language(top_context, default_accept_language)

# Set locale override.
await bidi_session.emulation.set_locale_override(
Expand All @@ -14,6 +16,7 @@ async def test_locale_set_override_and_reset(bidi_session, top_context,
)

assert await get_current_locale(top_context) == some_locale
await assert_accept_language(top_context, some_locale)

# Set locale override.
await bidi_session.emulation.set_locale_override(
Expand All @@ -22,6 +25,7 @@ async def test_locale_set_override_and_reset(bidi_session, top_context,
)

assert await get_current_locale(top_context) == another_locale
await assert_accept_language(top_context, another_locale)

# Set locale override.
await bidi_session.emulation.set_locale_override(
Expand All @@ -30,6 +34,7 @@ async def test_locale_set_override_and_reset(bidi_session, top_context,
)

assert await get_current_locale(top_context) == default_locale
await assert_accept_language(top_context, default_accept_language)


@pytest.mark.parametrize("value", [
Expand Down
27 changes: 0 additions & 27 deletions webdriver/tests/bidi/network/set_extra_headers/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,6 @@ async def get_navigation_headers(context):
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):
Expand All @@ -87,18 +72,6 @@ def get_headers_methods_invariant(request, get_fetch_headers,
raise Exception(f"Unsupported getter {request.param}")


@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):
Expand Down
28 changes: 28 additions & 0 deletions webdriver/tests/support/fixtures_bidi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,3 +1111,31 @@ async def assert_file_dialog_not_canceled(context=None):
cancel_event_future.cancel()

yield assert_file_dialog_not_canceled


@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
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

Loading