summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/orientation-event
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
commitfbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch)
tree4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /testing/web-platform/tests/orientation-event
parentReleasing progress-linux version 124.0.1-1~progress7.99u1. (diff)
downloadfirefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz
firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/orientation-event')
-rw-r--r--testing/web-platform/tests/orientation-event/README.md8
-rw-r--r--testing/web-platform/tests/orientation-event/motion/rounding.https.html38
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/null-values.https.html41
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/rounding.https.html29
-rw-r--r--testing/web-platform/tests/orientation-event/resources/orientation-event-helpers.js11
5 files changed, 104 insertions, 23 deletions
diff --git a/testing/web-platform/tests/orientation-event/README.md b/testing/web-platform/tests/orientation-event/README.md
deleted file mode 100644
index 14ea2f5117..0000000000
--- a/testing/web-platform/tests/orientation-event/README.md
+++ /dev/null
@@ -1,8 +0,0 @@
-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/motion/rounding.https.html b/testing/web-platform/tests/orientation-event/motion/rounding.https.html
new file mode 100644
index 0000000000..846da79dfb
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/motion/rounding.https.html
@@ -0,0 +1,38 @@
+<!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';
+
+function check_properties_for_coarsening(obj, properties) {
+ assert_not_equals(obj, null, 'Expected event object');
+ for (const prop of properties) {
+ assertValueIsCoarsened(obj[prop]);
+ }
+}
+
+promise_test(async (t) => {
+ const helper = new SensorTestHelper(t, 'devicemotion');
+ await helper.grantSensorsPermissions();
+ await helper.initializeSensors();
+
+ const value = 1.23456789;
+ const motionData = generateMotionData(value, value, value,
+ value, value, value,
+ value, value, value);
+ await helper.setData(motionData);
+
+ const event = await new Promise(resolve => {
+ window.addEventListener('devicemotion', t.step_func(ev => {
+ resolve(ev);
+ }, { once: true }));
+ });
+
+ check_properties_for_coarsening(event.acceleration, ['x', 'y', 'z']);
+ check_properties_for_coarsening(event.accelerationIncludingGravity, ['x', 'y', 'z']);
+ check_properties_for_coarsening(event.rotationRate, ['alpha', 'beta', 'gamma']);
+}, 'Tests that devicemotion values are correctly rounded.');
+</script>
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>
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
index 01e91c62ae..dab876fc6a 100644
--- a/testing/web-platform/tests/orientation-event/resources/orientation-event-helpers.js
+++ b/testing/web-platform/tests/orientation-event/resources/orientation-event-helpers.js
@@ -203,6 +203,17 @@ function generateOrientationData(alpha, beta, gamma, absolute) {
return orientationData;
}
+function assertValueIsCoarsened(value) {
+ // Checks that the precision of the value is at most 0.1.
+ // https://www.w3.org/TR/orientation-event/ specification defines that all
+ // measurements are required to be coarsened to 0.1 degrees, 0.1 m/s^2 or
+ // 0.1 deg/s.
+ const resolution = 0.1;
+ const coarsenedValue = Math.round(value / resolution) * resolution;
+ assert_approx_equals(value, coarsenedValue, Number.EPSILON,
+ `Expected ${value}'s precision to be at most ${resolution}`);
+}
+
function assertEventEquals(actualEvent, expectedEvent) {
// If two doubles differ by less than this amount, we can consider them
// to be effectively equal.