Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 66efc1c

Browse files
moz-wptsync-botlutien
authored andcommitted
Bug 1963443 [wpt PR 52250] - [wdspec] test geolocation "positionUnavailable",
Automatic update from web-platform-tests [wdspec] test geolocation "positionUnavailable" (#52250) Spec: w3c/webdriver-bidi#911 -- wpt-commits: 4e5ff79b8032c5762b1548341324a7d357301c2d wpt-pr: 52250 Differential Revision: https://phabricator.services.mozilla.com/D248839
1 parent 523cef2 commit 66efc1c

File tree

4 files changed

+177
-4
lines changed

4 files changed

+177
-4
lines changed

testing/web-platform/tests/tools/webdriver/webdriver/bidi/modules/emulation.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,16 @@ class Emulation(BidiModule):
3535
def set_geolocation_override(
3636
self,
3737
coordinates: Union[CoordinatesOptions, Undefined] = UNDEFINED,
38+
error: Optional[Dict[str, Any]] = None,
3839
contexts: Optional[List[str]] = None,
3940
user_contexts: Optional[List[str]] = None,
4041
) -> Mapping[str, Any]:
41-
params: MutableMapping[str, Any] = {"coordinates": coordinates}
42+
params: MutableMapping[str, Any] = {}
4243

44+
if coordinates is not UNDEFINED:
45+
params["coordinates"] = coordinates
46+
if error is not None:
47+
params["error"] = error
4348
if contexts is not None:
4449
params["contexts"] = contexts
4550
if user_contexts is not None:

testing/web-platform/tests/webdriver/tests/bidi/emulation/set_geolocation_override/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async def get_current_geolocation(context):
1818
new Promise(
1919
resolve => window.navigator.geolocation.getCurrentPosition(
2020
position => resolve(position.coords.toJSON()),
21-
error => resolve({code: error.code, message: error.message}),
21+
error => resolve({code: error.code}),
2222
{timeout: 500 * multiplier}
2323
))
2424
""",
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import pytest
2+
3+
from webdriver.bidi.modules.script import ContextTarget
4+
5+
from ... import remote_mapping_to_dict
6+
7+
pytestmark = pytest.mark.asyncio
8+
9+
ERROR = {"type": "positionUnavailable"}
10+
EXPECTED_ERROR = {"code": 2}
11+
12+
13+
async def test_get_current_position(bidi_session, new_tab, url,
14+
get_current_geolocation, set_geolocation_permission):
15+
test_url = url("/common/blank.html")
16+
await bidi_session.browsing_context.navigate(
17+
context=new_tab["context"],
18+
url=test_url,
19+
wait="complete",
20+
)
21+
await set_geolocation_permission(new_tab)
22+
23+
await bidi_session.emulation.set_geolocation_override(
24+
contexts=[new_tab["context"]], error=ERROR
25+
)
26+
27+
assert await get_current_geolocation(new_tab) == EXPECTED_ERROR
28+
29+
30+
async def test_watch_position(
31+
bidi_session,
32+
new_tab,
33+
url,
34+
subscribe_events,
35+
wait_for_event,
36+
wait_for_future_safe,
37+
set_geolocation_permission,
38+
):
39+
await subscribe_events(["script.message"])
40+
41+
test_url = url("/common/blank.html")
42+
await bidi_session.browsing_context.navigate(
43+
context=new_tab["context"],
44+
url=test_url,
45+
wait="complete",
46+
)
47+
await set_geolocation_permission(new_tab)
48+
49+
await bidi_session.emulation.set_geolocation_override(
50+
contexts=[new_tab["context"]],
51+
error=ERROR
52+
)
53+
54+
on_script_message = wait_for_event("script.message")
55+
await bidi_session.browsing_context.activate(context=new_tab["context"])
56+
await bidi_session.script.call_function(
57+
arguments=[{"type": "channel", "value": {"channel": "channel_name"}}],
58+
function_declaration="""(channel) =>
59+
window.navigator.geolocation.watchPosition(
60+
(result) => channel("unexpected result"),
61+
(error) => channel({code: error.code})
62+
)
63+
""",
64+
target=ContextTarget(new_tab["context"]),
65+
await_promise=False,
66+
)
67+
event_data = await wait_for_future_safe(on_script_message)
68+
69+
assert remote_mapping_to_dict(event_data["data"]["value"]) == EXPECTED_ERROR
70+
71+
72+
async def test_persists_on_reload(
73+
bidi_session, url, new_tab, get_current_geolocation, set_geolocation_permission
74+
):
75+
test_url = url("/common/blank.html")
76+
await bidi_session.browsing_context.navigate(
77+
context=new_tab["context"],
78+
url=test_url,
79+
wait="complete",
80+
)
81+
await set_geolocation_permission(new_tab)
82+
83+
# Set geolocation override.
84+
await bidi_session.emulation.set_geolocation_override(
85+
contexts=[new_tab["context"]],
86+
error=ERROR,
87+
)
88+
89+
assert await get_current_geolocation(new_tab) == EXPECTED_ERROR
90+
91+
await bidi_session.browsing_context.reload(
92+
context=new_tab["context"], wait="complete"
93+
)
94+
95+
assert await get_current_geolocation(new_tab) == EXPECTED_ERROR
96+
97+
98+
async def test_persists_on_navigation(
99+
bidi_session, url, new_tab, get_current_geolocation, set_geolocation_permission
100+
):
101+
test_url = url("/common/blank.html")
102+
await bidi_session.browsing_context.navigate(
103+
context=new_tab["context"],
104+
url=test_url,
105+
wait="complete",
106+
)
107+
await set_geolocation_permission(new_tab)
108+
109+
# Set geolocation override.
110+
await bidi_session.emulation.set_geolocation_override(
111+
contexts=[new_tab["context"]],
112+
error=ERROR,
113+
)
114+
115+
assert await get_current_geolocation(new_tab) == EXPECTED_ERROR
116+
117+
await bidi_session.browsing_context.navigate(
118+
context=new_tab["context"],
119+
url=url("/webdriver/tests/support/html/default.html"),
120+
wait="complete",
121+
)
122+
123+
assert await get_current_geolocation(new_tab) == EXPECTED_ERROR

testing/web-platform/tests/webdriver/tests/bidi/emulation/set_geolocation_override/invalid.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import webdriver.bidi.error as error
44
from webdriver.bidi.modules.emulation import CoordinatesOptions
5-
from webdriver.bidi.undefined import UNDEFINED
65

76

87
pytestmark = pytest.mark.asyncio
@@ -75,7 +74,7 @@ async def test_params_contexts_iframe(bidi_session, new_tab, get_test_page):
7574
)
7675

7776

78-
@pytest.mark.parametrize("value", [UNDEFINED, False, 42, "foo", []])
77+
@pytest.mark.parametrize("value", [False, 42, "foo", []])
7978
async def test_params_coordinates_invalid_type(bidi_session, top_context, value):
8079
with pytest.raises(error.InvalidArgumentException):
8180
await bidi_session.emulation.set_geolocation_override(
@@ -333,3 +332,49 @@ async def test_params_user_contexts_entry_invalid_value(bidi_session, value):
333332
},
334333
user_contexts=[value],
335334
)
335+
336+
337+
async def test_params_coordinates_and_error(bidi_session, top_context):
338+
with pytest.raises(error.InvalidArgumentException):
339+
await bidi_session.emulation.set_geolocation_override(
340+
contexts=[top_context["context"]],
341+
coordinates={
342+
"latitude": 10,
343+
"longitude": 10,
344+
},
345+
error={"type": "positionUnavailable"}
346+
)
347+
348+
349+
async def test_params_no_coordinates_no_error(bidi_session, top_context):
350+
with pytest.raises(error.InvalidArgumentException):
351+
await bidi_session.emulation.set_geolocation_override(
352+
contexts=[top_context["context"]],
353+
)
354+
355+
356+
@pytest.mark.parametrize("value", [False, 42, "foo", []])
357+
async def test_params_error_invalid_type(bidi_session, top_context, value):
358+
with pytest.raises(error.InvalidArgumentException):
359+
await bidi_session.emulation.set_geolocation_override(
360+
contexts=[top_context["context"]],
361+
error=value,
362+
)
363+
364+
365+
async def test_params_error_empty_object(bidi_session, top_context):
366+
with pytest.raises(error.InvalidArgumentException):
367+
await bidi_session.emulation.set_geolocation_override(
368+
contexts=[top_context["context"]],
369+
error={},
370+
)
371+
372+
373+
async def test_params_error_invalid_value(bidi_session, top_context):
374+
with pytest.raises(error.InvalidArgumentException):
375+
await bidi_session.emulation.set_geolocation_override(
376+
contexts=[top_context["context"]],
377+
error={
378+
"type": "unknownError",
379+
},
380+
)

0 commit comments

Comments
 (0)