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