| OLD | NEW |
| 1 'use strict'; | 1 'use strict'; |
| 2 | 2 |
| 3 function sensor_mocks(mojo) { | 3 function sensor_mocks(mojo) { |
| 4 return define('Generic Sensor API mocks', [ | 4 return define('Generic Sensor API mocks', [ |
| 5 'mojo/public/js/core', | 5 'mojo/public/js/core', |
| 6 'mojo/public/js/bindings', | 6 'mojo/public/js/bindings', |
| 7 'mojo/public/js/connection', | 7 'mojo/public/js/connection', |
| 8 'device/generic_sensor/public/interfaces/sensor_provider.mojom', | 8 'device/generic_sensor/public/interfaces/sensor_provider.mojom', |
| 9 'device/generic_sensor/public/interfaces/sensor.mojom', | 9 'device/generic_sensor/public/interfaces/sensor.mojom', |
| 10 ], (core, bindings, connection, sensor_provider, sensor) => { | 10 ], (core, bindings, connection, sensor_provider, sensor) => { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 // Returns default configuration. | 42 // Returns default configuration. |
| 43 getDefaultConfiguration() { | 43 getDefaultConfiguration() { |
| 44 return Promise.resolve({frequency: 5}); | 44 return Promise.resolve({frequency: 5}); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Adds configuration for the sensor and starts reporting fake data | 47 // Adds configuration for the sensor and starts reporting fake data |
| 48 // through update_reading_function_ callback. | 48 // through update_reading_function_ callback. |
| 49 addConfiguration(configuration) { | 49 addConfiguration(configuration) { |
| 50 assert_not_equals(configuration, null, "Invalid sensor configuration."); | 50 assert_not_equals(configuration, null, "Invalid sensor configuration."); |
| 51 | 51 |
| 52 if (this.add_configuration_called_ != null) { | |
| 53 this.add_configuration_called_(this); | |
| 54 } | |
| 55 | |
| 56 if (!this.start_should_fail_ && this.update_reading_function_ != null) { | 52 if (!this.start_should_fail_ && this.update_reading_function_ != null) { |
| 57 let timeout = (1 / configuration.frequency) * 1000; | 53 let timeout = (1 / configuration.frequency) * 1000; |
| 58 this.sensor_reading_timer_id_ = window.setTimeout(() => { | 54 this.sensor_reading_timer_id_ = window.setTimeout(() => { |
| 59 this.update_reading_function_(this.buffer_); | 55 this.update_reading_function_(this.buffer_); |
| 60 if (this.reporting_mode_ === sensor.ReportingMode.ON_CHANGE) { | 56 if (this.reporting_mode_ === sensor.ReportingMode.ON_CHANGE) { |
| 61 this.client_.sensorReadingChanged(); | 57 this.client_.sensorReadingChanged(); |
| 62 } | 58 } |
| 63 }, timeout); | 59 }, timeout); |
| 60 } |
| 64 | 61 |
| 65 this.active_sensor_configurations_.push(configuration); | 62 this.active_sensor_configurations_.push(configuration); |
| 66 } | 63 |
| 64 if (this.add_configuration_called_ != null) |
| 65 this.add_configuration_called_(this); |
| 67 | 66 |
| 68 return sensorResponse(!this.start_should_fail_); | 67 return sensorResponse(!this.start_should_fail_); |
| 69 } | 68 } |
| 70 | 69 |
| 71 // Removes sensor configuration from the list of active configurations and | 70 // Removes sensor configuration from the list of active configurations and |
| 72 // stops notification about sensor reading changes if | 71 // stops notification about sensor reading changes if |
| 73 // active_sensor_configurations_ is empty. | 72 // active_sensor_configurations_ is empty. |
| 74 removeConfiguration(configuration) { | 73 removeConfiguration(configuration) { |
| 75 if (this.remove_configuration_called_ != null) { | 74 if (this.remove_configuration_called_ != null) { |
| 76 this.remove_configuration_called_(this); | 75 this.remove_configuration_called_(this); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 }); | 292 }); |
| 294 } | 293 } |
| 295 | 294 |
| 296 function sensor_test(func, name, properties) { | 295 function sensor_test(func, name, properties) { |
| 297 mojo_test(mojo => sensor_mocks(mojo).then(sensor => { | 296 mojo_test(mojo => sensor_mocks(mojo).then(sensor => { |
| 298 let result = Promise.resolve(func(sensor)); | 297 let result = Promise.resolve(func(sensor)); |
| 299 let cleanUp = () => { sensor.mockSensorProvider.reset(); }; | 298 let cleanUp = () => { sensor.mockSensorProvider.reset(); }; |
| 300 return result.then(cleanUp, cleanUp); | 299 return result.then(cleanUp, cleanUp); |
| 301 }), name, properties); | 300 }), name, properties); |
| 302 } | 301 } |
| OLD | NEW |