diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/payment-handler/can-make-payment-event.https.html | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
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.html | 270 |
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> |