OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
4 <script src="../resources/mojo-helpers.js"></script> | 4 <script src="../resources/mojo-helpers.js"></script> |
5 <script src="resources/sensor-helpers.js"></script> | 5 <script src="resources/sensor-helpers.js"></script> |
6 <script src="resources/generic-sensor-tests.js"></script> | 6 <script src="resources/generic-sensor-tests.js"></script> |
7 <script> | 7 <script> |
8 | 8 |
9 'use strict'; | 9 'use strict'; |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... | |
29 if (should_be_null) | 29 if (should_be_null) |
30 return sensor.quaternion == null && sensor.timestamp == null; | 30 return sensor.quaternion == null && sensor.timestamp == null; |
31 | 31 |
32 if (sensor.timestamp == null || | 32 if (sensor.timestamp == null || |
33 sensor.quaternion.toString() != kQuaternion.toString()) | 33 sensor.quaternion.toString() != kQuaternion.toString()) |
34 return false; | 34 return false; |
35 | 35 |
36 return true; | 36 return true; |
37 } | 37 } |
38 | 38 |
39 runGenericSensorTests(AbsoluteOrientationSensor, update_sensor_reading, verify_s ensor_reading); | 39 function checkPopulateMatrix(sensor, sensorType) { |
40 | 40 let sensorObject = new sensorType(); |
41 sensor_test(sensor => { | |
42 let sensorObject = new AbsoluteOrientationSensor(); | |
43 | 41 |
44 // Throws with insufficient buffer space. | 42 // Throws with insufficient buffer space. |
45 assert_throws({ name: 'TypeError' }, () => sensorObject.populateMatrix(new Flo at32Array(15))); | 43 assert_throws({ name: 'TypeError' }, () => sensorObject.populateMatrix(new Flo at32Array(15))); |
46 | 44 |
47 // Throws if no orientation data available. | 45 // Throws if no orientation data available. |
48 assert_throws({ name: 'NotReadableError' }, () => sensorObject.populateMatrix( new Float32Array(16))); | 46 assert_throws({ name: 'NotReadableError' }, () => sensorObject.populateMatrix( new Float32Array(16))); |
49 | 47 |
50 if (window.SharedArrayBuffer) { | 48 if (window.SharedArrayBuffer) { |
51 // Throws if passed SharedArrayBuffer view. | 49 // Throws if passed SharedArrayBuffer view. |
52 assert_throws({ name: 'TypeError' }, () => sensorObject.populateMatrix(new F loat32Array(new SharedArrayBuffer(16)))); | 50 assert_throws({ name: 'TypeError' }, () => sensorObject.populateMatrix(new F loat32Array(new SharedArrayBuffer(16)))); |
53 } | 51 } |
54 | 52 |
55 sensorObject.start(); | 53 sensorObject.start(); |
56 | 54 |
57 return sensor.mockSensorProvider.getCreatedSensor() | 55 return sensor.mockSensorProvider.getCreatedSensor() |
58 .then(mockSensor => { | 56 .then(mockSensor => { |
59 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading); | 57 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading); |
60 }) | 58 }) |
61 .then(mockSensor => { | 59 .then(mockSensor => { |
62 return new Promise((resolve, reject) => { | 60 return new Promise((resolve, reject) => { |
63 let wrapper = new CallbackWrapper(() => { | 61 let wrapper = new CallbackWrapper(() => { |
64 // Works for all supported types. | 62 // Works for all supported types. |
65 let rotationMatrix32 = new Float32Array(16); | 63 let rotationMatrix32 = new Float32Array(16); |
66 sensorObject.populateMatrix(rotationMatrix32); | 64 sensorObject.populateMatrix(rotationMatrix32); |
67 assert_array_equals(rotationMatrix32, kRotationMatrix); | 65 assert_array_equals(rotationMatrix32, kRotationMatrix); |
68 | 66 |
69 let rotationMatrix64 = new Float64Array(16); | 67 let rotationMatrix64 = new Float64Array(16); |
70 sensorObject.populateMatrix(rotationMatrix64); | 68 sensorObject.populateMatrix(rotationMatrix64); |
71 assert_array_equals(rotationMatrix64, kRotationMatrix); | 69 assert_array_equals(rotationMatrix64, kRotationMatrix); |
72 | 70 |
73 let rotationDOMMatrix = new DOMMatrix(); | 71 let rotationDOMMatrix = new DOMMatrix(); |
74 sensorObject.populateMatrix(rotationDOMMatrix); | 72 sensorObject.populateMatrix(rotationDOMMatrix); |
75 assert_array_equals(rotationDOMMatrix, kRotationDOMMatrix); | 73 assert_array_equals(rotationDOMMatrix, kRotationDOMMatrix); |
76 | 74 |
77 // Sets every matrix element. | 75 // Sets every matrix element. |
78 rotationMatrix64.fill(123); | 76 rotationMatrix64.fill(123); |
79 sensorObject.populateMatrix(rotationMatrix64); | 77 sensorObject.populateMatrix(rotationMatrix64); |
80 assert_array_equals(rotationMatrix64, kRotationMatrix); | 78 assert_array_equals(rotationMatrix64, kRotationMatrix); |
81 | 79 |
82 sensorObject.stop(); | 80 sensorObject.stop(); |
83 resolve(mockSensor); | 81 resolve(mockSensor); |
84 }, reject); | 82 }, reject); |
85 | 83 |
86 sensorObject.onchange = wrapper.callback; | 84 sensorObject.onchange = wrapper.callback; |
87 sensorObject.onerror = reject; | 85 sensorObject.onerror = reject; |
88 }); | 86 }); |
89 }) | 87 }) |
90 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); | 88 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); |
Reilly Grant (use Gerrit)
2017/05/30 18:41:48
.then(mockSensor => mockSensor.removeConfiguration
| |
89 } | |
90 | |
91 | |
92 runGenericSensorTests(AbsoluteOrientationSensor, update_sensor_reading, verify_s ensor_reading); | |
93 | |
94 sensor_test(sensor => { | |
95 return checkPopulateMatrix(sensor, AbsoluteOrientationSensor); | |
91 }, 'Test AbsoluteOrientationSensor.populateMatrix() method works correctly.'); | 96 }, 'Test AbsoluteOrientationSensor.populateMatrix() method works correctly.'); |
92 | 97 |
98 runGenericSensorTests(RelativeOrientationSensor, update_sensor_reading, verify_s ensor_reading); | |
99 | |
100 sensor_test(sensor => { | |
101 return checkPopulateMatrix(sensor, RelativeOrientationSensor); | |
102 }, 'Test RelativeOrientationSensor.populateMatrix() method works correctly.'); | |
103 | |
93 </script> | 104 </script> |
OLD | NEW |