summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/payment-request/updateWith-method-pmi-handling-manual.https.html
blob: 1a52978ca3e312392c754c08267405723e5f8800 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<meta charset="utf-8">
<title>Test for validity of payment method identifiers when calling updateWith() method</title>
<link rel="help" href="https://www.w3.org/TR/payment-request/#updatewith()-method">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
"use strict";
setup({
  explicit_done: true,
  explicit_timeout: true,
  allow_uncaught_exception: true,
});
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: "https://:@wpt.fyi:443/payment-request",
});

const validMethods = Object.freeze([
  validMethod,
  applePay,
  { supportedMethods: "basic-card" },
]);

const validAmount = Object.freeze({
  currency: "USD",
  value: "1.0",
});

const validTotal = Object.freeze({
  label: "Default Total",
  amount: validAmount,
});

const validShippingOption = Object.freeze({
  id: "standard",
  label: "Shipping option",
  amount: validAmount,
  selected: true,
});

const validDetails = Object.freeze({
  total: validTotal,
  shippingOptions: [validShippingOption],
});

const validModifier = Object.freeze({
  supportedMethods: "basic-card",
  total: validTotal,
});

function manualTest(button, { invalidMethod }) {
  button.disabled = true;
  promise_test(async t => {
    const request = new PaymentRequest(validMethods, validDetails, {
      requestShipping: true,
    });
    const listener = ev => {
      const invalidModifier = Object.assign({}, validModifier, {
        supportedMethods: invalidMethod,
      });
      const invalidDetails = Object.assign({}, validDetails, {
        modifiers: [validModifier, invalidModifier],
      });
      ev.updateWith(invalidDetails);
    };
    // We test against a valid and an invalid modifier
    request.addEventListener("shippingaddresschange", listener, { once: true });
    const showPromise = request.show();
    await promise_rejects_js(t, RangeError, showPromise);
  }, button.textContent.trim());
}
</script>
<h2>updateWith() method: test validity of payment method identifiers.</h2>
<p>
  When shown a payment sheet, select a different address.
</p>
<ol>
  <li>
    <button onclick="manualTest(this, {invalidMethod: 'https://:password@example.com'});">
      Must throw if the URL has a password.
    </button>
  </li>
  <li>
    <button onclick="manualTest(this, {invalidMethod: 'https://username@example.com'});">
      Must throw if the URL has a username.
    </button>
  </li>
  <li>
    <button onclick="manualTest(this, {invalidMethod: 'https://username:password@example.com/pay'});">
      Must throw if the URL has a username and a password.
    </button>
  </li>
  <li>
    <button onclick="manualTest(this, {invalidMethod: 'http://username:password@example.com/pay'});">
      Must throw if it's http, and has a username and password.
    </button>
  </li>
  <li>
    <button onclick="manualTest(this, {invalidMethod: 'http://foo.com:100000000/pay'});">
      Must throw if the URL is invalid (port range).
    </button>
  </li>
  <li>
    <button onclick="manualTest(this, {invalidMethod: 'basic-💳'});">
      Must throw if the PMI contains characters that are out of range.
    </button>
  </li>
  <li>
    <button onclick="manualTest(this, {invalidMethod: 'not-https://wpt.fyi/payment-request'});">
      Must throw if not https.
    </button>
  </li>
  <li>
    <button onclick="manualTest(this, {invalidMethod: '¡basic-*-card!'});">
      Must throw if the standardized PMI contains characters outside the ascii range.
    </button>
  </li>
  <li>
    <button onclick="manualTest(this, {invalidMethod: 'Basic-Card'});">
      Must throw if standardized PMI has uppercase characters.
    </button>
  </li>
  <li>
    <button onclick="done();">Done!</button>
  </li>
</ol>
<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>