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> | 6 <script> |
7 | 7 |
8 'use strict'; | 8 'use strict'; |
9 | 9 |
10 if (!window.testRunner) | 10 if (!window.testRunner) |
(...skipping 18 matching lines...) Expand all Loading... |
29 return new Promise((resolve, reject) => { | 29 return new Promise((resolve, reject) => { |
30 ambientLightSensor.onstatechange = event => { | 30 ambientLightSensor.onstatechange = event => { |
31 if(ambientLightSensor.state == 'errored') { | 31 if(ambientLightSensor.state == 'errored') { |
32 resolve(); | 32 resolve(); |
33 } | 33 } |
34 }; | 34 }; |
35 }); | 35 }); |
36 }, 'Test that sensor state changes to "errored" when sensor is not supported.'); | 36 }, 'Test that sensor state changes to "errored" when sensor is not supported.'); |
37 | 37 |
38 sensor_test(sensor => { | 38 sensor_test(sensor => { |
| 39 sensor.mockSensorProvider.setGetSensorShouldFail(true); |
| 40 let ambientLightSensor = new AmbientLightSensor(); |
| 41 ambientLightSensor.start(); |
| 42 return new Promise((resolve, reject) => { |
| 43 ambientLightSensor.onerror = event => { |
| 44 assert_equals(ambientLightSensor.state, 'errored'); |
| 45 console.log(event.error.message); |
| 46 assert_equals(event.error.name, 'NotFoundError'); |
| 47 resolve(); |
| 48 }; |
| 49 |
| 50 }); |
| 51 }, 'Test that "onerror" is send when sensor is not supported.'); |
| 52 |
| 53 |
| 54 sensor_test(sensor => { |
39 let ambientLightSensor = new AmbientLightSensor({frequency: 560}); | 55 let ambientLightSensor = new AmbientLightSensor({frequency: 560}); |
40 ambientLightSensor.start(); | 56 ambientLightSensor.start(); |
41 | 57 |
| 58 let testPromise = sensor.mockSensorProvider.getCreatedSensor() |
| 59 .then(mockSensor => { |
| 60 mockSensor.setStartShouldFail(true); |
| 61 return mockSensor.addConfigurationCalled(); }) |
| 62 .then(mockSensor => { |
| 63 return new Promise((resolve, reject) => { |
| 64 ambientLightSensor.onerror = event => { |
| 65 assert_equals(ambientLightSensor.state, 'errored'); |
| 66 assert_equals(event.error.name, 'OperationError'); |
| 67 resolve(); |
| 68 }; |
| 69 }); |
| 70 }); |
| 71 return testPromise; |
| 72 }, 'Test that "onerror" is send when start() call has failed.'); |
| 73 |
| 74 sensor_test(sensor => { |
| 75 let ambientLightSensor = new AmbientLightSensor({frequency: 560}); |
| 76 ambientLightSensor.start(); |
| 77 |
42 let testPromise = sensor.mockSensorProvider.getCreatedSensor() | 78 let testPromise = sensor.mockSensorProvider.getCreatedSensor() |
43 .then(mockSensor => { return mockSensor.addConfigurationCalled(); }) | 79 .then(mockSensor => { return mockSensor.addConfigurationCalled(); }) |
44 .then(mockSensor => { | 80 .then(mockSensor => { |
45 return new Promise((resolve, reject) => { | 81 return new Promise((resolve, reject) => { |
46 ambientLightSensor.onstatechange = event => { | 82 ambientLightSensor.onstatechange = event => { |
47 if (ambientLightSensor.state === 'idle') { | 83 if (ambientLightSensor.state === 'idle') { |
48 resolve(mockSensor); | 84 resolve(mockSensor); |
49 } | 85 } |
50 | 86 |
51 if (ambientLightSensor.state === 'active') { | 87 if (ambientLightSensor.state === 'active') { |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 ambientLightSensor.onerror = reject; | 260 ambientLightSensor.onerror = reject; |
225 }); | 261 }); |
226 }) | 262 }) |
227 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); | 263 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); |
228 | 264 |
229 return testPromise; | 265 return testPromise; |
230 }, 'Test that sensor receives suspend / resume notifications when page' | 266 }, 'Test that sensor receives suspend / resume notifications when page' |
231 +' visibility changes.'); | 267 +' visibility changes.'); |
232 | 268 |
233 </script> | 269 </script> |
OLD | NEW |