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(e); | 10 reject_func(e); |
11 } | 11 } |
12 } | 12 } |
13 } | 13 } |
14 | 14 |
15 get callback() { | 15 get callback() { |
16 return this.wrapper_func_; | 16 return this.wrapper_func_; |
17 } | 17 } |
18 } | 18 } |
19 | 19 |
20 function sensor_mocks(mojo) { | 20 function sensor_mocks(mojo) { |
21 return define('Generic Sensor API mocks', [ | 21 return define('Generic Sensor API mocks', [ |
22 'mojo/public/js/core', | 22 'mojo/public/js/core', |
23 'mojo/public/js/bindings', | 23 'mojo/public/js/bindings', |
24 'device/generic_sensor/public/interfaces/sensor_provider.mojom', | 24 'services/device/public/interfaces/sensor_provider.mojom', |
25 'device/generic_sensor/public/interfaces/sensor.mojom', | 25 'services/device/public/interfaces/sensor.mojom', |
26 'services/device/public/interfaces/constants.mojom', | 26 'services/device/public/interfaces/constants.mojom', |
27 ], (core, bindings, sensor_provider, sensor, deviceConstants) => { | 27 ], (core, bindings, sensor_provider, sensor, deviceConstants) => { |
28 | 28 |
29 // Helper function that returns resolved promise with result. | 29 // Helper function that returns resolved promise with result. |
30 function sensorResponse(success) { | 30 function sensorResponse(success) { |
31 return Promise.resolve({success}); | 31 return Promise.resolve({success}); |
32 } | 32 } |
33 | 33 |
34 // Class that mocks Sensor interface defined in sensor.mojom | 34 // Class that mocks Sensor interface defined in sensor.mojom |
35 class MockSensor { | 35 class MockSensor { |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 }; | 378 }; |
379 | 379 |
380 let onFailure = error => { | 380 let onFailure = error => { |
381 sensor.mockSensorProvider.reset(); | 381 sensor.mockSensorProvider.reset(); |
382 return new Promise((resolve, reject) => { setTimeout(() => {reject(error);
}, 0); }); | 382 return new Promise((resolve, reject) => { setTimeout(() => {reject(error);
}, 0); }); |
383 }; | 383 }; |
384 | 384 |
385 return Promise.resolve(func(sensor)).then(onSuccess, onFailure); | 385 return Promise.resolve(func(sensor)).then(onSuccess, onFailure); |
386 }), name, properties); | 386 }), name, properties); |
387 } | 387 } |
OLD | NEW |