Skip to content

Commit 9c29295

Browse files
authored
Test that PaymentRequest throws when its document is not active
See whatwg/html#2160 w3c/payment-request#361
1 parent 6653d7a commit 9c29295

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!doctype html>
2+
<title>PaymentRequest &lt;iframe allowpaymentrequest> in non-active document (cross-origin)</title>
3+
<script src=/resources/testharness.js></script>
4+
<script src=/resources/testharnessreport.js></script>
5+
<script src=/common/utils.js></script>
6+
<iframe id="iframe" allowpaymentrequest></iframe>
7+
<script>
8+
async_test((t) => {
9+
const iframe = document.getElementById('iframe');
10+
const paymentArgs = [[{supportedMethods: ['foo']}], {total: {label: 'label', amount: {currency: 'USD', value: '5.00'}}}];
11+
12+
onload = () => {
13+
const win = window[0];
14+
const grabbedPaymentRequest = win.PaymentRequest;
15+
win.location.href = make_absolute_url({
16+
hostname: '{{domains[www1]}}',
17+
path: '/common/blank.html'
18+
});
19+
iframe.onload = t.step_func_done(() => {
20+
assert_throws({name: 'SecurityError'}, () => {
21+
new grabbedPaymentRequest(...paymentArgs);
22+
});
23+
});
24+
}
25+
});
26+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!doctype html>
2+
<title>PaymentRequest &lt;iframe allowpaymentrequest> in non-active document (same-origin)</title>
3+
<script src=/resources/testharness.js></script>
4+
<script src=/resources/testharnessreport.js></script>
5+
<iframe id="iframe" allowpaymentrequest></iframe>
6+
<script>
7+
async_test((t) => {
8+
const iframe = document.getElementById('iframe');
9+
const paymentArgs = [[{supportedMethods: ['foo']}], {total: {label: 'label', amount: {currency: 'USD', value: '5.00'}}}];
10+
11+
onload = () => {
12+
const win = window[0];
13+
const grabbedPaymentRequest = win.PaymentRequest;
14+
win.location.href = '/common/blank.html';
15+
iframe.onload = t.step_func_done(() => {
16+
assert_throws({name: 'SecurityError'}, () => {
17+
new grabbedPaymentRequest(...paymentArgs);
18+
});
19+
});
20+
}
21+
});
22+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<title>PaymentRequest &lt;iframe allowpaymentrequest> basic</title>
3+
<script src=/resources/testharness.js></script>
4+
<script src=/resources/testharnessreport.js></script>
5+
<iframe id="iframe" allowpaymentrequest></iframe>
6+
<script>
7+
async_test((t) => {
8+
const paymentArgs = [[{supportedMethods: ['foo']}], {total: {label: 'label', amount: {currency: 'USD', value: '5.00'}}}];
9+
10+
onload = t.step_func_done(() => {
11+
new window[0].PaymentRequest(...paymentArgs);
12+
});
13+
});
14+
</script>

0 commit comments

Comments
 (0)