blob: 4cd6be75819da099a572b5b63b3541b4f8deae54 [file] [log] [blame]
<!-- webkit-test-runner [ enableBackForwardCache=true ] -->
<!DOCTYPE html>
<html>
<body>
<script src='/js-test-resources/js-test.js'></script>
<script src='/js-test-resources/ui-helper.js'></script>
<script src='/resources/payment-request.js'></script>
<script>
description('Tests that a page with a PaymentResponse in the Completed state goes into the back/forward cache.');
window.jsTestIsAsync = true;
window.addEventListener('pageshow', async function(event) {
debug('pageshow - ' + (event.persisted ? '' : 'not ') + 'from cache');
if (!event.persisted)
return;
testPassed('Page did enter and was restored from the back/forward cache');
debug('Testing that the promise returned by retry() was rejected with "AbortError".');
await shouldRejectWithErrorName('retryPromise', 'AbortError');
debug('Testing that PaymentResponse is now in the Closed state.');
await shouldRejectWithErrorName('response.complete()', 'AbortError');
await shouldRejectWithErrorName('response.retry()', 'AbortError');
finishJSTest();
}, false);
window.addEventListener('pagehide', function(event) {
debug('pagehide - ' + (event.persisted ? '' : 'not ') + 'entering cache');
if (event.persisted)
return;
testFailed('Page failed to enter the back/forward cache.');
finishJSTest();
}, false);
window.addEventListener('load', function() {
UIHelper.withUserGesture(async function() {
debug('Creating a PaymentResponse in the Created state with a retry promise.');
const request = new PaymentRequest([validPaymentMethod()], validPaymentDetails());
const responsePromise = request.show();
internals.mockPaymentCoordinator.acceptPayment();
response = await responsePromise;
retryPromise = response.retry();
setTimeout(function() {
window.location.href = '/navigation/resources/page-cache-helper.html';
}, 0);
});
}, false);
</script>
</body>
</html>