Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/sensor/absolute-orientation-sensor.html |
| diff --git a/third_party/WebKit/LayoutTests/sensor/absolute-orientation-sensor.html b/third_party/WebKit/LayoutTests/sensor/absolute-orientation-sensor.html |
| index 3667924b7e35499b362a0bd1bfc71f9bf50b3569..793feef2e2dc1cbb169b4f433f642e25cfb017e1 100644 |
| --- a/third_party/WebKit/LayoutTests/sensor/absolute-orientation-sensor.html |
| +++ b/third_party/WebKit/LayoutTests/sensor/absolute-orientation-sensor.html |
| @@ -16,6 +16,7 @@ const kRotationMatrix = [1, 0, 0, 0, |
| 0, -1, 0, 0, |
| 0, 0, -1, 0, |
| 0, 0, 0, 1]; |
| +const kRotationDOMMatrix = new DOMMatrix(kRotationMatrix); |
| function update_sensor_reading(buffer, expects_modified_reading, readsCount) { |
| buffer[1] = window.performance.now(); |
| @@ -33,11 +34,68 @@ function verify_sensor_reading(sensor, should_be_null) { |
| sensor.quaternion.toString() != kQuaternion.toString()) |
| return false; |
| - let rotationMatrix = new Float32Array(16); |
| - sensor.populateMatrix(rotationMatrix); |
| - return rotationMatrix.toString() == kRotationMatrix.toString(); |
| + return true; |
| } |
| runGenericSensorTests(AbsoluteOrientationSensor, update_sensor_reading, verify_sensor_reading); |
| +sensor_test(sensor => { |
| + let sensorObject = new AbsoluteOrientationSensor(); |
| + |
| + // Throws with insufficient buffer space. |
| + try { |
| + sensorObject.populateMatrix(new Float32Array(15)); |
| + assert_unreached("populateMatrix() can only be called for buffers with enough length."); |
| + } catch (error) { |
| + assert_equals(error.name, 'TypeError'); |
| + } |
| + |
| + // Throws at wrong sensor state. |
| + try { |
| + sensorObject.populateMatrix(new Float32Array(16)); |
| + assert_unreached("populateMatrix() can only be called at activated state."); |
| + } catch (error) { |
| + assert_equals(error.name, 'InvalidStateError'); |
|
Reilly Grant (use Gerrit)
2017/03/28 18:23:02
assert_throws can be used for this one.
Mikhail
2017/03/29 08:27:58
Indeed, thanks!
|
| + } |
| + |
| + sensorObject.start(); |
| + |
| + let testPromise = sensor.mockSensorProvider.getCreatedSensor() |
|
Reilly Grant (use Gerrit)
2017/03/28 18:23:02
return ...
Mikhail
2017/03/29 08:27:58
Done.
|
| + .then(mockSensor => { |
| + return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading); |
| + }) |
| + .then((mockSensor) => { |
|
Reilly Grant (use Gerrit)
2017/03/28 18:23:02
nit: unnecessary parens
Mikhail
2017/03/29 08:27:58
Done.
|
| + return new Promise((resolve, reject) => { |
| + let wrapper = new CallbackWrapper(() => { |
| + // Works for all supported types. |
| + let rotationMatrix32 = new Float32Array(16); |
| + sensorObject.populateMatrix(rotationMatrix32); |
| + assert_array_equals(rotationMatrix32, kRotationMatrix); |
| + |
| + let rotationMatrix64 = new Float64Array(16); |
| + sensorObject.populateMatrix(rotationMatrix64); |
| + assert_array_equals(rotationMatrix64, kRotationMatrix); |
| + |
| + let rotationDOMMatrix = new DOMMatrix(); |
| + sensorObject.populateMatrix(rotationDOMMatrix); |
| + assert_array_equals(rotationDOMMatrix, kRotationDOMMatrix); |
| + |
| + // Sets every matrix element. |
| + rotationMatrix64.fill(123); |
| + sensorObject.populateMatrix(rotationMatrix64); |
| + assert_array_equals(rotationMatrix64, kRotationMatrix); |
| + |
| + sensorObject.stop(); |
| + resolve(mockSensor); |
| + }, reject); |
| + |
| + sensorObject.onchange = wrapper.callback; |
| + sensorObject.onerror = reject; |
| + }); |
| + }) |
| + .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); |
| + |
| + return testPromise; |
| +}, 'Test AbsoluteOrientationSensor.populateMatrix() method works correctly.'); |
| + |
| </script> |