OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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(); | |
294 } | |
Reilly Grant (use Gerrit)
2016/11/28 19:40:33
nit: unnecessary braces
shalamov
2016/11/29 09:02:23
Done.
| |
289 } | 295 } |
290 | 296 |
291 // Sets flag that forces mock SensorProvider to fail when getSensor() is | 297 // Sets flag that forces mock SensorProvider to fail when getSensor() is |
292 // invoked. | 298 // invoked. |
293 setGetSensorShouldFail(should_fail) { | 299 setGetSensorShouldFail(should_fail) { |
294 this.get_sensor_should_fail_ = should_fail; | 300 this.get_sensor_should_fail_ = should_fail; |
295 } | 301 } |
296 | 302 |
297 // Returns mock sensor that was created in getSensor to the layout test. | 303 // Returns mock sensor that was created in getSensor to the layout test. |
298 getCreatedSensor() { | 304 getCreatedSensor() { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 } |
OLD | NEW |