OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <script src="../resources/testharness.js"></script> | |
3 <script src="../resources/testharnessreport.js"></script> | |
4 <script src="../resources/mojo-helpers.js"></script> | |
5 <script src="resources/sensor-helpers.js"></script> | |
6 <script src="resources/generic-sensor-tests.js"></script> | |
7 <script> | |
8 | |
9 'use strict'; | |
10 | |
11 if (!window.testRunner) | |
12 debug('This test cannot be run without the TestRunner'); | |
13 | |
14 const kQuaternion = [1, 0, 0, 0]; // 180 degrees around X axis. | |
15 const kRotationMatrix = [1, 0, 0, 0, | |
16 0, -1, 0, 0, | |
17 0, 0, -1, 0, | |
18 0, 0, 0, 1]; | |
19 const kRotationDOMMatrix = new DOMMatrix(kRotationMatrix); | |
20 | |
21 function update_sensor_reading(buffer) { | |
22 buffer[2] = 1; | |
23 buffer[3] = 0; | |
24 buffer[4] = 0; | |
25 buffer[5] = 0; | |
26 } | |
27 | |
28 function verify_sensor_reading(sensor, should_be_null) { | |
29 if (should_be_null) | |
30 return sensor.quaternion == null && sensor.timestamp == null; | |
31 | |
32 if (sensor.timestamp == null || | |
33 sensor.quaternion.toString() != kQuaternion.toString()) | |
34 return false; | |
35 | |
36 return true; | |
37 } | |
38 | |
39 runGenericSensorTests(AbsoluteOrientationSensor, update_sensor_reading, verify_s
ensor_reading); | |
40 | |
41 sensor_test(sensor => { | |
42 let sensorObject = new AbsoluteOrientationSensor(); | |
43 | |
44 // Throws with insufficient buffer space. | |
45 assert_throws({ name: 'TypeError' }, () => sensorObject.populateMatrix(new Flo
at32Array(15))); | |
46 | |
47 // Throws if no orientation data available. | |
48 assert_throws({ name: 'NotReadableError' }, () => sensorObject.populateMatrix(
new Float32Array(16))); | |
49 | |
50 if (window.SharedArrayBuffer) { | |
51 // Throws if passed SharedArrayBuffer view. | |
52 assert_throws({ name: 'TypeError' }, () => sensorObject.populateMatrix(new F
loat32Array(new SharedArrayBuffer(16)))); | |
53 } | |
54 | |
55 sensorObject.start(); | |
56 | |
57 return sensor.mockSensorProvider.getCreatedSensor() | |
58 .then(mockSensor => { | |
59 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading); | |
60 }) | |
61 .then(mockSensor => { | |
62 return new Promise((resolve, reject) => { | |
63 let wrapper = new CallbackWrapper(() => { | |
64 // Works for all supported types. | |
65 let rotationMatrix32 = new Float32Array(16); | |
66 sensorObject.populateMatrix(rotationMatrix32); | |
67 assert_array_equals(rotationMatrix32, kRotationMatrix); | |
68 | |
69 let rotationMatrix64 = new Float64Array(16); | |
70 sensorObject.populateMatrix(rotationMatrix64); | |
71 assert_array_equals(rotationMatrix64, kRotationMatrix); | |
72 | |
73 let rotationDOMMatrix = new DOMMatrix(); | |
74 sensorObject.populateMatrix(rotationDOMMatrix); | |
75 assert_array_equals(rotationDOMMatrix, kRotationDOMMatrix); | |
76 | |
77 // Sets every matrix element. | |
78 rotationMatrix64.fill(123); | |
79 sensorObject.populateMatrix(rotationMatrix64); | |
80 assert_array_equals(rotationMatrix64, kRotationMatrix); | |
81 | |
82 sensorObject.stop(); | |
83 resolve(mockSensor); | |
84 }, reject); | |
85 | |
86 sensorObject.onchange = wrapper.callback; | |
87 sensorObject.onerror = reject; | |
88 }); | |
89 }) | |
90 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); | |
91 }, 'Test AbsoluteOrientationSensor.populateMatrix() method works correctly.'); | |
92 | |
93 </script> | |
OLD | NEW |