diff options
Diffstat (limited to 'testing/web-platform/tests/orientation-event/orientation')
-rw-r--r-- | testing/web-platform/tests/orientation-event/orientation/null-values.https.html | 41 | ||||
-rw-r--r-- | testing/web-platform/tests/orientation-event/orientation/rounding.https.html | 29 |
2 files changed, 55 insertions, 15 deletions
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 index c54d73da50..9505e00954 100644 --- a/testing/web-platform/tests/orientation-event/orientation/null-values.https.html +++ b/testing/web-platform/tests/orientation-event/orientation/null-values.https.html @@ -7,21 +7,32 @@ <script> 'use strict'; -promise_test(async (t) => { - const helper = new SensorTestHelper(t, 'deviceorientation'); - await helper.grantSensorsPermissions(); - await helper.initializeSensors({disabledSensors: ['absolute-orientation', 'relative-orientation']}); +function test_null_orientation_data(eventType) { + promise_test(async t => { + const helper = new SensorTestHelper(t, eventType); + await helper.grantSensorsPermissions(); + await helper.initializeSensors( + {disabledSensors : [ 'absolute-orientation', 'relative-orientation' ]}); - const orientationData1 = generateOrientationData(1.1, 2.2, 3.3, false); - // Currently it is not possible to set individual values to null because the - // parsing algorithms used by - // https://w3c.github.io/sensors/#update-virtual-sensor-reading-command - // always expect numbers. - const orientationData2 = generateOrientationData(null, null, null, false); + const inputData = generateOrientationData(1.1, 2.2, 3.3, false); + // Currently it is not possible to set individual values to null because + // the parsing algorithms used by + // https://w3c.github.io/sensors/#update-virtual-sensor-reading-command + // always expect numbers. + const expectedData = generateOrientationData( + null, null, null, + /*absolute=*/ eventType === 'deviceorientationabsolute'); + const expectedEvent = eventType === 'deviceorientationabsolute' + ? getExpectedAbsoluteOrientationEvent + : getExpectedOrientationEvent; - // An example how setting relative-orientation sensor as disabled will output - // null values. Even if we try to set non null values to sensor. - await helper.setData(orientationData1); - await waitForEvent(getExpectedOrientationEvent(orientationData2)); -}, 'Tests using null values for some of the event properties.'); + // An example how setting the orientation sensors as disabled will always + // output null values. + await helper.setData(inputData); + await waitForEvent(expectedEvent(expectedData)); + }, `${eventType}: Missing values are set to null or true/false accordingly`); +} + +test_null_orientation_data('deviceorientation'); +test_null_orientation_data('deviceorientationabsolute'); </script> diff --git a/testing/web-platform/tests/orientation-event/orientation/rounding.https.html b/testing/web-platform/tests/orientation-event/orientation/rounding.https.html new file mode 100644 index 0000000000..89bfa1d53c --- /dev/null +++ b/testing/web-platform/tests/orientation-event/orientation/rounding.https.html @@ -0,0 +1,29 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/resources/testdriver.js"></script> +<script src="/resources/testdriver-vendor.js"></script> +<script src="../resources/orientation-event-helpers.js"></script> +<script> +'use strict'; + +promise_test(async (t) => { + const helper = new SensorTestHelper(t, 'deviceorientation'); + await helper.grantSensorsPermissions(); + await helper.initializeSensors(); + + const value = 1.23456789; + const orientationData = generateOrientationData(value, value, value, false); + await helper.setData(orientationData); + + const event = await new Promise(resolve => { + window.addEventListener('deviceorientation', t.step_func(ev => { + resolve(ev); + }, { once: true })); + }); + + assertValueIsCoarsened(event.alpha); + assertValueIsCoarsened(event.beta); + assertValueIsCoarsened(event.gamma); +}, 'Tests that deviceorientation values are correctly rounded.'); +</script> |