diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/payment-request/onpaymentmethodchange-attribute.https.html | |
parent | Initial commit. (diff) | |
download | firefox-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-request/onpaymentmethodchange-attribute.https.html')
-rw-r--r-- | testing/web-platform/tests/payment-request/onpaymentmethodchange-attribute.https.html | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/testing/web-platform/tests/payment-request/onpaymentmethodchange-attribute.https.html b/testing/web-platform/tests/payment-request/onpaymentmethodchange-attribute.https.html new file mode 100644 index 0000000000..f641bec4aa --- /dev/null +++ b/testing/web-platform/tests/payment-request/onpaymentmethodchange-attribute.https.html @@ -0,0 +1,79 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Test for onpaymentmethodchange attribute</title> +<link rel="help" href="https://w3c.github.io/browser-payment-api/#onpaymentmethodchange-attribute"> +<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", + }, + }, +}); + +test(() => { + const request = new PaymentRequest(defaultMethods, defaultDetails); + assert_idl_attribute(request, "onpaymentmethodchange"); +}, "Must have a onpaymentmethodchange IDL attribute"); + +test(() => { + const request = new PaymentRequest(defaultMethods, defaultDetails); + const ev = new Event("paymentmethodchange"); + let didHandle = false; + request.onpaymentmethodchange = evt => { + assert_equals(ev, evt, "must be same event"); + didHandle = true; + }; + request.dispatchEvent(ev); + assert_true(didHandle, "event did not fire"); +}, `onpaymentmethodchange attribute is a generic handler for "paymentmethodchange"`); + +test(() => { + const request = new PaymentRequest(defaultMethods, defaultDetails); + const ev = new PaymentMethodChangeEvent("paymentmethodchange"); + let didHandle = false; + request.onpaymentmethodchange = evt => { + assert_equals(ev, evt, "must be same event"); + didHandle = true; + }; + request.dispatchEvent(ev); + assert_true(didHandle, "event did not fire"); +}, `onpaymentmethodchange attribute is a handler for PaymentMethodChangeEvent`); + +test(() => { + const request = new PaymentRequest(defaultMethods, defaultDetails); + const ev = new PaymentMethodChangeEvent("paymentmethodchange", { + methodName: "test" + }); + let didHandle = false; + let didListen = false; + request.onpaymentmethodchange = evt => { + assert_equals(ev, evt, "must be same event"); + didHandle = true; + }; + request.addEventListener("paymentmethodchange", evt => { + assert_equals(ev, evt, "must be same event"); + didListen = true; + }); + request.dispatchEvent(ev); + assert_true(didHandle, "onpaymentmethodchange did not receive the event"); + assert_true(didListen, "addEventListener did not receive the event"); +}, `onpaymentmethodchange attribute and listeners both work`); +</script> |