diff --git a/testing/web-platform/meta/MANIFEST.json b/testing/web-platform/meta/MANIFEST.json index 79893b1aca4d..d377ccf14180 100644 --- a/testing/web-platform/meta/MANIFEST.json +++ b/testing/web-platform/meta/MANIFEST.json @@ -286809,6 +286809,26 @@ {} ] ], + "payment-handler/basic-card.js": [ + [ + {} + ] + ], + "payment-handler/basic-card.json": [ + [ + {} + ] + ], + "payment-handler/payment-app/payment.html": [ + [ + {} + ] + ], + "payment-handler/register-and-activate-service-worker.js": [ + [ + {} + ] + ], "payment-method-basic-card/OWNERS": [ [ {} @@ -348925,6 +348945,18 @@ {} ] ], + "payment-handler/payment-instruments.https.html": [ + [ + "/payment-handler/payment-instruments.https.html", + {} + ] + ], + "payment-handler/payment-request-event.https.html": [ + [ + "/payment-handler/payment-request-event.https.html", + {} + ] + ], "payment-method-basic-card/payment-request-canmakepayment-method.https.html": [ [ "/payment-method-basic-card/payment-request-canmakepayment-method.https.html", @@ -579278,10 +579310,34 @@ "c5e5d0fd086bbe946f99aa8836785c81a2bccb3d", "support" ], + "payment-handler/basic-card.js": [ + "40165fc47d8681622cde490a9a8ec3c8eaded43f", + "support" + ], + "payment-handler/basic-card.json": [ + "dbed6dd422b57b7c343b2171aeb9ad921eb3231c", + "support" + ], "payment-handler/interfaces.https.any.js": [ "a20a5909c9a94120049e45e543cc623b875ea7f5", "testharness" ], + "payment-handler/payment-app/payment.html": [ + "b2c68838b3d5df98f17ccfd1bf65c4de6579ae65", + "support" + ], + "payment-handler/payment-instruments.https.html": [ + "14a67dbd2670c661d61ac8dc61c950e572369279", + "testharness" + ], + "payment-handler/payment-request-event.https.html": [ + "f9556317297607b5e5f649343ae6f365a4df9552", + "testharness" + ], + "payment-handler/register-and-activate-service-worker.js": [ + "be0cc9201508bb936dc87307b12ee7545020778b", + "support" + ], "payment-method-basic-card/OWNERS": [ "ee0b02c59588d15b6efdb983c492ebbf50127e1c", "support" diff --git a/testing/web-platform/tests/payment-handler/basic-card.js b/testing/web-platform/tests/payment-handler/basic-card.js new file mode 100644 index 000000000000..86fcea711c5c --- /dev/null +++ b/testing/web-platform/tests/payment-handler/basic-card.js @@ -0,0 +1,117 @@ +self.addEventListener('paymentrequest', event => { + const expectedId = 'test-payment-request-identifier'; + if (event.paymentRequestId !== expectedId) { + const msg = `Expected payment request identifier "${expectedId}", but got "${ + event.paymentRequestId + }"`; + event.respondWith(Promise.reject(new Error(msg))); + return; + } + + if (event.methodData.length !== 1) { + const msg = `Expected one method data, but got ${ + event.methodData.length + } instead`; + event.respondWith(Promise.reject(new Error(msg))); + return; + } + + const methodData = event.methodData[0]; + const expectedMethodName = 'basic-card'; + if (methodData.supportedMethods !== expectedMethodName) { + const msg = `Expected payment method name "${expectedMethodName}", but got "${ + methodData.supportedMethods + }"`; + event.respondWith(Promise.reject(new Error(msg))); + return; + } + + if (methodData.data.supportedNetworks) { + const msg = + 'Expected no supported networks in payment method specific data'; + event.respondWith(Promise.reject(new Error(msg))); + return; + } + + const supportedTypes = methodData.data.supportedTypes; + if (!supportedTypes) { + const msg = 'Expected supported types in payment method specific data'; + event.respondWith(Promise.reject(new Error(msg))); + return; + } + + if (supportedTypes.length !== 1) { + const msg = `Expected one supported type, but got ${ + supportedTypes.length + } instead`; + event.respondWith(Promise.reject(new Error(msg))); + return; + } + + const supportedType = supportedTypes[0]; + const expectedSupportedType = 'prepaid'; + if (supportedType !== expectedSupportedType) { + const msg = `Expected supported type "${expectedSupportedType}", but got "${supportedType}"`; + event.respondWith(Promise.reject(new Error(msg))); + return; + } + + if (methodData.displayItems) { + const msg = 'Expected no display items'; + event.respondWith(Promise.reject(new Error(msg))); + return; + } + + const total = event.total; + if (!total) { + const msg = 'Expected total'; + event.respondWith(Promise.reject(new Error(msg))); + return; + } + + if (total.label) { + const msg = 'Expected no total label'; + event.respondWith(Promise.reject(new Error(msg))); + return; + } + + const expectedCurrency = 'USD'; + if (total.currency !== expectedCurrency) { + const msg = `Expected currency "${expectedCurrency}", but got "${ + total.currency + }"`; + event.respondWith(Promise.reject(new Error(msg))); + return; + } + + const expectedValue = '0.01'; + if (total.value !== expectedValue) { + const msg = `Expected value "${expectedValue}", but got "${total.value}"`; + event.respondWith(Promise.reject(new Error(msg))); + return; + } + + event.respondWith({ + methodName: 'basic-card', + details: { + billingAddress: { + addressLine: ['1875 Explorer St #1000'], + city: 'Reston', + country: 'US', + dependentLocality: '', + languageCode: '', + organization: 'Google', + phone: '+15555555555', + postalCode: '20190', + recipient: 'Jon Doe', + region: 'VA', + sortingCode: '', + }, + cardNumber: '4111111111111111', + cardSecurityCode: '123', + cardholderName: 'Jon Doe', + expiryMonth: '12', + expiryYear: '2028', + }, + }); +}); diff --git a/testing/web-platform/tests/payment-handler/basic-card.json b/testing/web-platform/tests/payment-handler/basic-card.json new file mode 100644 index 000000000000..002dd875849a --- /dev/null +++ b/testing/web-platform/tests/payment-handler/basic-card.json @@ -0,0 +1,10 @@ +{ + "name": "Test Basic Card Payment Handler", + "icons": [ + { + "src": "/images/rgrg-256x256.png", + "sizes": "256x256", + "type": "image/png" + } + ] +} diff --git a/testing/web-platform/tests/payment-handler/payment-app/payment.html b/testing/web-platform/tests/payment-handler/payment-app/payment.html new file mode 100644 index 000000000000..37d2452ed916 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/payment-app/payment.html @@ -0,0 +1,5 @@ + + +Test Payment App +

Account balance: $10.00

+ diff --git a/testing/web-platform/tests/payment-handler/payment-instruments.https.html b/testing/web-platform/tests/payment-handler/payment-instruments.https.html new file mode 100644 index 000000000000..abe25cee5cd7 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/payment-instruments.https.html @@ -0,0 +1,356 @@ + + +Tests for PaymentInstruments interface + + + + + + diff --git a/testing/web-platform/tests/payment-handler/payment-request-event.https.html b/testing/web-platform/tests/payment-handler/payment-request-event.https.html new file mode 100644 index 000000000000..952ee385229c --- /dev/null +++ b/testing/web-platform/tests/payment-handler/payment-request-event.https.html @@ -0,0 +1,105 @@ + + +Tests for PaymentRequestEvent + + + + + +

When the payment sheet is shown, please authorize the mock payment.

+ diff --git a/testing/web-platform/tests/payment-handler/register-and-activate-service-worker.js b/testing/web-platform/tests/payment-handler/register-and-activate-service-worker.js new file mode 100644 index 000000000000..fb54c5c06488 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/register-and-activate-service-worker.js @@ -0,0 +1,28 @@ +async function registerAndActiveServiceWorker(script, scope, callback) { + const registration = await navigator.serviceWorker.register(script, {scope}); + const serviceWorker = + registration.installing || registration.waiting || registration.active; + if (serviceWorker) { + waitForServiceWorkerActivation(scope, callback); + return; + } + + registration.addEventListener('updatefound', event => { + waitForServiceWorkerActivation(scope, callback); + }); +} + +async function waitForServiceWorkerActivation(scope, callback) { + const registration = await navigator.serviceWorker.getRegistration(scope); + if (registration.active) { + callback(registration); + return; + } + + const serviceWorker = registration.installing || registration.waiting; + serviceWorker.addEventListener('statechange', event => { + if (event.target.state == 'activated') { + callback(registration); + } + }); +}