From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../web-platform/tests/payment-handler/META.yml | 4 + .../tests/payment-handler/app-can-make-payment.js | 58 ++++ .../payment-handler/app-change-payment-method.js | 30 ++ .../payment-handler/app-change-shipping-address.js | 44 +++ .../payment-handler/app-change-shipping-option.js | 44 +++ .../tests/payment-handler/app-simple.js | 74 ++++ .../app-supports-shipping-contact-delegation.js | 44 +++ .../can-make-payment-event-constructor.https.html | 14 + ...ment-event-constructor.https.serviceworker.html | 13 + ...ayment-event-constructor.https.serviceworker.js | 47 +++ ...-make-payment-event-constructor.https.worker.js | 7 + .../can-make-payment-event.https.html | 264 ++++++++++++++ .../change-payment-method-manual.https.html | 170 +++++++++ .../change-shipping-address-manual.https.html | 161 +++++++++ .../change-shipping-option-manual.https.html | 160 +++++++++ .../tests/payment-handler/idlharness.https.any.js | 47 +++ .../tests/payment-handler/manifest.json | 10 + .../tests/payment-handler/payment-app/payment.html | 5 + .../payment-handler/payment-instruments.https.html | 379 +++++++++++++++++++++ .../payment-request-event-constructor.https.html | 14 + ...uest-event-constructor.https.serviceworker.html | 13 + ...equest-event-constructor.https.serviceworker.js | 45 +++ ...yment-request-event-constructor.https.worker.js | 7 + .../payment-request-event-manual.https.html | 88 +++++ .../register-and-activate-service-worker.js | 28 ++ .../same-object-attributes.https.html | 19 ++ ...s-shipping-contact-delegation-manual.https.html | 88 +++++ .../payment-handler/untrusted-event.https.html | 56 +++ .../tests/payment-handler/untrusted-event.js | 59 ++++ 29 files changed, 1992 insertions(+) create mode 100644 testing/web-platform/tests/payment-handler/META.yml create mode 100644 testing/web-platform/tests/payment-handler/app-can-make-payment.js create mode 100644 testing/web-platform/tests/payment-handler/app-change-payment-method.js create mode 100644 testing/web-platform/tests/payment-handler/app-change-shipping-address.js create mode 100644 testing/web-platform/tests/payment-handler/app-change-shipping-option.js create mode 100644 testing/web-platform/tests/payment-handler/app-simple.js create mode 100644 testing/web-platform/tests/payment-handler/app-supports-shipping-contact-delegation.js create mode 100644 testing/web-platform/tests/payment-handler/can-make-payment-event-constructor.https.html create mode 100644 testing/web-platform/tests/payment-handler/can-make-payment-event-constructor.https.serviceworker.html create mode 100644 testing/web-platform/tests/payment-handler/can-make-payment-event-constructor.https.serviceworker.js create mode 100644 testing/web-platform/tests/payment-handler/can-make-payment-event-constructor.https.worker.js create mode 100644 testing/web-platform/tests/payment-handler/can-make-payment-event.https.html create mode 100644 testing/web-platform/tests/payment-handler/change-payment-method-manual.https.html create mode 100644 testing/web-platform/tests/payment-handler/change-shipping-address-manual.https.html create mode 100644 testing/web-platform/tests/payment-handler/change-shipping-option-manual.https.html create mode 100644 testing/web-platform/tests/payment-handler/idlharness.https.any.js create mode 100644 testing/web-platform/tests/payment-handler/manifest.json create mode 100644 testing/web-platform/tests/payment-handler/payment-app/payment.html create mode 100644 testing/web-platform/tests/payment-handler/payment-instruments.https.html create mode 100644 testing/web-platform/tests/payment-handler/payment-request-event-constructor.https.html create mode 100644 testing/web-platform/tests/payment-handler/payment-request-event-constructor.https.serviceworker.html create mode 100644 testing/web-platform/tests/payment-handler/payment-request-event-constructor.https.serviceworker.js create mode 100644 testing/web-platform/tests/payment-handler/payment-request-event-constructor.https.worker.js create mode 100644 testing/web-platform/tests/payment-handler/payment-request-event-manual.https.html create mode 100644 testing/web-platform/tests/payment-handler/register-and-activate-service-worker.js create mode 100644 testing/web-platform/tests/payment-handler/same-object-attributes.https.html create mode 100644 testing/web-platform/tests/payment-handler/supports-shipping-contact-delegation-manual.https.html create mode 100644 testing/web-platform/tests/payment-handler/untrusted-event.https.html create mode 100644 testing/web-platform/tests/payment-handler/untrusted-event.js (limited to 'testing/web-platform/tests/payment-handler') diff --git a/testing/web-platform/tests/payment-handler/META.yml b/testing/web-platform/tests/payment-handler/META.yml new file mode 100644 index 0000000000..eff7624d05 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/META.yml @@ -0,0 +1,4 @@ +spec: https://w3c.github.io/payment-handler/ +suggested_reviewers: + - marcoscaceres + - rsolomakhin diff --git a/testing/web-platform/tests/payment-handler/app-can-make-payment.js b/testing/web-platform/tests/payment-handler/app-can-make-payment.js new file mode 100644 index 0000000000..cd27bce02e --- /dev/null +++ b/testing/web-platform/tests/payment-handler/app-can-make-payment.js @@ -0,0 +1,58 @@ +let responseType = 'canMakePayment-true'; +self.addEventListener('message', event => { + responseType = event.data.responseType; +}); + +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; + } +}); + +// Respond 'true' to the 'abortpayment' event to allow tests to use abort() to +// close an ongoing PaymentRequest. +self.addEventListener('abortpayment', event => { + event.respondWith(true); +}); diff --git a/testing/web-platform/tests/payment-handler/app-change-payment-method.js b/testing/web-platform/tests/payment-handler/app-change-payment-method.js new file mode 100644 index 0000000000..0e5a4768e7 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/app-change-payment-method.js @@ -0,0 +1,30 @@ +self.addEventListener('canmakepayment', (event) => { + event.respondWith(true); +}); + +async function responder(event) { + const methodName = event.methodData[0].supportedMethods; + if (!event.changePaymentMethod) { + return { + methodName, + details: { + changePaymentMethodReturned: + 'The changePaymentMethod() method is not implemented.', + }, + }; + } + let changePaymentMethodReturned; + try { + const response = await event.changePaymentMethod(methodName, { + country: 'US', + }); + changePaymentMethodReturned = response; + } catch (err) { + changePaymentMethodReturned = err.message; + } + return {methodName, details: {changePaymentMethodReturned}}; +} + +self.addEventListener('paymentrequest', (event) => { + event.respondWith(responder(event)); +}); diff --git a/testing/web-platform/tests/payment-handler/app-change-shipping-address.js b/testing/web-platform/tests/payment-handler/app-change-shipping-address.js new file mode 100644 index 0000000000..df39258dc9 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/app-change-shipping-address.js @@ -0,0 +1,44 @@ +self.addEventListener('canmakepayment', (event) => { + event.respondWith(true); +}); + +async function responder(event) { + const methodName = event.methodData[0].supportedMethods; + const shippingOption = event.shippingOptions[0].id; + const shippingAddress = { + addressLine: [ + '1875 Explorer St #1000', + ], + city: 'Reston', + country: 'US', + dependentLocality: '', + organization: 'Google', + phone: '+15555555555', + postalCode: '20190', + recipient: 'John Smith', + region: 'VA', + sortingCode: '', + }; + if (!event.changeShippingAddress) { + return { + methodName, + details: { + changeShippingAddressReturned: + 'The changeShippingAddress() method is not implemented.', + }, + }; + } + let changeShippingAddressReturned; + try { + const response = await event.changeShippingAddress(shippingAddress); + changeShippingAddressReturned = response; + } catch (err) { + changeShippingAddressReturned = err.message; + } + return {methodName, details: {changeShippingAddressReturned}, shippingAddress, + shippingOption}; +} + +self.addEventListener('paymentrequest', (event) => { + event.respondWith(responder(event)); +}); diff --git a/testing/web-platform/tests/payment-handler/app-change-shipping-option.js b/testing/web-platform/tests/payment-handler/app-change-shipping-option.js new file mode 100644 index 0000000000..ac3307b619 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/app-change-shipping-option.js @@ -0,0 +1,44 @@ +self.addEventListener('canmakepayment', (event) => { + event.respondWith(true); +}); + +async function responder(event) { + const methodName = event.methodData[0].supportedMethods; + const shippingOption = event.shippingOptions[0].id; + const shippingAddress = { + addressLine: [ + '1875 Explorer St #1000', + ], + city: 'Reston', + country: 'US', + dependentLocality: '', + organization: 'Google', + phone: '+15555555555', + postalCode: '20190', + recipient: 'John Smith', + region: 'VA', + sortingCode: '', + }; + if (!event.changeShippingOption) { + return { + methodName, + details: { + changeShippingOptionReturned: + 'The changeShippingOption() method is not implemented.', + }, + }; + } + let changeShippingOptionReturned; + try { + const response = await event.changeShippingOption(shippingOption); + changeShippingOptionReturned = response; + } catch (err) { + changeShippingOptionReturned = err.message; + } + return {methodName, details: {changeShippingOptionReturned}, shippingAddress, + shippingOption}; +} + +self.addEventListener('paymentrequest', (event) => { + event.respondWith(responder(event)); +}); diff --git a/testing/web-platform/tests/payment-handler/app-simple.js b/testing/web-platform/tests/payment-handler/app-simple.js new file mode 100644 index 0000000000..833a01f47e --- /dev/null +++ b/testing/web-platform/tests/payment-handler/app-simple.js @@ -0,0 +1,74 @@ +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 = window.location.origin + '/payment-handler/payment-app/'; + 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; + } + + 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: expectedMethodName, + }); +}); diff --git a/testing/web-platform/tests/payment-handler/app-supports-shipping-contact-delegation.js b/testing/web-platform/tests/payment-handler/app-supports-shipping-contact-delegation.js new file mode 100644 index 0000000000..770e2de64f --- /dev/null +++ b/testing/web-platform/tests/payment-handler/app-supports-shipping-contact-delegation.js @@ -0,0 +1,44 @@ +self.addEventListener('canmakepayment', (event) => { + event.respondWith(true); +}); + +function responder(event) { + const methodName = event.methodData[0].supportedMethods; + const shippingOption = event.paymentOptions.requestShipping + ? event.shippingOptions[0].id + : ''; + const payerName = + event.paymentOptions.requestPayerName ? 'John Smith' : ''; + const payerEmail = + event.paymentOptions.requestPayerEmail ? 'smith@gmail.com' : ''; + const payerPhone = + event.paymentOptions.requestPayerPhone ? '+15555555555' : ''; + const shippingAddress = event.paymentOptions.requestShipping ? { + addressLine: [ + '1875 Explorer St #1000', + ], + city: 'Reston', + country: 'US', + dependentLocality: '', + organization: 'Google', + phone: '+15555555555', + postalCode: '20190', + recipient: 'John Smith', + region: 'VA', + sortingCode: '', + } : {}; + + return { + methodName, + details: { token: '123456789'}, + payerName, + payerEmail, + payerPhone, + shippingAddress, + shippingOption + }; +} + +self.addEventListener('paymentrequest', (event) => { + event.respondWith(responder(event)); +}); diff --git a/testing/web-platform/tests/payment-handler/can-make-payment-event-constructor.https.html b/testing/web-platform/tests/payment-handler/can-make-payment-event-constructor.https.html new file mode 100644 index 0000000000..6892f01aa9 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/can-make-payment-event-constructor.https.html @@ -0,0 +1,14 @@ + + +Test for CanMakePaymentEvent Constructor + + + + + diff --git a/testing/web-platform/tests/payment-handler/can-make-payment-event-constructor.https.serviceworker.html b/testing/web-platform/tests/payment-handler/can-make-payment-event-constructor.https.serviceworker.html new file mode 100644 index 0000000000..afff850dc4 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/can-make-payment-event-constructor.https.serviceworker.html @@ -0,0 +1,13 @@ + + +Test for CanMakePaymentEvent Constructor + + + + + diff --git a/testing/web-platform/tests/payment-handler/can-make-payment-event-constructor.https.serviceworker.js b/testing/web-platform/tests/payment-handler/can-make-payment-event-constructor.https.serviceworker.js new file mode 100644 index 0000000000..5b334d9c3a --- /dev/null +++ b/testing/web-platform/tests/payment-handler/can-make-payment-event-constructor.https.serviceworker.js @@ -0,0 +1,47 @@ +importScripts('/resources/testharness.js'); + +test(() => { + try { + new CanMakePaymentEvent('test', undefined); + new CanMakePaymentEvent('test', null); + new CanMakePaymentEvent('test', {}); + } catch (err) { + assert_unreached(`Unexpected exception: ${err.message}`); + } +}, 'CanMakePaymentEvent can be constructed in service worker.'); + +test(() => { + const ev = new CanMakePaymentEvent('test', { + bubbles: true, + cancelable: true, + composed: true, + }); + assert_false(ev.isTrusted, 'constructed in script, so not be trusted'); + assert_true(ev.bubbles, 'set by EventInitDict'); + assert_true(ev.cancelable, 'set by EventInitDict'); + assert_true(ev.composed, 'set by EventInitDict'); + assert_equals(ev.target, null, 'initially null'); + assert_equals(ev.type, 'test'); +}, 'CanMakePaymentEvent can be constructed with an EventInitDict, even if not trusted'); + +test(() => { + const ev = new CanMakePaymentEvent('test', { + topOrigin: 'https://foo.com', + paymentRequestOrigin: 'https://bar.com', + methodData: [], + modifiers: [], + }); + assert_false(ev.isTrusted, 'constructed in script, so not be trusted'); + assert_equals(ev.topOrigin, undefined); + assert_equals(ev.paymentRequestOrigin, undefined); + assert_equals(ev.methodData, undefined); + assert_equals(ev.modifiers, undefined); +}, 'CanMakePaymentEvent can be constructed with a CanMakePaymentEventInit, even if not trusted'); + +test(() => { + const ev = new CanMakePaymentEvent('test', {}); + self.addEventListener('test', evt => { + assert_equals(ev, evt); + }); + self.dispatchEvent(ev); +}, 'CanMakePaymentEvent can be dispatched, even if not trusted'); diff --git a/testing/web-platform/tests/payment-handler/can-make-payment-event-constructor.https.worker.js b/testing/web-platform/tests/payment-handler/can-make-payment-event-constructor.https.worker.js new file mode 100644 index 0000000000..d88bddceaf --- /dev/null +++ b/testing/web-platform/tests/payment-handler/can-make-payment-event-constructor.https.worker.js @@ -0,0 +1,7 @@ +importScripts('/resources/testharness.js'); + +test(() => { + assert_false('CanMakePaymentEvent' in self); +}, 'CanMakePaymentEvent constructor must not be exposed in worker'); + +done(); diff --git a/testing/web-platform/tests/payment-handler/can-make-payment-event.https.html b/testing/web-platform/tests/payment-handler/can-make-payment-event.https.html new file mode 100644 index 0000000000..941c206e3b --- /dev/null +++ b/testing/web-platform/tests/payment-handler/can-make-payment-event.https.html @@ -0,0 +1,264 @@ + + +Tests for CanMakePaymentEvent + + + + + + + diff --git a/testing/web-platform/tests/payment-handler/change-payment-method-manual.https.html b/testing/web-platform/tests/payment-handler/change-payment-method-manual.https.html new file mode 100644 index 0000000000..1640420c62 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/change-payment-method-manual.https.html @@ -0,0 +1,170 @@ + + +Tests for PaymentRequestEvent.changePaymentMethod() + + + + + + + +

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

+ diff --git a/testing/web-platform/tests/payment-handler/change-shipping-address-manual.https.html b/testing/web-platform/tests/payment-handler/change-shipping-address-manual.https.html new file mode 100644 index 0000000000..3b98d56a25 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/change-shipping-address-manual.https.html @@ -0,0 +1,161 @@ + + +Tests for PaymentRequestEvent.changeShippingAddress() + + + + + + + +

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

+ diff --git a/testing/web-platform/tests/payment-handler/change-shipping-option-manual.https.html b/testing/web-platform/tests/payment-handler/change-shipping-option-manual.https.html new file mode 100644 index 0000000000..2511fc5ea0 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/change-shipping-option-manual.https.html @@ -0,0 +1,160 @@ + + +Tests for PaymentRequestEvent.changeShippingOption() + + + + + + + +

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

+ diff --git a/testing/web-platform/tests/payment-handler/idlharness.https.any.js b/testing/web-platform/tests/payment-handler/idlharness.https.any.js new file mode 100644 index 0000000000..dfb0190aba --- /dev/null +++ b/testing/web-platform/tests/payment-handler/idlharness.https.any.js @@ -0,0 +1,47 @@ +// META: global=window,worker +// META: script=/resources/WebIDLParser.js +// META: script=/resources/idlharness.js +// META: script=/service-workers/service-worker/resources/test-helpers.sub.js +// META: timeout=long + +'use strict'; + +// https://w3c.github.io/payment-handler/ + +idl_test( + ['payment-handler'], + ['service-workers', 'html', 'dom'], + async (idl_array, t) => { + const isWindow = self.GLOBAL.isWindow(); + const isServiceWorker = 'ServiceWorkerGlobalScope' in self; + const hasRegistration = isServiceWorker || isWindow; + + if (hasRegistration) { + idl_array.add_objects({ + ServiceWorkerRegistration: ['registration'], + PaymentManager: ['paymentManager'], + PaymentInstruments: ['instruments'], + }); + } + if (isServiceWorker) { + idl_array.add_objects({ + ServiceWorkerGlobalScope: ['self'], + CanMakePaymentEvent: ['new CanMakePaymentEvent("type")'], + PaymentRequestEvent: ['new PaymentRequestEvent("type")'], + }) + } + + if (isWindow) { + const scope = '/service-workers/service-worker/resources/'; + const reg = await service_worker_unregister_and_register( + t, '/service-workers/service-worker/resources/empty-worker.js', scope); + self.registration = reg; + await wait_for_state(t, reg.installing, "activated"); + add_completion_callback(() => reg.unregister()); + } + if (hasRegistration) { + self.paymentManager = self.registration.paymentManager; + self.instruments = self.paymentManager.instruments; + } + } +); diff --git a/testing/web-platform/tests/payment-handler/manifest.json b/testing/web-platform/tests/payment-handler/manifest.json new file mode 100644 index 0000000000..875d74b663 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/manifest.json @@ -0,0 +1,10 @@ +{ + "name": "Test 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 0000000000..37d2452ed9 --- /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 0000000000..121c131568 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/payment-instruments.https.html @@ -0,0 +1,379 @@ + + +Tests for PaymentInstruments interface + + + + + + diff --git a/testing/web-platform/tests/payment-handler/payment-request-event-constructor.https.html b/testing/web-platform/tests/payment-handler/payment-request-event-constructor.https.html new file mode 100644 index 0000000000..31ac8cafa7 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/payment-request-event-constructor.https.html @@ -0,0 +1,14 @@ + + +Test for PaymentRequestEvent Constructor + + + + + diff --git a/testing/web-platform/tests/payment-handler/payment-request-event-constructor.https.serviceworker.html b/testing/web-platform/tests/payment-handler/payment-request-event-constructor.https.serviceworker.html new file mode 100644 index 0000000000..a64c4290e0 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/payment-request-event-constructor.https.serviceworker.html @@ -0,0 +1,13 @@ + + +Test for PaymentRequestEvent Constructor + + + + + diff --git a/testing/web-platform/tests/payment-handler/payment-request-event-constructor.https.serviceworker.js b/testing/web-platform/tests/payment-handler/payment-request-event-constructor.https.serviceworker.js new file mode 100644 index 0000000000..1aea7000c1 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/payment-request-event-constructor.https.serviceworker.js @@ -0,0 +1,45 @@ +importScripts('/resources/testharness.js'); + +test(() => { + try { + new PaymentRequestEvent('test', undefined); + new PaymentRequestEvent('test', null); + new PaymentRequestEvent('test', {}); + } catch (err) { + assert_unreached(`Unexpected exception: ${err.message}`); + } +}, 'PaymentRequestEvent can be constucted in service worker.'); + +test(() => { + const ev = new PaymentRequestEvent('test', { + bubbles: true, + cancelable: true, + composed: true, + }); + assert_false(ev.isTrusted, 'constructed in script, so not be trusted'); + assert_true(ev.bubbles, 'set by EventInitDict'); + assert_true(ev.cancelable, 'set by EventInitDict'); + assert_true(ev.composed, 'set by EventInitDict'); + assert_equals(ev.target, null, 'initially null'); + assert_equals(ev.type, 'test'); +}, 'PaymentRequestEvent can be constructed with an EventInitDict, even if not trusted'); + +test(() => { + const ev = new PaymentRequestEvent('test', { + topOrigin: 'https://foo.com', + paymentRequestOrigin: 'https://bar.com', + methodData: [], + modifiers: [], + }); + assert_false(ev.isTrusted, 'constructed in script, so not be trusted'); + assert_equals(ev.topOrigin, 'https://foo.com'); + assert_equals(ev.paymentRequestOrigin, 'https://bar.com'); +}, 'PaymentRequestEvent can be constructed with a PaymentRequestEventInit, even if not trusted'); + +test(() => { + const ev = new PaymentRequestEvent('test', {}); + self.addEventListener('test', evt => { + assert_equals(ev, evt); + }); + self.dispatchEvent(ev); +}, 'PaymentRequestEvent can be dispatched, even if not trusted'); diff --git a/testing/web-platform/tests/payment-handler/payment-request-event-constructor.https.worker.js b/testing/web-platform/tests/payment-handler/payment-request-event-constructor.https.worker.js new file mode 100644 index 0000000000..fdb71aa845 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/payment-request-event-constructor.https.worker.js @@ -0,0 +1,7 @@ +importScripts('/resources/testharness.js'); + +test(() => { + assert_false('PaymentRequestEvent' in self); +}, 'PaymentRequestEvent constructor must not be exposed in worker'); + +done(); diff --git a/testing/web-platform/tests/payment-handler/payment-request-event-manual.https.html b/testing/web-platform/tests/payment-handler/payment-request-event-manual.https.html new file mode 100644 index 0000000000..e595dd2160 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/payment-request-event-manual.https.html @@ -0,0 +1,88 @@ + + +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 0000000000..fb54c5c064 --- /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); + } + }); +} diff --git a/testing/web-platform/tests/payment-handler/same-object-attributes.https.html b/testing/web-platform/tests/payment-handler/same-object-attributes.https.html new file mode 100644 index 0000000000..2e5dea3a4a --- /dev/null +++ b/testing/web-platform/tests/payment-handler/same-object-attributes.https.html @@ -0,0 +1,19 @@ + + + +Test for [SameObject] attributes + + + + diff --git a/testing/web-platform/tests/payment-handler/supports-shipping-contact-delegation-manual.https.html b/testing/web-platform/tests/payment-handler/supports-shipping-contact-delegation-manual.https.html new file mode 100644 index 0000000000..939e542926 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/supports-shipping-contact-delegation-manual.https.html @@ -0,0 +1,88 @@ + + +Tests for Delegation of shipping and contact collection to PH + + + + + + +

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

+ diff --git a/testing/web-platform/tests/payment-handler/untrusted-event.https.html b/testing/web-platform/tests/payment-handler/untrusted-event.https.html new file mode 100644 index 0000000000..900ac79d0d --- /dev/null +++ b/testing/web-platform/tests/payment-handler/untrusted-event.https.html @@ -0,0 +1,56 @@ + + + +Test for untrusted event + + + + diff --git a/testing/web-platform/tests/payment-handler/untrusted-event.js b/testing/web-platform/tests/payment-handler/untrusted-event.js new file mode 100644 index 0000000000..e067952cc3 --- /dev/null +++ b/testing/web-platform/tests/payment-handler/untrusted-event.js @@ -0,0 +1,59 @@ +let sender = null; + +self.addEventListener('message', e => { + sender = e.source; + + if (e.data == 'paymentrequest') { + self.dispatchEvent(new PaymentRequestEvent('paymentrequest', { + methodData: [{ + supportedMethods: 'https://example.com/pay' + }], + total: { + currency: 'USD', + value: '100' + }, + modifiers: [{ + supportedMethods: 'https://example.com/pay' + }] + })); + } else if (e.data == 'canmakepayment') { + self.dispatchEvent(new CanMakePaymentEvent('canmakepayment', { + methodData: [{ + supportedMethods: 'https://example.com/pay' + }], + modifiers: [{ + supportedMethods: 'https://example.com/pay' + }] + })); + } +}); + +self.addEventListener('paymentrequest', async e => { + const result = []; + + try { + e.respondWith({}); + } catch (exception) { + result.push(exception.name); + } + + try { + await e.openWindow('payment-app/payment.html'); + } catch (exception) { + result.push(exception.name); + } + + sender.postMessage(result); +}); + +self.addEventListener('canmakepayment', async e => { + const result = []; + + try { + e.respondWith({}); + } catch (exception) { + result.push(exception.name); + } + + sender.postMessage(result); +}); -- cgit v1.2.3