Skip to content

Commit fa24c5a

Browse files
lutienmoz-wptsync-bot
authored andcommitted
[wdspec] Add a test for setting locale and timezone override at the same time.
Differential Revision: https://phabricator.services.mozilla.com/D270851 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1997556 gecko-commit: a15226bdc709b2b28fe16d9da4ab1ac85efa4041 gecko-reviewers: jdescottes
1 parent d5d5da0 commit fa24c5a

File tree

4 files changed

+90
-52
lines changed

4 files changed

+90
-52
lines changed

webdriver/tests/bidi/emulation/combined/__init__.py

Whitespace-only changes.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import pytest
2+
3+
pytestmark = pytest.mark.asyncio
4+
5+
6+
async def test_locale_and_timezone_for_user_context(
7+
bidi_session,
8+
create_user_context,
9+
new_tab,
10+
some_locale,
11+
assert_locale_against_default,
12+
assert_locale_against_value,
13+
get_current_timezone,
14+
default_timezone,
15+
some_timezone,
16+
):
17+
user_context = await create_user_context()
18+
19+
await assert_locale_against_default(new_tab)
20+
assert await get_current_timezone(new_tab) == default_timezone
21+
22+
# Set locale override.
23+
await bidi_session.emulation.set_locale_override(
24+
user_contexts=[user_context], locale=some_locale
25+
)
26+
27+
# Set timezone override.
28+
await bidi_session.emulation.set_timezone_override(
29+
user_contexts=[user_context], timezone=some_timezone
30+
)
31+
32+
# Create a new context in the user context.
33+
context_in_user_context = await bidi_session.browsing_context.create(
34+
user_context=user_context, type_hint="tab"
35+
)
36+
37+
# Assert the locale and timezone is emulated in a new browsing context of the user context.
38+
await assert_locale_against_value(some_locale, context_in_user_context)
39+
assert await get_current_timezone(context_in_user_context) == some_timezone

webdriver/tests/bidi/emulation/set_locale_override/conftest.py renamed to webdriver/tests/bidi/emulation/conftest.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from webdriver.bidi.modules.script import ContextTarget
55

66
LOCALES = ["de-DE", "es-ES", "fr-FR", "it-IT"]
7+
TIMEZONES = ["Asia/Yekaterinburg", "Europe/Berlin", "America/New_York", "Asia/Tokyo"]
78

89

910
@pytest_asyncio.fixture
@@ -154,3 +155,53 @@ async def assert_locale_against_value(value, context, sandbox_name=None):
154155
assert await get_current_navigator_languages(context, sandbox_name) == [value]
155156

156157
return assert_locale_against_value
158+
159+
160+
@pytest_asyncio.fixture
161+
async def get_current_timezone(bidi_session):
162+
async def get_current_timezone(context, sandbox=None):
163+
result = await bidi_session.script.evaluate(
164+
expression="Intl.DateTimeFormat().resolvedOptions().timeZone",
165+
target=ContextTarget(context["context"], sandbox=sandbox),
166+
await_promise=False,
167+
)
168+
return result["value"]
169+
170+
return get_current_timezone
171+
172+
173+
@pytest_asyncio.fixture
174+
async def default_timezone(get_current_timezone, top_context):
175+
"""
176+
Returns default timezone.
177+
"""
178+
return await get_current_timezone(top_context)
179+
180+
181+
@pytest.fixture
182+
def some_timezone(default_timezone):
183+
"""
184+
Returns some timezone which is not equal to `default_timezone`.
185+
"""
186+
for timezone in TIMEZONES:
187+
if timezone != default_timezone:
188+
return timezone
189+
190+
raise Exception(
191+
f"Unexpectedly could not find timezone different from the default {default_timezone}"
192+
)
193+
194+
195+
@pytest.fixture
196+
def another_timezone(default_timezone, some_timezone):
197+
"""
198+
Returns some another timezone which is not equal to `default_timezone` nor to
199+
`some_timezone`.
200+
"""
201+
for timezone in TIMEZONES:
202+
if timezone != default_timezone and timezone != some_timezone:
203+
return timezone
204+
205+
raise Exception(
206+
f"Unexpectedly could not find timezone different from the default {default_timezone} and {some_timezone}"
207+
)

webdriver/tests/bidi/emulation/set_timezone_override/conftest.py

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,6 @@
33

44
from webdriver.bidi.modules.script import ContextTarget
55

6-
TIMEZONES = [
7-
"Asia/Yekaterinburg", "Europe/Berlin", "America/New_York", "Asia/Tokyo"
8-
]
9-
10-
11-
@pytest_asyncio.fixture
12-
async def get_current_timezone(bidi_session):
13-
async def get_current_timezone(context, sandbox=None):
14-
result = await bidi_session.script.evaluate(
15-
expression="Intl.DateTimeFormat().resolvedOptions().timeZone",
16-
target=ContextTarget(context["context"], sandbox=sandbox),
17-
await_promise=False,
18-
)
19-
return result["value"]
20-
21-
return get_current_timezone
22-
23-
24-
@pytest_asyncio.fixture
25-
async def default_timezone(get_current_timezone, top_context):
26-
"""
27-
Returns default timezone.
28-
"""
29-
return await get_current_timezone(top_context)
30-
31-
32-
@pytest.fixture
33-
def some_timezone(default_timezone):
34-
"""
35-
Returns some timezone which is not equal to `default_timezone`.
36-
"""
37-
for timezone in TIMEZONES:
38-
if timezone != default_timezone:
39-
return timezone
40-
41-
raise Exception(
42-
f"Unexpectedly could not find timezone different from the default {default_timezone}")
43-
44-
45-
@pytest.fixture
46-
def another_timezone(default_timezone, some_timezone):
47-
"""
48-
Returns some another timezone which is not equal to `default_timezone` nor to
49-
`some_timezone`.
50-
"""
51-
for timezone in TIMEZONES:
52-
if timezone != default_timezone and timezone != some_timezone:
53-
return timezone
54-
55-
raise Exception(
56-
f"Unexpectedly could not find timezone different from the default {default_timezone} and {some_timezone}")
57-
586

597
@pytest_asyncio.fixture
608
async def get_timezone_offset(bidi_session):

0 commit comments

Comments
 (0)