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

Side by Side Diff: third_party/WebKit/LayoutTests/vibration/vibration-iframe.html

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 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script>
4 <script src="../resources/mojo-helpers.js"></script>
5 <script src="resources/vibration-helpers.js"></script>
6 <script>
7
8 'use strict';
9
10 if (!window.testRunner)
11 debug('This test cannot be run without the TestRunner');
12
13 // TODO(leonhsl): Add more test cases http://crbug.com/701288
14
15 vibration_test(vibration => {
16 let mockForSubFrame = new vibration.MockVibrationManager;
17 let promise = new Promise(resolve => {
18 let iframe = document.createElement('iframe');
19 iframe.src = 'resources/vibrate-from-iframe.html';
20 iframe.onload = () => {
21 iframe.contentWindow.gin.define(
22 "Mojo Service Registry",
23 [ 'content/public/renderer/frame_interfaces' ],
24 (frameInterfaces) => {
25 frameInterfaces.addInterfaceOverrideForTesting(
26 vibration.VibrationManager.name,
27 handle => { mockForSubFrame.bindingSet.addBinding(
28 mockForSubFrame, handle); });
29 iframe.contentWindow.postMessage('Ready', '*');
30 });
31 };
32
33 document.body.appendChild(iframe);
34
35 window.onmessage = msg => {
36 if (msg.data === 'Vibrate') {
37 // Navigate the sub frame.
38 iframe.src = 'about:blank';
39 } else if (msg.data === 'Cancel') {
40 // Cancel is triggered by sub frame navigation on above.
41 resolve(msg.data);
42 }
43 };
44 });
45
46 return promise.then(msgData => {
47 assert_equals(msgData, 'Cancel');
48 assert_equals(mockForSubFrame.getDuration(), 1234);
49 assert_true(mockForSubFrame.isCancelled());
50 });
51 }, 'Iframe reload would cancel the vibration started by it before.');
timvolodine 2017/03/15 18:20:18 could this be formulated as an affirmation? e.g. '
leonhsl(Using Gerrit) 2017/03/16 06:32:42 Done. Seems 'git cl format' does not work for js/
timvolodine 2017/03/16 15:32:21 yes try 'git cl format --js'?
leonhsl(Using Gerrit) 2017/03/17 03:55:15 Done and Thanks!
52
53 vibration_test(vibration => {
54 let mockForSubFrame = new vibration.MockVibrationManager;
55 let promise = new Promise(resolve => {
56 let iframe = document.createElement('iframe');
57 iframe.src = 'resources/vibrate-from-iframe.html';
58 iframe.onload = () => {
59 iframe.contentWindow.gin.define(
60 "Mojo Service Registry",
61 [ 'content/public/renderer/frame_interfaces' ],
62 (frameInterfaces) => {
63 frameInterfaces.addInterfaceOverrideForTesting(
64 vibration.VibrationManager.name,
65 handle => { mockForSubFrame.bindingSet.addBinding(
66 mockForSubFrame, handle); });
67 iframe.contentWindow.postMessage('Ready', '*');
timvolodine 2017/03/15 18:20:18 if the alignment here correct? a bit hard to read
leonhsl(Using Gerrit) 2017/03/16 06:32:42 Done.
68 });
69 };
70
71 document.body.appendChild(iframe);
72
73 window.onmessage = msg => {
74 if (msg.data === 'Vibrate') {
75 // Destroy the sub frame.
76 document.body.removeChild(iframe);
77 } else if (msg.data === 'Cancel') {
78 // Cancel is triggered by sub frame destroy on above.
79 resolve(msg.data);
80 }
81 };
82 });
83
84 return promise.then(msgData => {
85 assert_equals(msgData, 'Cancel');
86 assert_equals(mockForSubFrame.getDuration(), 1234);
87 assert_true(mockForSubFrame.isCancelled());
88 });
89 }, 'Iframe destroy would cancel the vibration started by it before.');
timvolodine 2017/03/15 18:20:18 same here
leonhsl(Using Gerrit) 2017/03/16 06:32:42 Done.
90
91 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698