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 /browser/extensions/formautofill/test/mochitest/test_address_level_1_submission.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 'browser/extensions/formautofill/test/mochitest/test_address_level_1_submission.html')
-rw-r--r-- | browser/extensions/formautofill/test/mochitest/test_address_level_1_submission.html | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/browser/extensions/formautofill/test/mochitest/test_address_level_1_submission.html b/browser/extensions/formautofill/test/mochitest/test_address_level_1_submission.html new file mode 100644 index 0000000000..9d6ad1f7ea --- /dev/null +++ b/browser/extensions/formautofill/test/mochitest/test_address_level_1_submission.html @@ -0,0 +1,102 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta charset="utf-8"> + <title>Test autofill submission for a country without address-level1</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <script src="/tests/SimpleTest/EventUtils.js"></script> + <script type="text/javascript" src="formautofill_common.js"></script> + <script type="text/javascript" src="satchel_common.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +Form autofill test: Test autofill submission for a country without address-level1 + +<script> +/* import-globals-from ../../../../../toolkit/components/satchel/test/satchel_common.js */ + +"use strict"; + +const TEST_ADDRESSES = [{ + organization: "Mozilla", + "street-address": "123 Sesame Street", + "address-level1": "AL", + country: "DE", + timesUsed: 1, +}]; + +add_task(async function test_DE_is_valid_testcase() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["extensions.formautofill.addresses.capture.enabled", true], + ["extensions.formautofill.addresses.supportedCountries", "US,CA,DE"], + ["extensions.formautofill.creditCards.supportedCountries", "US,CA,DE"], + ], + }); + let chromeScript = SpecialPowers.loadChromeScript(function test_country_data() { + /* eslint-env mozilla/chrome-script */ + const {AddressDataLoader} = ChromeUtils.importESModule("resource://gre/modules/shared/FormAutofillUtils.sys.mjs"); + let data = AddressDataLoader.getData("DE"); + addMessageListener("CheckSubKeys", () => { + return !data.defaultLocale.sub_keys; + }); + }); + + SimpleTest.registerCleanupFunction(() => { + chromeScript.destroy(); + }); + + let result = await chromeScript.sendQuery("CheckSubKeys"); + ok(result, "Check that there are no sub_keys for the test country"); +}); + +add_task(async function test_form_will_submit_without_sub_keys() { + await SpecialPowers.pushPrefEnv({ + set: [ + // This needs to match the country in the previous test and must have no sub_keys. + ["browser.search.region", "DE"], + // We already verified the first time use case in browser test + ["extensions.formautofill.firstTimeUse", false], + ["extensions.formautofill.addresses.capture.enabled", true], + ["extensions.formautofill.addresses.supportedCountries", "US,CA,DE"], + ["extensions.formautofill.addresses.supported", "detect"] + ], + }); + // Click a field to get the form handler created + await focusAndWaitForFieldsIdentified("input[autocomplete='organization']"); + + let loadPromise = new Promise(resolve => { + /* eslint-disable-next-line mozilla/balanced-listeners */ + document.getElementById("submit_frame").addEventListener("load", resolve); + }); + + clickOnElement("input[type=submit]"); + await onStorageChanged("add"); + // Check if timesUsed is set correctly + let matching = await checkAddresses(TEST_ADDRESSES); + ok(matching, "Address saved as expected"); + + await loadPromise; + isnot(window.submit_frame.location.href, "about:blank", "Check form submitted"); +}); + +</script> + +<div> + <!-- Submit to the frame so that the test doesn't get replaced. We don't return + -- false in onsubmit since we're testing the submission succeeds. --> + <iframe id="submit_frame" name="submit_frame"></iframe> + <form action="/" target="submit_frame" method="POST"> + <p><label>organization: <input autocomplete="organization" value="Mozilla"></label></p> + <p><label>streetAddress: <input autocomplete="street-address" value="123 Sesame Street"></label></p> + <p><label>address-level1: <select autocomplete="address-level1"> + <option selected>AL</option> + <option>AK</option> + </select></label></p> + <p><label>country: <input autocomplete="country" value="DE"></label></p> + <p><input type="submit"></p> + </form> + +</div> +</body> +</html> |