Files
tubestation/testing/web-platform/tests/payment-handler/app-can-make-payment.js
Rouslan Solomakhin d67bc10a7e Bug 1811295 [wpt PR 38064] - [Web Platform Test] Just-in-time install for can-make-payment test, a=testonly
Automatic update from web-platform-tests
[Web Platform Test] Just-in-time install for can-make-payment test

Before this patch, the can-make-payment-event.https.html was installing
a payment handler using the PaymentInstruments API and was expecting the
response to "canmakepayment" event to determine the response to the
PaymentRequest.canMakePayment() method, as well as whether a payment
handler can be invoked.

This was suboptimal because the PaymentInstruments API is being removed
in favor for just-in-time (JIT) install and the "canmakepayment" event
determines only the response to the
PaymentRequest.hasEnrolledInstrument() method.

This patch changes can-make-payment-event.https.html to install payment
handlers just-in-time (JIT), to assert that canMakePayment() returns
true for a JIT-installable payment handler, including before the
installation, and to assert that PaymentRequest.show() will invoke the
payment handler regardless of the response to the "canmakepayment"
event.

After this patch, can-make-payment-event.https.html passes when running
locally in the full browser and does not use any APIs that are planned
to be removed. (The expectations file still shows failures because the
WPT automation uses content_shell, which does not have full support for
the Web Payment API.)

Bug: 1327265, 1406898
Change-Id: I27d44e4d61f741333dae2dd4a1a142dfdb6147a6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4178406
Reviewed-by: Nick Burris <nburris@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1094570}

--

wpt-commits: 6460d0e17c9016f24ba71df28897d0bd1a5b425f
wpt-pr: 38064
2023-02-01 13:58:53 +00:00

58 lines
1.5 KiB
JavaScript

let responseType = 'canMakePayment-true';
self.addEventListener('canmakepayment', event => {
if (event.methodData) {
const msg = 'Expected no method data.';
event.respondWith(Promise.reject(new Error(msg)));
return;
}
if (event.modifiers) {
const msg = 'Expected no modifiers';
event.respondWith(Promise.reject(new Error(msg)));
return;
}
if (event.topOrigin) {
const msg = `Unexpected topOrigin.`;
event.respondWith(Promise.reject(new Error(msg)));
return;
}
if (event.paymentRequestOrigin) {
const msg = `Unexpected iframe origin.`;
event.respondWith(Promise.reject(new Error(msg)));
return;
}
switch (responseType) {
case 'canMakePayment-true':
event.respondWith(true);
break;
case 'canMakePayment-false':
event.respondWith(false);
break;
case 'canMakePayment-promise-true':
event.respondWith(Promise.resolve(true));
break;
case 'canMakePayment-promise-false':
event.respondWith(Promise.resolve(false));
break;
case 'canMakePayment-custom-error':
event.respondWith(Promise.reject(new Error('Custom error')));
break;
default:
const msg = `Unrecognized payment method name "${methodName}".`;
event.respondWith(Promise.reject(new Error(msg)));
break;
}
});
self.addEventListener('paymentrequest', event => {
responseType = event.methodData[0].data.responseType;
event.respondWith({
methodName: event.methodData[0].supportedMethods,
details: {status: 'success'},
});
});