Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: third_party/WebKit/LayoutTests/vibration/resources/vibration-helpers.js

Issue 2731953003: [DeviceService] Replace vibration_browsertest.cc with layout tests. (Closed)
Patch Set: Add TODO Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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('Vibrate', '*');
19 return Promise.resolve();
20 }
21
22 cancel() {
23 this.cancelled_ = true;
24 window.postMessage('Cancel', '*');
25 }
26
27 getDuration() {
28 return this.vibrate_milliseconds_;
29 }
30
31 isCancelled() {
32 return this.cancelled_;
33 }
34
35 reset() {
36 this.vibrate_milliseconds_ = -1;
37 this.cancelled_ = false;
38 }
39 }
40
41 let mockVibrationManager = new MockVibrationManager;
42 mojo.frameInterfaces.addInterfaceOverrideForTesting(
43 vibrationManager.VibrationManager.name,
44 handle => {
45 mockVibrationManager.bindingSet.addBinding(mockVibrationManager, handl e);
46 });
47
48 return Promise.resolve({
49 // Interface instance bound to main frame.
50 mockVibrationManager: mockVibrationManager,
51 // Constructor for mock VibrationManager class.
52 MockVibrationManager: MockVibrationManager,
53 // Loaded mojom interface.
54 VibrationManager: vibrationManager.VibrationManager,
55 });
56 });
57 }
58
59 function vibration_test(func, name, properties) {
60 mojo_test(mojo => vibration_mocks(mojo).then(vibration => {
61 let result = Promise.resolve(func(vibration));
62 let cleanUp = () => vibration.mockVibrationManager.reset();
63 result.then(cleanUp, cleanUp);
64 return result;
65 }), name, properties);
66 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698