w3c / webdriver

Remote control interface that enables introspection and control of user agents.
https://w3c.github.io/webdriver/
Other
676 stars 190 forks source link

A means to emit geolocation positions #1700

Open marcoscaceres opened 1 year ago

marcoscaceres commented 1 year ago

It would be great if Web Driver provided a means for a user agent to emit a Geolocation coordinates. These would be picked up by the Geolocation API's requestPosition() and watchPosition() methods.

This would be beneficial to both web developers and implementers.

The straw person is to allow developers to pass an JSON object with a shape that matches GeolocationCoordinates.

Then the UA can just echo that as a real GeolocationCoordinates object.

On WPT, at least, (and yes, I'm aware test_driver is not part of this spec.. just showing it as a use case) I'm imagining something like:

await test_driver.set_permission({"name": "geolocation"}, "granted");
const positionPromise = new Promise((res, rej) => navigator.geolocation.getCurrentPosition(res, rej));
await test_driver.emit_geo_position({ latitude: -37, longitude: 100 });
const position = await positionPromise; 

Similarly, with watchPosition(), one would get the 3 positions:

navigator.geolocation.watchPosition(console.log);
await test_driver.emit_geo_position({ latitude: 37, longitude: 100 });
await test_driver.emit_geo_position({ latitude: 36, longitude: 100 });
await test_driver.emit_geo_position({ latitude: 35, longitude: 100 });

Thoughts?