diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/merchant-validation | |
parent | Initial commit. (diff) | |
download | firefox-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/merchant-validation')
5 files changed, 254 insertions, 0 deletions
diff --git a/testing/web-platform/tests/merchant-validation/META.yml b/testing/web-platform/tests/merchant-validation/META.yml new file mode 100644 index 0000000000..20ab3ff9ef --- /dev/null +++ b/testing/web-platform/tests/merchant-validation/META.yml @@ -0,0 +1,3 @@ +spec: https://w3c.github.io/merchant-validation/ +suggested_reviewers: + - marcoscaceres diff --git a/testing/web-platform/tests/merchant-validation/complete-method.tentative.https.html b/testing/web-platform/tests/merchant-validation/complete-method.tentative.https.html new file mode 100644 index 0000000000..36bfdb2160 --- /dev/null +++ b/testing/web-platform/tests/merchant-validation/complete-method.tentative.https.html @@ -0,0 +1,15 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<link rel="help" href="https://w3c.github.io/browser-payment-api/#dom-merchantvalidationevent-complete"> +<title>Test for the MerchantValidationEvent's complete() method.</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<script> +test(() => { + const event = new MerchantValidationEvent("test"); + assert_throws_dom("InvalidStateError", () => { + event.complete(""); + }) +}, "If event's isTrusted attribute is false, then then throw an InvalidStateError DOMException."); +</script> diff --git a/testing/web-platform/tests/merchant-validation/constructor.tentative.http.html b/testing/web-platform/tests/merchant-validation/constructor.tentative.http.html new file mode 100644 index 0000000000..8368c79a3b --- /dev/null +++ b/testing/web-platform/tests/merchant-validation/constructor.tentative.http.html @@ -0,0 +1,11 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Test for MerchantValidationEvent Constructor (insecure)</title> +<link rel="help" href="https://w3c.github.io/browser-payment-api/#merchantvalidationevent-interface"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +test(() => { + assert_false("MerchantValidationEvent" in Window); +}, "MerchantValidationEvent constructor must not be exposed in insecure context"); +</script> diff --git a/testing/web-platform/tests/merchant-validation/constructor.tentative.https.html b/testing/web-platform/tests/merchant-validation/constructor.tentative.https.html new file mode 100644 index 0000000000..cab7b10236 --- /dev/null +++ b/testing/web-platform/tests/merchant-validation/constructor.tentative.https.html @@ -0,0 +1,147 @@ +<!DOCTYPE html> +<!-- Copyright © 2017 Chromium authors and World Wide Web Consortium, (Massachusetts Institute of Technology, ERCIM, Keio University, Beihang). --> +<meta charset="utf-8"> +<title>Test for MerchantValidationEvent Constructor</title> +<link rel="help" href="https://w3c.github.io/browser-payment-api/#merchantvalidationevent-constructor"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +const applePay = Object.freeze({ + supportedMethods: "https://apple.com/apple-pay", + data: { + version: 3, + merchantIdentifier: "merchant.com.example", + countryCode: "US", + merchantCapabilities: ["supports3DS"], + supportedNetworks: ["visa"], + } +}); +const examplePay = Object.freeze({ supportedMethods: "https://example.com/pay" }); +const defaultMethods = Object.freeze([examplePay, applePay]); +const defaultDetails = Object.freeze({ + total: { + label: "Total", + amount: { + currency: "USD", + value: "1.00", + }, + }, +}); + +test(() => { + new MerchantValidationEvent("test"); +}, "MerchantValidationEvent can be constructed in secure-context."); + +test(() => { + const ev = new MerchantValidationEvent("test", { + bubbles: true, + cancelable: true, + composed: true, + }); + assert_false(ev.isTrusted, "constructed in script, so not 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"); +}, "MerchantValidationEvent can be constructed with an EventInitDict, even if not trusted."); + +test(() => { + const request = new PaymentRequest(defaultMethods, defaultDetails); + const ev = new MerchantValidationEvent("test"); + request.addEventListener("test", evt => { + assert_equals(ev, evt); + }); + request.dispatchEvent(ev); +}, "MerchantValidationEvent can be dispatched, even if not trusted."); + +test(() => { + const validationURL = "https://pass.com"; + const event = new MerchantValidationEvent("test", { validationURL }); + assert_idl_attribute(event, "validationURL"); + assert_equals(event.validationURL, "https://pass.com/"); +}, "Must have a validationURL IDL attribute, which is initialized with to the validationURL dictionary value."); + +test(() => { + const validationURL = "http://\u005B"; // invalid URL + assert_throws_js(TypeError, () => { + new MerchantValidationEvent("test", { validationURL }); + }); +}, "Must throw TypeError if initialized with an invalid URL."); + +test(() => { + const validationURL = ""; + const relativePaths = ["", ".", "/test"]; + for (const path of relativePaths) { + const event = new MerchantValidationEvent("test", { validationURL: path }); + const expected = new URL(path, document.location.href).href; + assert_equals(event.validationURL, expected); + } +}, "Relative validationURLs use the document as the base."); + +test(() => { + const validationURL = "pass"; + const base = document.createElement("base"); + base.href = "https://pass.com"; + document.head.append(base); + const event = new MerchantValidationEvent("test", { validationURL }); + try { + assert_idl_attribute(event, "validationURL"); + assert_equals(event.validationURL, "https://pass.com/pass"); + } finally { + base.remove(); + } +}, "Relative validationURLs use the document.baseURI as the base."); + +test(() => { + const methodName = "https://pass.com"; + const event = new MerchantValidationEvent("test", { methodName }); + assert_idl_attribute(event, "methodName"); + assert_equals(event.methodName, "https://pass.com"); +}, "Must have a methodName IDL attribute, which is initialized with to the methodName dictionary value."); + +test(() => { + const event = new MerchantValidationEvent("test", {}); + assert_equals(event.methodName, ""); +}, "When no methodName is passed, methodName attribute defaults to the empty string"); + +test(() => { + const validPMIs = [ + "https://example.com/pay", + "https://example.com/pay?version=1", + "https://example.com/pay/version/1", + "secure-payment-confirmation", + "https://apple.com/apple-pay", + // special case for as default value + "", + ]; + for (const methodName of validPMIs) { + const event = new MerchantValidationEvent("test", { methodName }); + assert_equals(event.methodName, methodName); + } +}, "MerchantValidationEvent can be constructed with valid PMIs"); + +test(() => { + const invalidPMIs = [ + // ❌ Contains Unicode character outside the valid ranges. + "secure-💳", + // ❌ Contains uppercase characters. + "Secure-Payment-Confirmation", + // ❌ Contains Unicode characters outside the valid ranges. + "¡secure-*-payment-confirmation!", + // ❌ Uses http://, a username, and a password. + "http://username:password@example.com/pay", + // ❌ Uses unknown URI scheme. + "unknown://example.com/pay", + ]; + for (const methodName of invalidPMIs) { + assert_throws_js( + RangeError, + () => { + const event = new MerchantValidationEvent("test", { methodName }); + }, + `expected to throw when constructed with invalid PMI: '${methodName}'` + ); + } +}, "MerchantValidationEvent can't be constructed with invalid PMIs"); +</script> diff --git a/testing/web-platform/tests/merchant-validation/onmerchantvalidation-attribute.https.html b/testing/web-platform/tests/merchant-validation/onmerchantvalidation-attribute.https.html new file mode 100644 index 0000000000..d31ac2dd72 --- /dev/null +++ b/testing/web-platform/tests/merchant-validation/onmerchantvalidation-attribute.https.html @@ -0,0 +1,78 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Test for PaymentRequest's onmerchantvalidation attribute</title> +<link rel="help" href="https://w3c.github.io/browser-payment-api/#dom-paymentrequest-onmerchantvalidation"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +"use strict"; +const testMethod = Object.freeze({ supportedMethods: "not-a-real-method" }); +const applePay = Object.freeze({ + supportedMethods: "https://apple.com/apple-pay", + data: { + version: 3, + merchantIdentifier: "merchant.com.example", + countryCode: "US", + merchantCapabilities: ["supports3DS"], + supportedNetworks: ["visa"], + }, +}); +const defaultMethods = Object.freeze([testMethod, applePay]); +const defaultDetails = Object.freeze({ + total: { + label: "Total", + amount: { + currency: "USD", + value: "1.00", + }, + }, +}); +const validationURL = "https://example.com"; + +test(() => { + const request = new PaymentRequest(defaultMethods, defaultDetails); + assert_idl_attribute(request, "onmerchantvalidation"); +}, "Must have a onmerchantvalidation IDL attribute"); + +test(() => { + const request = new PaymentRequest(defaultMethods, defaultDetails); + const ev = new Event("merchantvalidation"); + let didHandle = false; + request.onmerchantvalidation = evt => { + assert_equals(ev, evt, "must be same event"); + didHandle = true; + }; + request.dispatchEvent(ev); + assert_true(didHandle, "event did not fire"); +}, `onmerchantvalidation attribute is a generic handler for "merchantvalidation"`); + +test(() => { + const request = new PaymentRequest(defaultMethods, defaultDetails); + const ev = new MerchantValidationEvent("merchantvalidation", { validationURL }); + let didHandle = false; + request.onmerchantvalidation = evt => { + assert_equals(ev, evt, "must be same event"); + didHandle = true; + }; + request.dispatchEvent(ev); + assert_true(didHandle, "event did not fire"); +}, `onmerchantvalidation attribute is a handler for MerchantValidationEvent`); + +test(() => { + const request = new PaymentRequest(defaultMethods, defaultDetails); + const ev = new MerchantValidationEvent("merchantvalidation", { validationURL }); + let didHandle = false; + let didListen = false; + request.onmerchantvalidation = evt => { + assert_equals(ev, evt, "must be same event"); + didHandle = true; + }; + request.addEventListener("merchantvalidation", evt => { + assert_equals(ev, evt, "must be same event"); + didListen = true; + }); + request.dispatchEvent(ev); + assert_true(didHandle, "onmerchantvalidation must receive the event"); + assert_true(didListen, "addEventListener must receive the event"); +}, `onmerchantvalidation attribute and listeners both work`); +</script> |