From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. 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 | 33 +++ ...ion-events-unavailable-on-insecure-origins.html | 55 +++++ .../orientation-event/idlharness.https.window.js | 19 ++ .../motion/add-during-dispatch.https.html | 30 +++ .../motion/add-listener-from-callback.https.html | 49 ++++ .../motion/create-event.https.html | 41 ++++ .../motion/free-fall-manual.https.html | 48 ++++ .../motion/multiple-event-listeners.https.html | 26 +++ .../motion/null-values.https.html | 39 ++++ .../motion/optional-event-properties.https.html | 257 +++++++++++++++++++++ .../motion/page-visibility-manual.https.html | 28 +++ .../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 | 19 ++ .../add-listener-from-callback.https.html | 47 ++++ .../basic-operation-absolute.https.html | 28 +++ .../orientation/basic-operation.https.html | 29 +++ .../orientation/create-event.https.html | 40 ++++ .../horizontal-surface-manual.https.html | 34 +++ .../multiple-event-listeners.https.html | 22 ++ .../orientation/no-synchronous-events.https.html | 27 +++ .../orientation/null-values.https.html | 30 +++ .../optional-event-properties.https.html | 73 ++++++ .../orientation/page-visibility-manual.https.html | 28 +++ .../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 | 19 ++ .../resources/orientation-event-helpers.js | 188 +++++++++++++++ 36 files changed, 1623 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-manual.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-manual.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..c7ad5ecaef --- /dev/null +++ b/testing/web-platform/tests/orientation-event/device-orientation-events-of-detached-documents.https.html @@ -0,0 +1,33 @@ + +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..571a388f64 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/device-orientation-events-unavailable-on-insecure-origins.html @@ -0,0 +1,55 @@ + +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..3a895b9d09 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/add-during-dispatch.https.html @@ -0,0 +1,30 @@ + + + + + + + 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..0803d7cc9b --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/add-listener-from-callback.https.html @@ -0,0 +1,49 @@ + + + + + + + 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..3b13d632ac --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/multiple-event-listeners.https.html @@ -0,0 +1,26 @@ + + + + + + + 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..b6a2a1622f --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/null-values.https.html @@ -0,0 +1,39 @@ + + + + + + + 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-manual.https.html b/testing/web-platform/tests/orientation-event/motion/page-visibility-manual.https.html new file mode 100644 index 0000000000..37e48ce979 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/page-visibility-manual.https.html @@ -0,0 +1,28 @@ + + + + + + + +

Switch the page to the background, then switch back to it.

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..610b1b3c56 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/absolute-fallback.https.html @@ -0,0 +1,19 @@ + + + + + + + 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..8f8cfa29c4 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/add-listener-from-callback.https.html @@ -0,0 +1,47 @@ + + + + + + + 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..61fd218781 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/basic-operation-absolute.https.html @@ -0,0 +1,28 @@ + + + + + + + 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..45fe38006e --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/basic-operation.https.html @@ -0,0 +1,29 @@ + + + + + + + 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..473b7f8828 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/multiple-event-listeners.https.html @@ -0,0 +1,22 @@ + + + + + + + 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..e5d7621123 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/no-synchronous-events.https.html @@ -0,0 +1,27 @@ + + + + + + + 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..f9e4aa6420 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/null-values.https.html @@ -0,0 +1,30 @@ + + + + + + + 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-manual.https.html b/testing/web-platform/tests/orientation-event/orientation/page-visibility-manual.https.html new file mode 100644 index 0000000000..033f17602b --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/page-visibility-manual.https.html @@ -0,0 +1,28 @@ + + + + + + + +

Switch the page to the background, then switch back to it.

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..c84588d598 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/updates.https.html @@ -0,0 +1,19 @@ + + + + + + + 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..1f0deba278 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/resources/orientation-event-helpers.js @@ -0,0 +1,188 @@ +'use strict'; + +// These tests rely on the User Agent providing an implementation of +// platform sensor backends. +// +// In Chromium-based browsers this implementation is provided by a polyfill +// in order to reduce the amount of test-only code shipped to users. To enable +// these tests the browser must be run with these options: +// +// --enable-blink-features=MojoJS,MojoJSTest +async function loadChromiumResources() { + await import('/resources/chromium/generic_sensor_mocks.js'); +} + +async function initialize_generic_sensor_tests() { + if (typeof GenericSensorTest === 'undefined') { + const script = document.createElement('script'); + script.src = '/resources/test-only-api.js'; + script.async = false; + const p = new Promise((resolve, reject) => { + script.onload = () => { resolve(); }; + script.onerror = e => { reject(e); }; + }) + document.head.appendChild(script); + await p; + + if (isChromiumBased) { + await loadChromiumResources(); + } + } + assert_implements(GenericSensorTest, 'GenericSensorTest is unavailable.'); + let sensorTest = new GenericSensorTest(); + await sensorTest.initialize(); + return sensorTest; +} + +function sensor_test(func, name, properties) { + promise_test(async (t) => { + t.add_cleanup(() => { + if (sensorTest) + return sensorTest.reset(); + }); + + let sensorTest = await initialize_generic_sensor_tests(); + return func(t, sensorTest.getSensorProvider()); + }, name, properties); +} + +const MOTION_ROTATION_EPSILON = 1e-8; + +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; +} + +async function setMockSensorDataForType(sensorProvider, sensorType, mockDataArray) { + const createdSensor = await sensorProvider.getCreatedSensor(sensorType); + // We call setSensorReadingAndUpdateSharedBuffer() rather than + // setSensorReading() to accommodate Blink's Device Orientation + // implementation, which uses its own timer to read the sensor's shared + // memory buffer rather than relying on SensorReadingChanged(). This timer + // may fire out of sync with the JS timer in MockSensor.startReading(), so + // the former might read the shared memory buffer before the latter has + // updated |this.buffer_|. We thus immediately update the buffer here + // (without consuming data from the ring buffer). + return createdSensor.setSensorReadingImmediately([mockDataArray]); +} + +// Device[Orientation|Motion]EventPump treat NaN as a missing value. +let nullToNan = x => (x === null ? NaN : x); + +function setMockMotionData(sensorProvider, motionData) { + const degToRad = Math.PI / 180; + return Promise.all([ + setMockSensorDataForType(sensorProvider, "Accelerometer", [ + nullToNan(motionData.accelerationIncludingGravityX), + nullToNan(motionData.accelerationIncludingGravityY), + nullToNan(motionData.accelerationIncludingGravityZ), + ]), + setMockSensorDataForType(sensorProvider, "LinearAccelerationSensor", [ + nullToNan(motionData.accelerationX), + nullToNan(motionData.accelerationY), + nullToNan(motionData.accelerationZ), + ]), + setMockSensorDataForType(sensorProvider, "Gyroscope", [ + nullToNan(motionData.rotationRateAlpha) * degToRad, + nullToNan(motionData.rotationRateBeta) * degToRad, + nullToNan(motionData.rotationRateGamma) * degToRad, + ]), + ]); +} + +function setMockOrientationData(sensorProvider, orientationData) { + let sensorType = orientationData.absolute + ? "AbsoluteOrientationEulerAngles" : "RelativeOrientationEulerAngles"; + return setMockSensorDataForType(sensorProvider, sensorType, [ + nullToNan(orientationData.beta), + nullToNan(orientationData.gamma), + nullToNan(orientationData.alpha), + ]); +} + +function assertEventEquals(actualEvent, expectedEvent) { + for (let key1 of Object.keys(Object.getPrototypeOf(expectedEvent))) { + if (typeof expectedEvent[key1] === "object" && expectedEvent[key1] !== null) { + for (let key2 of Object.keys(expectedEvent[key1])) { + assert_equals(actualEvent[key1][key2], expectedEvent[key1][key2], + `$[key1].$[key2]`); + } + } 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