OLD | NEW |
---|---|
(Empty) | |
1 'use strict'; | |
2 | |
3 function vibration_mocks(mojo) { | |
4 return define('VibrationManager mocks', [ | |
5 'mojo/public/js/bindings', | |
6 'device/vibration/vibration_manager.mojom', | |
7 ], (bindings, vibrationManager) => { | |
8 class MockVibrationManager { | |
9 constructor() { | |
10 this.bindingSet = new bindings.BindingSet(vibrationManager.VibrationMana ger); | |
11 | |
12 this.vibrate_milliseconds_ = -1; | |
13 this.cancelled_ = false; | |
14 } | |
15 | |
16 vibrate(milliseconds) { | |
17 this.vibrate_milliseconds_ = milliseconds; | |
18 window.postMessage(milliseconds, '*'); | |
leonhsl(Using Gerrit)
2017/03/07 15:00:41
I'm not sure whether this is the best practice to
| |
19 return Promise.resolve(); | |
20 } | |
21 | |
22 cancel() { | |
23 this.cancelled_ = true; | |
24 } | |
25 | |
26 getDuration() { | |
27 return this.vibrate_milliseconds_; | |
28 } | |
29 | |
30 isCancelled() { | |
31 return this.cancelled_; | |
32 } | |
33 | |
34 reset() { | |
35 this.vibrate_milliseconds_ = -1; | |
36 this.cancelled_ = false; | |
37 } | |
38 } | |
39 | |
40 let mockVibrationManager = new MockVibrationManager; | |
41 mojo.frameInterfaces.addInterfaceOverrideForTesting( | |
42 vibrationManager.VibrationManager.name, | |
43 handle => { | |
44 mockVibrationManager.bindingSet.addBinding(mockVibrationManager, handl e); | |
45 }); | |
46 | |
47 return Promise.resolve({ | |
48 // Interface instance bound to main frame. | |
49 mockVibrationManager: mockVibrationManager, | |
50 // Constructor for mock VibrationManager class. | |
51 MockVibrationManager: MockVibrationManager, | |
52 // Loaded mojom interface. | |
53 VibrationManager: vibrationManager.VibrationManager, | |
54 }); | |
55 }); | |
56 } | |
57 | |
58 function vibration_test(func, name, properties) { | |
59 mojo_test(mojo => vibration_mocks(mojo).then(vibration => { | |
60 let result = Promise.resolve(func(vibration)); | |
61 let cleanUp = () => vibration.mockVibrationManager.reset(); | |
62 result.then(cleanUp, cleanUp); | |
63 return result; | |
64 }), name, properties); | |
65 } | |
OLD | NEW |