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

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: 'git cl format --js' for js/html 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(
5 'VibrationManager mocks',
6 [
7 'mojo/public/js/bindings',
8 'device/vibration/vibration_manager.mojom',
9 ],
10 (bindings, vibrationManager) => {
11 class MockVibrationManager {
12 constructor() {
13 this.bindingSet =
14 new bindings.BindingSet(vibrationManager.VibrationManager);
15
16 this.vibrate_milliseconds_ = -1;
17 this.cancelled_ = false;
18 }
19
20 vibrate(milliseconds) {
21 this.vibrate_milliseconds_ = milliseconds;
22 window.postMessage('Vibrate', '*');
23 return Promise.resolve();
24 }
25
26 cancel() {
27 this.cancelled_ = true;
28 window.postMessage('Cancel', '*');
29 }
30
31 getDuration() {
32 return this.vibrate_milliseconds_;
33 }
34
35 isCancelled() {
36 return this.cancelled_;
37 }
38
39 reset() {
40 this.vibrate_milliseconds_ = -1;
41 this.cancelled_ = false;
42 }
43 }
44
45 let mockVibrationManager = new MockVibrationManager;
46 mojo.frameInterfaces.addInterfaceOverrideForTesting(
47 vibrationManager.VibrationManager.name, handle => {
48 mockVibrationManager.bindingSet.addBinding(
49 mockVibrationManager, handle);
50 });
51
52 return Promise.resolve({
53 // Interface instance bound to main frame.
54 mockVibrationManager: mockVibrationManager,
55 // Constructor for mock VibrationManager class.
56 MockVibrationManager: MockVibrationManager,
57 // Loaded mojom interface.
58 VibrationManager: vibrationManager.VibrationManager,
59 });
60 });
61 }
62
63 function vibration_test(func, name, properties) {
64 mojo_test(
65 mojo => vibration_mocks(mojo).then(vibration => {
66 let result = Promise.resolve(func(vibration));
67 let cleanUp = () => vibration.mockVibrationManager.reset();
68 result.then(cleanUp, cleanUp);
69 return result;
70 }),
71 name, properties);
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698