| OLD | NEW |
| 1 'use strict'; | 1 'use strict'; |
| 2 | 2 |
| 3 function vibration_mocks(mojo) { | 3 function vibration_mocks(mojo) { |
| 4 return define( | 4 return define( |
| 5 'VibrationManager mocks', | 5 'VibrationManager mocks', |
| 6 [ | 6 [ |
| 7 'mojo/public/js/bindings', | 7 'mojo/public/js/bindings', |
| 8 'device/vibration/vibration_manager.mojom', | 8 'device/vibration/vibration_manager.mojom', |
| 9 'services/device/public/interfaces/constants.mojom', |
| 9 ], | 10 ], |
| 10 (bindings, vibrationManager) => { | 11 (bindings, vibrationManager, deviceConstants) => { |
| 11 class MockVibrationManager { | 12 class MockVibrationManager { |
| 12 constructor() { | 13 constructor() { |
| 13 this.bindingSet = | 14 this.bindingSet = |
| 14 new bindings.BindingSet(vibrationManager.VibrationManager); | 15 new bindings.BindingSet(vibrationManager.VibrationManager); |
| 15 | 16 |
| 16 this.vibrate_milliseconds_ = -1; | 17 this.vibrate_milliseconds_ = -1; |
| 17 this.cancelled_ = false; | 18 this.cancelled_ = false; |
| 18 } | 19 } |
| 19 | 20 |
| 20 vibrate(milliseconds) { | 21 vibrate(milliseconds) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 36 return this.cancelled_; | 37 return this.cancelled_; |
| 37 } | 38 } |
| 38 | 39 |
| 39 reset() { | 40 reset() { |
| 40 this.vibrate_milliseconds_ = -1; | 41 this.vibrate_milliseconds_ = -1; |
| 41 this.cancelled_ = false; | 42 this.cancelled_ = false; |
| 42 } | 43 } |
| 43 } | 44 } |
| 44 | 45 |
| 45 let mockVibrationManager = new MockVibrationManager; | 46 let mockVibrationManager = new MockVibrationManager; |
| 46 mojo.frameInterfaces.addInterfaceOverrideForTesting( | 47 mojo.connector.addInterfaceOverrideForTesting( |
| 48 deviceConstants.kServiceName, |
| 47 vibrationManager.VibrationManager.name, handle => { | 49 vibrationManager.VibrationManager.name, handle => { |
| 48 mockVibrationManager.bindingSet.addBinding( | 50 mockVibrationManager.bindingSet.addBinding( |
| 49 mockVibrationManager, handle); | 51 mockVibrationManager, handle); |
| 50 }); | 52 }); |
| 51 | 53 |
| 52 return Promise.resolve({ | 54 return Promise.resolve({ |
| 53 // Interface instance bound to main frame. | 55 // Mock interface instance bound. |
| 54 mockVibrationManager: mockVibrationManager, | 56 mockVibrationManager: mockVibrationManager, |
| 55 // Constructor for mock VibrationManager class. | |
| 56 MockVibrationManager: MockVibrationManager, | |
| 57 // Loaded mojom interface. | |
| 58 VibrationManager: vibrationManager.VibrationManager, | |
| 59 }); | 57 }); |
| 60 }); | 58 }); |
| 61 } | 59 } |
| 62 | 60 |
| 63 function vibration_test(func, name, properties) { | 61 function vibration_test(func, name, properties) { |
| 64 mojo_test( | 62 mojo_test( |
| 65 mojo => vibration_mocks(mojo).then(vibration => { | 63 mojo => vibration_mocks(mojo).then(vibration => { |
| 66 let result = Promise.resolve(func(vibration)); | 64 let result = Promise.resolve(func(vibration)); |
| 67 let cleanUp = () => vibration.mockVibrationManager.reset(); | 65 let cleanUp = () => vibration.mockVibrationManager.reset(); |
| 68 result.then(cleanUp, cleanUp); | 66 result.then(cleanUp, cleanUp); |
| 69 return result; | 67 return result; |
| 70 }), | 68 }), |
| 71 name, properties); | 69 name, properties); |
| 72 } | 70 } |
| OLD | NEW |