OLD | NEW |
---|---|
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 // Run a set of tests for a given |sensorType|. |updateReading| is | 3 // Run a set of tests for a given |sensorType|. |updateReading| is |
4 // a called by the test to provide the mock values for sensor. |verifyReading| | 4 // a called by the test to provide the mock values for sensor. |verifyReading| |
5 // is called so that the value read in JavaScript are the values expected (the o nes | 5 // is called so that the value read in JavaScript are the values expected (the o nes |
6 // sent by |updateReading|). | 6 // sent by |updateReading|). |
7 function runGenericSensorTests(sensorType, updateReading, verifyReading) { | 7 function runGenericSensorTests(sensorType, updateReading, verifyReading) { |
8 test(() => assert_throws( | 8 test(() => assert_throws( |
9 new RangeError(), | 9 new RangeError(), |
10 () => new sensorType({frequency: -60})), | 10 () => new sensorType({frequency: -60})), |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 }, reject); | 297 }, reject); |
298 | 298 |
299 let slowSensorWrapper = new CallbackWrapper(() => { | 299 let slowSensorWrapper = new CallbackWrapper(() => { |
300 slowSensorNotifiedCounter++; | 300 slowSensorNotifiedCounter++; |
301 if (slowSensorNotifiedCounter == 1) { | 301 if (slowSensorNotifiedCounter == 1) { |
302 fastSensor.start(); | 302 fastSensor.start(); |
303 } else if (slowSensorNotifiedCounter == 2) { | 303 } else if (slowSensorNotifiedCounter == 2) { |
304 // By the moment slow sensor (9 Hz) is notified for the | 304 // By the moment slow sensor (9 Hz) is notified for the |
305 // next time, the fast sensor (30 Hz) has been notified | 305 // next time, the fast sensor (30 Hz) has been notified |
306 // for int(30/9) = 3 times. | 306 // for int(30/9) = 3 times. |
307 assert_equals(fastSensorNotifiedCounter, 3); | 307 // In actual implementation updates are bound to rAF, |
308 // (not to a timer) sometimes fast sensor gets invoked 4 times. | |
309 assert_true(fastSensorNotifiedCounter == 3 || | |
310 fastSensorNotifiedCounter == 4); | |
foolip
2016/12/19 13:23:47
Shouldn't this change have caused the number of up
| |
308 fastSensor.stop(); | 311 fastSensor.stop(); |
309 slowSensor.stop(); | 312 slowSensor.stop(); |
310 resolve(mockSensor); | 313 resolve(mockSensor); |
311 } | 314 } |
312 }, reject); | 315 }, reject); |
313 | 316 |
314 fastSensor.onchange = fastSensorWrapper.callback; | 317 fastSensor.onchange = fastSensorWrapper.callback; |
315 slowSensor.onchange = slowSensorWrapper.callback; | 318 slowSensor.onchange = slowSensorWrapper.callback; |
316 fastSensor.onerror = reject; | 319 fastSensor.onerror = reject; |
317 slowSensor.onerror = reject; | 320 slowSensor.onerror = reject; |
318 }); | 321 }); |
319 }) | 322 }) |
320 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); | 323 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); |
321 | 324 |
322 return testPromise; | 325 return testPromise; |
323 } | 326 } |
324 | 327 |
325 sensor_test(sensor => { | 328 sensor_test(sensor => { |
326 return checkFrequencyHintWorks(sensor); | 329 return checkFrequencyHintWorks(sensor); |
327 }, 'Test that frequency hint works (onchange reporting).'); | 330 }, 'Test that frequency hint works (onchange reporting).'); |
328 | 331 |
329 sensor_test(sensor => { | 332 sensor_test(sensor => { |
330 sensor.mockSensorProvider.setContinuousReportingMode(); | 333 sensor.mockSensorProvider.setContinuousReportingMode(); |
331 return checkFrequencyHintWorks(sensor); | 334 return checkFrequencyHintWorks(sensor); |
332 }, 'Test that frequency hint works (continuous reporting).'); | 335 }, 'Test that frequency hint works (continuous reporting).'); |
333 } | 336 } |
OLD | NEW |