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

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

Issue 2870073002: [Sensors] Decouple sensor readings update from rAF (Closed)
Patch Set: [Sensors] Decouple sensor readings update from rAF Created 3 years, 7 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/sensor/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 sensor_test(sensor => { 8 sensor_test(sensor => {
9 sensor.mockSensorProvider.setGetSensorShouldFail(true); 9 sensor.mockSensorProvider.setGetSensorShouldFail(true);
10 let sensorObject = new sensorType; 10 let sensorObject = new sensorType;
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 338
339 let slowSensorWrapper = new CallbackWrapper(() => { 339 let slowSensorWrapper = new CallbackWrapper(() => {
340 slowSensorNotifiedCounter++; 340 slowSensorNotifiedCounter++;
341 if (slowSensorNotifiedCounter == 1) { 341 if (slowSensorNotifiedCounter == 1) {
342 fastSensor.start(); 342 fastSensor.start();
343 readingUpdatesCounter = mockSensor.reading_updates_count(); 343 readingUpdatesCounter = mockSensor.reading_updates_count();
344 } else if (slowSensorNotifiedCounter == 2) { 344 } else if (slowSensorNotifiedCounter == 2) {
345 // By the moment slow sensor (9 Hz) is notified for the 345 // By the moment slow sensor (9 Hz) is notified for the
346 // next time, the fast sensor (30 Hz) has been notified 346 // next time, the fast sensor (30 Hz) has been notified
347 // for int(30/9) = 3 times. 347 // for int(30/9) = 3 times.
348 // In actual implementation updates are bound to rAF,
349 // (not to a timer) so fluctuations are possible, so we
350 // reference to the actual elapsed updates count.
351 let elapsedUpdates = mockSensor.reading_updates_count() - readin gUpdatesCounter; 348 let elapsedUpdates = mockSensor.reading_updates_count() - readin gUpdatesCounter;
352 assert_approx_equals(fastSensorNotifiedCounter, elapsedUpdates, 1); 349 assert_equals(fastSensorNotifiedCounter, elapsedUpdates);
353 fastSensor.stop(); 350 fastSensor.stop();
354 slowSensor.stop(); 351 slowSensor.stop();
355 resolve(mockSensor); 352 resolve(mockSensor);
356 } 353 }
357 }, reject); 354 }, reject);
358 355
359 fastSensor.onchange = fastSensorWrapper.callback; 356 fastSensor.onchange = fastSensorWrapper.callback;
360 slowSensor.onchange = slowSensorWrapper.callback; 357 slowSensor.onchange = slowSensorWrapper.callback;
361 fastSensor.onerror = reject; 358 fastSensor.onerror = reject;
362 slowSensor.onerror = reject; 359 slowSensor.onerror = reject;
363 }); 360 });
364 }) 361 })
365 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); 362 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); });
366 363
367 return testPromise; 364 return testPromise;
368 } 365 }
369 366
370 sensor_test(sensor => { 367 sensor_test(sensor => {
371 return checkFrequencyHintWorks(sensor); 368 return checkFrequencyHintWorks(sensor);
372 }, 'Test that frequency hint works (onchange reporting).'); 369 }, 'Test that frequency hint works (onchange reporting).');
373 370
374 sensor_test(sensor => { 371 sensor_test(sensor => {
375 sensor.mockSensorProvider.setContinuousReportingMode(); 372 sensor.mockSensorProvider.setContinuousReportingMode();
376 return checkFrequencyHintWorks(sensor); 373 return checkFrequencyHintWorks(sensor);
377 }, 'Test that frequency hint works (continuous reporting).'); 374 }, 'Test that frequency hint works (continuous reporting).');
378 } 375 }
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/sensor/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698