|
7 | 7 | <script>
|
8 | 8 | 'use strict';
|
9 | 9 |
|
10 |
| -promise_test(async (t) => { |
11 |
| - const helper = new SensorTestHelper(t, 'deviceorientation'); |
12 |
| - await helper.grantSensorsPermissions(); |
13 |
| - await helper.initializeSensors({disabledSensors: ['absolute-orientation', 'relative-orientation']}); |
| 10 | +function test_null_orientation_data(eventType) { |
| 11 | + promise_test(async t => { |
| 12 | + const helper = new SensorTestHelper(t, eventType); |
| 13 | + await helper.grantSensorsPermissions(); |
| 14 | + await helper.initializeSensors( |
| 15 | + {disabledSensors : [ 'absolute-orientation', 'relative-orientation' ]}); |
14 | 16 |
|
15 |
| - const orientationData1 = generateOrientationData(1.1, 2.2, 3.3, false); |
16 |
| - // Currently it is not possible to set individual values to null because the |
17 |
| - // parsing algorithms used by |
18 |
| - // https://w3c.github.io/sensors/#update-virtual-sensor-reading-command |
19 |
| - // always expect numbers. |
20 |
| - const orientationData2 = generateOrientationData(null, null, null, false); |
| 17 | + const inputData = generateOrientationData(1.1, 2.2, 3.3, false); |
| 18 | + // Currently it is not possible to set individual values to null because |
| 19 | + // the parsing algorithms used by |
| 20 | + // https://w3c.github.io/sensors/#update-virtual-sensor-reading-command |
| 21 | + // always expect numbers. |
| 22 | + const expectedData = generateOrientationData( |
| 23 | + null, null, null, |
| 24 | + /*absolute=*/ eventType === 'deviceorientationabsolute'); |
| 25 | + const expectedEvent = eventType === 'deviceorientationabsolute' |
| 26 | + ? getExpectedAbsoluteOrientationEvent |
| 27 | + : getExpectedOrientationEvent; |
21 | 28 |
|
22 |
| - // An example how setting relative-orientation sensor as disabled will output |
23 |
| - // null values. Even if we try to set non null values to sensor. |
24 |
| - await helper.setData(orientationData1); |
25 |
| - await waitForEvent(getExpectedOrientationEvent(orientationData2)); |
26 |
| -}, 'Tests using null values for some of the event properties.'); |
| 29 | + // An example how setting the orientation sensors as disabled will always |
| 30 | + // output null values. |
| 31 | + await helper.setData(inputData); |
| 32 | + await waitForEvent(expectedEvent(expectedData)); |
| 33 | + }, `${eventType}: Missing values are set to null or true/false accordingly`); |
| 34 | +} |
| 35 | + |
| 36 | +test_null_orientation_data('deviceorientation'); |
| 37 | +test_null_orientation_data('deviceorientationabsolute'); |
27 | 38 | </script>
|
0 commit comments