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); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 191 |
192 startReading() { | 192 startReading() { |
193 if (this.update_reading_function_ != null) { | 193 if (this.update_reading_function_ != null) { |
194 this.stopReading(); | 194 this.stopReading(); |
195 let max_frequency_used = | 195 let max_frequency_used = |
196 this.active_sensor_configurations_[0].frequency; | 196 this.active_sensor_configurations_[0].frequency; |
197 let timeout = (1 / max_frequency_used) * 1000; | 197 let timeout = (1 / max_frequency_used) * 1000; |
198 this.sensor_reading_timer_id_ = window.setInterval(() => { | 198 this.sensor_reading_timer_id_ = window.setInterval(() => { |
199 if (this.update_reading_function_) { | 199 if (this.update_reading_function_) { |
200 this.update_reading_function_(this.buffer_); | 200 this.update_reading_function_(this.buffer_); |
| 201 // For all tests sensor reading should have monotonically |
| 202 // increasing timestamp in seconds. |
| 203 this.buffer_[1] = window.performance.now() * 0.001; |
201 this.reading_updates_count_++; | 204 this.reading_updates_count_++; |
202 } | 205 } |
203 if (this.reporting_mode_ === sensor.ReportingMode.ON_CHANGE) { | 206 if (this.reporting_mode_ === sensor.ReportingMode.ON_CHANGE) { |
204 this.client_.sensorReadingChanged(); | 207 this.client_.sensorReadingChanged(); |
205 } | 208 } |
206 }, timeout); | 209 }, timeout); |
207 } | 210 } |
208 } | 211 } |
209 | 212 |
210 stopReading() { | 213 stopReading() { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 }; | 378 }; |
376 | 379 |
377 let onFailure = error => { | 380 let onFailure = error => { |
378 sensor.mockSensorProvider.reset(); | 381 sensor.mockSensorProvider.reset(); |
379 return new Promise((resolve, reject) => { setTimeout(() => {reject(error);
}, 0); }); | 382 return new Promise((resolve, reject) => { setTimeout(() => {reject(error);
}, 0); }); |
380 }; | 383 }; |
381 | 384 |
382 return Promise.resolve(func(sensor)).then(onSuccess, onFailure); | 385 return Promise.resolve(func(sensor)).then(onSuccess, onFailure); |
383 }), name, properties); | 386 }), name, properties); |
384 } | 387 } |
OLD | NEW |