summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/payment-method-basic-card/payment-request-canmakepayment-method.https.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/payment-method-basic-card/payment-request-canmakepayment-method.https.html
parentInitial commit. (diff)
downloadthunderbird-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-method-basic-card/payment-request-canmakepayment-method.https.html')
-rw-r--r--testing/web-platform/tests/payment-method-basic-card/payment-request-canmakepayment-method.https.html89
1 files changed, 89 insertions, 0 deletions
diff --git a/testing/web-platform/tests/payment-method-basic-card/payment-request-canmakepayment-method.https.html b/testing/web-platform/tests/payment-method-basic-card/payment-request-canmakepayment-method.https.html
new file mode 100644
index 0000000000..f1b0c28abb
--- /dev/null
+++ b/testing/web-platform/tests/payment-method-basic-card/payment-request-canmakepayment-method.https.html
@@ -0,0 +1,89 @@
+<!DOCTYPE html>
+<!-- Copyright © 2017 World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). -->
+<meta charset="utf-8">
+<title>Payment Method Basic Card: Tests that basic card is a supported method</title>
+<link rel="help" href="https://w3c.github.io/browser-payment-api/#show-method">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+const basicCard = Object.freeze({ supportedMethods: "basic-card", data: {} });
+const defaultMethods = Object.freeze([basicCard]);
+const defaultDetails = Object.freeze({
+ total: {
+ label: "Total",
+ amount: {
+ currency: "USD",
+ value: "1.00",
+ },
+ },
+});
+
+const notSupportedMethod = Object.freeze({
+ supportedMethods: "this-is-not-supported",
+});
+
+promise_test(async t => {
+ const request = new PaymentRequest([notSupportedMethod], defaultDetails);
+ assert_false(
+ await request.canMakePayment(),
+ `canMakePaymentPromise should be false`
+ );
+}, `Must return false when the PMI is not supported at by the user agent.`);
+
+function* pmiGenerator(howMany = 256) {
+ for (i = 0; i < howMany; i++) {
+ yield {
+ supportedMethods: `this-is-not-supported`,
+ data: { key: "value" },
+ };
+ }
+}
+
+promise_test(async t => {
+ //Smoke test
+ const canMakePaymentPromise = new PaymentRequest(
+ [notSupportedMethod],
+ defaultDetails
+ ).canMakePayment();
+ assert_false(
+ await canMakePaymentPromise,
+ "Expected canMakePaymentPromise smoke test to resolve with false"
+ );
+ // Actual test - Make a big array with random PMIs,
+ // put basic-card in the middle of it!
+ const pmis = []
+ .concat(Array.from(pmiGenerator(250)))
+ .concat(basicCard)
+ .concat(Array.from(pmiGenerator(250)));
+ const request = new PaymentRequest(pmis, defaultDetails);
+ assert_true(
+ await request.canMakePayment(),
+ `canMakePaymentPromise should be true, because basic-card is present`
+ );
+}, `Must return true when basic-card is amongst unsupported PMIs.`);
+
+promise_test(async t => {
+ const request = new PaymentRequest(defaultMethods, defaultDetails);
+ try {
+ assert_true(
+ await request.canMakePayment(),
+ `canMakePaymentPromise must resolve to true`
+ );
+ assert_true(
+ await request.canMakePayment(),
+ `canMakePaymentPromise must resolve to true`
+ );
+ // try to trigger optional behavior
+ for (let i = 0; i < 1024; i++) {
+ const temp = new PaymentRequest(defaultMethods, defaultDetails);
+ await Promise.all([temp.canMakePayment(), request.canMakePayment()]);
+ }
+ } catch (err) {
+ assert_equals(
+ err.name,
+ "NotAllowedError",
+ "if it throws, then it must be a NotAllowedError."
+ );
+ }
+}, `If basic-card is supported, then return a promise that resolves to true.`);
+</script>