Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automation support using WebDriver #122

Closed
rakuco opened this issue Nov 13, 2023 · 8 comments · Fixed by #124
Closed

Add automation support using WebDriver #122

rakuco opened this issue Nov 13, 2023 · 8 comments · Fixed by #124

Comments

@rakuco
Copy link
Member

rakuco commented Nov 13, 2023

This was discussed during TPAC 2023. WebDriver support in the Generic Sensor API spec was fully rewritten a few months ago, and the tests in WPT are not implementation-specific anymore.

It would be good to do the same with this spec, as several existing web tests in WPT rely on Chromium Mojo JS mocks and are therefore not easily interoperable.

One idea would be to make this specification reference the automation bits in the Generic Sensor API one (in other words, implementations are not expected to implement the Generic Sensor API itself, only the WebDriver extension commands defined in https://w3c.github.io/sensors/#automation). This would make it possible to set e.g. DeviceMotionEvent data by calling test_driver.create_virtual_sensor("accelerometer") (and others) and test_driver.update_virtual_sensor("accelerometer", {x: 1, y: 2, z: 3}).

If this is a worthwhile approach, then the two opens I see at the moment are

  1. What kind of virtual sensor type to use for the deviceorientation and deviceorientationabsolute events. We can clearly use "accelerometer", "linear-acceleration" and "gyroscope" for DeviceMotionEvent, but there's no clear mapping to one or more sensor types for DeviceOrientationEvent. One could require "accelerometer" and "gyroscope" for relative orientation, for example, but implementations are arguably free to obtain the Euler angles data from the platform in another manner altogether, so I'm tempted to just go with making this specification define additional virtual sensor types, "relative-orientation-data" and "absolute-orientation-data" that takes Euler angles directly.
  2. At the risk of contradicting some of the statements above, using 3 separate sensors ("accelerometer", "linear-acceleration" and "gyroscope") for DeviceMotionEvent may be racy since a new event may fire while one of the sensors is still being updated. In this case, we may need to define a new virtual sensor type that takes all 3 readings at once, and leave it to the implementation to update all readings at once on the platform side.
@reillyeon
Copy link
Member

  • What kind of virtual sensor type to use for the deviceorientation and deviceorientationabsolute events. We can clearly use "accelerometer", "linear-acceleration" and "gyroscope" for DeviceMotionEvent, but there's no clear mapping to one or more sensor types for DeviceOrientationEvent. One could require "accelerometer" and "gyroscope" for relative orientation, for example, but implementations are arguably free to obtain the Euler angles data from the platform in another manner altogether, so I'm tempted to just go with making this specification define additional virtual sensor types, "relative-orientation-data" and "absolute-orientation-data" that takes Euler angles directly.

I'm leaning towards the virtual sensors defined in https://w3c.github.io/orientation-sensor/#automation, the only issue being that they use quaternions instead of Euler angles.

  • At the risk of contradicting some of the statements above, using 3 separate sensors ("accelerometer", "linear-acceleration" and "gyroscope") for DeviceMotionEvent may be racy since a new event may fire while one of the sensors is still being updated. In this case, we may need to define a new virtual sensor type that takes all 3 readings at once, and leave it to the implementation to update all readings at once on the platform side.

I don't know about iOS, but on Android the underlying platform API provides accelerometer and gyroscope data independently so these two data sources don't provide readings at the same time and I think it's reasonable for the test interface to reflect that since it is something implementations must deal with.

@rakuco
Copy link
Member Author

rakuco commented Nov 15, 2023

  • What kind of virtual sensor type to use for the deviceorientation and deviceorientationabsolute events. We can clearly use "accelerometer", "linear-acceleration" and "gyroscope" for DeviceMotionEvent, but there's no clear mapping to one or more sensor types for DeviceOrientationEvent. One could require "accelerometer" and "gyroscope" for relative orientation, for example, but implementations are arguably free to obtain the Euler angles data from the platform in another manner altogether, so I'm tempted to just go with making this specification define additional virtual sensor types, "relative-orientation-data" and "absolute-orientation-data" that takes Euler angles directly.

I'm leaning towards the virtual sensors defined in https://w3c.github.io/orientation-sensor/#automation, the only issue being that they use quaternions instead of Euler angles.

The simplest option would then be having some extra sensor types (e.g. "absolute-orientation-euler" and "relative-orientation-euler") with a custom parsing algorithm that reads alpha, beta and gamma values and ensures they are within the ranges we allow for each ([0, 360) for alpha, for example).

I can start working on a PR if this approach (including building it upon the virtual sensor infrastructure from Generic Sensors) sounds sane enough.

@rakuco
Copy link
Member Author

rakuco commented Nov 16, 2023

Switching the existing tests in WPT to this approach does seem to work, doing this from a spec perspective is a bit tricky.

The idea is to be able to say "we only depend on the Automation section", but the Automation section itself references concepts from other parts of the spec.

For example, if we were to define a per-type virtual sensor metadata entry for "relative-orientation-euler", we'd need to define a corresponding virtual sensor type, which is a sensor type. A sensor type requires one or more IDL interfaces, powerful feature names and permissions policy tokens. Similarly, if we want to use the "accelerometer" virtual sensor type for Device Motion, it means referencing https://w3c.github.io/accelerometer/#accelerometer-automation, which references the Accelerometer sensor type that requires the presence of the Accelerometer IDL interface.

In practice, this is a lot of spec legalese, but it's hard to ignore when changing this specification.

Copying the content from the Generic Sensor spec doesn't fully solve the problem either, as we'd then have conflicting behavior definitions for sensors like accelerometer and gyroscope.

@reillyeon
Copy link
Member

What if we added an Automation section to this spec which hooked into the virtual sensor update algorithms and said "when a quaternion value is provided here, convert it to Euler angles and provide it here"?

@rakuco
Copy link
Member Author

rakuco commented Nov 18, 2023

I don't think this addresses the underlying problem of virtual sensors depending on and referencing <dfn>s that are not Automation-related. In the case of using accelerometer and gyroscope types for DeviceMotionEvent, for example, wouldn't it mean this spec would also implicitly depend on the Accelerometer sensor type and IDL interface?

@rakuco
Copy link
Member Author

rakuco commented Nov 20, 2023

Hmm, I think if I tweak the Automation section in the Generic Sensor spec, I can remove the explicit link between virtual sensors and sensor types in the per-type virtual sensor metadata mapping by making the sensor type itself optionally have the same string that identifies a virtual sensor type.

The Device Orientation spec side would still be a bit hand-wavy, but I guess that's to be expected.

@reillyeon
Copy link
Member

Agreed, the challenge is that the Generic Sensors spec has "platform sensor" as a core concept which can be replaced by a virtual sensor while this specification what the source of the data is.

rakuco added a commit to w3c/sensors that referenced this issue Nov 21, 2023
This practically untangles the concepts in the Automation section from the
rest of the specification, which helps the Device Orientation API
specification adopt it as discussed in w3c/deviceorientation#122.

Now a sensor type itself can optionally define a "virtual sensor type",
a string. It is the same string used to refer to a given virtual sensor type
in the WebDriver extension commands.

In practice, this means that:
- The per-top-level traversable virtual sensor mapping has become a mapping
  of virtual sensor types to virtual sensor.
- The per-type virtual sensor metadata mapping has become a mapping of
  virtual sensor types to virtual sensor metadata.
- Sensor types that define a virtual sensor type attempt to retrieve a
  virtual sensor from the virtual sensor mapping using this string as key.

There are no user-visible changes or changes to the WebDriver extension
commands, it is only the concepts and data structures used internally in the
specification that have changed a little.

Derived specifications will need to be adjusted accordingly once this pull
request is merged.
rakuco added a commit that referenced this issue Nov 21, 2023
This PR integrates with the automation concepts defined in
https://w3c.github.io/sensors/#automation to allow providing motion or
orientation readings via virtual sensors through the WebDriver extension
commands defined there.

IMPORTANT: This does not mean that this specification requires
implementations to support the Generic Sensor API specification and its
derived specifications. Only the Automation section is being referenced, and
when necessary some algorithms and definitions are being duplicated here,
especially for Device Motion automation.

Device Orientation:
- The "absolute-orientation-euler" and "relative-orientation-euler" virtual
  sensor types are defined in this specification, along with a parsing
  algorithm that reads alpha, beta and gamma doubles.

Device Motion:
- Readings are controlled via the "accelerometer", "linear-acceleration" and
  "gyroscope" virtual sensor types. They are defined in the Accelerometer
  and Gyroscope specifications. A fallback path for implementations that do
  not support those specs has been provided.

Fixes #122.
@rakuco
Copy link
Member Author

rakuco commented Nov 21, 2023

Hmm, I think if I tweak the Automation section in the Generic Sensor spec, I can remove the explicit link between virtual sensors and sensor types in the per-type virtual sensor metadata mapping by making the sensor type itself optionally have the same string that identifies a virtual sensor type.

The Device Orientation spec side would still be a bit hand-wavy, but I guess that's to be expected.

I've made an attempt to do this in w3c/sensors#475. The Device Orientation side is in #124.

rakuco added a commit to w3c/sensors that referenced this issue Nov 22, 2023
…#475)

This practically untangles the concepts in the Automation section from the
rest of the specification, which helps the Device Orientation API
specification adopt it as discussed in w3c/deviceorientation#122.

Now a sensor type itself can optionally define a "virtual sensor type",
a string. It is the same string used to refer to a given virtual sensor type
in the WebDriver extension commands.

In practice, this means that:
- The per-top-level traversable virtual sensor mapping has become a mapping
  of virtual sensor types to virtual sensor.
- The per-type virtual sensor metadata mapping has become a mapping of
  virtual sensor types to virtual sensor metadata.
- Sensor types that define a virtual sensor type attempt to retrieve a
  virtual sensor from the virtual sensor mapping using this string as key.

There are no user-visible changes or changes to the WebDriver extension
commands, it is only the concepts and data structures used internally in the
specification that have changed a little.

Derived specifications will need to be adjusted accordingly once this pull
request is merged.
rakuco added a commit that referenced this issue Dec 5, 2023
This PR integrates with the automation concepts defined in
https://w3c.github.io/sensors/#automation to allow providing motion or
orientation readings via virtual sensors through the WebDriver extension
commands defined there.

IMPORTANT: This does not mean that this specification requires
implementations to support the Generic Sensor API specification and its
derived specifications. Only the Automation section is being referenced, and
when necessary some algorithms and definitions are being duplicated here,
especially for Device Motion automation.

The definitions of the "accelerometer", "linear-acceleration", "gyroscope",
"absolute-orientation", and "relative-orientation" virtual sensor types have
been moved here from their original specifications. As suggested in #124 and
similarly to what has been discussed in PRs #121 and #123, since this
specification is further along the Rec track and is implemented by more
engines, it makes sense to have the exported definitions here and reference
them from the other specs instead.

Device Motion:
- Readings are controlled via the "accelerometer", "linear-acceleration" and
  "gyroscope" virtual sensor types.

Device Orientation:
- The "absolute-orientation" and "relative-orientation" virtual sensor types
  are defined in this specification, along with a parsing algorithm that
  reads alpha, beta and gamma doubles.
  Compared to device motion, however, we have an additional problem in that
  device orientation data is provided in Euler angles and Orientation Sensor
  uses quaternions.
  The idea is to parse readings by reading alpha/beta/gamma keys from the
  WebDriver extension command and use them in the "fire orientation event"
  algorithm and skip using quaternions altogether. The Orientation Sensor
  spec can then augment the "parse orientation data reading" algorithm with
  the required steps to both 1) accept a "quaternion" key in the WebDriver
  extension command (and convert it to Euler angles as well) and 2) derive a
  quaternion from the alpha/beta/gamma Euler angles.

Fixes #122.
rakuco added a commit that referenced this issue Jan 4, 2024
This PR integrates with the automation concepts defined in
https://w3c.github.io/sensors/#automation to allow providing motion or
orientation readings via virtual sensors through the WebDriver extension
commands defined there.

IMPORTANT: This does not mean that this specification requires
implementations to support the Generic Sensor API specification and its
derived specifications. Only the Automation section is being referenced, and
when necessary some algorithms and definitions are being duplicated here,
especially for Device Motion automation.

The definitions of the "accelerometer", "linear-acceleration", "gyroscope",
"absolute-orientation", and "relative-orientation" virtual sensor types have
been moved here from their original specifications. As suggested in #124 and
similarly to what has been discussed in PRs #121 and #123, since this
specification is further along the Rec track and is implemented by more
engines, it makes sense to have the exported definitions here and reference
them from the other specs instead.

Device Motion:
- Readings are controlled via the "accelerometer", "linear-acceleration" and
  "gyroscope" virtual sensor types.

Device Orientation:
- The "absolute-orientation" and "relative-orientation" virtual sensor types
  are defined in this specification, along with a parsing algorithm that
  reads alpha, beta and gamma doubles.
  Compared to device motion, however, we have an additional problem in that
  device orientation data is provided in Euler angles and Orientation Sensor
  uses quaternions.
  The idea is to parse readings by reading alpha/beta/gamma keys from the
  WebDriver extension command and use them in the "fire orientation event"
  algorithm and skip using quaternions altogether. The Orientation Sensor
  spec can then augment the "parse orientation data reading" algorithm with
  the required steps to both 1) accept a "quaternion" key in the WebDriver
  extension command (and convert it to Euler angles as well) and 2) derive a
  quaternion from the alpha/beta/gamma Euler angles.

Fixes #122.
rakuco added a commit that referenced this issue Jan 4, 2024
This PR integrates with the automation concepts defined in
https://w3c.github.io/sensors/#automation to allow providing motion or
orientation readings via virtual sensors through the WebDriver extension
commands defined there.

IMPORTANT: This does not mean that this specification requires
implementations to support the Generic Sensor API specification and its
derived specifications. Only the Automation section is being referenced, and
when necessary some algorithms and definitions are being duplicated here,
especially for Device Motion automation.

The definitions of the "accelerometer", "linear-acceleration", "gyroscope",
"absolute-orientation", and "relative-orientation" virtual sensor types have
been moved here from their original specifications. As suggested in #124 and
similarly to what has been discussed in PRs #121 and #123, since this
specification is further along the Rec track and is implemented by more
engines, it makes sense to have the exported definitions here and reference
them from the other specs instead.

Device Motion:
- Readings are controlled via the "accelerometer", "linear-acceleration" and
  "gyroscope" virtual sensor types.

Device Orientation:
- The "absolute-orientation" and "relative-orientation" virtual sensor types
  are defined in this specification, along with a parsing algorithm that
  reads alpha, beta and gamma doubles.
  Compared to device motion, however, we have an additional problem in that
  device orientation data is provided in Euler angles and Orientation Sensor
  uses quaternions.
  The idea is to parse readings by reading alpha/beta/gamma keys from the
  WebDriver extension command and use them in the "fire orientation event"
  algorithm and skip using quaternions altogether. The Orientation Sensor
  spec can then augment the "parse orientation data reading" algorithm with
  the required steps to both 1) accept a "quaternion" key in the WebDriver
  extension command (and convert it to Euler angles as well) and 2) derive a
  quaternion from the alpha/beta/gamma Euler angles.

Fixes #122.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants