| <!DOCTYPE html> |
| <meta charset=utf-8> |
| <title>Password input element</title> |
| <link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org"> |
| <link rel="help" href="https://html.spec.whatwg.org/multipage/#password-state-%28type=password%29"> |
| <script src="/resources/testharness.js"></script> |
| <script src="/resources/testharnessreport.js"></script> |
| <div id="log"></div> |
| <div style="display: none"> |
| <input id="password" type="password" /> |
| <input id=password2 type=password value="password"> |
| <input id="password_with_value" type="password" value="foobar" /> |
| </div> |
| <script type="text/javascript"> |
| setup(function() { |
| window.password = document.getElementById("password"); |
| }); |
| |
| test(function() { |
| assert_equals(password.value, ""); |
| assert_equals(document.getElementById("password_with_value").value, "foobar"); |
| }, "Value returns the current value for password"); |
| |
| test(function() { |
| password.value = "A"; |
| assert_equals(password.value, "A"); |
| assert_equals(password.getAttribute("value"), null); |
| password.value = "B"; |
| assert_equals(password.value, "B"); |
| assert_equals(password.getAttribute("value"), null); |
| }, "Setting value changes the current value for password, but not the value content attribute"); |
| |
| test(function() { |
| // Any LF (\n) must be stripped. |
| password.value = "\nAB"; |
| assert_equals(password.value, "AB"); |
| password.value = "A\nB"; |
| assert_equals(password.value, "AB"); |
| password.value = "AB\n"; |
| assert_equals(password.value, "AB"); |
| |
| // Any CR (\r) must be stripped. |
| password.value = "\rAB"; |
| assert_equals(password.value, "AB"); |
| password.value = "A\rB"; |
| assert_equals(password.value, "AB"); |
| password.value = "AB\r"; |
| assert_equals(password.value, "AB"); |
| |
| // Any combinations of LF CR must be stripped. |
| password.value = "\r\nAB"; |
| assert_equals(password.value, "AB"); |
| password.value = "A\r\nB"; |
| assert_equals(password.value, "AB"); |
| password.value = "AB\r\n"; |
| assert_equals(password.value, "AB"); |
| password.value = "\r\nA\n\rB\r\n"; |
| assert_equals(password.value, "AB"); |
| }, "Value sanitization algorithm should strip line breaks for password"); |
| |
| var pass = document.getElementById('password2'); |
| |
| test(function(){ |
| assert_equals(pass.value, "password"); |
| pass.value = " pass word "; |
| assert_equals(pass.value, " pass word "); |
| }, "sanitization algorithm doesn't strip leading and trailing whitespaces"); |
| |
| test(function(){ |
| pass.value = "pass\u000Aword"; |
| assert_equals(pass.value, "password"); |
| pass.value = "\u000Apassword\u000A"; |
| assert_equals(pass.value, "password"); |
| pass.value = "pass\u000Dword"; |
| assert_equals(pass.value, "password"); |
| pass.value = "\u000Dpassword\u000D"; |
| assert_equals(pass.value, "password"); |
| }, "sanitization algorithm strips line breaks"); |
| </script> |