summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/payment-handler/can-make-payment-event.https.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/payment-handler/can-make-payment-event.https.html
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/payment-handler/can-make-payment-event.https.html')
-rw-r--r--testing/web-platform/tests/payment-handler/can-make-payment-event.https.html270
1 files changed, 270 insertions, 0 deletions
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..776c68be43
--- /dev/null
+++ b/testing/web-platform/tests/payment-handler/can-make-payment-event.https.html
@@ -0,0 +1,270 @@
+<!doctype html>
+<meta charset="utf-8">
+<title>Tests for CanMakePaymentEvent</title>
+<link rel="help" href="https://w3c.github.io/payment-handler/#the-canmakepaymentevent">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script>
+const DEFAULT_METHOD_NAME = window.location.origin + '/payment-handler/'
+ + 'can-make-payment-event-manifest.json';
+
+async function registerApp(responseType = 'canMakePayment-true') {
+ const request = new PaymentRequest(
+ [{supportedMethods: DEFAULT_METHOD_NAME, data: {responseType}}],
+ {total: {label: 'Total', amount: {currency: 'USD', value: '0.01'}}});
+ const response = await test_driver.bless('installing a payment app', () =>
+ request.show()
+ );
+ return response.complete('success');
+}
+
+function buildPaymentRequest(methodName = DEFAULT_METHOD_NAME) {
+ const unsupportedMethodName = methodName + '/unsupported';
+ return new PaymentRequest(
+ [
+ {
+ supportedMethods: methodName,
+ data: {
+ defaultParameter: 'defaultValue',
+ },
+ },
+ {
+ supportedMethods: unsupportedMethodName,
+ data: {
+ defaultUnsupportedParameter: 'defaultUnsupportedValue',
+ },
+ },
+ ],
+ {
+ total: {
+ label: 'Total',
+ amount: {
+ currency: 'USD',
+ value: '0',
+ },
+ },
+ displayItems: [
+ {
+ label: 'Nada',
+ amount: {currency: 'USD', value: '0'},
+ },
+ ],
+ modifiers: [
+ {
+ supportedMethods: [methodName],
+ data: {
+ modifiedParameter: 'modifiedValue',
+ },
+ total: {
+ label: 'Modified Total',
+ amount: {
+ currency: 'USD',
+ value: '0.0001',
+ },
+ },
+ additionalDisplayItems: [
+ {
+ label: 'Something',
+ amount: {currency: 'USD', value: '0.0001'},
+ },
+ ],
+ },
+ {
+ supportedMethods: [unsupportedMethodName],
+ data: {
+ modifiedUnsupportedParameter: 'modifiedUnsupportedValue',
+ },
+ total: {
+ label: 'Modified Unsupported Total',
+ amount: {
+ currency: 'USD',
+ value: '10',
+ },
+ },
+ additionalDisplayItems: [
+ {
+ label: 'Something Unsupported',
+ amount: {currency: 'USD', value: '10'},
+ },
+ ],
+ },
+ ],
+ },
+ );
+}
+
+promise_test(async t => {
+ // Intentionally do not install the payment app.
+ const request = buildPaymentRequest();
+ assert_not_equals(request, undefined);
+ let paymentRequestCanMakePaymentResult;
+ try {
+ paymentRequestCanMakePaymentResult = await request.canMakePayment();
+ } catch (err) {
+ assert_equals(
+ err.name,
+ 'NotAllowedError',
+ 'If it throws, then it must be NotAllowedError',
+ );
+ }
+ assert_true(
+ paymentRequestCanMakePaymentResult,
+ 'canMakePayment() must return true.',
+ );
+
+ await test_driver.bless('installing a payment app just-in-time');
+ const response = await request.show();
+ assert_equals('success', response.details.status);
+ return response.complete('success');
+}, 'If a payment handler is not installed, but can be installed just-in-time, then the payment method is supported.');
+
+promise_test(async t => {
+ // Intentionally do not install the payment app.
+ const request = buildPaymentRequest(DEFAULT_METHOD_NAME + '/non-existent');
+ assert_not_equals(request, undefined);
+ let paymentRequestCanMakePaymentResult;
+ try {
+ paymentRequestCanMakePaymentResult = await request.canMakePayment();
+ } catch (err) {
+ assert_equals(
+ err.name,
+ 'NotAllowedError',
+ 'If it throws, then it must be NotAllowedError',
+ );
+ }
+ assert_false(
+ paymentRequestCanMakePaymentResult,
+ 'canMakePayment() must return false.',
+ );
+
+ const response = await test_driver.bless('invoking a payemnt app');
+ await promise_rejects_dom(t, 'NotSupportedError', request.show());
+}, 'If a payment handler is not installed and cannot be installed just-in-time, then the payment method is not supported.');
+
+promise_test(async t => {
+ await registerApp('canMakePayment-false');
+ const request = buildPaymentRequest();
+ assert_not_equals(request, undefined);
+ let paymentRequestCanMakePaymentResult;
+ try {
+ paymentRequestCanMakePaymentResult = await request.canMakePayment();
+ } catch (err) {
+ assert_equals(
+ err.name,
+ 'NotAllowedError',
+ 'If it throws, then it must be NotAllowedError',
+ );
+ }
+ assert_true(
+ paymentRequestCanMakePaymentResult,
+ 'canMakePayment() must return true.',
+ );
+
+ await test_driver.bless('invoking a payment app');
+ const response = await request.show();
+ assert_equals('success', response.details.status);
+ return response.complete('success');
+}, 'If CanMakePaymentEvent.respondWith(false) is called, then canMakePayment() still returns true and the app can still be invoked.');
+
+promise_test(async t => {
+ await registerApp('canMakePayment-promise-false');
+ const request = buildPaymentRequest();
+ assert_not_equals(request, undefined);
+ let paymentRequestCanMakePaymentResult;
+ try {
+ paymentRequestCanMakePaymentResult = await request.canMakePayment();
+ } catch (err) {
+ assert_equals(
+ err.name,
+ 'NotAllowedError',
+ 'If it throws, then it must be NotAllowedError',
+ );
+ }
+ assert_true(
+ paymentRequestCanMakePaymentResult,
+ 'canMakePayment() must return true.',
+ );
+
+ await test_driver.bless('invoking a payment app');
+ const response = await request.show();
+ assert_equals('success', response.details.status);
+ return response.complete('success');
+}, 'If CanMakePaymentEvent.respondWith(Promise.resolve(false)) is called, then canMakePayment() still returns true and the app can still be invoked.');
+
+promise_test(async t => {
+ await registerApp('canMakePayment-true');
+ const request = buildPaymentRequest();
+ assert_not_equals(request, undefined);
+ let paymentRequestCanMakePaymentResult;
+ try {
+ paymentRequestCanMakePaymentResult = await request.canMakePayment();
+ } catch (err) {
+ assert_equals(
+ err.name,
+ 'NotAllowedError',
+ 'If it throws, then it must be NotAllowedError',
+ );
+ }
+ assert_true(
+ paymentRequestCanMakePaymentResult,
+ 'canMakePayment() must return true.',
+ );
+
+ await test_driver.bless('invoking a payment app');
+ const response = await request.show();
+ assert_equals('success', response.details.status);
+ return response.complete('success');
+}, 'If CanMakePaymentEvent.respondWith(true) is called, then canMakePayment() returns true and the app can be invoked.');
+
+promise_test(async t => {
+ await registerApp('canMakePayment-promise-true');
+ const request = buildPaymentRequest();
+ assert_not_equals(request, undefined);
+ let paymentRequestCanMakePaymentResult;
+ try {
+ paymentRequestCanMakePaymentResult = await request.canMakePayment();
+ } catch (err) {
+ assert_equals(
+ err.name,
+ 'NotAllowedError',
+ 'If it throws, then it must be NotAllowedError',
+ );
+ }
+ assert_true(
+ paymentRequestCanMakePaymentResult,
+ 'canMakePayment() must return true.',
+ );
+
+ await test_driver.bless('invoking a payment app');
+ const response = await request.show();
+ assert_equals('success', response.details.status);
+ return response.complete('success');
+}, 'If CanMakePaymentEvent.respondWith(Promise.resolve(true)) is called, then canMakePayment() returns true and the app can be invoked.');
+
+promise_test(async t => {
+ await registerApp('canMakePayment-custom-error');
+ const request = buildPaymentRequest();
+ assert_not_equals(request, undefined);
+ let paymentRequestCanMakePaymentResult;
+ try {
+ paymentRequestCanMakePaymentResult = await request.canMakePayment();
+ } catch (err) {
+ assert_equals(
+ err.name,
+ 'NotAllowedError',
+ 'If it throws, then it must be NotAllowedError',
+ );
+ }
+ assert_true(
+ paymentRequestCanMakePaymentResult,
+ 'canMakePayment() must return true.',
+ );
+
+ await test_driver.bless('invoking a payment app');
+ const response = await request.show();
+ assert_equals('success', response.details.status);
+ return response.complete('success');
+}, 'If CanMakePaymentEvent.respondWith(Promise.reject(error)) is called, then canMakePayment() still returns true and the app can still be invoked.');
+</script>