tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_basic_autocomplete_form.html (7681B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test basic autofill</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <script src="/tests/SimpleTest/EventUtils.js"></script>
      8  <script type="text/javascript" src="formautofill_common.js"></script>
      9  <script type="text/javascript" src="satchel_common.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     11 </head>
     12 <body>
     13 Form autofill test: simple form address autofill
     14 
     15 <script>
     16 /* import-globals-from ../../../../../toolkit/components/satchel/test/satchel_common.js */
     17 
     18 "use strict";
     19 
     20 let MOCK_STORAGE = [{
     21  organization: "Sesame Street",
     22  "street-address": "123 Sesame Street.\n2-line\n3-line",
     23  tel: "+13453453456",
     24  country: "US",
     25  "address-level1": "NY",
     26 }, {
     27  organization: "Mozilla",
     28  "street-address": "331 E. Evelyn Avenue\n2-line\n3-line",
     29  tel: "+16509030800",
     30  country: "US",
     31  "address-level1": "CA",
     32 }];
     33 
     34 async function setupAddressStorage() {
     35  await addAddress(MOCK_STORAGE[0]);
     36  await addAddress(MOCK_STORAGE[1]);
     37 }
     38 
     39 async function setupFormHistory() {
     40  await updateFormHistory([
     41    {op: "add", fieldname: "tel", value: "+1234567890"},
     42    {op: "add", fieldname: "email", value: "foo@mozilla.com"},
     43  ]);
     44 }
     45 
     46 initPopupListener();
     47 
     48 // Form with history only.
     49 add_task(async function history_only_menu_checking() {
     50  await setupFormHistory();
     51 
     52  await setInput("#tel", "", true);
     53  await notExpectPopup();
     54  synthesizeKey("KEY_ArrowDown");
     55  await expectPopup();
     56  checkMenuEntries(["+1234567890"], false);
     57 });
     58 
     59 // Test to ensure the abandoned heuristic is no longer applied:
     60 // Do not display history search result if less than 3 inputs are covered by all saved
     61 // fields in the storage.
     62 add_task(async function all_saved_fields_less_than_threshold() {
     63  const email = "test@test.com";
     64  await addAddress({
     65    email,
     66  });
     67 
     68  await setInput("#email", "", true);
     69  await notExpectPopup();
     70  synthesizeKey("KEY_ArrowDown");
     71  await expectPopup();
     72  checkMenuEntriesComment([
     73    makeAddressComment({
     74      primary: email,
     75      secondary: "United States",
     76      status: "Also autofills address"
     77    })], 2);
     78 
     79  await cleanUpAddresses();
     80 });
     81 
     82 // Form with both history and address storage.
     83 add_task(async function check_menu_when_both_existed() {
     84  await setupAddressStorage();
     85 
     86  await setInput("#organization", "", true);
     87  await notExpectPopup();
     88  synthesizeKey("KEY_ArrowDown");
     89  await expectPopup();
     90  checkMenuEntriesComment(MOCK_STORAGE.map(address =>
     91    makeAddressComment({
     92      primary: address.organization,
     93      secondary: FormAutofillUtils.toOneLineAddress(address["street-address"]),
     94      status: "Also autofills address, phone"
     95    })
     96  ), 2);
     97 
     98  await setInput("#street-address", "", true);
     99  await notExpectPopup();
    100  synthesizeKey("KEY_ArrowDown");
    101  await expectPopup();
    102  checkMenuEntriesComment(MOCK_STORAGE.map(address =>
    103    makeAddressComment({
    104      primary: FormAutofillUtils.toOneLineAddress(address["street-address"]),
    105      secondary: address.organization,
    106      status: "Also autofills organization, phone"
    107    })
    108  ), 2);
    109 
    110  await setInput("#tel", "", true);
    111  await notExpectPopup();
    112  synthesizeKey("KEY_ArrowDown");
    113  await expectPopup();
    114  checkMenuEntriesComment(MOCK_STORAGE.map(address =>
    115    makeAddressComment({
    116      primary: address.tel,
    117      secondary: FormAutofillUtils.toOneLineAddress(address["street-address"]),
    118      status: "Also autofills address, organization"
    119    })
    120  ), 2);
    121 
    122  await setInput("#address-line1", "", true);
    123  await notExpectPopup();
    124  synthesizeKey("KEY_ArrowDown");
    125  await expectPopup();
    126  checkMenuEntriesComment(MOCK_STORAGE.map(address =>
    127    makeAddressComment({
    128      primary: FormAutofillUtils.toOneLineAddress(address["street-address"]),
    129      secondary: address.organization,
    130      status: "Also autofills organization, phone"
    131    })
    132  ), 2);
    133 });
    134 
    135 // Display history search result if no matched data in addresses.
    136 add_task(async function check_fallback_for_mismatched_field() {
    137  await setInput("#email", "", true);
    138  await notExpectPopup();
    139  synthesizeKey("KEY_ArrowDown");
    140  await expectPopup();
    141  checkMenuEntries(["foo@mozilla.com"], false);
    142 });
    143 
    144 // Display history search result if address autofill is disabled.
    145 add_task(async function check_search_result_for_pref_off() {
    146  await SpecialPowers.pushPrefEnv({
    147    set: [["extensions.formautofill.addresses.enabled", false]],
    148  });
    149 
    150  await setInput("#tel", "", true);
    151  await notExpectPopup();
    152  synthesizeKey("KEY_ArrowDown");
    153  await expectPopup();
    154  checkMenuEntries(["+1234567890"], false);
    155 
    156  await SpecialPowers.popPrefEnv();
    157 });
    158 
    159 // Autofill the address from dropdown menu.
    160 add_task(async function check_fields_after_form_autofill() {
    161  const focusedInput = await setInput("#organization", "Moz", true);
    162  await notExpectPopup();
    163  synthesizeKey("KEY_ArrowDown");
    164  await expectPopup();
    165  checkMenuEntriesComment(MOCK_STORAGE.map(address =>
    166    makeAddressComment({
    167      primary: address.organization,
    168      secondary: FormAutofillUtils.toOneLineAddress(address["street-address"]),
    169      status: "Also autofills address, phone"
    170    })
    171  ).slice(1), 2);
    172  synthesizeKey("KEY_ArrowDown");
    173  await triggerAutofillAndCheckProfile(MOCK_STORAGE[1]);
    174  synthesizeKey("KEY_Escape");
    175  is(focusedInput.value, "Mozilla", "Filled field shouldn't be reverted by ESC key");
    176 });
    177 
    178 // Test to ensure the abandoned heuristic is no longer applied:
    179 // Do not fallback to history search after autofill address.
    180 add_task(async function check_fallback_after_form_autofill() {
    181  await setInput("#tel", "", true);
    182  await triggerPopupAndHoverItem("#tel", 0);
    183  checkMenuEntriesComment(MOCK_STORAGE.map(address =>
    184    makeAddressComment({
    185      primary: address.tel,
    186      secondary: FormAutofillUtils.toOneLineAddress(address["street-address"]),
    187      status: "Also autofills address, organization"
    188    })
    189  ), 2);
    190 });
    191 
    192 // Resume form autofill once all the autofilled fileds are changed.
    193 add_task(async function check_form_autofill_resume() {
    194  document.querySelector("#tel").blur();
    195  document.querySelector("#form1").reset();
    196  await setInput("#tel", "");
    197  await triggerPopupAndHoverItem("#tel", 0);
    198  checkMenuEntriesComment(MOCK_STORAGE.map(address =>
    199    makeAddressComment({
    200      primary: address.tel,
    201      secondary: FormAutofillUtils.toOneLineAddress(address["street-address"]),
    202      status: "Also autofills address, organization"
    203    })
    204  ), 2);
    205  await triggerAutofillAndCheckProfile(MOCK_STORAGE[0]);
    206 });
    207 
    208 </script>
    209 
    210 <p id="display"></p>
    211 
    212 <div id="content">
    213 
    214  <form id="form1">
    215    <p>This is a basic form.</p>
    216    <p><label>organization: <input id="organization" name="organization" autocomplete="organization" type="text"></label></p>
    217    <p><label>streetAddress: <input id="street-address" name="street-address" autocomplete="street-address" type="text"></label></p>
    218    <p><label>address-line1: <input id="address-line1" name="address-line1" autocomplete="address-line1" type="text"></label></p>
    219    <p><label>tel: <input id="tel" name="tel" autocomplete="tel" type="text"></label></p>
    220    <p><label>email: <input id="email" name="email" autocomplete="email" type="text"></label></p>
    221    <p><label>country: <select id="country" name="country" autocomplete="country">
    222      <option/>
    223      <option value="US">United States</option>
    224    </select></label></p>
    225    <p><label>states: <select id="address-level1" name="address-level1" autocomplete="address-level1">
    226      <option/>
    227      <option value="CA">California</option>
    228      <option value="NY">New York</option>
    229      <option value="WA">Washington</option>
    230    </select></label></p>
    231  </form>
    232 
    233 </div>
    234 
    235 <pre id="test"></pre>
    236 </body>
    237 </html>