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

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

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

Powered by Google App Engine
This is Rietveld 408576698