browser/extensions/formautofill/test/mochitest/test_address_level_1_submission.html
author Matthew Noorenberghe <mozilla@noorenberghe.ca>
Sun, 22 Apr 2018 17:16:08 -0700
changeset 786361 3de0c3e8d0f1ebf238431c1b476cb0bfa71a8f78
parent 786358 e9532c7aa08d2e922ede37a84a20d3388ae158f1
child 788930 8b0c7a7da06e7da31c71e0271b7e0da338f1972e
permissions -rw-r--r--
Bug 1433876 - Follow-up eslint fix to handle Bug 1454813 rename of SpawnTask.js. r=MattN MozReview-Commit-ID: 1MI5566qmUF

<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test autofill submission for a country without address-level1</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/AddTask.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 ../../../../../testing/mochitest/tests/SimpleTest/AddTask.js */
/* import-globals-from ../../../../../toolkit/components/satchel/test/satchel_common.js */
/* import-globals-from formautofill_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() {
  let chromeScript = SpecialPowers.loadChromeScript(function test_country_data() {
    ChromeUtils.import("resource://formautofill/FormAutofillUtils.jsm");
    let data = AddressDataLoader.getData("DE");
    /* global addMessageListener */
    addMessageListener("CheckSubKeys", () => {
      return !data.defaultLocale.sub_keys;
    });
  });

  SimpleTest.registerCleanupFunction(() => {
    chromeScript.destroy();
  });

  let result = chromeScript.sendSyncMessage("CheckSubKeys");
  ok(result[0][0], "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],
    ],
  });

  // 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>