Skip to content

Commit 662cf6e

Browse files
lutienmoz-wptsync-bot
authored andcommitted
[wdspec] Add tests for "emulation.setScreenOrientationOverride" command in iframes.
Differential Revision: https://phabricator.services.mozilla.com/D262789 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1974167 gecko-commit: 573eeceeda30046a018b52c57e7404e76e95fe49 gecko-reviewers: webdriver-reviewers, jdescottes
1 parent bc1c54d commit 662cf6e

File tree

3 files changed

+130
-3
lines changed

3 files changed

+130
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88

99
@pytest_asyncio.fixture
1010
async def get_screen_orientation(bidi_session):
11-
async def get_screen_orientation(context):
11+
async def get_screen_orientation(context, top_context=None):
1212
# Activation is required, as orientation is only available on an active
1313
# context.
14-
await bidi_session.browsing_context.activate(context=context["context"])
15-
14+
await bidi_session.browsing_context.activate(
15+
context=top_context["context"] if top_context else context["context"]
16+
)
1617
result = await bidi_session.script.evaluate(
1718
expression="""({
1819
angle: screen.orientation.angle,

webdriver/tests/bidi/emulation/set_screen_orientation_override/contexts.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,55 @@ async def test_multiple_contexts(
6767
assert await get_screen_orientation(new_tab) == default_screen_orientation
6868
assert await get_screen_orientation(
6969
top_context) == default_screen_orientation
70+
71+
72+
@pytest.mark.parametrize("domain", ["", "alt"], ids=["same_origin", "cross_origin"])
73+
async def test_iframe(
74+
bidi_session,
75+
new_tab,
76+
get_screen_orientation,
77+
some_bidi_screen_orientation,
78+
some_web_screen_orientation,
79+
another_bidi_screen_orientation,
80+
another_web_screen_orientation,
81+
inline,
82+
domain,
83+
):
84+
await bidi_session.emulation.set_screen_orientation_override(
85+
contexts=[new_tab["context"]],
86+
screen_orientation=some_bidi_screen_orientation,
87+
)
88+
89+
# Assert screen orientation in the required context.
90+
assert await get_screen_orientation(new_tab) == some_web_screen_orientation
91+
92+
iframe_url = inline("<div id='in-iframe'>foo</div>", domain=domain)
93+
page_url = inline(f"<iframe src='{iframe_url}'></iframe>")
94+
95+
# Load the page with iframes.
96+
await bidi_session.browsing_context.navigate(
97+
context=new_tab["context"],
98+
url=page_url,
99+
wait="complete",
100+
)
101+
102+
contexts = await bidi_session.browsing_context.get_tree(root=new_tab["context"])
103+
iframe = contexts[0]["children"][0]
104+
105+
# Assert locale is emulated in the iframe context.
106+
assert (
107+
await get_screen_orientation(iframe, top_context=new_tab)
108+
== some_web_screen_orientation
109+
)
110+
111+
# Set another screen orientation override.
112+
await bidi_session.emulation.set_screen_orientation_override(
113+
contexts=[new_tab["context"]],
114+
screen_orientation=another_bidi_screen_orientation,
115+
)
116+
117+
# Assert screen orientation is emulated in the iframe context.
118+
assert (
119+
await get_screen_orientation(iframe, top_context=new_tab)
120+
== another_web_screen_orientation
121+
)

webdriver/tests/bidi/emulation/set_screen_orientation_override/screen_orientation.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

33
from . import get_angle
4+
from ... import remote_mapping_to_dict
45

56
pytestmark = pytest.mark.asyncio
67

@@ -32,3 +33,76 @@ async def test_screen_orientation(bidi_session, top_context,
3233
# Assert screen orientation is the default.
3334
assert await get_screen_orientation(
3435
top_context) == default_screen_orientation
36+
37+
38+
async def test_screen_orientation_change_event(
39+
bidi_session,
40+
new_tab,
41+
some_bidi_screen_orientation,
42+
some_web_screen_orientation,
43+
another_bidi_screen_orientation,
44+
another_web_screen_orientation,
45+
default_screen_orientation,
46+
subscribe_events,
47+
add_preload_script,
48+
wait_for_event,
49+
wait_for_future_safe,
50+
inline,
51+
):
52+
await subscribe_events(["script.message"])
53+
await add_preload_script(
54+
function_declaration="""(channel) => {
55+
window.screen.orientation.addEventListener(
56+
"change",
57+
(e)=>channel({type: e.target.type, angle: e.target.angle})
58+
)
59+
}""",
60+
arguments=[{"type": "channel", "value": {"channel": "change_event"}}],
61+
)
62+
63+
await bidi_session.browsing_context.navigate(
64+
context=new_tab["context"], url=inline("<div>foo</div>"), wait="complete"
65+
)
66+
67+
on_script_message = wait_for_event("script.message")
68+
69+
# Set screen orientation override.
70+
await bidi_session.emulation.set_screen_orientation_override(
71+
contexts=[new_tab["context"]], screen_orientation=some_bidi_screen_orientation
72+
)
73+
74+
event_data = await wait_for_future_safe(on_script_message)
75+
76+
assert (
77+
remote_mapping_to_dict(event_data["data"]["value"])
78+
== some_web_screen_orientation
79+
)
80+
81+
on_script_message = wait_for_event("script.message")
82+
83+
# Set another screen orientation override.
84+
await bidi_session.emulation.set_screen_orientation_override(
85+
contexts=[new_tab["context"]],
86+
screen_orientation=another_bidi_screen_orientation,
87+
)
88+
89+
event_data = await wait_for_future_safe(on_script_message)
90+
91+
assert (
92+
remote_mapping_to_dict(event_data["data"]["value"])
93+
== another_web_screen_orientation
94+
)
95+
96+
on_script_message = wait_for_event("script.message")
97+
98+
# Reset screen orientation override.
99+
await bidi_session.emulation.set_screen_orientation_override(
100+
contexts=[new_tab["context"]], screen_orientation=None
101+
)
102+
103+
event_data = await wait_for_future_safe(on_script_message)
104+
105+
assert (
106+
remote_mapping_to_dict(event_data["data"]["value"])
107+
== default_screen_orientation
108+
)

0 commit comments

Comments
 (0)