summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/forms/the-input-element/password.html
blob: aac54aa1c72252d2e32355456407ce4d10cb33e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!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>