Bug 1527222 [wpt PR 15332] - [Payment Request][WPT] Fix inactive page tests., a=testonly
[gecko.git] / testing / web-platform / tests / payment-request / rejects_if_not_active.https.html
blob3c7e85ba970f8c6f2d608f02dd2f60f911124da2
1 <!DOCTYPE html>
2 <meta charset=utf-8>
3 <title>PaymentRequest show() rejects if doc is not fully active</title>
4 <link rel="help" href="https://w3c.github.io/payment-request/#show-method">
5 <script src="/resources/testharness.js"></script>
6 <script src="/resources/testharnessreport.js"></script>
7 <script src="/resources/testdriver.js"></script>
8 <script src="/resources/testdriver-vendor.js"></script>
9 <body>
10 <script>
11 const applePay = Object.freeze({
12 supportedMethods: "https://apple.com/apple-pay",
13 data: {
14 version: 3,
15 merchantIdentifier: "merchant.com.example",
16 countryCode: "US",
17 merchantCapabilities: ["supports3DS"],
18 supportedNetworks: ["visa"],
20 });
21 const validMethod = Object.freeze({
22 supportedMethods: "basic-card",
23 });
24 const validMethods = Object.freeze([validMethod, applePay]);
25 const validAmount = Object.freeze({
26 currency: "USD",
27 value: "5.00",
28 });
29 const validTotal = Object.freeze({
30 label: "Total due",
31 amount: validAmount,
32 });
33 const validDetails = Object.freeze({
34 total: validTotal,
35 });
37 function getLoadedPaymentRequest(iframe, url) {
38 return new Promise(resolve => {
39 iframe.addEventListener(
40 "load",
41 () => {
42 const { PaymentRequest } = iframe.contentWindow;
43 const request = new PaymentRequest(validMethods, validDetails);
44 resolve(request);
46 { once: true }
48 iframe.src = url;
49 });
52 promise_test(async t => {
53 const iframe = document.createElement("iframe");
54 iframe.allowPaymentRequest = true;
55 document.body.appendChild(iframe);
56 // Make a request in the iframe.
57 const request = await getLoadedPaymentRequest(
58 iframe,
59 "/payment-request/resources/page1.html"
61 const showPromise = await test_driver.bless("show payment request", () => {
62 return request.show();
63 });
64 // Navigate the iframe to a new location. Wait for the load event to fire.
65 await new Promise(resolve => {
66 iframe.addEventListener("load", resolve);
67 iframe.src = "/payment-request/resources/page2.html";
68 });
69 await promise_rejects(
71 "AbortError",
72 showPromise,
73 "The iframe was navigated away, so showPromise must reject with AbortError"
75 // We are done, so clean up.
76 iframe.remove();
77 }, "If a payment request is showing, but its document is navigated away (so no longer fully active), the payment request aborts.");
78 </script>