w3c / sensors

Generic Sensor API
https://www.w3.org/TR/generic-sensor/
Other
127 stars 59 forks source link

automation: Save readings set when no sensors are active #487

Open rakuco opened 4 months ago

rakuco commented 4 months ago

I didn't originally intend to make such big changes, but it was impossible to add a fix for #478 without also dealing with the inconsistencies in how platform sensors were defined.

From the larger commit of the bunch:


As described in #478, the current behavior is underspecified and allows implementations to discard readings provided to the "Update virtual sensor reading" WebDriver endpoint when no sensors are currently registered to receive readings.

This makes writing some tests (especially Device Orientation API ones) harder, as one then needs to order calls in a very specific way so that a virtual sensor is created, a sensor is activated, a virtual sensor reading is provided and then it is consumed by a sensor. To complicate things further, implementations may differ in when they deactivate sensors (think page visibility handling, for example).

It is easier to mandate one specific behavior:

In practice, this means one can call test_driver.update_virtual_sensor() before a Sensor object is even created (or a Device Orientation event listener is added), or that if one calls Sensor.stop() followed by Sensor.start() the previous reading will be reported again.

Making this possible requires several changes across the specification though, as virtual sensors need to keep track of platform sensors but platform sensors did not have their lifetime properly defined. Furthermore, the virtual sensor changes need to be flexible enough to be possible to use them in the Device Orientation specification, which has no concept of platform sensors or sensor types at all.

Platform sensors:

Virtual sensors:

The interaction between per-document platform sensors and per-top-level traversable virtual sensors works as follows:


Fixes #444 (removes all remaining browsing context references). Related to #478. Related to #463.


Preview | Diff