From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../web-platform/tests/orientation-event/META.yml | 4 + .../web-platform/tests/orientation-event/README.md | 8 + ...ntation-events-of-detached-documents.https.html | 48 ++++ ...ion-events-unavailable-on-insecure-origins.html | 61 +++++ .../orientation-event/idlharness.https.window.js | 19 ++ .../motion/add-during-dispatch.https.html | 36 +++ .../motion/add-listener-from-callback.https.html | 53 ++++ .../motion/create-event.https.html | 41 +++ .../motion/free-fall-manual.https.html | 48 ++++ .../motion/multiple-event-listeners.https.html | 30 +++ .../motion/null-values.https.html | 53 ++++ .../motion/optional-event-properties.https.html | 257 +++++++++++++++++++ .../motion/page-visibility.https.html | 52 ++++ .../motion/requestPermission.https.window.js | 48 ++++ .../motion/screen-upmost-manual.https.html | 51 ++++ .../motion/screen-upright-manual.https.html | 50 ++++ .../motion/t025-manual.https.html | 38 +++ .../motion/t028-manual.https.html | 36 +++ .../orientation/absolute-fallback.https.html | 23 ++ .../add-listener-from-callback.https.html | 59 +++++ .../basic-operation-absolute.https.html | 34 +++ .../orientation/basic-operation.https.html | 34 +++ .../orientation/create-event.https.html | 40 +++ .../horizontal-surface-manual.https.html | 34 +++ .../multiple-event-listeners.https.html | 27 ++ .../orientation/no-synchronous-events.https.html | 24 ++ .../orientation/null-values.https.html | 27 ++ .../optional-event-properties.https.html | 73 ++++++ .../orientation/page-visibility.https.html | 50 ++++ .../orientation/requestPermission.https.window.js | 48 ++++ .../orientation/t006-manual.https.html | 30 +++ .../orientation/t009-manual.https.html | 30 +++ .../orientation/t010-manual.https.html | 30 +++ .../orientation/t012-manual.https.html | 41 +++ .../orientation/updates.https.html | 37 +++ .../resources/orientation-event-helpers.js | 274 +++++++++++++++++++++ 36 files changed, 1848 insertions(+) create mode 100644 testing/web-platform/tests/orientation-event/META.yml create mode 100644 testing/web-platform/tests/orientation-event/README.md create mode 100644 testing/web-platform/tests/orientation-event/device-orientation-events-of-detached-documents.https.html create mode 100644 testing/web-platform/tests/orientation-event/device-orientation-events-unavailable-on-insecure-origins.html create mode 100644 testing/web-platform/tests/orientation-event/idlharness.https.window.js create mode 100644 testing/web-platform/tests/orientation-event/motion/add-during-dispatch.https.html create mode 100644 testing/web-platform/tests/orientation-event/motion/add-listener-from-callback.https.html create mode 100644 testing/web-platform/tests/orientation-event/motion/create-event.https.html create mode 100644 testing/web-platform/tests/orientation-event/motion/free-fall-manual.https.html create mode 100644 testing/web-platform/tests/orientation-event/motion/multiple-event-listeners.https.html create mode 100644 testing/web-platform/tests/orientation-event/motion/null-values.https.html create mode 100644 testing/web-platform/tests/orientation-event/motion/optional-event-properties.https.html create mode 100644 testing/web-platform/tests/orientation-event/motion/page-visibility.https.html create mode 100644 testing/web-platform/tests/orientation-event/motion/requestPermission.https.window.js create mode 100644 testing/web-platform/tests/orientation-event/motion/screen-upmost-manual.https.html create mode 100644 testing/web-platform/tests/orientation-event/motion/screen-upright-manual.https.html create mode 100644 testing/web-platform/tests/orientation-event/motion/t025-manual.https.html create mode 100644 testing/web-platform/tests/orientation-event/motion/t028-manual.https.html create mode 100644 testing/web-platform/tests/orientation-event/orientation/absolute-fallback.https.html create mode 100644 testing/web-platform/tests/orientation-event/orientation/add-listener-from-callback.https.html create mode 100644 testing/web-platform/tests/orientation-event/orientation/basic-operation-absolute.https.html create mode 100644 testing/web-platform/tests/orientation-event/orientation/basic-operation.https.html create mode 100644 testing/web-platform/tests/orientation-event/orientation/create-event.https.html create mode 100644 testing/web-platform/tests/orientation-event/orientation/horizontal-surface-manual.https.html create mode 100644 testing/web-platform/tests/orientation-event/orientation/multiple-event-listeners.https.html create mode 100644 testing/web-platform/tests/orientation-event/orientation/no-synchronous-events.https.html create mode 100644 testing/web-platform/tests/orientation-event/orientation/null-values.https.html create mode 100644 testing/web-platform/tests/orientation-event/orientation/optional-event-properties.https.html create mode 100644 testing/web-platform/tests/orientation-event/orientation/page-visibility.https.html create mode 100644 testing/web-platform/tests/orientation-event/orientation/requestPermission.https.window.js create mode 100644 testing/web-platform/tests/orientation-event/orientation/t006-manual.https.html create mode 100644 testing/web-platform/tests/orientation-event/orientation/t009-manual.https.html create mode 100644 testing/web-platform/tests/orientation-event/orientation/t010-manual.https.html create mode 100644 testing/web-platform/tests/orientation-event/orientation/t012-manual.https.html create mode 100644 testing/web-platform/tests/orientation-event/orientation/updates.https.html create mode 100644 testing/web-platform/tests/orientation-event/resources/orientation-event-helpers.js (limited to 'testing/web-platform/tests/orientation-event') diff --git a/testing/web-platform/tests/orientation-event/META.yml b/testing/web-platform/tests/orientation-event/META.yml new file mode 100644 index 0000000000..88014849d0 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/META.yml @@ -0,0 +1,4 @@ +spec: https://w3c.github.io/deviceorientation/ +suggested_reviewers: + - reillyeon + - timvolodine diff --git a/testing/web-platform/tests/orientation-event/README.md b/testing/web-platform/tests/orientation-event/README.md new file mode 100644 index 0000000000..14ea2f5117 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/README.md @@ -0,0 +1,8 @@ +The `resources/orientation-event-helpers.js` tests depend on the implementation of +the `GenericSensorTest` interface which is defined in [README.md](../generic-sensor/README.md). + +The Chromium implementation of the `GenericSensorTest` interface is located in +[generic_sensor_mocks.js](../resources/chromium/generic_sensor_mocks.js). + +Other browser vendors should provide their own implementations of +the `GenericSensorTest` interface. diff --git a/testing/web-platform/tests/orientation-event/device-orientation-events-of-detached-documents.https.html b/testing/web-platform/tests/orientation-event/device-orientation-events-of-detached-documents.https.html new file mode 100644 index 0000000000..f05be6d0d2 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/device-orientation-events-of-detached-documents.https.html @@ -0,0 +1,48 @@ + + + +Device sensor event listeners for `window` of detached documents. + + + + + + + + + + diff --git a/testing/web-platform/tests/orientation-event/device-orientation-events-unavailable-on-insecure-origins.html b/testing/web-platform/tests/orientation-event/device-orientation-events-unavailable-on-insecure-origins.html new file mode 100644 index 0000000000..6d2eee402f --- /dev/null +++ b/testing/web-platform/tests/orientation-event/device-orientation-events-unavailable-on-insecure-origins.html @@ -0,0 +1,61 @@ + +Device Sensor Events not exposed to insecure origins + + + + + + + diff --git a/testing/web-platform/tests/orientation-event/idlharness.https.window.js b/testing/web-platform/tests/orientation-event/idlharness.https.window.js new file mode 100644 index 0000000000..ba816bb87c --- /dev/null +++ b/testing/web-platform/tests/orientation-event/idlharness.https.window.js @@ -0,0 +1,19 @@ +// META: script=/resources/WebIDLParser.js +// META: script=/resources/idlharness.js +// META: timeout=long + +// https://w3c.github.io/deviceorientation/spec-source-orientation.html + +'use strict'; + +idl_test( + ['orientation-event'], + ['html', 'dom'], + idl_array => { + idl_array.add_objects({ + Window: ['window'], + DeviceOrientationEvent: ['new DeviceOrientationEvent("foo")'], + DeviceMotionEvent: ['new DeviceMotionEvent("foo")'], + }); + } +); diff --git a/testing/web-platform/tests/orientation-event/motion/add-during-dispatch.https.html b/testing/web-platform/tests/orientation-event/motion/add-during-dispatch.https.html new file mode 100644 index 0000000000..262715ce55 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/add-during-dispatch.https.html @@ -0,0 +1,36 @@ + + + + + + + diff --git a/testing/web-platform/tests/orientation-event/motion/add-listener-from-callback.https.html b/testing/web-platform/tests/orientation-event/motion/add-listener-from-callback.https.html new file mode 100644 index 0000000000..1f8cca86b2 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/add-listener-from-callback.https.html @@ -0,0 +1,53 @@ + + + + + + + diff --git a/testing/web-platform/tests/orientation-event/motion/create-event.https.html b/testing/web-platform/tests/orientation-event/motion/create-event.https.html new file mode 100644 index 0000000000..e8a2c469b1 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/create-event.https.html @@ -0,0 +1,41 @@ + + + + diff --git a/testing/web-platform/tests/orientation-event/motion/free-fall-manual.https.html b/testing/web-platform/tests/orientation-event/motion/free-fall-manual.https.html new file mode 100644 index 0000000000..c71f61fa69 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/free-fall-manual.https.html @@ -0,0 +1,48 @@ + + + + DeviceMotionEvent: A device in free-fall, with the screen horizontal and upmost + + + + + + +

Free fall the device to run the test, with the screen horizontal and upmost.

+
+ + + + diff --git a/testing/web-platform/tests/orientation-event/motion/multiple-event-listeners.https.html b/testing/web-platform/tests/orientation-event/motion/multiple-event-listeners.https.html new file mode 100644 index 0000000000..f94c9d136e --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/multiple-event-listeners.https.html @@ -0,0 +1,30 @@ + + + + + + + diff --git a/testing/web-platform/tests/orientation-event/motion/null-values.https.html b/testing/web-platform/tests/orientation-event/motion/null-values.https.html new file mode 100644 index 0000000000..f875afcd64 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/null-values.https.html @@ -0,0 +1,53 @@ + + + + + + + diff --git a/testing/web-platform/tests/orientation-event/motion/optional-event-properties.https.html b/testing/web-platform/tests/orientation-event/motion/optional-event-properties.https.html new file mode 100644 index 0000000000..0a73721cb9 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/optional-event-properties.https.html @@ -0,0 +1,257 @@ + + + + diff --git a/testing/web-platform/tests/orientation-event/motion/page-visibility.https.html b/testing/web-platform/tests/orientation-event/motion/page-visibility.https.html new file mode 100644 index 0000000000..2925af9331 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/page-visibility.https.html @@ -0,0 +1,52 @@ + + + + + + + + + + + + diff --git a/testing/web-platform/tests/orientation-event/motion/requestPermission.https.window.js b/testing/web-platform/tests/orientation-event/motion/requestPermission.https.window.js new file mode 100644 index 0000000000..2c96d26d10 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/requestPermission.https.window.js @@ -0,0 +1,48 @@ +// META: script=/resources/testdriver.js +// META: script=/resources/testdriver-vendor.js + +'use strict'; + +// The Device Orientation spec does not fully integrate with the Permissions +// spec and does not list the permissions that are expected for +// requestPermission() to work. The list below was based on the permission +// tokens corresponding to the sensors used to implement support for motion +// events. They also match the feature policy tokens required by both Blink and +// WebKit. +const permissionDescriptorNames = ['accelerometer', 'gyroscope']; + +promise_test(async (t) => { + await Promise.all(permissionDescriptorNames.map( + name => test_driver.set_permission({name}, 'granted'))); + + const permission = await DeviceMotionEvent.requestPermission(); + assert_equals(permission, 'granted'); +}, 'requestPermission() returns "granted" for granted permissions without user activation'); + +promise_test(async (t) => { + await Promise.all(permissionDescriptorNames.map( + name => test_driver.set_permission({name}, 'granted'))); + + return test_driver.bless('enable user activation', async () => { + const permission = await DeviceMotionEvent.requestPermission(); + assert_equals(permission, 'granted'); + }); +}, 'requestPermission() returns "granted" for granted permissions with user activation'); + +promise_test(async (t) => { + await Promise.all(permissionDescriptorNames.map( + name => test_driver.set_permission({name}, 'denied'))); + + const permission = await DeviceMotionEvent.requestPermission(); + assert_equals(permission, 'denied'); +}, 'requestPermission() returns "denied" for denied permissions without user activation'); + +promise_test(async (t) => { + await Promise.all(permissionDescriptorNames.map( + name => test_driver.set_permission({name}, 'denied'))); + + return test_driver.bless('enable user activation', async () => { + const permission = await DeviceMotionEvent.requestPermission(); + assert_equals(permission, 'denied'); + }); +}, 'requestPermission() returns "denied" for denied permissions with user activation'); diff --git a/testing/web-platform/tests/orientation-event/motion/screen-upmost-manual.https.html b/testing/web-platform/tests/orientation-event/motion/screen-upmost-manual.https.html new file mode 100644 index 0000000000..560c3e3a1f --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/screen-upmost-manual.https.html @@ -0,0 +1,51 @@ + + + + DeviceMotionEvent: A device lying flat on a horizontal surface with the screen upmost + + + + + + +

Put the device on a horizontal surface with the screen upmost.

+
+ + + + diff --git a/testing/web-platform/tests/orientation-event/motion/screen-upright-manual.https.html b/testing/web-platform/tests/orientation-event/motion/screen-upright-manual.https.html new file mode 100644 index 0000000000..8a1b6d27da --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/screen-upright-manual.https.html @@ -0,0 +1,50 @@ + + + + DeviceMotionEvent: A device with the screen upright + + + + + + +

Put the device with the screen upright.

+
+ + + + diff --git a/testing/web-platform/tests/orientation-event/motion/t025-manual.https.html b/testing/web-platform/tests/orientation-event/motion/t025-manual.https.html new file mode 100644 index 0000000000..9489855fcd --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/t025-manual.https.html @@ -0,0 +1,38 @@ + + + + Implementations that are unable to provide acceleration data without the effect of gravity may instead supply the acceleration including the effect of gravity + + + + + + + +

Move the device to run the test.

+
+ + + + diff --git a/testing/web-platform/tests/orientation-event/motion/t028-manual.https.html b/testing/web-platform/tests/orientation-event/motion/t028-manual.https.html new file mode 100644 index 0000000000..669c4e47e0 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/t028-manual.https.html @@ -0,0 +1,36 @@ + + + + The interval property must be expressed in milliseconds. It must be a constant, to simplify filtering of the data by the Web application + + + + + + + +

Move the device to run the test.

+
+ + + + diff --git a/testing/web-platform/tests/orientation-event/orientation/absolute-fallback.https.html b/testing/web-platform/tests/orientation-event/orientation/absolute-fallback.https.html new file mode 100644 index 0000000000..27a430728e --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/absolute-fallback.https.html @@ -0,0 +1,23 @@ + + + + + + + diff --git a/testing/web-platform/tests/orientation-event/orientation/add-listener-from-callback.https.html b/testing/web-platform/tests/orientation-event/orientation/add-listener-from-callback.https.html new file mode 100644 index 0000000000..7f664ab400 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/add-listener-from-callback.https.html @@ -0,0 +1,59 @@ + + + + + + + diff --git a/testing/web-platform/tests/orientation-event/orientation/basic-operation-absolute.https.html b/testing/web-platform/tests/orientation-event/orientation/basic-operation-absolute.https.html new file mode 100644 index 0000000000..bebd69b952 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/basic-operation-absolute.https.html @@ -0,0 +1,34 @@ + + + + + + + diff --git a/testing/web-platform/tests/orientation-event/orientation/basic-operation.https.html b/testing/web-platform/tests/orientation-event/orientation/basic-operation.https.html new file mode 100644 index 0000000000..c4d26e3744 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/basic-operation.https.html @@ -0,0 +1,34 @@ + + + + + + + diff --git a/testing/web-platform/tests/orientation-event/orientation/create-event.https.html b/testing/web-platform/tests/orientation-event/orientation/create-event.https.html new file mode 100644 index 0000000000..a21f95655e --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/create-event.https.html @@ -0,0 +1,40 @@ + + + + diff --git a/testing/web-platform/tests/orientation-event/orientation/horizontal-surface-manual.https.html b/testing/web-platform/tests/orientation-event/orientation/horizontal-surface-manual.https.html new file mode 100644 index 0000000000..0b7302e704 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/horizontal-surface-manual.https.html @@ -0,0 +1,34 @@ + + + + DeviceOrientationEvent: A device lying flat on a horizontal surface + + + + + + +

Put the device on a horizontal surface to run the test.

+
+ + + + diff --git a/testing/web-platform/tests/orientation-event/orientation/multiple-event-listeners.https.html b/testing/web-platform/tests/orientation-event/orientation/multiple-event-listeners.https.html new file mode 100644 index 0000000000..a32f9f3a1f --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/multiple-event-listeners.https.html @@ -0,0 +1,27 @@ + + + + + + + diff --git a/testing/web-platform/tests/orientation-event/orientation/no-synchronous-events.https.html b/testing/web-platform/tests/orientation-event/orientation/no-synchronous-events.https.html new file mode 100644 index 0000000000..97dccfbc31 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/no-synchronous-events.https.html @@ -0,0 +1,24 @@ + + + + + + + diff --git a/testing/web-platform/tests/orientation-event/orientation/null-values.https.html b/testing/web-platform/tests/orientation-event/orientation/null-values.https.html new file mode 100644 index 0000000000..c54d73da50 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/null-values.https.html @@ -0,0 +1,27 @@ + + + + + + + diff --git a/testing/web-platform/tests/orientation-event/orientation/optional-event-properties.https.html b/testing/web-platform/tests/orientation-event/orientation/optional-event-properties.https.html new file mode 100644 index 0000000000..150ce5ca1d --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/optional-event-properties.https.html @@ -0,0 +1,73 @@ + + + + diff --git a/testing/web-platform/tests/orientation-event/orientation/page-visibility.https.html b/testing/web-platform/tests/orientation-event/orientation/page-visibility.https.html new file mode 100644 index 0000000000..bcb4beeb8e --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/page-visibility.https.html @@ -0,0 +1,50 @@ + + + + + + + + + + + + diff --git a/testing/web-platform/tests/orientation-event/orientation/requestPermission.https.window.js b/testing/web-platform/tests/orientation-event/orientation/requestPermission.https.window.js new file mode 100644 index 0000000000..4a39a238d0 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/requestPermission.https.window.js @@ -0,0 +1,48 @@ +// META: script=/resources/testdriver.js +// META: script=/resources/testdriver-vendor.js + +'use strict'; + +// The Device Orientation spec does not fully integrate with the Permissions +// spec and does not list the permissions that are expected for +// requestPermission() to work. The list below was based on the permissions +// listed in https://w3c.github.io/orientation-sensor/#model for the low-level +// sensors that power absolute and relative orientation sensors. +const permissionDescriptorNames = + ['accelerometer', 'gyroscope', 'magnetometer']; + +promise_test(async (t) => { + await Promise.all(permissionDescriptorNames.map( + name => test_driver.set_permission({name}, 'granted'))); + + const permission = await DeviceOrientationEvent.requestPermission(); + assert_equals(permission, 'granted'); +}, 'requestPermission() returns "granted" for granted permissions without user activation'); + +promise_test(async (t) => { + await Promise.all(permissionDescriptorNames.map( + name => test_driver.set_permission({name}, 'granted'))); + + return test_driver.bless('enable user activation', async () => { + const permission = await DeviceOrientationEvent.requestPermission(); + assert_equals(permission, 'granted'); + }); +}, 'requestPermission() returns "granted" for granted permissions with user activation'); + +promise_test(async (t) => { + await Promise.all(permissionDescriptorNames.map( + name => test_driver.set_permission({name}, 'denied'))); + + const permission = await DeviceOrientationEvent.requestPermission(); + assert_equals(permission, 'denied'); +}, 'requestPermission() returns "denied" for denied permissions without user activation'); + +promise_test(async (t) => { + await Promise.all(permissionDescriptorNames.map( + name => test_driver.set_permission({name}, 'denied'))); + + return test_driver.bless('enable user activation', async () => { + const permission = await DeviceOrientationEvent.requestPermission(); + assert_equals(permission, 'denied'); + }); +}, 'requestPermission() returns "denied" for denied permissions with user activation'); diff --git a/testing/web-platform/tests/orientation-event/orientation/t006-manual.https.html b/testing/web-platform/tests/orientation-event/orientation/t006-manual.https.html new file mode 100644 index 0000000000..e41f4634e8 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/t006-manual.https.html @@ -0,0 +1,30 @@ + + + + Rotate the device frame around its z axis + + + + + + + +

Rotate the device frame around its z axis to run the test.

+
+ + + + diff --git a/testing/web-platform/tests/orientation-event/orientation/t009-manual.https.html b/testing/web-platform/tests/orientation-event/orientation/t009-manual.https.html new file mode 100644 index 0000000000..d00f7e71b0 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/t009-manual.https.html @@ -0,0 +1,30 @@ + + + + Rotate the device frame around its x axis + + + + + + + +

Rotate the device frame around its x axis to run the test.

+
+ + + + diff --git a/testing/web-platform/tests/orientation-event/orientation/t010-manual.https.html b/testing/web-platform/tests/orientation-event/orientation/t010-manual.https.html new file mode 100644 index 0000000000..9a6e00e1f7 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/t010-manual.https.html @@ -0,0 +1,30 @@ + + + + Rotate the device frame around its y axis + + + + + + + +

Rotate the device frame around its y axis to run the test.

+
+ + + + diff --git a/testing/web-platform/tests/orientation-event/orientation/t012-manual.https.html b/testing/web-platform/tests/orientation-event/orientation/t012-manual.https.html new file mode 100644 index 0000000000..e5ac1c98b4 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/t012-manual.https.html @@ -0,0 +1,41 @@ + + + + Implementations that are unable to provide all three angles must set the values of the unknown angles to null + + + + + + + +

Precondition: implementation is unable to provide all three angles

+

Rotate the device to run the test.

+
+ + + + diff --git a/testing/web-platform/tests/orientation-event/orientation/updates.https.html b/testing/web-platform/tests/orientation-event/orientation/updates.https.html new file mode 100644 index 0000000000..fe1811535b --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/updates.https.html @@ -0,0 +1,37 @@ + + + + + + + diff --git a/testing/web-platform/tests/orientation-event/resources/orientation-event-helpers.js b/testing/web-platform/tests/orientation-event/resources/orientation-event-helpers.js new file mode 100644 index 0000000000..01e91c62ae --- /dev/null +++ b/testing/web-platform/tests/orientation-event/resources/orientation-event-helpers.js @@ -0,0 +1,274 @@ +'use strict'; + +// @class SensorTestHelper +// +// SensorTestHelper is a helper utilities for orientation event tests. +// +// Usage example with device orientation: +// const helper = new SensorTestHelper(t, 'deviceorientation'); +// await helper.grantSensorsPermissions(); +// await helper.initializeSensors(); +// const generatedData = generateOrientationData(1, 2, 3, false); +// await helper.setData(generatedData); +// await waitForEvent(getExpectedOrientationEvent(generatedData)); +class SensorTestHelper { + #eventName; + #sensorsEnabledByDefault; + #enabledSensors; + #disabledSensors; + #testObject; + + // @param {object} t - A testharness.js subtest instance. + // @param {string} eventName - A name of event. Accepted values are + // devicemotion, deviceorientation or + // deviceorientationabsolute. + constructor(t, eventName) { + this.#eventName = eventName; + this.#testObject = t; + this.#testObject.add_cleanup(() => this.reset()); + + switch (this.#eventName) { + case 'devicemotion': + this.#sensorsEnabledByDefault = + new Set(['accelerometer', 'gyroscope', 'linear-acceleration']); + break; + case 'deviceorientation': + this.#sensorsEnabledByDefault = new Set(['relative-orientation']); + break; + case 'deviceorientationabsolute': + this.#sensorsEnabledByDefault = new Set(['absolute-orientation']); + break; + default: + throw new Error(`Invalid event name ${this.#eventName}`); + } + } + + // Creates virtual sensors that will be used in tests. + // + // This function must be called before event listeners are added or calls + // to setData() or waitForEvent() are made. + // + // The |options| parameter is an object that accepts the following entries: + // - enabledSensors: A list of virtual sensor names that will be created + // instead of the default ones for a given event type. + // - disabledSensors: A list of virtual sensor names that will be created + // in a disabled state, so that creating a sensor of + // a given type is guaranteed to fail. + // An Error is thrown if the same name is passed to both options. + // + // A default list of virtual sensors based on the |eventName| parameter passed + // to the constructor is used if |options| is not specified. + // + // Usage examples + // Use default sensors for the given event type: + // await helper.initializeSensors() + // Enable specific sensors: + // await helper.initializeSensors({ + // enabledSensors: ['accelerometer', 'gyroscope'] + // }) + // Disable some sensors, make some report as not available: + // await helper.initializeSensors({ + // disabledSensors: ['gyroscope'] + // }) + // Enable some sensors, make some report as not available: + // await helper.initializeSensors({ + // enabledSensors: ['accelerometer'], + // disabledSensors: ['gyroscope'] + // }) + async initializeSensors(options = {}) { + this.#disabledSensors = new Set(options.disabledSensors || []); + // Check that a sensor name is not in both |options.enabledSensors| and + // |options.disabledSensors|. + for (const sensor of (options.enabledSensors || [])) { + if (this.#disabledSensors.has(sensor)) { + throw new Error(`${sensor} can be defined only as enabledSensors or disabledSensors`); + } + } + + this.#enabledSensors = new Set(options.enabledSensors || this.#sensorsEnabledByDefault); + // Remove sensors from enabledSensors that are in disabledSensors + for (const sensor of this.#disabledSensors) { + this.#enabledSensors.delete(sensor); + } + + const createVirtualSensorPromises = []; + for (const sensor of this.#enabledSensors) { + createVirtualSensorPromises.push( + test_driver.create_virtual_sensor(sensor)); + } + for (const sensor of this.#disabledSensors) { + createVirtualSensorPromises.push( + test_driver.create_virtual_sensor(sensor, {connected: false})); + } + await Promise.all(createVirtualSensorPromises); + } + + // Updates virtual sensor with given data. + // @param {object} data - Generated data by generateMotionData or + // generateOrientationData which is passed to + // test_driver.update_virtual_sensor(). + async setData(data) { + // WebDriver expects numbers for all values in the readings it receives. We + // convert null to zero here, but any other numeric value would work, as it + // is the presence of one or more sensors in initializeSensors()' + // options.disabledSensors that cause null to be reported in one or more + // event attributes. + const nullToZero = x => (x === null ? 0 : x); + if (this.#eventName === 'devicemotion') { + const degToRad = Math.PI / 180; + await Promise.all([ + test_driver.update_virtual_sensor('accelerometer', { + 'x': nullToZero(data.accelerationIncludingGravityX), + 'y': nullToZero(data.accelerationIncludingGravityY), + 'z': nullToZero(data.accelerationIncludingGravityZ), + }), + test_driver.update_virtual_sensor('linear-acceleration', { + 'x': nullToZero(data.accelerationX), + 'y': nullToZero(data.accelerationY), + 'z': nullToZero(data.accelerationZ), + }), + test_driver.update_virtual_sensor('gyroscope', { + 'x': nullToZero(data.rotationRateAlpha) * degToRad, + 'y': nullToZero(data.rotationRateBeta) * degToRad, + 'z': nullToZero(data.rotationRateGamma) * degToRad, + }), + ]); + } else { + const sensorType = + data.absolute ? 'absolute-orientation' : 'relative-orientation'; + await test_driver.update_virtual_sensor(sensorType, { + alpha: nullToZero(data.alpha), + beta: nullToZero(data.beta), + gamma: nullToZero(data.gamma), + }); + } + } + + // Grants permissions to sensors. Depending on |eventName|, requests + // permission to use either the DeviceMotionEvent or the + // DeviceOrientationEvent API. + async grantSensorsPermissions() { + // Required by all event types. + await test_driver.set_permission({name: 'accelerometer'}, 'granted'); + await test_driver.set_permission({name: 'gyroscope'}, 'granted'); + if (this.#eventName == 'deviceorientationabsolute') { + await test_driver.set_permission({name: 'magnetometer'}, 'granted'); + } + + const interfaceName = this.#eventName == 'devicemotion' ? + DeviceMotionEvent : + DeviceOrientationEvent; + await test_driver.bless('enable user activation', async () => { + const permission = await interfaceName.requestPermission(); + assert_equals(permission, 'granted'); + }); + } + + // Resets SensorTestHelper to default state. Removes all created virtual + // sensors. + async reset() { + const createdVirtualSensors = + new Set([...this.#enabledSensors, ...this.#disabledSensors]); + + const sensorRemovalPromises = []; + for (const sensor of createdVirtualSensors) { + sensorRemovalPromises.push(test_driver.remove_virtual_sensor(sensor)); + } + await Promise.all(sensorRemovalPromises); + } +} + +function generateMotionData( + accelerationX, accelerationY, accelerationZ, accelerationIncludingGravityX, + accelerationIncludingGravityY, accelerationIncludingGravityZ, + rotationRateAlpha, rotationRateBeta, rotationRateGamma, interval = 16) { + const motionData = { + accelerationX: accelerationX, + accelerationY: accelerationY, + accelerationZ: accelerationZ, + accelerationIncludingGravityX: accelerationIncludingGravityX, + accelerationIncludingGravityY: accelerationIncludingGravityY, + accelerationIncludingGravityZ: accelerationIncludingGravityZ, + rotationRateAlpha: rotationRateAlpha, + rotationRateBeta: rotationRateBeta, + rotationRateGamma: rotationRateGamma, + interval: interval + }; + return motionData; +} + +function generateOrientationData(alpha, beta, gamma, absolute) { + const orientationData = + {alpha: alpha, beta: beta, gamma: gamma, absolute: absolute}; + return orientationData; +} + +function assertEventEquals(actualEvent, expectedEvent) { + // If two doubles differ by less than this amount, we can consider them + // to be effectively equal. + const EPSILON = 1e-8; + + for (let key1 of Object.keys(Object.getPrototypeOf(expectedEvent))) { + if (typeof expectedEvent[key1] === 'object' && + expectedEvent[key1] !== null) { + assertEventEquals(actualEvent[key1], expectedEvent[key1]); + } else if (typeof expectedEvent[key1] === 'number') { + assert_approx_equals( + actualEvent[key1], expectedEvent[key1], EPSILON, key1); + } else { + assert_equals(actualEvent[key1], expectedEvent[key1], key1); + } + } +} + +function getExpectedOrientationEvent(expectedOrientationData) { + return new DeviceOrientationEvent('deviceorientation', { + alpha: expectedOrientationData.alpha, + beta: expectedOrientationData.beta, + gamma: expectedOrientationData.gamma, + absolute: expectedOrientationData.absolute, + }); +} + +function getExpectedAbsoluteOrientationEvent(expectedOrientationData) { + return new DeviceOrientationEvent('deviceorientationabsolute', { + alpha: expectedOrientationData.alpha, + beta: expectedOrientationData.beta, + gamma: expectedOrientationData.gamma, + absolute: expectedOrientationData.absolute, + }); +} + +function getExpectedMotionEvent(expectedMotionData) { + return new DeviceMotionEvent('devicemotion', { + acceleration: { + x: expectedMotionData.accelerationX, + y: expectedMotionData.accelerationY, + z: expectedMotionData.accelerationZ, + }, + accelerationIncludingGravity: { + x: expectedMotionData.accelerationIncludingGravityX, + y: expectedMotionData.accelerationIncludingGravityY, + z: expectedMotionData.accelerationIncludingGravityZ, + }, + rotationRate: { + alpha: expectedMotionData.rotationRateAlpha, + beta: expectedMotionData.rotationRateBeta, + gamma: expectedMotionData.rotationRateGamma, + }, + interval: expectedMotionData.interval, + }); +} + +function waitForEvent(expected_event) { + return new Promise((resolve, reject) => { + window.addEventListener(expected_event.type, (event) => { + try { + assertEventEquals(event, expected_event); + resolve(); + } catch (e) { + reject(e); + } + }, {once: true}); + }); +} -- cgit v1.2.3