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

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: Fixes for review comments from Reilly 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 this.remove_configuration_called_ = null; 46 this.remove_configuration_called_ = null;
47 this.active_sensor_configurations_ = []; 47 this.active_sensor_configurations_ = [];
48 let rv = core.mapBuffer(handle, offset, size, 48 let rv = core.mapBuffer(handle, offset, size,
49 core.MAP_BUFFER_FLAG_NONE); 49 core.MAP_BUFFER_FLAG_NONE);
50 assert_equals(rv.result, core.RESULT_OK, "Failed to map shared buffer"); 50 assert_equals(rv.result, core.RESULT_OK, "Failed to map shared buffer");
51 this.buffer_array_ = rv.buffer; 51 this.buffer_array_ = rv.buffer;
52 this.buffer_ = new Float64Array(this.buffer_array_); 52 this.buffer_ = new Float64Array(this.buffer_array_);
53 this.resetBuffer(); 53 this.resetBuffer();
54 bindings.StubBindings(this.stub_).delegate = this; 54 bindings.StubBindings(this.stub_).delegate = this;
55 bindings.StubBindings(this.stub_).connectionErrorHandler = () => { 55 bindings.StubBindings(this.stub_).connectionErrorHandler = () => {
56 reset(); 56 this.reset();
57 }; 57 };
58 } 58 }
59 59
60 // Returns default configuration. 60 // Returns default configuration.
61 getDefaultConfiguration() { 61 getDefaultConfiguration() {
62 return Promise.resolve({frequency: 5}); 62 return Promise.resolve({frequency: 5});
63 } 63 }
64 64
65 // Adds configuration for the sensor and starts reporting fake data 65 // Adds configuration for the sensor and starts reporting fake data
66 // through update_reading_function_ callback. 66 // through update_reading_function_ callback.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 this.active_sensor_.client_ = proxy; 265 this.active_sensor_.client_ = proxy;
266 }, sensor.SensorClient); 266 }, sensor.SensorClient);
267 return getSensorResponse(init_params, client_handle); 267 return getSensorResponse(init_params, client_handle);
268 } 268 }
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 bindings.StubBindings(this.stub_).connectionErrorHandler = () => {
276 this.reset();
277 };
275 } 278 }
276 279
277 // Mock functions 280 // Mock functions
278 281
279 // Resets state of mock SensorProvider between test runs. 282 // Resets state of mock SensorProvider between test runs.
280 reset() { 283 reset() {
281 if (this.active_sensor_ != null) { 284 if (this.active_sensor_ != null) {
282 this.active_sensor_.reset(); 285 this.active_sensor_.reset();
283 this.active_sensor_ = null; 286 this.active_sensor_ = null;
284 } 287 }
285 288
286 this.get_sensor_should_fail_ = false; 289 this.get_sensor_should_fail_ = false;
287 this.resolve_func_ = null; 290 this.resolve_func_ = null;
288 this.max_frequency_ = 60; 291 this.max_frequency_ = 60;
292 if (this.stub_)
293 bindings.StubBindings(this.stub_).close();
289 } 294 }
290 295
291 // Sets flag that forces mock SensorProvider to fail when getSensor() is 296 // Sets flag that forces mock SensorProvider to fail when getSensor() is
292 // invoked. 297 // invoked.
293 setGetSensorShouldFail(should_fail) { 298 setGetSensorShouldFail(should_fail) {
294 this.get_sensor_should_fail_ = should_fail; 299 this.get_sensor_should_fail_ = should_fail;
295 } 300 }
296 301
297 // Returns mock sensor that was created in getSensor to the layout test. 302 // Returns mock sensor that was created in getSensor to the layout test.
298 getCreatedSensor() { 303 getCreatedSensor() {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 }; 345 };
341 346
342 let onFailure = () => { 347 let onFailure = () => {
343 sensor.mockSensorProvider.reset(); 348 sensor.mockSensorProvider.reset();
344 return new Promise((resolve, reject) => { setTimeout(reject, 0); }); 349 return new Promise((resolve, reject) => { setTimeout(reject, 0); });
345 }; 350 };
346 351
347 return Promise.resolve(func(sensor)).then(onSuccess, onFailure); 352 return Promise.resolve(func(sensor)).then(onSuccess, onFailure);
348 }), name, properties); 353 }), name, properties);
349 } 354 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698