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 payment feature when disabled may not be called by | 6 // This test ensures that payment feature when disabled may not be called by |
7 // any iframe even when allowpaymentrequest is set. | 7 // any iframe even when allowpaymentrequest is set. |
8 | 8 |
9 Header("Feature-Policy: {\"payment\": []}"); | 9 Header("Feature-Policy: {\"payment\": []}"); |
10 ?> | 10 ?> |
11 | 11 |
12 <!DOCTYPE html> | 12 <!DOCTYPE html> |
13 <script src="../../resources/testharness.js"></script> | 13 <script src="../../resources/testharness.js"></script> |
14 <script src="../../resources/testharnessreport.js"></script> | 14 <script src="../../resources/testharnessreport.js"></script> |
| 15 <iframe></iframe> |
| 16 <iframe allowpaymentrequest></iframe> |
15 <script> | 17 <script> |
16 if (window.testRunner) { | 18 var srcs = [ |
17 testRunner.dumpAsText(); | 19 "resources/feature-policy-payment.html", |
18 testRunner.dumpChildFramesAsText(); | 20 "http://localhost:8000/feature-policy/resources/feature-policy-payment.html" |
| 21 ]; |
| 22 |
| 23 function loadFrame(iframe, src) { |
| 24 var allowpaymentrequest = iframe.hasAttribute('allowpaymentrequest'); |
| 25 promise_test(function() { |
| 26 iframe.src = src; |
| 27 return new Promise(function(resolve, reject) { |
| 28 window.addEventListener('message', function(e) { |
| 29 resolve(e.data); |
| 30 }, { once: true }); |
| 31 }).then(function(data) { |
| 32 assert_false(data.enabled, 'Paymentrequest():'); |
| 33 assert_equals(data.name, 'SecurityError', 'Exception Name:'); |
| 34 assert_equals(data.message, "Failed to construct 'PaymentRequest': " + |
| 35 "Must be in a top-level browsing context or an iframe needs to " + |
| 36 "specify 'allowpaymentrequest' explicitly", 'Error Message:'); |
| 37 }); |
| 38 }, 'Paymentrequest disabled on URL: ' + src + ' with allowpaymentrequest = ' + |
| 39 allowpaymentrequest); |
| 40 } |
| 41 |
| 42 window.onload = function() { |
| 43 var iframes = document.getElementsByTagName('iframe'); |
| 44 for (var iframe of iframes) { |
| 45 for (var src of srcs) { |
| 46 loadFrame(iframe, src); |
| 47 } |
19 } | 48 } |
| 49 } |
20 </script> | 50 </script> |
21 <iframe id="f1" src="resources/feature-policy-payment-disabled.html"></iframe> | |
22 <iframe id="f2" src="http://localhost:8000/feature-policy/resources/feature-poli
cy-payment-disabled.html"></iframe> | |
23 <iframe id="f3" src="resources/feature-policy-payment-disabled.html" allowpaymen
trequest></iframe> | |
24 <iframe id="f4" src="http://localhost:8000/feature-policy/resources/feature-poli
cy-payment-disabled.html" allowpaymentrequest></iframe> | |
OLD | NEW |