Skip to content

Commit a1e473f

Browse files
e2e test
1 parent 467c57f commit a1e473f

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

tests/emulation/__snapshots__/test_geolocation.ambr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
# serializer version: 1
2+
# name: test_geolocation_emulate_unavailable
3+
dict({
4+
'type': 'object',
5+
'value': list([
6+
list([
7+
'code',
8+
dict({
9+
'type': 'number',
10+
'value': 2,
11+
}),
12+
]),
13+
]),
14+
})
15+
# ---
216
# name: test_geolocation_per_user_context
317
dict({
418
'type': 'object',

tests/emulation/test_geolocation.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async def get_geolocation(websocket, context_id):
5858
new Promise(
5959
resolve => window.navigator.geolocation.getCurrentPosition(
6060
position => resolve(position.coords.toJSON()),
61-
error => resolve({code: error.code, message: error.message}),
61+
error => resolve({code: error.code}),
6262
{timeout: 200}
6363
))
6464
""",
@@ -123,6 +123,47 @@ async def test_geolocation_set_and_clear(websocket, context_id, url_example,
123123
assert initial_geolocation == await get_geolocation(websocket, context_id)
124124

125125

126+
@pytest.mark.asyncio
127+
async def test_geolocation_emulate_unavailable(websocket, context_id,
128+
url_example, snapshot):
129+
await goto_url(websocket, context_id, url_example)
130+
131+
await set_permission(websocket, get_origin(url_example),
132+
{'name': 'geolocation'}, 'granted')
133+
134+
initial_geolocation = await get_geolocation(websocket, context_id)
135+
136+
await execute_command(
137+
websocket, {
138+
'method': 'emulation.setGeolocationOverride',
139+
'params': {
140+
'contexts': [context_id],
141+
'error': {
142+
'type': 'positionUnavailable'
143+
}
144+
}
145+
})
146+
147+
emulated_geolocation = await get_geolocation(websocket, context_id)
148+
149+
assert initial_geolocation != emulated_geolocation, "Geolocation should have changed"
150+
assert emulated_geolocation == snapshot(
151+
), "New geolocation should match snapshot"
152+
153+
# Clear geolocation override.
154+
await execute_command(
155+
websocket, {
156+
'method': 'emulation.setGeolocationOverride',
157+
'params': {
158+
'contexts': [context_id],
159+
'coordinates': None
160+
}
161+
})
162+
163+
# Assert the geolocation has returned to the original state.
164+
assert initial_geolocation == await get_geolocation(websocket, context_id)
165+
166+
126167
@pytest.mark.asyncio
127168
async def test_geolocation_per_user_context(websocket, url_example,
128169
url_example_another_origin,

0 commit comments

Comments
 (0)