test_autocomplete.html (4786B)
1 <!DOCTYPE html> 2 <html> 3 <!-- 4 Test @autocomplete on <input>/<select>/<textarea> 5 --> 6 <head> 7 <title>Test for @autocomplete</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/> 10 <script> 11 "use strict"; 12 13 var values = [ 14 // @autocomplete content attribute, expected IDL attribute value 15 16 // Missing or empty attribute 17 [undefined, ""], 18 ["", ""], 19 20 // One token 21 ["on", "on"], 22 ["On", "on"], 23 ["off", "off"], 24 ["OFF", "off"], 25 ["name", "name"], 26 [" name ", "name"], 27 ["username", "username"], 28 [" username ", "username"], 29 ["cc-csc", ""], 30 ["one-time-code", ""], 31 ["language", ""], 32 [" language ", ""], 33 ["tel-extension", ""], 34 ["foobar", ""], 35 ["section-blue", ""], 36 [" WEBAUTHN ", "webauthn"], 37 38 // One token + WebAuthn credential type 39 ["on webauthn", ""], 40 ["off webauthn", ""], 41 ["webauthn webauthn", ""], 42 ["username WebAuthn", "username webauthn"], 43 ["current-PASSWORD webauthn", "current-password webauthn"], 44 45 // Two tokens 46 ["on off", ""], 47 ["off on", ""], 48 ["username tel", ""], 49 ["tel username ", ""], 50 [" username tel ", ""], 51 ["tel mobile", ""], 52 ["tel shipping", ""], 53 ["shipping tel", "shipping tel"], 54 ["shipPING tel", "shipping tel"], 55 ["mobile tel", "mobile tel"], 56 [" MoBiLe TeL ", "mobile tel"], 57 ["pager impp", ""], 58 ["fax tel-extension", ""], 59 ["XXX tel", ""], 60 ["XXX username", ""], 61 ["name section-blue", ""], 62 ["scetion-blue cc-name", ""], 63 ["pager language", ""], 64 ["fax url", ""], 65 ["section-blue name", "section-blue name"], 66 ["section-blue tel", "section-blue tel"], 67 ["webauthn username", ""], 68 69 // Two tokens + WebAuthn credential type 70 ["fax url webauthn", ""], 71 ["shipping tel webauthn", "shipping tel webauthn"], 72 73 // Three tokens 74 ["billing invalid tel", ""], 75 ["___ mobile tel", ""], 76 ["mobile foo tel", ""], 77 ["mobile tel foo", ""], 78 ["tel mobile billing", ""], 79 ["billing mobile tel", "billing mobile tel"], 80 [" BILLing MoBiLE tEl ", "billing mobile tel"], 81 ["billing home tel", "billing home tel"], 82 ["home section-blue tel", ""], 83 ["setion-blue work email", ""], 84 ["section-blue home address-level2", ""], 85 ["section-blue shipping name", "section-blue shipping name"], 86 ["section-blue mobile tel", "section-blue mobile tel"], 87 ["shipping webauthn tel", ""], 88 89 // Three tokens + WebAuthn credential type 90 ["invalid mobile tel webauthn", ""], 91 ["section-blue shipping name webauthn", "section-blue shipping name webauthn"], 92 93 // Four tokens 94 ["billing billing mobile tel", ""], 95 ["name section-blue shipping home", ""], 96 ["secti shipping work address-line1", ""], 97 ["section-blue shipping home name", ""], 98 ["section-blue shipping mobile tel", "section-blue shipping mobile tel"], 99 ["section-blue webauthn mobile tel", ""], 100 101 // Four tokens + WebAuthn credential type 102 ["section-blue shipping home name webauthn", ""], 103 ["section-blue shipping mobile tel webauthn", "section-blue shipping mobile tel webauthn"], 104 105 // Five tokens (invalid) 106 ["billing billing billing mobile tel", ""], 107 ["section-blue section-blue billing mobile tel", ""], 108 ["section-blue section-blue billing webauthn tel", ""], 109 110 // Five tokens + WebAuthn credential type (invalid) 111 ["billing billing billing mobile tel webauthn", ""], 112 ]; 113 114 var types = [undefined, "hidden", "text", "search"]; // Valid types for all non-multiline hints. 115 116 function checkAutocompleteValues(field, type) { 117 for (var test of values) { 118 if (typeof(test[0]) === "undefined") 119 field.removeAttribute("autocomplete"); 120 else 121 field.setAttribute("autocomplete", test[0]); 122 is(field.autocomplete, test[1], "Checking @autocomplete for @type=" + type + " of: " + test[0]); 123 is(field.autocomplete, test[1], "Checking cached @autocomplete for @type=" + type + " of: " + test[0]); 124 } 125 } 126 127 function start() { 128 var inputField = document.getElementById("input-field"); 129 for (var type of types) { 130 // Switch the input type 131 if (typeof(type) === "undefined") 132 inputField.removeAttribute("type"); 133 else 134 inputField.type = type; 135 checkAutocompleteValues(inputField, type || ""); 136 } 137 138 var selectField = document.getElementById("select-field"); 139 checkAutocompleteValues(selectField, "select"); 140 141 var textarea = document.getElementById("textarea"); 142 checkAutocompleteValues(textarea, "textarea"); 143 144 SimpleTest.finish(); 145 } 146 147 SimpleTest.waitForExplicitFinish(); 148 SpecialPowers.pushPrefEnv({"set": [["dom.forms.autocomplete.formautofill", true]]}, start); 149 </script> 150 </head> 151 152 <body> 153 <p id="display"></p> 154 <div id="content" style="display: none"> 155 <form> 156 <input id="input-field" /> 157 <select id="select-field" /> 158 <textarea id="textarea"></textarea> 159 </form> 160 </div> 161 <pre id="test"> 162 </pre> 163 </body> 164 </html>