mirror of
https://github.com/servo/servo
synced 2026-05-10 09:02:30 +02:00
79 lines
2.3 KiB
HTML
79 lines
2.3 KiB
HTML
<!DOCTYPE html>
|
|
<meta charset=utf-8>
|
|
<title>PaymentRequest show() rejects if doc is not fully active</title>
|
|
<link rel="help" href="https://w3c.github.io/payment-request/#show-method">
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="/resources/testdriver.js"></script>
|
|
<script src="/resources/testdriver-vendor.js"></script>
|
|
<body>
|
|
<script>
|
|
const applePay = Object.freeze({
|
|
supportedMethods: "https://apple.com/apple-pay",
|
|
data: {
|
|
version: 3,
|
|
merchantIdentifier: "merchant.com.example",
|
|
countryCode: "US",
|
|
merchantCapabilities: ["supports3DS"],
|
|
supportedNetworks: ["visa"],
|
|
}
|
|
});
|
|
const validMethod = Object.freeze({
|
|
supportedMethods: "basic-card",
|
|
});
|
|
const validMethods = Object.freeze([validMethod, applePay]);
|
|
const validAmount = Object.freeze({
|
|
currency: "USD",
|
|
value: "5.00",
|
|
});
|
|
const validTotal = Object.freeze({
|
|
label: "Total due",
|
|
amount: validAmount,
|
|
});
|
|
const validDetails = Object.freeze({
|
|
total: validTotal,
|
|
});
|
|
|
|
function getLoadedPaymentRequest(iframe, url) {
|
|
return new Promise(resolve => {
|
|
iframe.addEventListener(
|
|
"load",
|
|
() => {
|
|
const { PaymentRequest } = iframe.contentWindow;
|
|
const request = new PaymentRequest(validMethods, validDetails);
|
|
resolve(request);
|
|
},
|
|
{ once: true }
|
|
);
|
|
iframe.src = url;
|
|
});
|
|
}
|
|
|
|
promise_test(async t => {
|
|
const iframe = document.createElement("iframe");
|
|
iframe.allowPaymentRequest = true;
|
|
document.body.appendChild(iframe);
|
|
// Make a request in the iframe.
|
|
const request = await getLoadedPaymentRequest(
|
|
iframe,
|
|
"/payment-request/resources/page1.html"
|
|
);
|
|
const showPromise = await test_driver.bless("show payment request", () => {
|
|
return request.show();
|
|
});
|
|
// Navigate the iframe to a new location. Wait for the load event to fire.
|
|
await new Promise(resolve => {
|
|
iframe.addEventListener("load", resolve);
|
|
iframe.src = "/payment-request/resources/page2.html";
|
|
});
|
|
await promise_rejects(
|
|
t,
|
|
"AbortError",
|
|
showPromise,
|
|
"The iframe was navigated away, so showPromise must reject with AbortError"
|
|
);
|
|
// We are done, so clean up.
|
|
iframe.remove();
|
|
}, "If a payment request is showing, but its document is navigated away (so no longer fully active), the payment request aborts.");
|
|
</script>
|