summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/payment-request/payment-request-abort-method.https.html
blob: 32b87970b4df49d2eef4945e3869f4abfcaa537a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE html>
<meta charset="utf-8" />
<title>Test for PaymentRequest.abort() method</title>
<link rel="help" href="https://w3c.github.io/payment-request/#abort-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>
<script>
"use strict";
setup({
  // Ignore unhandled rejections resulting from .show()'s acceptPromise
  // not being explicitly handled.
  allow_uncaught_exception: true,
  explicit_timeout: true,
});
const basicCard = Object.freeze({ supportedMethods: "basic-card" });
const applePay = Object.freeze({
  supportedMethods: "https://apple.com/apple-pay",
  data: {
    version: 3,
    merchantIdentifier: "merchant.com.example",
    countryCode: "US",
    merchantCapabilities: ["supports3DS"],
    supportedNetworks: ["visa"],
  },
});
const defaultMethods = Object.freeze([basicCard, applePay]);
const defaultDetails = Object.freeze({
  total: {
    label: "Total",
    amount: {
      currency: "USD",
      value: "1.00",
    },
  },
});

promise_test(async t => {
  // request is in "created" state
  const request = new PaymentRequest(defaultMethods, defaultDetails);
  await promise_rejects_dom(t, "InvalidStateError", request.abort());
}, `Throws if the promise [[state]] is not "interactive"`);

promise_test(async t => {
  const request = new PaymentRequest(defaultMethods, defaultDetails);
  const promises = new Set([
    request.abort(),
    request.abort(),
    request.abort(),
  ]);
  assert_equals(promises.size, 3, "Must have three unique objects");
}, "Calling abort() multiple times is always a new object.");

promise_test(async t => {
  const request = new PaymentRequest(defaultMethods, defaultDetails);
  await test_driver.bless("show payment request");
  const acceptPromise = request.show();
  await request.abort();
  await promise_rejects_dom(t, "AbortError", acceptPromise);
  // As request is now "closed", trying to show it will fail
  await test_driver.bless("show payment request");
  await promise_rejects_dom(t, "InvalidStateError", request.show());
}, "The same request cannot be shown multiple times.");

promise_test(async t => {
  // request is in "created" state.
  const request = new PaymentRequest(defaultMethods, defaultDetails);
  await promise_rejects_dom(t, "InvalidStateError", request.abort());
  // Call it again, for good measure.
  await promise_rejects_dom(t, "InvalidStateError", request.abort());
  // The request's state is "created", so let's show it
  // which changes the state to "interactive.".
  await test_driver.bless("show payment request");
  const acceptPromise = request.show();
  // Let's set request the state to "closed" by calling .abort()
  await request.abort();
  // The request is now "closed", so...
  await promise_rejects_dom(t, "InvalidStateError", request.abort());
  await promise_rejects_dom(t, "AbortError", acceptPromise);
}, "Aborting a request before it is shown doesn't prevent it from being shown later.");
</script>
<small>
  If you find a buggy test, please
  <a href="https://github.com/web-platform-tests/wpt/issues">file a bug</a> and
  tag one of the
  <a
    href="https://github.com/web-platform-tests/wpt/blob/master/payment-request/META.yml"
    >suggested reviewers</a
  >.
</small>