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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading); | 176 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading); |
177 }) | 177 }) |
178 .then((mockSensor) => { | 178 .then((mockSensor) => { |
179 return new Promise((resolve, reject) => { | 179 return new Promise((resolve, reject) => { |
180 ambientLightSensor.onstatechange = event => { | 180 ambientLightSensor.onstatechange = event => { |
181 if (ambientLightSensor.state === 'idle') { | 181 if (ambientLightSensor.state === 'idle') { |
182 resolve(mockSensor); | 182 resolve(mockSensor); |
183 } | 183 } |
184 }; | 184 }; |
185 | 185 |
186 ambientLightSensor.onchange = e => { | 186 ambientLightSensor.onchange = e => { |
shalamov
2016/11/04 13:06:53
If event doesn't have associated reading, maybe yo
Mikhail
2016/11/04 13:20:47
Done.
| |
187 assert_equals(e.reading.illuminance, kDefaultReadingValue); | 187 assert_equals(ambientLightSensor.reading.illuminance, kDefaultReadin gValue); |
188 ambientLightSensor.stop(); | 188 ambientLightSensor.stop(); |
189 }; | 189 }; |
190 | 190 |
191 ambientLightSensor.onerror = reject; | 191 ambientLightSensor.onerror = reject; |
192 }); | 192 }); |
193 }) | 193 }) |
194 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); | 194 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); |
195 | 195 |
196 return testPromise; | 196 return testPromise; |
197 }, 'Test that onChange is called and sensor reading is valid.'); | 197 }, 'Test that onChange is called and sensor reading is valid.'); |
198 | 198 |
199 sensor_test(sensor => { | 199 sensor_test(sensor => { |
200 let ambientLightSensor = new AmbientLightSensor({frequency: 60}); | 200 let ambientLightSensor = new AmbientLightSensor({frequency: 60}); |
201 ambientLightSensor.start(); | 201 ambientLightSensor.start(); |
202 let testPromise = sensor.mockSensorProvider.getCreatedSensor() | 202 let testPromise = sensor.mockSensorProvider.getCreatedSensor() |
203 .then(mockSensor => { | 203 .then(mockSensor => { |
204 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading); | 204 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading); |
205 }) | 205 }) |
206 .then((mockSensor) => { | 206 .then((mockSensor) => { |
207 return new Promise((resolve, reject) => { | 207 return new Promise((resolve, reject) => { |
208 ambientLightSensor.onstatechange = () => { | 208 ambientLightSensor.onstatechange = () => { |
209 if (ambientLightSensor.state === 'idle') { | 209 if (ambientLightSensor.state === 'idle') { |
210 assert_equals(ambientLightSensor.reading, null); | 210 assert_equals(ambientLightSensor.reading, null); |
211 resolve(mockSensor); | 211 resolve(mockSensor); |
212 } | 212 } |
213 } | 213 } |
214 | 214 |
215 ambientLightSensor.onchange = e => { | 215 ambientLightSensor.onchange = e => { |
216 assert_equals(e.reading.illuminance, kDefaultReadingValue); | 216 assert_equals(ambientLightSensor.reading.illuminance, kDefaultReadin gValue); |
217 ambientLightSensor.stop(); | 217 ambientLightSensor.stop(); |
218 } | 218 } |
219 ambientLightSensor.onerror = reject; | 219 ambientLightSensor.onerror = reject; |
220 }); | 220 }); |
221 }) | 221 }) |
222 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); | 222 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); |
223 | 223 |
224 return testPromise; | 224 return testPromise; |
225 }, 'Test that sensor reading is not updated when sensor is stopped.'); | 225 }, 'Test that sensor reading is not updated when sensor is stopped.'); |
226 | 226 |
227 sensor_test(sensor => { | 227 sensor_test(sensor => { |
228 let ambientLightSensor = new AmbientLightSensor(); | 228 let ambientLightSensor = new AmbientLightSensor(); |
229 ambientLightSensor.start(); | 229 ambientLightSensor.start(); |
230 let testPromise = sensor.mockSensorProvider.getCreatedSensor() | 230 let testPromise = sensor.mockSensorProvider.getCreatedSensor() |
231 .then(mockSensor => { | 231 .then(mockSensor => { |
232 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading); | 232 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading); |
233 }) | 233 }) |
234 .then((mockSensor) => { | 234 .then((mockSensor) => { |
235 return new Promise((resolve, reject) => { | 235 return new Promise((resolve, reject) => { |
236 ambientLightSensor.onchange = e => { | 236 ambientLightSensor.onchange = e => { |
237 if (e.reading.illuminance == kDefaultReadingValue) { | 237 if (ambientLightSensor.reading.illuminance == kDefaultReadingValue) { |
238 resolve(mockSensor); | 238 resolve(mockSensor); |
239 } | 239 } |
240 } | 240 } |
241 ambientLightSensor.onerror = reject; | 241 ambientLightSensor.onerror = reject; |
242 }); | 242 }); |
243 }) | 243 }) |
244 .then((mockSensor) => { | 244 .then((mockSensor) => { |
245 testRunner.setPageVisibility("hidden"); | 245 testRunner.setPageVisibility("hidden"); |
246 return mockSensor.suspendCalled(); | 246 return mockSensor.suspendCalled(); |
247 }) | 247 }) |
(...skipping 11 matching lines...) Expand all Loading... | |
259 ambientLightSensor.stop(); | 259 ambientLightSensor.stop(); |
260 ambientLightSensor.onerror = reject; | 260 ambientLightSensor.onerror = reject; |
261 }); | 261 }); |
262 }) | 262 }) |
263 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); | 263 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); |
264 | 264 |
265 return testPromise; | 265 return testPromise; |
266 }, 'Test that sensor receives suspend / resume notifications when page' | 266 }, 'Test that sensor receives suspend / resume notifications when page' |
267 +' visibility changes.'); | 267 +' visibility changes.'); |
268 | 268 |
269 | |
270 sensor_test(sensor => { | |
271 let sensor1 = new AmbientLightSensor({frequency: 60}); | |
272 sensor1.start(); | |
273 | |
274 let sensor2 = new AmbientLightSensor({frequency: 20}); | |
275 sensor2.start(); | |
276 let testPromise = sensor.mockSensorProvider.getCreatedSensor() | |
277 .then(mockSensor => { | |
278 return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading); | |
279 }) | |
280 .then((mockSensor) => { | |
281 return new Promise((resolve, reject) => { | |
282 sensor1.onstatechange = event => { | |
283 if (sensor1.state === 'idle') { | |
284 resolve(mockSensor); | |
285 } | |
286 }; | |
287 | |
288 sensor1.onchange = e => { | |
289 // Reading value is correct. | |
290 assert_equals(sensor1.reading.illuminance, kDefaultReadingValue); | |
291 | |
292 // Both sensors share the same reading instance. | |
293 let reading = sensor1.reading; | |
294 assert_equals(reading, sensor2.reading); | |
295 | |
296 // After first sensor stops its reading is null, reading for second | |
297 // sensor sensor remains. | |
298 sensor1.stop(); | |
299 assert_equals(sensor1.reading, null); | |
300 assert_equals(sensor2.reading.illuminance, kDefaultReadingValue); | |
301 | |
302 sensor2.stop(); | |
303 assert_equals(sensor2.reading, null); | |
304 reject(); | |
305 | |
306 // Cached reading remains. | |
307 assert_equals(reading.illuminance, kDefaultReadingValue); | |
308 }; | |
309 | |
310 sensor1.onerror = reject; | |
311 sensor2.onerror = reject; | |
312 }); | |
313 }) | |
314 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); | |
315 | |
316 return testPromise; | |
317 }, 'Test that sensor reading is correct.'); | |
318 | |
269 </script> | 319 </script> |
OLD | NEW |