-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test snapshotting of allowpaymentrequest attribute
Test for whatwg/html#2195
- Loading branch information
Showing
4 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
payment-request/allowpaymentrequest/echo-PaymentRequest.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!doctype html> | ||
<script> | ||
window.onmessage = (e) => { | ||
const paymentArgs = [[{supportedMethods: ['foo']}], {total: {label: 'label', amount: {currency: 'USD', value: '5.00'}}}]; | ||
|
||
if (e.data === 'What is the result of new PaymentRequest(...)?') { | ||
try { | ||
new PaymentRequest(...paymentArgs); | ||
e.source.postMessage({message: 'Success'}, '*'); | ||
} catch(ex) { | ||
e.source.postMessage({message: 'Got an exception', details: [ex instanceof DOMException, ex.code, ex.name]}, '*'); | ||
} | ||
} else { | ||
e.source.postMessage('Incorrect message', '*'); | ||
} | ||
} | ||
</script> | ||
<p>This page echos the result of new PaymentRequest(...).</p> |
38 changes: 38 additions & 0 deletions
38
payment-request/allowpaymentrequest/removing-allowpaymentrequest.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!doctype html> | ||
<title>PaymentRequest removing allowpaymentrequest after load and then navigating</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<div id="log"></div> | ||
<script> | ||
async_test((t) => { | ||
const iframe = document.createElement('iframe'); | ||
iframe.allowPaymentRequest = true; | ||
|
||
let i = 0; | ||
|
||
const path = location.pathname.substring(0, location.pathname.lastIndexOf('/') + 1); | ||
iframe.src = "https://{{domains[www1]}}:{{ports[https][0]}}" + path + "echo-PaymentRequest.html"; | ||
iframe.onload = t.step_func(() => { | ||
if (i === 0) { | ||
iframe.allowPaymentRequest = false; | ||
} | ||
iframe.contentWindow.postMessage('What is the result of new PaymentRequest(...)?', '*'); | ||
}); | ||
|
||
window.onmessage = t.step_func((e) => { | ||
i++; | ||
if (i === 1) { | ||
assert_equals(e.data.message, 'Success', 'before navigation'); | ||
|
||
// Navigate the iframe. This will fire a second 'load' event on the iframe. | ||
iframe.contentWindow.location.href = iframe.src + '?2'; | ||
} else { | ||
assert_equals(e.data.message, 'Got an exception', 'after navigation'); | ||
assert_array_equals(e.data.details, [true /* ex instanceof DOMException*/, 18 /* ex.code */, 'SecurityError' /* ex.name */], 'after navigation'); | ||
t.done(); | ||
} | ||
}); | ||
|
||
document.body.appendChild(iframe); | ||
}); | ||
</script> |
31 changes: 31 additions & 0 deletions
31
payment-request/allowpaymentrequest/setting-allowpaymentrequest-timing.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!doctype html> | ||
<title>PaymentRequest setting allowpaymentrequest after document creation, before response</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<div id="log"></div> | ||
<script> | ||
// Set allowpaymentrequest attribute in a timeout after <iframe> has been inserted to the document. | ||
// The iframe's response is delayed so it happens after the attribute is set. | ||
|
||
async_test((t) => { | ||
const iframe = document.createElement('iframe'); | ||
// no allowpaymentrequest attribute | ||
|
||
const path = location.pathname.substring(0, location.pathname.lastIndexOf('/') + 1); | ||
iframe.src = "https://{{domains[www1]}}:{{ports[https][0]}}" + path + "echo-PaymentRequest.html?pipe=trickle(d3)"; | ||
iframe.onload = t.step_func(() => { | ||
iframe.contentWindow.postMessage('What is the result of new PaymentRequest(...)?', '*'); | ||
}); | ||
|
||
window.onmessage = t.step_func_done((e) => { | ||
assert_equals(e.data.message, 'Got an exception'); | ||
assert_array_equals(e.data.details, [true /* ex instanceof DOMException*/, 18 /* ex.code */, 'SecurityError' /* ex.name */]); | ||
}); | ||
|
||
document.body.appendChild(iframe); | ||
|
||
setTimeout(() => { | ||
iframe.allowPaymentRequest = true; | ||
}, 10); | ||
}); | ||
</script> |
38 changes: 38 additions & 0 deletions
38
payment-request/allowpaymentrequest/setting-allowpaymentrequest.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!doctype html> | ||
<title>PaymentRequest setting allowpaymentrequest after load and then navigating</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<div id="log"></div> | ||
<script> | ||
async_test((t) => { | ||
const iframe = document.createElement('iframe'); | ||
// no allowpaymentrequest attribute | ||
|
||
let i = 0; | ||
|
||
const path = location.pathname.substring(0, location.pathname.lastIndexOf('/') + 1); | ||
iframe.src = "https://{{domains[www1]}}:{{ports[https][0]}}" + path + "echo-PaymentRequest.html"; | ||
iframe.onload = t.step_func(() => { | ||
if (i === 0) { | ||
iframe.allowPaymentRequest = true; | ||
} | ||
iframe.contentWindow.postMessage('What is the result of new PaymentRequest(...)?', '*'); | ||
}); | ||
|
||
window.onmessage = t.step_func((e) => { | ||
i++; | ||
if (i === 1) { | ||
assert_equals(e.data.message, 'Got an exception', 'before navigation'); | ||
assert_array_equals(e.data.details, [true /* ex instanceof DOMException*/, 18 /* ex.code */, 'SecurityError' /* ex.name */], 'before navigation'); | ||
|
||
// Navigate the iframe. This will fire a second 'load' event on the iframe. | ||
iframe.contentWindow.location.href = iframe.src + '?2'; | ||
} else { | ||
assert_equals(e.data.message, 'Success', 'after navigation'); | ||
t.done(); | ||
} | ||
}); | ||
|
||
document.body.appendChild(iframe); | ||
}); | ||
</script> |