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

Commit 1d05642

Browse files
authored
Fix timeout in payment-is-showing.https.html (#18157)
* popupShowPromise will never settle after popup navigates away. Remove promise_rejects * Remove unnecessary console.log
1 parent 0a6beaa commit 1d05642

File tree

2 files changed

+54
-19
lines changed

2 files changed

+54
-19
lines changed

payment-request/blank.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
<!DOCTYPE html> <meta charset="utf-8" />
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Blank Page</title>
6+
<script>
7+
window.onload = function(event) {
8+
// This is needed to ensure the onload event fires when this page is
9+
// opened as a popup.
10+
// See https://github.com/web-platform-tests/wpt/pull/18157
11+
};
12+
</script>
13+
</head>
14+
<body>
15+
</body>
16+
</html>

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

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
rel="help"
55
href="https://w3c.github.io/browser-payment-api/#dfn-payment-request-is-showing"
66
/>
7+
<meta name="timeout" content="long">
78
<script src="/resources/testharness.js"></script>
89
<script src="/resources/testharnessreport.js"></script>
910
<script src="/resources/testdriver-vendor.js"></script>
@@ -399,31 +400,50 @@
399400
}, "Navigating an iframe as a nested browsing context sets 'payment request is showing boolean' to false.");
400401

401402
promise_test(async t => {
402-
const [popupWindow, popupRequest, showPromise] = await test_driver.bless(
403-
'test navigating popup after show()',
404-
async () => {
405-
const popupWindow = await loadPopupInsideUserGesture();
406-
const popupRequest = new popupWindow.PaymentRequest(methods, details);
407-
return [popupWindow, popupRequest, popupRequest.show()];
408-
},
409-
);
403+
const [popupWindow, popupRequest, popupShowPromise] =
404+
await test_driver.bless(
405+
'trigger payment in a popup window',
406+
async () => {
407+
const popupWindow = await loadPopupInsideUserGesture();
408+
const popupRequest = new popupWindow.PaymentRequest(methods, details);
409+
return [popupWindow, popupRequest, popupRequest.show()];
410+
});
410411

411412
// We navigate away, causing the payment sheet to close
412413
// and the request is showing boolean to become false.
413414
popupWindow.location = 'blank.html?abc=123';
414415
await new Promise(resolve => (popupWindow.onload = resolve));
415-
await promise_rejects(
416-
t,
417-
'AbortError',
418-
showPromise,
419-
'Navigating away must cause the showPromise to reject with an AbortError',
420-
);
421-
popupWindow.close();
422416

423-
// Now we should be ok to spin up a new payment request.
417+
// Don't wait for |popupShowPromise| to reject because it may never do
418+
// (see https://github.com/w3c/payment-request/issues/872). Instead, try
419+
// to spin up a new payment request and make sure it succeeds.
424420
const request = new window.PaymentRequest(methods, details);
425-
request.show();
426-
await request.abort();
421+
const [showPromise] = await test_driver.bless(
422+
'trigger payment in main window',
423+
() => {
424+
return [request.show()];
425+
});
426+
427+
// If a payment sheet fails to show, it should reject immediately. If it
428+
// hasn't rejected in 1 second, then the test has passed.
429+
t.step_timeout(async () => {
430+
// We're done. Clean up.
431+
popupWindow.close();
432+
await request.abort();
433+
t.done();
434+
}, 1000);
435+
436+
// If the navigation in popup window failed to close the original payment
437+
// sheet there, |showPromise| should reject immediately and this indicates
438+
// a failure of this test.
439+
await showPromise.then(() => {
440+
assert_true(false,
441+
"Second payment sheet should be pending but is resolved.");
442+
})
443+
.catch(e => {
444+
assert_true(false,
445+
"Second payment sheet should be pending but is rejected.");
446+
});
427447
}, "Navigating a popup as a nested browsing context sets 'payment request is showing boolean' to false.");
428448
</script>
429449
</body>

0 commit comments

Comments
 (0)