Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: third_party/WebKit/LayoutTests/sensor/absolute-orientation-sensor.html

Issue 2785493002: [Sensors] OrientationSensor.populateMatrix() works also with Float64Array and DOMMatrix types (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 try {
47 sensorObject.populateMatrix(new Float32Array(15));
48 assert_unreached("populateMatrix() can only be called for buffers with enoug h length.");
49 } catch (error) {
50 assert_equals(error.name, 'TypeError');
51 }
52
53 // Throws at wrong sensor state.
54 try {
55 sensorObject.populateMatrix(new Float32Array(16));
56 assert_unreached("populateMatrix() can only be called at activated state.");
57 } catch (error) {
58 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!
59 }
60
61 sensorObject.start();
62
63 let testPromise = sensor.mockSensorProvider.getCreatedSensor()
Reilly Grant (use Gerrit) 2017/03/28 18:23:02 return ...
Mikhail 2017/03/29 08:27:58 Done.
64 .then(mockSensor => {
65 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading);
66 })
67 .then((mockSensor) => {
Reilly Grant (use Gerrit) 2017/03/28 18:23:02 nit: unnecessary parens
Mikhail 2017/03/29 08:27:58 Done.
68 return new Promise((resolve, reject) => {
69 let wrapper = new CallbackWrapper(() => {
70 // Works for all supported types.
71 let rotationMatrix32 = new Float32Array(16);
72 sensorObject.populateMatrix(rotationMatrix32);
73 assert_array_equals(rotationMatrix32, kRotationMatrix);
74
75 let rotationMatrix64 = new Float64Array(16);
76 sensorObject.populateMatrix(rotationMatrix64);
77 assert_array_equals(rotationMatrix64, kRotationMatrix);
78
79 let rotationDOMMatrix = new DOMMatrix();
80 sensorObject.populateMatrix(rotationDOMMatrix);
81 assert_array_equals(rotationDOMMatrix, kRotationDOMMatrix);
82
83 // Sets every matrix element.
84 rotationMatrix64.fill(123);
85 sensorObject.populateMatrix(rotationMatrix64);
86 assert_array_equals(rotationMatrix64, kRotationMatrix);
87
88 sensorObject.stop();
89 resolve(mockSensor);
90 }, reject);
91
92 sensorObject.onchange = wrapper.callback;
93 sensorObject.onerror = reject;
94 });
95 })
96 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); });
97
98 return testPromise;
99 }, 'Test AbsoluteOrientationSensor.populateMatrix() method works correctly.');
100
43 </script> 101 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698