| 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 // In actual implementation updates are bound to rAF, | 307 assert_equals(fastSensorNotifiedCounter, 3); |
| 308 // (not to a timer) sometimes fast sensor gets invoked 4 times. | |
| 309 assert_true(fastSensorNotifiedCounter == 3 || | |
| 310 fastSensorNotifiedCounter == 4); | |
| 311 fastSensor.stop(); | 308 fastSensor.stop(); |
| 312 slowSensor.stop(); | 309 slowSensor.stop(); |
| 313 resolve(mockSensor); | 310 resolve(mockSensor); |
| 314 } | 311 } |
| 315 }, reject); | 312 }, reject); |
| 316 | 313 |
| 317 fastSensor.onchange = fastSensorWrapper.callback; | 314 fastSensor.onchange = fastSensorWrapper.callback; |
| 318 slowSensor.onchange = slowSensorWrapper.callback; | 315 slowSensor.onchange = slowSensorWrapper.callback; |
| 319 fastSensor.onerror = reject; | 316 fastSensor.onerror = reject; |
| 320 slowSensor.onerror = reject; | 317 slowSensor.onerror = reject; |
| 321 }); | 318 }); |
| 322 }) | 319 }) |
| 323 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); | 320 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); |
| 324 | 321 |
| 325 return testPromise; | 322 return testPromise; |
| 326 } | 323 } |
| 327 | 324 |
| 328 sensor_test(sensor => { | 325 sensor_test(sensor => { |
| 329 return checkFrequencyHintWorks(sensor); | 326 return checkFrequencyHintWorks(sensor); |
| 330 }, 'Test that frequency hint works (onchange reporting).'); | 327 }, 'Test that frequency hint works (onchange reporting).'); |
| 331 | 328 |
| 332 sensor_test(sensor => { | 329 sensor_test(sensor => { |
| 333 sensor.mockSensorProvider.setContinuousReportingMode(); | 330 sensor.mockSensorProvider.setContinuousReportingMode(); |
| 334 return checkFrequencyHintWorks(sensor); | 331 return checkFrequencyHintWorks(sensor); |
| 335 }, 'Test that frequency hint works (continuous reporting).'); | 332 }, 'Test that frequency hint works (continuous reporting).'); |
| 336 } | 333 } |
| OLD | NEW |