password.html (2948B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>Password input element</title> 4 <link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org"> 5 <link rel="help" href="https://html.spec.whatwg.org/multipage/#password-state-%28type=password%29"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <div id="log"></div> 9 <div style="display: none"> 10 <input id="password" type="password" /> 11 <input id=password2 type=password value="password"> 12 <input id="password_with_value" type="password" value="foobar" /> 13 </div> 14 <script type="text/javascript"> 15 setup(function() { 16 window.password = document.getElementById("password"); 17 }); 18 19 test(function() { 20 assert_equals(password.value, ""); 21 assert_equals(document.getElementById("password_with_value").value, "foobar"); 22 }, "Value returns the current value for password"); 23 24 test(function() { 25 password.value = "A"; 26 assert_equals(password.value, "A"); 27 assert_equals(password.getAttribute("value"), null); 28 password.value = "B"; 29 assert_equals(password.value, "B"); 30 assert_equals(password.getAttribute("value"), null); 31 }, "Setting value changes the current value for password, but not the value content attribute"); 32 33 test(function() { 34 // Any LF (\n) must be stripped. 35 password.value = "\nAB"; 36 assert_equals(password.value, "AB"); 37 password.value = "A\nB"; 38 assert_equals(password.value, "AB"); 39 password.value = "AB\n"; 40 assert_equals(password.value, "AB"); 41 42 // Any CR (\r) must be stripped. 43 password.value = "\rAB"; 44 assert_equals(password.value, "AB"); 45 password.value = "A\rB"; 46 assert_equals(password.value, "AB"); 47 password.value = "AB\r"; 48 assert_equals(password.value, "AB"); 49 50 // Any combinations of LF CR must be stripped. 51 password.value = "\r\nAB"; 52 assert_equals(password.value, "AB"); 53 password.value = "A\r\nB"; 54 assert_equals(password.value, "AB"); 55 password.value = "AB\r\n"; 56 assert_equals(password.value, "AB"); 57 password.value = "\r\nA\n\rB\r\n"; 58 assert_equals(password.value, "AB"); 59 }, "Value sanitization algorithm should strip line breaks for password"); 60 61 var pass = document.getElementById('password2'); 62 63 test(function(){ 64 assert_equals(pass.value, "password"); 65 pass.value = " pass word "; 66 assert_equals(pass.value, " pass word "); 67 }, "sanitization algorithm doesn't strip leading and trailing whitespaces"); 68 69 test(function(){ 70 pass.value = "pass\u000Aword"; 71 assert_equals(pass.value, "password"); 72 pass.value = "\u000Apassword\u000A"; 73 assert_equals(pass.value, "password"); 74 pass.value = "pass\u000Dword"; 75 assert_equals(pass.value, "password"); 76 pass.value = "\u000Dpassword\u000D"; 77 assert_equals(pass.value, "password"); 78 }, "sanitization algorithm strips line breaks"); 79 </script>