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

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

Issue 2529343002: [sensors] Fix flakiness in generic sensors tests (Closed)
Patch Set: Created 4 years 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 // Wraps callback and calls reject_func if callback throws an error. 3 // Wraps callback and calls reject_func if callback throws an error.
4 class CallbackWrapper { 4 class CallbackWrapper {
5 constructor(callback, reject_func) { 5 constructor(callback, reject_func) {
6 this.wrapper_func_ = (args) => { 6 this.wrapper_func_ = (args) => {
7 try { 7 try {
8 callback(args); 8 callback(args);
9 } catch(e) { 9 } catch(e) {
10 reject_func(); 10 reject_func();
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 269
270 // Binds object to mojo message pipe 270 // Binds object to mojo message pipe
271 bindToPipe(pipe) { 271 bindToPipe(pipe) {
272 this.stub_ = connection.bindHandleToStub( 272 this.stub_ = connection.bindHandleToStub(
273 pipe, sensor_provider.SensorProvider); 273 pipe, sensor_provider.SensorProvider);
274 bindings.StubBindings(this.stub_).delegate = this; 274 bindings.StubBindings(this.stub_).delegate = this;
275 } 275 }
276 276
277 // Mock functions 277 // Mock functions
278 278
279 // Resets mock sensor provider stub bindings.
280 resetSensorProvider() {
281 this.reset();
282 bindings.StubBindings(this.stub_).close();
283 }
284
279 // Resets state of mock SensorProvider between test runs. 285 // Resets state of mock SensorProvider between test runs.
280 reset() { 286 reset() {
281 if (this.active_sensor_ != null) { 287 if (this.active_sensor_ != null) {
282 this.active_sensor_.reset(); 288 this.active_sensor_.reset();
283 this.active_sensor_ = null; 289 this.active_sensor_ = null;
284 } 290 }
285 291
286 this.get_sensor_should_fail_ = false; 292 this.get_sensor_should_fail_ = false;
287 this.resolve_func_ = null; 293 this.resolve_func_ = null;
288 this.max_frequency_ = 60; 294 this.max_frequency_ = 60;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 }; 346 };
341 347
342 let onFailure = () => { 348 let onFailure = () => {
343 sensor.mockSensorProvider.reset(); 349 sensor.mockSensorProvider.reset();
344 return new Promise((resolve, reject) => { setTimeout(reject, 0); }); 350 return new Promise((resolve, reject) => { setTimeout(reject, 0); });
345 }; 351 };
346 352
347 return Promise.resolve(func(sensor)).then(onSuccess, onFailure); 353 return Promise.resolve(func(sensor)).then(onSuccess, onFailure);
348 }), name, properties); 354 }), name, properties);
349 } 355 }
356
357 function resetSensorProvider() {
358 sensor_test(sensor => {
359 sensor.mockSensorProvider.resetSensorProvider();
360 return Promise.resolve();
361 }, 'Reset sensor provider proxy.');
362 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698