-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
orientation-event: Add Permissions Policy integration tests #45428
base: master
Are you sure you want to change the base?
orientation-event: Add Permissions Policy integration tests #45428
Conversation
Add tests for deviceorientationabsolute, deviceorientation and devicemotion as described in https://w3c.github.io/deviceorientation/#permissions-policy-integration: - The deviceorientation event requires the "accelerometer" and "gyroscope" features. - The deviceorientationabsolute event requires the "accelerometer", "gyroscope" and "magnetometer" features. - The devicemotion event requires the "accelerometer" and "gyroscope" features. (WebKit currently requires the "magnetometer" feature for deviceorientation events, see https://bugs.webkit.org/show_bug.cgi?id=271891). The tests being added follow permissions-policy/README.md's recommendations: - Tests with different Permissions-Policy header values and how they influence usage in the top-level frame, same-origin iframes and cross-origin iframes. - Different values for the "allow" attribute and how they influece same-origin and cross-origin iframes. - Usage of the "allow" attribute with redirection. This is the minimum amount of coverage we need. These tests can be expanded to include: - Calls to `run_all_fp_tests_allow_self()` to test the behavior of the default policy for each feature (it requires making the function work with more than one feature). - The relative orientation to absolute orientation fallback behavior that depends on whether the "magnetometer" feature is enabled. - Not enabling all features (it may cause an explosion in the number of tests though).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nits
...eviceorientationabsolute-allowed-by-permissions-policy-attribute-redirect-on-load.https.html
Outdated
Show resolved
Hide resolved
...eviceorientationabsolute-allowed-by-permissions-policy-attribute-redirect-on-load.https.html
Outdated
Show resolved
Hide resolved
...policy/deviceorientation-allowed-by-permissions-policy-attribute-redirect-on-load.https.html
Outdated
Show resolved
Hide resolved
...policy/deviceorientation-allowed-by-permissions-policy-attribute-redirect-on-load.https.html
Outdated
Show resolved
Hide resolved
...ions-policy/devicemotion-allowed-by-permissions-policy-attribute-redirect-on-load.https.html
Outdated
Show resolved
Hide resolved
...ions-policy/devicemotion-allowed-by-permissions-policy-attribute-redirect-on-load.https.html
Outdated
Show resolved
Hide resolved
...ions-policy/devicemotion-allowed-by-permissions-policy-attribute-redirect-on-load.https.html
Outdated
Show resolved
Hide resolved
promise_test(async t => { | ||
const helper = new SensorTestHelper(t, 'devicemotion'); | ||
await helper.grantSensorsPermissions(); | ||
await helper.initializeSensors(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This puts a dependency on create_virtual_sensor :( Are we sure there isn't some other way to test this?
With other permission policy tests, we usually just have a simple iframe that tries to use the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This puts a dependency on create_virtual_sensor :( Are we sure there isn't some other way to test this?
I don't think so. This API does not have any mechanisms to throw an exception when permissions policy checks fail like other APIs do, so we need a way to verify that the checks have failed, in which case we wait for readings not to be delivered. We could try to reach consensus on w3c/deviceorientation#118, but it wouldn't help with the case in which we need to verify that the checks do pass, as without virtual sensors we'd be entirely dependent on the presence of specific hardware for them to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, yeah... I was trying to think of something too... and the only thing was trying to create the events in JS, which is silly.
Co-authored-by: Reilly Grant <[email protected]>
Co-authored-by: Reilly Grant <[email protected]>
Co-authored-by: Reilly Grant <[email protected]>
Co-authored-by: Reilly Grant <[email protected]>
Co-authored-by: Reilly Grant <[email protected]>
Co-authored-by: Reilly Grant <[email protected]>
permissions-policy/resources/permissions-policy-orientation-event.sub.html
Outdated
Show resolved
Hide resolved
|
||
async function waitForOrientationEvent(eventName) { | ||
if (eventName !== 'devicemotion' && eventName !== 'deviceorientation' && eventName !== 'deviceorientationabsolute') { | ||
return 'ERROR'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should throw real errors here. It might make things easier to debug if things go wrong.
// policy checks fail, so what we do here is wait for the timeout and the | ||
// devicemotion event handler to race each other. | ||
value = await new Promise((resolve, reject) => { | ||
const timeoutId = window.setTimeout(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't fly... it's gonna be super racy on testing infrastructure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have anything else in mind? This API doesn't throw any errors or fire any events when a permissions/permissions policy check fails, so the only other option would be adding a ReportingObserver and waiting for a permissions-policy-violation report. Would that be acceptable?
value = await new Promise((resolve, reject) => { | ||
const timeoutId = window.setTimeout(() => { | ||
window.removeEventListener(eventName, handler); | ||
reject('NO-EVENT'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reject with real error if we do this... otherwise we lose the error stack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is not having an error stack really a problem in this case? test_feature_availability_with_post_message_result()
expects a string, so throwing an Error here would essentially require some plumbing that would ultimately result in a string comparison anyway.
The Promise.resolve() idea was copy-pasted from another file, but adding a load event handler makes it more clear and in line with other files in permissions-policy/resources. While here, use Promise.then() instead of async/await to match other files as well.
Hey, promise to take a look soon! At a conference this week, but will try to sneak these in! |
Add tests for deviceorientationabsolute, deviceorientation and devicemotion
as described in
https://w3c.github.io/deviceorientation/#permissions-policy-integration:
features.
"gyroscope" and "magnetometer" features.
features.
(WebKit currently requires the "magnetometer" feature for deviceorientation
events, see https://bugs.webkit.org/show_bug.cgi?id=271891).
The tests being added follow permissions-policy/README.md's recommendations:
influence usage in the top-level frame, same-origin iframes and
cross-origin iframes.
same-origin and cross-origin iframes.
This is the minimum amount of coverage we need. These tests can be expanded
to include:
run_all_fp_tests_allow_self()
to test the behavior of thedefault policy for each feature (it requires making the function work with
more than one feature).
depends on whether the "magnetometer" feature is enabled.
tests though).