| OLD | NEW |
| 1 <?php | 1 <?php |
| 2 // Copyright 2016 The Chromium Authors. All rights reserved. | 2 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
| 4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
| 5 | 5 |
| 6 // This test ensures that navigator.vibrate when enabled for self only works on | 6 // This test ensures that navigator.vibrate when enabled for self only works on |
| 7 // the same origin. | 7 // the same origin. |
| 8 | 8 |
| 9 Header("Feature-Policy: {\"vibrate\": [\"self\"]}"); | 9 Header("Feature-Policy: {\"vibrate\": [\"self\"]}"); |
| 10 ?> | 10 ?> |
| 11 | 11 |
| 12 <!DOCTYPE html> | 12 <!DOCTYPE html> |
| 13 <html> | |
| 14 <head> | |
| 15 <script src="../../resources/testharness.js"></script> | 13 <script src="../../resources/testharness.js"></script> |
| 16 <script src="../../resources/testharnessreport.js"></script> | 14 <script src="../../resources/testharnessreport.js"></script> |
| 15 <iframe></iframe> |
| 17 <script> | 16 <script> |
| 18 if (window.testRunner) { | 17 var srcs = [ |
| 19 testRunner.dumpAsText(); | 18 "resources/feature-policy-vibrate.html", |
| 20 testRunner.dumpChildFramesAsText(); | 19 "http://localhost:8000/feature-policy-experimental-features/resources/feature-
policy-vibrate.html"]; |
| 20 |
| 21 function sendClick() { |
| 22 // The iframe uses eventSender to emulate a user navigatation, which requires |
| 23 // absolute coordinates. |
| 24 this.contentWindow.postMessage({x: this.offsetLeft, y: this.offsetTop}, "*"); |
| 21 } | 25 } |
| 22 | 26 |
| 23 function loaded() { | 27 window.onload = function () { |
| 24 var iframes = document.getElementsByTagName('iframe'); | 28 var iframe = document.querySelector('iframe'); |
| 25 for (var i = 0; i < iframes.length; ++i) { | 29 iframe.addEventListener('load', sendClick); |
| 26 var iframe = iframes[i]; | 30 function loadFrame(src) { |
| 27 // The iframe uses eventSender to emulate a user navigatation, which require
s absolute coordinates. | 31 promise_test(function() { |
| 28 iframe.contentWindow.postMessage({x: iframe.offsetLeft, y: iframe.offsetTop}
, "*"); | 32 iframe.src = src; |
| 33 return new Promise(function(resolve, reject) { |
| 34 window.addEventListener('message', function(e) { |
| 35 if (e.data.type === 'result') { |
| 36 resolve(e.data); |
| 37 } |
| 38 }); |
| 39 }).then(function(data) { |
| 40 // vibrate is only enabled within the same origin. |
| 41 if (src === srcs[0]) { |
| 42 assert_true(data.enabled, 'navigator.vibrate():'); |
| 43 } else { |
| 44 assert_false(data.enabled, 'navigator.vibrate():'); |
| 45 } |
| 46 }); |
| 47 }, 'Navigator.vibrate enabled for self on URL: ' + src); |
| 48 } |
| 49 for (var src of srcs) { |
| 50 loadFrame(src); |
| 29 } | 51 } |
| 30 } | 52 } |
| 31 </script> | 53 </script> |
| 32 </head> | |
| 33 <body onload="loaded();"> | |
| 34 <iframe id="f1" src="resources/feature-policy-vibrate-enabled.html"></iframe> | |
| 35 <iframe id="f2" src="http://localhost:8000/feature-policy-experimental-features/
resources/feature-policy-vibrate-disabled.html"></iframe> | |
| 36 </body> | |
| 37 </html> | |
| OLD | NEW |