Index: third_party/WebKit/LayoutTests/vibration/vibration-iframe.html |
diff --git a/third_party/WebKit/LayoutTests/vibration/vibration-iframe.html b/third_party/WebKit/LayoutTests/vibration/vibration-iframe.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..41b646e82de9f27e07ba75f1428a99c9c6be09d7 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/vibration/vibration-iframe.html |
@@ -0,0 +1,91 @@ |
+<!DOCTYPE html> |
+<script src="../resources/testharness.js"></script> |
+<script src="../resources/testharnessreport.js"></script> |
+<script src="../resources/mojo-helpers.js"></script> |
+<script src="resources/vibration-helpers.js"></script> |
+<script> |
+ |
+'use strict'; |
+ |
+if (!window.testRunner) |
+ debug('This test cannot be run without the TestRunner'); |
+ |
+// TODO(leonhsl): Add more test cases http://crbug.com/701288 |
+ |
+vibration_test(vibration => { |
+ let mockForSubFrame = new vibration.MockVibrationManager; |
+ let promise = new Promise(resolve => { |
+ let iframe = document.createElement('iframe'); |
+ iframe.src = 'resources/vibrate-from-iframe.html'; |
+ iframe.onload = () => { |
+ iframe.contentWindow.gin.define( |
+ "Mojo Service Registry", |
+ [ 'content/public/renderer/frame_interfaces' ], |
+ (frameInterfaces) => { |
+ frameInterfaces.addInterfaceOverrideForTesting( |
+ vibration.VibrationManager.name, |
+ handle => { mockForSubFrame.bindingSet.addBinding( |
+ mockForSubFrame, handle); }); |
+ iframe.contentWindow.postMessage('Ready', '*'); |
+ }); |
+ }; |
+ |
+ document.body.appendChild(iframe); |
+ |
+ window.onmessage = msg => { |
+ if (msg.data === 'Vibrate') { |
+ // Navigate the sub frame. |
+ iframe.src = 'about:blank'; |
+ } else if (msg.data === 'Cancel') { |
+ // Cancel is triggered by sub frame navigation on above. |
+ resolve(msg.data); |
+ } |
+ }; |
+ }); |
+ |
+ return promise.then(msgData => { |
+ assert_equals(msgData, 'Cancel'); |
+ assert_equals(mockForSubFrame.getDuration(), 1234); |
+ assert_true(mockForSubFrame.isCancelled()); |
+ }); |
+}, '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!
|
+ |
+vibration_test(vibration => { |
+ let mockForSubFrame = new vibration.MockVibrationManager; |
+ let promise = new Promise(resolve => { |
+ let iframe = document.createElement('iframe'); |
+ iframe.src = 'resources/vibrate-from-iframe.html'; |
+ iframe.onload = () => { |
+ iframe.contentWindow.gin.define( |
+ "Mojo Service Registry", |
+ [ 'content/public/renderer/frame_interfaces' ], |
+ (frameInterfaces) => { |
+ frameInterfaces.addInterfaceOverrideForTesting( |
+ vibration.VibrationManager.name, |
+ handle => { mockForSubFrame.bindingSet.addBinding( |
+ mockForSubFrame, handle); }); |
+ 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.
|
+ }); |
+ }; |
+ |
+ document.body.appendChild(iframe); |
+ |
+ window.onmessage = msg => { |
+ if (msg.data === 'Vibrate') { |
+ // Destroy the sub frame. |
+ document.body.removeChild(iframe); |
+ } else if (msg.data === 'Cancel') { |
+ // Cancel is triggered by sub frame destroy on above. |
+ resolve(msg.data); |
+ } |
+ }; |
+ }); |
+ |
+ return promise.then(msgData => { |
+ assert_equals(msgData, 'Cancel'); |
+ assert_equals(mockForSubFrame.getDuration(), 1234); |
+ assert_true(mockForSubFrame.isCancelled()); |
+ }); |
+}, '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.
|
+ |
+</script> |