diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/payments/test/test_payerDetails.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/payments/test/test_payerDetails.html')
-rw-r--r-- | dom/payments/test/test_payerDetails.html | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/dom/payments/test/test_payerDetails.html b/dom/payments/test/test_payerDetails.html new file mode 100644 index 0000000000..9a241803af --- /dev/null +++ b/dom/payments/test/test_payerDetails.html @@ -0,0 +1,107 @@ +<!DOCTYPE HTML> +<meta charset="utf-8"> +<title>Test for PaymentResponse.prototype.onpayerdetailchange</title> +<link rel="stylesheet" href="/tests/SimpleTest/test.css" /> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<script src="./DefaultData.js"></script> +<script> + SimpleTest.waitForExplicitFinish(); + + const gUrl = SimpleTest.getTestFileURL("PayerDetailsChromeScript.js"); + const gScript = SpecialPowers.loadChromeScript(gUrl); + + function okTester(result) { + return message => ok(result, message); + } + const passListener = okTester(true); + const failListener = okTester(false); + + gScript.addMessageListener("test-fail", failListener); + gScript.addMessageListener("test-pass", passListener); + + function sendOnce(message) { + return data => { + return new Promise(resolve => { + const doneMsg = `${message}-complete`; + gScript.addMessageListener(doneMsg, function listener() { + gScript.removeMessageListener(doneMsg, listener); + resolve(); + }); + gScript.sendAsyncMessage(message, data); + }); + }; + } + const sendTearDown = sendOnce("teardown"); + + async function loopTest(iterations) { + const handler = SpecialPowers.getDOMWindowUtils(window).setHandlingUserInput( + true + ); + const options = { + requestPayerName: true, + requestPayerEmail: true, + requestPayerPhone: true, + } + const request = new PaymentRequest(defaultMethods, defaultDetails, options); + const response = await request.show(); + is(response.payerName, "", ".payerName must initially be ''"); + is(response.payerEmail, "", ".payerEmail must initially be ''"); + is(response.payerPhone, "", ".payerPhone must initially be ''"); + for (let i = 0; i < iterations; i++) { + const payer = { + name: `test name ${i}`, + phone: `test phone ${i}`, + email: `test email ${i}`, + } + + // Capture the event to firing + const eventPromise = new Promise(resolve => { + response.onpayerdetailchange = resolve; + }); + const retryPromise = response.retry({ + error: "retry-fire-payerdetaichangeevent", + payer + }); + const event = await eventPromise; + + // Check things got updated + is(response.payerName, payer.name, `.payerName must be "${payer.name}"`); + is(response.payerEmail, payer.email, `.payerEmail must be "${payer.email}"`); + is(response.payerPhone, payer.phone, `.payerPhone must be "${payer.phone}"`); + + // Finally, let's do an updateWith() + event.updateWith({ error: "update-with", payerErrors: payer, ...defaultDetails }); + + await retryPromise; + } + + await response.complete("success"); + handler.destruct(); + } + + async function teardown() { + await sendTearDown(); + gScript.removeMessageListener("test-fail", failListener); + gScript.removeMessageListener("test-pass", passListener); + gScript.destroy(); + SimpleTest.finish(); + } + + async function runTests() { + try { + await loopTest(5); // lets go around 5 times + } catch (err) { + ok(false, `Unexpected error: ${err}.`); + } finally { + await teardown(); + } + } + + window.addEventListener("load", () => { + const prefs = [["dom.payments.request.enabled", true]]; + SpecialPowers.pushPrefEnv({ set: prefs }, runTests); + }); +</script> + +<body> + <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1472026">Mozilla Bug 1472026</a> |