summaryrefslogtreecommitdiff
path: root/dom/html/test/test_bug613019.html
blob: bb28d108a1e8b7b0589266f2584396c4932f021a (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
80
81
82
83
84
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=613019
-->
<head>
  <title>Test for Bug 613019</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=613019">Mozilla Bug 613019</a>
<div id="content">
  <input type="text" maxlength="2" style="width:200px" value="Test">
  <textarea maxlength="2" style="width:200px">Test</textarea>
  <input type="text" minlength="6" style="width:200px" value="Test">
  <textarea minlength="6" style="width:200px">Test</textarea>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Bug 613019 **/

function testInteractivityOfMaxLength(elem) {
  // verify that user interactivity is necessary for validity state to apply.
  is(elem.value, "Test", "Element has incorrect starting value.");
  is(elem.validity.tooLong, false, "Element should not be tooLong.");

  elem.setSelectionRange(elem.value.length, elem.value.length)
  elem.focus();

  synthesizeKey("VK_BACK_SPACE", {});
  is(elem.value, "Tes", "Element value was not changed correctly.");
  is(elem.validity.tooLong, true, "Element should still be tooLong.");

  synthesizeKey("VK_BACK_SPACE", {});
  is(elem.value, "Te", "Element value was not changed correctly.");
  is(elem.validity.tooLong, false, "Element should no longer be tooLong.");

  elem.value = "Test";
  is(elem.validity.tooLong, false,
     "Element should not be tooLong after non-interactive value change.");
}

function testInteractivityOfMinLength(elem) {
  // verify that user interactivity is necessary for validity state to apply.
  is(elem.value, "Test", "Element has incorrect starting value.");
  is(elem.validity.tooLong, false, "Element should not be tooShort.");

  elem.setSelectionRange(elem.value.length, elem.value.length)
  elem.focus();

  synthesizeKey("e", {});
  is(elem.value, "Teste", "Element value was not changed correctly.");
  is(elem.validity.tooShort, true, "Element should still be tooShort.");

  synthesizeKey("d", {});
  is(elem.value, "Tested", "Element value was not changed correctly.");
  is(elem.validity.tooShort, false, "Element should no longer be tooShort.");

  elem.value = "Test";
  is(elem.validity.tooShort, false,
     "Element should not be tooShort after non-interactive value change.");
}

function test() {
  window.getSelection().removeAllRanges();
  testInteractivityOfMaxLength(document.querySelector("input[type=text][maxlength]"));
  testInteractivityOfMaxLength(document.querySelector("textarea[maxlength]"));
  testInteractivityOfMinLength(document.querySelector("input[type=text][minlength]"));
  testInteractivityOfMinLength(document.querySelector("textarea[minlength]"));
  SimpleTest.finish();
}

window.onload = function() {
  SimpleTest.waitForExplicitFinish();
  setTimeout(test, 0);
};

</script>
</pre>
</body>
</html>