[Payment Request] Update web platform tests
[WebKit-https.git] / LayoutTests / imported / w3c / web-platform-tests / payment-request / payment-request-canmakepayment-method-protection.https.html
1 <!DOCTYPE html>
2 <meta charset="utf-8">
3 <title>Tests for PaymentRequest.canMakePayment() method</title>
4 <link rel="help" href="https://w3c.github.io/browser-payment-api/#show-method">
5 <script src="/resources/testharness.js"></script>
6 <script src="/resources/testharnessreport.js"></script>
7 <script src='/resources/testdriver-vendor.js'></script>
8 <script src="/resources/testdriver.js"></script>
9 <script>
10 const basicCard = Object.freeze({ supportedMethods: "basic-card" });
11 const applePay = Object.freeze({ supportedMethods: "https://apple.com/apple-pay" });
12 const defaultMethods = Object.freeze([basicCard, applePay]);
13 const defaultDetails = Object.freeze({
14   total: {
15     label: "Total",
16     amount: {
17       currency: "USD",
18       value: "1.00",
19     },
20   },
21 });
22
23 promise_test(async t => {
24   // This test might never actually hit its assertion, but that's allowed.
25   const request = new PaymentRequest(defaultMethods, defaultDetails);
26   for (let i = 0; i < 1000; i++) {
27     try {
28       await request.canMakePayment();
29     } catch (err) {
30       assert_equals(
31         err.name,
32         "NotAllowedError",
33         "if it throws, then it must be a NotAllowedError."
34       );
35       break;
36     }
37   }
38   for (let i = 0; i < 1000; i++) {
39     try {
40       await new PaymentRequest(defaultMethods, defaultDetails).canMakePayment();
41     } catch (err) {
42       assert_equals(
43         err.name,
44         "NotAllowedError",
45         "if it throws, then it must be a NotAllowedError."
46       );
47       break;
48     }
49   }
50 }, `Optionally, at the user agent's discretion, return a promise rejected with a "NotAllowedError" DOMException.`);
51 </script>
52
53 <small>
54   If you find a buggy test, please <a href="https://github.com/web-platform-tests/wpt/issues">file a bug</a>
55   and tag one of the <a href="https://github.com/web-platform-tests/wpt/blob/master/payment-request/META.yml">suggested reviewers</a>.
56 </small>