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

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: 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
« no previous file with comments | « third_party/WebKit/LayoutTests/vibration/mock-vibration.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(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 }
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/vibration/mock-vibration.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698