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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 core.createSharedBuffer( | 242 core.createSharedBuffer( |
243 this.shared_buffer_size_in_bytes_, | 243 this.shared_buffer_size_in_bytes_, |
244 core.CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE); | 244 core.CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE); |
245 assert_equals(rv.result, core.RESULT_OK, "Failed to create buffer"); | 245 assert_equals(rv.result, core.RESULT_OK, "Failed to create buffer"); |
246 this.shared_buffer_handle_ = rv.handle; | 246 this.shared_buffer_handle_ = rv.handle; |
247 this.active_sensor_ = null; | 247 this.active_sensor_ = null; |
248 this.get_sensor_should_fail_ = false; | 248 this.get_sensor_should_fail_ = false; |
249 this.resolve_func_ = null; | 249 this.resolve_func_ = null; |
250 this.is_continuous_ = false; | 250 this.is_continuous_ = false; |
251 this.max_frequency_ = 60; | 251 this.max_frequency_ = 60; |
| 252 this.min_frequency_ = 1; |
252 this.binding_ = new bindings.Binding(sensor_provider.SensorProvider, | 253 this.binding_ = new bindings.Binding(sensor_provider.SensorProvider, |
253 this); | 254 this); |
254 } | 255 } |
255 | 256 |
256 // Returns initialized Sensor proxy to the client. | 257 // Returns initialized Sensor proxy to the client. |
257 getSensor(type, request) { | 258 getSensor(type, request) { |
258 if (this.get_sensor_should_fail_) { | 259 if (this.get_sensor_should_fail_) { |
259 var ignored = new sensor.SensorClientPtr(); | 260 var ignored = new sensor.SensorClientPtr(); |
260 return getSensorResponse(null, bindings.makeRequest(ignored)); | 261 return getSensorResponse(null, bindings.makeRequest(ignored)); |
261 } | 262 } |
(...skipping 19 matching lines...) Expand all Loading... |
281 assert_equals(rv.result, core.RESULT_OK); | 282 assert_equals(rv.result, core.RESULT_OK); |
282 | 283 |
283 let default_config = {frequency: 5}; | 284 let default_config = {frequency: 5}; |
284 | 285 |
285 let init_params = | 286 let init_params = |
286 new sensor_provider.SensorInitParams( | 287 new sensor_provider.SensorInitParams( |
287 { memory: rv.handle, | 288 { memory: rv.handle, |
288 buffer_offset: offset, | 289 buffer_offset: offset, |
289 mode: reporting_mode, | 290 mode: reporting_mode, |
290 default_configuration: default_config, | 291 default_configuration: default_config, |
| 292 minimum_frequency: this.min_frequency_, |
291 maximum_frequency: this.max_frequency_}); | 293 maximum_frequency: this.max_frequency_}); |
292 | 294 |
293 if (this.resolve_func_ !== null) { | 295 if (this.resolve_func_ !== null) { |
294 this.resolve_func_(this.active_sensor_); | 296 this.resolve_func_(this.active_sensor_); |
295 } | 297 } |
296 | 298 |
297 this.active_sensor_.client_ = new sensor.SensorClientPtr(); | 299 this.active_sensor_.client_ = new sensor.SensorClientPtr(); |
298 return getSensorResponse( | 300 return getSensorResponse( |
299 init_params, bindings.makeRequest(this.active_sensor_.client_)); | 301 init_params, bindings.makeRequest(this.active_sensor_.client_)); |
300 } | 302 } |
(...skipping 11 matching lines...) Expand all Loading... |
312 // Resets state of mock SensorProvider between test runs. | 314 // Resets state of mock SensorProvider between test runs. |
313 reset() { | 315 reset() { |
314 if (this.active_sensor_ != null) { | 316 if (this.active_sensor_ != null) { |
315 this.active_sensor_.reset(); | 317 this.active_sensor_.reset(); |
316 this.active_sensor_ = null; | 318 this.active_sensor_ = null; |
317 } | 319 } |
318 | 320 |
319 this.get_sensor_should_fail_ = false; | 321 this.get_sensor_should_fail_ = false; |
320 this.resolve_func_ = null; | 322 this.resolve_func_ = null; |
321 this.max_frequency_ = 60; | 323 this.max_frequency_ = 60; |
| 324 this.min_frequency_ = 1; |
322 this.is_continuous_ = false; | 325 this.is_continuous_ = false; |
323 this.binding_.close(); | 326 this.binding_.close(); |
324 } | 327 } |
325 | 328 |
326 // Sets flag that forces mock SensorProvider to fail when getSensor() is | 329 // Sets flag that forces mock SensorProvider to fail when getSensor() is |
327 // invoked. | 330 // invoked. |
328 setGetSensorShouldFail(should_fail) { | 331 setGetSensorShouldFail(should_fail) { |
329 this.get_sensor_should_fail_ = should_fail; | 332 this.get_sensor_should_fail_ = should_fail; |
330 } | 333 } |
331 | 334 |
(...skipping 10 matching lines...) Expand all Loading... |
342 | 345 |
343 // Forces sensor to use |reporting_mode| as an update mode. | 346 // Forces sensor to use |reporting_mode| as an update mode. |
344 setContinuousReportingMode() { | 347 setContinuousReportingMode() { |
345 this.is_continuous_ = true; | 348 this.is_continuous_ = true; |
346 } | 349 } |
347 | 350 |
348 // Sets the maximum frequency for a concrete sensor. | 351 // Sets the maximum frequency for a concrete sensor. |
349 setMaximumSupportedFrequency(frequency) { | 352 setMaximumSupportedFrequency(frequency) { |
350 this.max_frequency_ = frequency; | 353 this.max_frequency_ = frequency; |
351 } | 354 } |
| 355 |
| 356 // Sets the minimum frequency for a concrete sensor. |
| 357 setMinimumSupportedFrequency(frequency) { |
| 358 this.min_frequency_ = frequency; |
| 359 } |
352 } | 360 } |
353 | 361 |
354 let mockSensorProvider = new MockSensorProvider; | 362 let mockSensorProvider = new MockSensorProvider; |
355 mojo.frameInterfaces.addInterfaceOverrideForTesting( | 363 mojo.frameInterfaces.addInterfaceOverrideForTesting( |
356 sensor_provider.SensorProvider.name, | 364 sensor_provider.SensorProvider.name, |
357 pipe => { | 365 pipe => { |
358 mockSensorProvider.bindToPipe(pipe); | 366 mockSensorProvider.bindToPipe(pipe); |
359 }); | 367 }); |
360 | 368 |
361 return Promise.resolve({ | 369 return Promise.resolve({ |
(...skipping 13 matching lines...) Expand all Loading... |
375 }; | 383 }; |
376 | 384 |
377 let onFailure = error => { | 385 let onFailure = error => { |
378 sensor.mockSensorProvider.reset(); | 386 sensor.mockSensorProvider.reset(); |
379 return new Promise((resolve, reject) => { setTimeout(() => {reject(error);
}, 0); }); | 387 return new Promise((resolve, reject) => { setTimeout(() => {reject(error);
}, 0); }); |
380 }; | 388 }; |
381 | 389 |
382 return Promise.resolve(func(sensor)).then(onSuccess, onFailure); | 390 return Promise.resolve(func(sensor)).then(onSuccess, onFailure); |
383 }), name, properties); | 391 }), name, properties); |
384 } | 392 } |
OLD | NEW |