Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit 5c3c67a

Browse files
Danyao Wangmarcoscaceres
authored andcommitted
Catch all promise rejections so the test harness doesn't fail due to uncaught rejection
1 parent 2a71f56 commit 5c3c67a

File tree

1 file changed

+60
-7
lines changed

1 file changed

+60
-7
lines changed

payment-request/payment-is-showing.https.html

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,10 @@
153153
// We first show a payment request via the the top level browsing context,
154154
// windowRequest.show() sets "is showing boolean" to true. Then we try to
155155
// show a payment request in the iframe, which should reject.
156-
const [iframeShowPromise] = await test_driver.bless(
156+
const [windowShowPromise, iframeShowPromise] = await test_driver.bless(
157157
"testing iframe show() blocked by payment sheet in top window",
158158
() => {
159-
windowRequest.show();
160-
return [iframeRequest.show()];
159+
return [windowRequest.show(), iframeRequest.show()];
161160
},
162161
);
163162

@@ -170,6 +169,12 @@
170169

171170
// Cleanup
172171
await windowRequest.abort();
172+
await promise_rejects(
173+
t,
174+
"AbortError",
175+
windowShowPromise,
176+
"The window payment request should be aborted by test.",
177+
);
173178
iframe.remove();
174179
}, "An iframe cannot show a payment request if the top-level window is already showing one.");
175180

@@ -200,15 +205,22 @@
200205
];
201206
},
202207
);
203-
await popupRequest.abort();
204-
popupWindow.close();
205208

206209
await promise_rejects(
207210
t,
208211
"AbortError",
209212
windowShowPromise,
210213
"Expected window's showPromise to reject, request is already showing",
211214
);
215+
216+
await popupRequest.abort();
217+
await promise_rejects(
218+
t,
219+
"AbortError",
220+
popupShowPromise,
221+
"Expected popupShowPromise to be aborted by test.",
222+
);
223+
popupWindow.close();
212224
}, "Using a popup window prevents the top-browsing context from showing a payment request");
213225

214226
promise_test(async t => {
@@ -263,6 +275,12 @@
263275
);
264276

265277
await windowRequest.abort();
278+
await promise_rejects(
279+
t,
280+
"AbortError",
281+
windowShowPromise,
282+
"Expect window promise to be aborted by test."
283+
);
266284
popupWindow.close();
267285
iframe.remove();
268286
}, "Given multiple nested browsing contexts, and window calls show() first, other nested browsing contexts can't show a request.");
@@ -313,6 +331,12 @@
313331
);
314332

315333
await popupRequest.abort();
334+
await promise_rejects(
335+
t,
336+
"AbortError",
337+
popupShowPromise,
338+
"Expected popupShowPromise to be aborted by test.",
339+
);
316340
popupWindow.close();
317341
iframe.remove();
318342
}, "Given multiple nested browsing contexts, and popup calls show() first, other nested browsing contexts can't show a request.");
@@ -368,6 +392,12 @@
368392
);
369393

370394
await iframeRequest.abort();
395+
await promise_rejects(
396+
t,
397+
"AbortError",
398+
iframeShowPromise,
399+
"Expected iframeShowPromise to be aborted by test."
400+
);
371401
popupWindow.close();
372402
iframe.remove();
373403
}, "Given multiple nested browsing contexts, and an iframe calls show() first, other nested browsing contexts can't show a request.");
@@ -395,8 +425,31 @@
395425

396426
// Now we should be ok to spin up a new payment request
397427
const request = new window.PaymentRequest(methods, details);
398-
const showPromise = request.show();
399-
await request.abort();
428+
const [showPromise] = await test_driver.bless(
429+
"start a new payment request",
430+
() => {
431+
return [request.show()];
432+
});
433+
434+
// If a payment sheet fails to show, it should reject immediately. If it
435+
// hasn't rejected in 1 second, then the test has passed.
436+
t.step_timeout(async () => {
437+
// We're done. Clean up.
438+
await request.abort();
439+
t.done();
440+
});
441+
442+
// If the navigation in iframe failed to close the original payment sheet
443+
// there, |showPromise| should reject immediately and this indicates a
444+
// failure of this test.
445+
await showPromise.then(() => {
446+
assert_true(false,
447+
"Second payment sheet should be pending but is resolved.");
448+
})
449+
.catch(e => {
450+
assert_true(false,
451+
"Second payment sheet should be pending but is rejected." + e.message);
452+
});
400453
}, "Navigating an iframe as a nested browsing context sets 'payment request is showing boolean' to false.");
401454

402455
promise_test(async t => {

0 commit comments

Comments
 (0)