summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/payment-handler/app-simple.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/payment-handler/app-simple.js
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/payment-handler/app-simple.js')
-rw-r--r--testing/web-platform/tests/payment-handler/app-simple.js74
1 files changed, 74 insertions, 0 deletions
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,
+ });
+});