tor-browser

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

test_autocompleteinfo.html (8913B)


      1 <!DOCTYPE html>
      2 <html>
      3 <!--
      4 Test getAutocompleteInfo() on <input> and <select>
      5 -->
      6 <head>
      7  <title>Test for getAutocompleteInfo()</title>
      8  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      9  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
     10 </head>
     11 
     12 <body>
     13 <p id="display"></p>
     14 <div id="content" style="display: none">
     15  <form>
     16    <input id="input"/>
     17    <select id="select" />
     18  </form>
     19 </div>
     20 <pre id="test">
     21 <script>
     22 "use strict";
     23 
     24 var values = [
     25  // Missing or empty attribute
     26  [undefined, {}, ""],
     27  ["", {}, ""],
     28 
     29  // One token
     30  ["on", {fieldName: "on" }, "on"],
     31  ["On", {fieldName: "on" }, "on"],
     32  ["off", {fieldName: "off", canAutomaticallyPersist: false}, "off" ],
     33  ["name", {fieldName: "name" }, "name"],
     34  [" name ", {fieldName: "name" }, "name"],
     35  ["username", {fieldName: "username"}, "username"],
     36  [" username ", {fieldName: "username"}, "username"],
     37  ["current-password", {fieldName: "current-password", canAutomaticallyPersist: false}, "current-password"],
     38  ["new-password", {fieldName: "new-password", canAutomaticallyPersist: false}, "new-password"],
     39  ["cc-number", {fieldName: "cc-number", canAutomaticallyPersist: false}, "cc-number"],
     40  ["cc-csc", {fieldName: "cc-csc", canAutomaticallyPersist: false}, ""],
     41  ["one-time-code", {fieldName: "one-time-code", canAutomaticallyPersist: false}, ""],
     42  ["language", {fieldName: "language"}, ""],
     43  [" language ", {fieldName: "language"}, ""],
     44  ["tel-extension", {fieldName: "tel-extension"}, ""],
     45  ["foobar", {}, ""],
     46  ["section-blue", {}, ""],
     47  [" WEBAUTHN ", {fieldName: "webauthn", credentialType: "webauthn"}, "webauthn"],
     48 
     49  // One token + WebAuthn credential type
     50  ["on webauthn", {}, ""],
     51  ["off webauthn", {}, ""],
     52  ["webauthn webauthn", {}, ""],
     53  ["username WebAuthn", {fieldName: "username", credentialType: "webauthn"}, "username webauthn"],
     54  ["current-PASSWORD webauthn", {fieldName: "current-password", credentialType: "webauthn", canAutomaticallyPersist: false}, "current-password webauthn"],
     55 
     56  // Two tokens
     57  ["on off", {}, ""],
     58  ["off on", {}, ""],
     59  ["username tel", {}, ""],
     60  ["tel username ", {}, ""],
     61  [" username tel ", {}, ""],
     62  ["tel mobile", {}, ""],
     63  ["tel shipping", {}, ""],
     64  ["shipping tel", {addressType: "shipping", fieldName: "tel"}, "shipping tel"],
     65  ["shipPING tel", {addressType: "shipping", fieldName: "tel"}, "shipping tel"],
     66  ["mobile tel", {contactType: "mobile", fieldName: "tel"}, "mobile tel"],
     67  ["  MoBiLe  TeL  ", {contactType: "mobile", fieldName: "tel"}, "mobile tel"],
     68  ["pager impp", {contactType: "pager", fieldName: "impp"}, ""],
     69  ["fax tel-extension", {contactType: "fax", fieldName: "tel-extension"}, ""],
     70  ["XXX tel", {}, ""],
     71  ["XXX username", {}, ""],
     72  ["name section-blue", {}, ""],
     73  ["scetion-blue cc-name", {}, ""],
     74  ["pager language", {}, ""],
     75  ["fax url", {}, ""],
     76  ["section-blue name", {section: "section-blue", fieldName: "name"}, "section-blue name"],
     77  ["section-blue tel", {section: "section-blue", fieldName: "tel"}, "section-blue tel"],
     78  ["webauthn username", {}, ""],
     79 
     80  // Two tokens + WebAuthn credential type
     81  ["fax url webauthn", {}, ""],
     82  ["shipping tel webauthn", {addressType: "shipping", fieldName: "tel", credentialType: "webauthn"}, "shipping tel webauthn"],
     83 
     84  // Three tokens
     85  ["billing invalid tel", {}, ""],
     86  ["___ mobile tel", {}, ""],
     87  ["mobile foo tel", {}, ""],
     88  ["mobile tel foo", {}, ""],
     89  ["tel mobile billing", {}, ""],
     90  ["billing mobile tel", {addressType: "billing", contactType: "mobile", fieldName: "tel"}, "billing mobile tel"],
     91  ["  BILLing   MoBiLE   tEl  ", {addressType: "billing", contactType: "mobile", fieldName: "tel"}, "billing mobile tel"],
     92  ["billing home tel", {addressType: "billing", contactType: "home", fieldName: "tel"}, "billing home tel"],
     93  ["home section-blue tel", {}, ""],
     94  ["setion-blue work email", {}, ""],
     95  ["section-blue home address-level2", {}, ""],
     96  ["section-blue shipping name", {section: "section-blue", addressType: "shipping", fieldName: "name"}, "section-blue shipping name"],
     97  ["section-blue mobile tel", {section: "section-blue", contactType: "mobile", fieldName: "tel"}, "section-blue mobile tel"],
     98  ["shipping webauthn tel", {}, ""],
     99 
    100  // Three tokens + WebAuthn credential type
    101  ["invalid mobile tel webauthn", {}, ""],
    102  ["section-blue shipping name webauthn", {section: "section-blue", addressType: "shipping", fieldName: "name", credentialType: "webauthn"}, "section-blue shipping name webauthn"],
    103 
    104  // Four tokens
    105  ["billing billing mobile tel", {}, ""],
    106  ["name section-blue shipping home", {}, ""],
    107  ["secti shipping work address-line1", {}, ""],
    108  ["section-blue shipping home name", {}, ""],
    109  ["section-blue shipping mobile tel", {section: "section-blue", addressType: "shipping", contactType: "mobile", fieldName: "tel"}, "section-blue shipping mobile tel"],
    110  ["section-blue webauthn mobile tel", {}, ""],
    111 
    112  // Four tokens + WebAuthn credential type
    113  ["section-blue shipping home name webauthn", {}, ""],
    114  ["section-blue shipping mobile tel webauthn", {section: "section-blue", addressType: "shipping", contactType: "mobile", fieldName: "tel", credentialType: "webauthn"}, "section-blue shipping mobile tel webauthn"],
    115 
    116  // Five tokens (invalid)
    117  ["billing billing billing mobile tel", {}, ""],
    118  ["section-blue section-blue billing mobile tel", {}, ""],
    119  ["section-blue section-blue billing webauthn tel", {}, ""],
    120 
    121  // Five tokens + WebAuthn credential type (invalid)
    122  ["billing billing billing mobile tel webauthn", {}, ""],
    123 ];
    124 
    125 var autocompleteInfoFieldIds = ["input", "select"];
    126 var autocompleteEnabledTypes = ["hidden", "text", "search", "url", "tel",
    127                                "email", "password", "date", "time", "number",
    128                                "range", "color"];
    129 var autocompleteDisabledTypes = ["reset", "submit", "image", "button", "radio",
    130                                 "checkbox", "file"];
    131 
    132 function testInputTypes() {
    133  let field = document.getElementById("input");
    134 
    135  for (var type of autocompleteEnabledTypes) {
    136    testAutocomplete(field, type, true);
    137  }
    138 
    139  for (var type of autocompleteDisabledTypes) {
    140    testAutocomplete(field, type, false);
    141  }
    142 
    143  // Clear input type attribute.
    144  field.removeAttribute("type");
    145 }
    146 
    147 function testAutocompleteInfoValue(aEnabled) {
    148  for (var fieldId of autocompleteInfoFieldIds) {
    149    let field = document.getElementById(fieldId);
    150 
    151    for (var test of values) {
    152      if (typeof(test[0]) === "undefined")
    153        field.removeAttribute("autocomplete");
    154      else
    155        field.setAttribute("autocomplete", test[0]);
    156 
    157      var info = field.getAutocompleteInfo();
    158      if (aEnabled) {
    159        // We need to consider if getAutocompleteInfo() is valid,
    160        // but @autocomplete is invalid case, because @autocomplete
    161        // has smaller set of values.
    162        is(field.autocomplete, test[2], "Checking @autocomplete of: " + test[0]);
    163      }
    164 
    165      is(info.section, "section" in test[1] ? test[1].section : "",
    166        "Checking autocompleteInfo.section for " + field + ": " + test[0]);
    167      is(info.addressType, "addressType" in test[1] ? test[1].addressType : "",
    168        "Checking autocompleteInfo.addressType for " + field + ": " + test[0]);
    169      is(info.contactType, "contactType" in test[1] ? test[1].contactType : "",
    170        "Checking autocompleteInfo.contactType for " + field + ": " + test[0]);
    171      is(info.fieldName, "fieldName" in test[1] ? test[1].fieldName : "",
    172        "Checking autocompleteInfo.fieldName for " + field + ": " + test[0]);
    173      is(info.credentialType, "credentialType" in test[1] ? test[1].credentialType: "",
    174        "Checking autocompleteInfo.credentialType for " + field + ": " + test[0]);
    175      is(info.canAutomaticallyPersist, "canAutomaticallyPersist" in test[1] ? test[1].canAutomaticallyPersist : true,
    176        "Checking autocompleteInfo.canAutomaticallyPersist for " + field + ": " + test[0]);
    177    }
    178  }
    179 }
    180 
    181 function testAutocomplete(aField, aType, aEnabled) {
    182  aField.type = aType;
    183  if (aEnabled) {
    184    ok(aField.getAutocompleteInfo() !== null, "getAutocompleteInfo shouldn't return null");
    185  } else {
    186    is(aField.getAutocompleteInfo(), null, "getAutocompleteInfo should return null");
    187  }
    188 }
    189 
    190 // getAutocompleteInfo() should be able to parse all tokens as defined
    191 // in the spec regardless of whether dom.forms.autocomplete.formautofill pref
    192 // is on or off.
    193 add_task(async function testAutocompletePreferenceEnabled() {
    194  await SpecialPowers.pushPrefEnv({"set": [["dom.forms.autocomplete.formautofill", true]]}, testInputTypes);
    195  testAutocompleteInfoValue(true);
    196 });
    197 
    198 add_task(async function testAutocompletePreferenceDisabled() {
    199  await SpecialPowers.pushPrefEnv({"set": [["dom.forms.autocomplete.formautofill", false]]}, testInputTypes);
    200  testAutocompleteInfoValue(false);
    201 });
    202 
    203 </script>
    204 </pre>
    205 </body>
    206 </html>