@@ -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
127168async def test_geolocation_per_user_context (websocket , url_example ,
128169 url_example_another_origin ,
0 commit comments