summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/payment-request/payment-response/retry-method-manual.https.html
blob: a5aab49e387d326c68bcca32d2ad5fe59385f517 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<!doctype html>
<meta charset="utf8">
<link rel="help" href="https://w3c.github.io/payment-request/#dom-paymentresponse-retry">
<title>
  PaymentResponse.prototype.retry() method
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="helpers.js"></script>
<script>
test(() => {
  assert_true(
    "retry" in PaymentResponse.prototype,
    "retry must be in prototype"
  );
  assert_true(
    PaymentResponse.prototype.retry instanceof Function,
    "retry must be a function"
  );
}, "PaymentResponse.prototype must have a retry() function (smoke test).");

function checkCompletedCantRetry(button) {
  button.disabled = true;
  promise_test(async t => {
    const { response } = await getPaymentRequestResponse();
    // sets response.[[complete]] to true.
    await response.complete("success");
    return promise_rejects_dom(
      t,
      "InvalidStateError",
      response.retry(),
      "response.[[complete]] is true, so rejects with InvalidStateError."
    );
  }, button.textContent.trim());
}

function repeatedCallsToRetry(button) {
  button.disabled = true;
  promise_test(async t => {
    const { response } = await getPaymentRequestResponse();
    const retryPromise = response.retry();
    await promise_rejects_dom(
      t,
      "InvalidStateError",
      response.retry(),
      "Calling retry() again rejects with an InvalidStateError"
    );
    await retryPromise;
    await response.complete("success");
  }, button.textContent.trim());
}

function callCompleteWhileRetrying(button) {
  button.disabled = true;
  promise_test(async t => {
    const { response } = await getPaymentRequestResponse();
    const retryPromise = response.retry();
    const completePromise1 = response.complete("success");
    const completePromise2 = response.complete("fail");
    assert_not_equals(
      completePromise1,
      completePromise2,
      "complete() must return unique promises"
    );
    await promise_rejects_dom(
      t,
      "InvalidStateError",
      completePromise1,
      "Calling complete() while retrying rejects with an InvalidStateError"
    );
    await promise_rejects_dom(
      t,
      "InvalidStateError",
      completePromise2,
      "Calling complete() while retrying rejects with an InvalidStateError"
    );
    assert_not_equals(
      completePromise1,
      completePromise2,
      "complete() must return unique promises"
    );
    await retryPromise;
    await response.complete("success");
  }, button.textContent.trim());
}

function callingRequestAbortMustNotAbort(button) {
  button.disabled = true;
  promise_test(async t => {
    const { response, request } = await getPaymentRequestResponse();
    const retryPromise = response.retry();
    await promise_rejects_dom(
      t,
      "InvalidStateError",
      request.abort(),
      "Calling request.abort() while retrying rejects with an InvalidStateError"
    );
    await retryPromise;
    await response.complete("success");
  }, button.textContent.trim());
}

function canRetryMultipleTimes(button) {
  button.disabled = true;
  promise_test(async t => {
    const { response } = await getPaymentRequestResponse();
    assert_equals(
      await response.retry(),
      undefined,
      "Expected undefined as the resolve value"
    );
    assert_equals(
      await response.retry(),
      undefined,
      "Expected undefined as the resolve value"
    );
    await response.complete("success");
    await promise_rejects_dom(
      t,
      "InvalidStateError",
      response.retry(),
      "Calling retry() after complete() rejects with a InvalidStateError"
    );
  }, button.textContent.trim());
}

function userCanAbortARetry(button) {
  button.disabled = true;
  promise_test(async t => {
    const { response } = await getPaymentRequestResponse();
    await promise_rejects_dom(
      t,
      "AbortError",
      response.retry(),
      "The user aborting a retry rejects with a AbortError"
    );
    await promise_rejects_dom(
      t,
      "InvalidStateError",
      response.retry(),
      "After the user aborts, response [[complete]] is true so retry() must reject with InvalidStateError"
    );
    await promise_rejects_dom(
      t,
      "InvalidStateError",
      response.complete("success"),
      "After the user aborts, response [[complete]] is true, so complete() rejects with a InvalidStateError"
    );
  }, button.textContent.trim());
}

function userIsShownErrorsFields(button) {
  button.disabled = true;
  promise_test(async t => {
    const { response, request } = await getPaymentRequestResponse({ requestShipping: true });
    const retryPromise = response.retry({
      shippingAddress: { city: "Invalid city", addressLine: "Invalid address line" },
    });
    await retryPromise;
    await response.complete("success");
  }, button.textContent.trim());
}

function abortTheUpdate(button) {
  button.disabled = true;
  promise_test(async t => {
    const { response, request } = await getPaymentRequestResponse({
      requestShipping: true,
    });
    const shipOptionChangePromise = new Promise(resolve => {
      request.onshippingoptionchange = event => {
        // causes "abort the update" to run
        event.updateWith({ total: "error!" });
        resolve();
      };
    });
    const retryPromise = response.retry();
    await shipOptionChangePromise;
    await promise_rejects_js(
      t,
      TypeError,
      retryPromise,
      "retry() aborts with a TypeError, because totals' value is invalid"
    );
    await promise_rejects_dom(
      t,
      "InvalidStateError",
      response.complete("success"),
      "After the user aborts, response [[complete]] is true, so complete() rejects with a InvalidStateError"
    );
  }, button.textContent.trim());
}

function callingRetryReturnsUniquePromise(button){
  button.disabled = true;
  promise_test(async t => {
    const { response } = await getPaymentRequestResponse();
    const retryPromise = response.retry();
    const promises = new Set([
      retryPromise,
      response.retry(),
      response.retry(),
    ]);
    assert_equals(promises.size, 3, "Must have three unique objects");
    await retryPromise;
    await response.complete();
  }, button.textContent.trim());
};


</script>
<h2>
    Manual Tests for PaymentResponse.retry() - Please run in order!
</h2>
<p>
  Click on each button in sequence from top to bottom without refreshing the page.
  Each button will bring up the Payment Request UI window.
</p>
<p>
  When presented with the payment sheet, use any credit card select to "Pay" multiple times.
</p>
<ol>
  <li>
    <button onclick="checkCompletedCantRetry(this);">
      A completed payment request cannot be retried.
    </button>
  </li>
  <li>
    <button onclick="repeatedCallsToRetry(this);">
      Calling retry() more than once yield a rejected promise, but the
      retryPromise resolves independently.
    </button>
  </li>
  <li>
    <button onclick="callCompleteWhileRetrying(this);">
      Calling complete() while a retry() is in progress results in an InvalidStateError.
    </button>
  </li>
  <li>
    <button onclick="callingRequestAbortMustNotAbort(this);">
      Trying to abort() via PaymentRequest is not possible.
    </button>
  </li>
  <li>
    <button onclick="canRetryMultipleTimes(this);">
      It's possible to retry() multiple times and eventually complete().
      After complete(), however, retry() rejects with an InvalidStateError.
    </button>
  </li>
  <li>
    <p>
      When shown the payment sheet, hit pay once, then abort retrying the payment.
    </p>
    <button onclick="userCanAbortARetry(this);">
      The user aborting retrying a payment causes the retryPromise to reject with AbortError.
      Aborting a payment is causes it complete.
    </button>
  </li>
  <li>
    <p>
      When shown the payment sheet, hit pay once. Check payment sheet for error fields.
      Then hit escape or otherwise abort the payment.
    </p>
    <button onclick="userIsShownErrorsFields(this);">
      When retrying, the user is shown error fields to fix.
    </button>
  </li>
  <li>
    <p>
      When shown the payment sheet, hit pay once.
      Then, change the shipping option.
      Select to pay again.
    </p>
    <button onclick="abortTheUpdate(this);">
      When "abort the update" occurs because of an update error,
      the `retryPromise` is rejected and response.[[complete]] becomes true.
    </button>
  </li>
  <li>
    <p>
      When shown the payment sheet, hit pay once. Then retry once.
    </p>
    <button onclick="callingRetryReturnsUniquePromise(this);">
      Calling retry() multiple times is always a new object.
    </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">owners</a>.
</small>