| 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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 284 |
| 285 let testPromise = sensor.mockSensorProvider.getCreatedSensor() | 285 let testPromise = sensor.mockSensorProvider.getCreatedSensor() |
| 286 .then(mockSensor => { | 286 .then(mockSensor => { |
| 287 mockSensor.setExpectsModifiedReading(true); | 287 mockSensor.setExpectsModifiedReading(true); |
| 288 return mockSensor.setUpdateSensorReadingFunction(updateReading); | 288 return mockSensor.setUpdateSensorReadingFunction(updateReading); |
| 289 }) | 289 }) |
| 290 .then(mockSensor => { | 290 .then(mockSensor => { |
| 291 return new Promise((resolve, reject) => { | 291 return new Promise((resolve, reject) => { |
| 292 let fastSensorNotifiedCounter = 0; | 292 let fastSensorNotifiedCounter = 0; |
| 293 let slowSensorNotifiedCounter = 0; | 293 let slowSensorNotifiedCounter = 0; |
| 294 let readingUpdatesCounter = 0; | |
| 295 | 294 |
| 296 let fastSensorWrapper = new CallbackWrapper(() => { | 295 let fastSensorWrapper = new CallbackWrapper(() => { |
| 297 fastSensorNotifiedCounter++; | 296 fastSensorNotifiedCounter++; |
| 298 }, reject); | 297 }, reject); |
| 299 | 298 |
| 300 let slowSensorWrapper = new CallbackWrapper(() => { | 299 let slowSensorWrapper = new CallbackWrapper(() => { |
| 301 slowSensorNotifiedCounter++; | 300 slowSensorNotifiedCounter++; |
| 302 if (slowSensorNotifiedCounter == 1) { | 301 if (slowSensorNotifiedCounter == 1) { |
| 303 fastSensor.start(); | 302 fastSensor.start(); |
| 304 readingUpdatesCounter = mockSensor.reading_updates_count(); | |
| 305 } else if (slowSensorNotifiedCounter == 2) { | 303 } else if (slowSensorNotifiedCounter == 2) { |
| 306 // By the moment slow sensor (9 Hz) is notified for the | 304 // By the moment slow sensor (9 Hz) is notified for the |
| 307 // next time, the fast sensor (30 Hz) has been notified | 305 // next time, the fast sensor (30 Hz) has been notified |
| 308 // for int(30/9) = 3 times. | 306 // for int(30/9) = 3 times. |
| 309 // In actual implementation updates are bound to rAF, | 307 assert_equals(fastSensorNotifiedCounter, 3); |
| 310 // (not to a timer) so fluctuations are possible, so we | |
| 311 // reference to the actual elapsed updates count. | |
| 312 let elapsedUpdates = mockSensor.reading_updates_count() - readin
gUpdatesCounter; | |
| 313 assert_equals(fastSensorNotifiedCounter, elapsedUpdates); | |
| 314 fastSensor.stop(); | 308 fastSensor.stop(); |
| 315 slowSensor.stop(); | 309 slowSensor.stop(); |
| 316 resolve(mockSensor); | 310 resolve(mockSensor); |
| 317 } | 311 } |
| 318 }, reject); | 312 }, reject); |
| 319 | 313 |
| 320 fastSensor.onchange = fastSensorWrapper.callback; | 314 fastSensor.onchange = fastSensorWrapper.callback; |
| 321 slowSensor.onchange = slowSensorWrapper.callback; | 315 slowSensor.onchange = slowSensorWrapper.callback; |
| 322 fastSensor.onerror = reject; | 316 fastSensor.onerror = reject; |
| 323 slowSensor.onerror = reject; | 317 slowSensor.onerror = reject; |
| 324 }); | 318 }); |
| 325 }) | 319 }) |
| 326 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); | 320 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); |
| 327 | 321 |
| 328 return testPromise; | 322 return testPromise; |
| 329 } | 323 } |
| 330 | 324 |
| 331 sensor_test(sensor => { | 325 sensor_test(sensor => { |
| 332 return checkFrequencyHintWorks(sensor); | 326 return checkFrequencyHintWorks(sensor); |
| 333 }, 'Test that frequency hint works (onchange reporting).'); | 327 }, 'Test that frequency hint works (onchange reporting).'); |
| 334 | 328 |
| 335 sensor_test(sensor => { | 329 sensor_test(sensor => { |
| 336 sensor.mockSensorProvider.setContinuousReportingMode(); | 330 sensor.mockSensorProvider.setContinuousReportingMode(); |
| 337 return checkFrequencyHintWorks(sensor); | 331 return checkFrequencyHintWorks(sensor); |
| 338 }, 'Test that frequency hint works (continuous reporting).'); | 332 }, 'Test that frequency hint works (continuous reporting).'); |
| 339 } | 333 } |
| OLD | NEW |