Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: third_party/WebKit/LayoutTests/sensor/resources/generic-sensor-tests.js

Issue 2604483004: [Sensors] Reland: Reland: Align sensor reading updates and 'onchange' notification with rAF. (Closed)
Patch Set: Patch with fix Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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;
294 295
295 let fastSensorWrapper = new CallbackWrapper(() => { 296 let fastSensorWrapper = new CallbackWrapper(() => {
296 fastSensorNotifiedCounter++; 297 fastSensorNotifiedCounter++;
297 }, reject); 298 }, reject);
298 299
299 let slowSensorWrapper = new CallbackWrapper(() => { 300 let slowSensorWrapper = new CallbackWrapper(() => {
300 slowSensorNotifiedCounter++; 301 slowSensorNotifiedCounter++;
301 if (slowSensorNotifiedCounter == 1) { 302 if (slowSensorNotifiedCounter == 1) {
302 fastSensor.start(); 303 fastSensor.start();
304 readingUpdatesCounter = mockSensor.reading_updates_count();
303 } else if (slowSensorNotifiedCounter == 2) { 305 } else if (slowSensorNotifiedCounter == 2) {
304 // By the moment slow sensor (9 Hz) is notified for the 306 // By the moment slow sensor (9 Hz) is notified for the
305 // next time, the fast sensor (30 Hz) has been notified 307 // next time, the fast sensor (30 Hz) has been notified
306 // for int(30/9) = 3 times. 308 // for int(30/9) = 3 times.
307 assert_equals(fastSensorNotifiedCounter, 3); 309 // In actual implementation updates are bound to rAF,
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);
308 fastSensor.stop(); 314 fastSensor.stop();
309 slowSensor.stop(); 315 slowSensor.stop();
310 resolve(mockSensor); 316 resolve(mockSensor);
311 } 317 }
312 }, reject); 318 }, reject);
313 319
314 fastSensor.onchange = fastSensorWrapper.callback; 320 fastSensor.onchange = fastSensorWrapper.callback;
315 slowSensor.onchange = slowSensorWrapper.callback; 321 slowSensor.onchange = slowSensorWrapper.callback;
316 fastSensor.onerror = reject; 322 fastSensor.onerror = reject;
317 slowSensor.onerror = reject; 323 slowSensor.onerror = reject;
318 }); 324 });
319 }) 325 })
320 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); 326 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); });
321 327
322 return testPromise; 328 return testPromise;
323 } 329 }
324 330
325 sensor_test(sensor => { 331 sensor_test(sensor => {
326 return checkFrequencyHintWorks(sensor); 332 return checkFrequencyHintWorks(sensor);
327 }, 'Test that frequency hint works (onchange reporting).'); 333 }, 'Test that frequency hint works (onchange reporting).');
328 334
329 sensor_test(sensor => { 335 sensor_test(sensor => {
330 sensor.mockSensorProvider.setContinuousReportingMode(); 336 sensor.mockSensorProvider.setContinuousReportingMode();
331 return checkFrequencyHintWorks(sensor); 337 return checkFrequencyHintWorks(sensor);
332 }, 'Test that frequency hint works (continuous reporting).'); 338 }, 'Test that frequency hint works (continuous reporting).');
333 } 339 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698