summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/ValidityState-tooLong-textarea.html
blob: 626f17b93ec44e4b32e9c694d2143e2bce3e11df (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description('Tests for tooLong flag with &lt;textarea> elements.');

var textarea = document.createElement('textarea');
document.body.appendChild(textarea);

debug('No maxlength and no value');
shouldBeFalse('textarea.validity.tooLong');

debug('');
debug('Non-dirty value');
textarea.defaultValue = 'abcde';
textarea.maxLength = 3;
shouldBe('textarea.value.length', '5');
shouldBeFalse('textarea.validity.tooLong');

textarea.defaultValue = 'abcdef';
shouldBe('textarea.value.length', '6');
shouldBeFalse('textarea.validity.tooLong');

debug('');
debug('Dirty value and longer than maxLength');
textarea = document.createElement('textarea');
document.body.appendChild(textarea);
textarea.defaultValue = 'abcde';
textarea.maxLength = 3;
textarea.focus();
textarea.setSelectionRange(5, 5);  // Move the cursor at the end.
eventSender.keyDown('backspace');
shouldBe('textarea.value.length', '4');
shouldBeTrue('textarea.validity.tooLong');
// Make the value <=maxLength.
eventSender.keyDown('backspace');
shouldBeFalse('textarea.validity.tooLong');

debug('');
debug('Sets a value via DOM property');
textarea = document.createElement('textarea');
document.body.appendChild(textarea);
textarea.maxLength = 3;
textarea.value = 'abcde';
shouldBeFalse('textarea.validity.tooLong');

debug('');
debug('Disabling makes the control valid');
textarea.focus();
textarea.setSelectionRange(5, 5);  // Move the cursor at the end.
eventSender.keyDown('backspace');
shouldBeTrue('textarea.validity.tooLong');
shouldBeFalse('textarea.disabled = true; textarea.validity.tooLong');
shouldBeTrue('textarea.disabled = false; textarea.validity.tooLong');

debug('');
debug('Grapheme length is not greater than maxLength though character length is greater');
// fancyX should be treated as 1 grapheme.
// U+0305 COMBINING OVERLINE
// U+0332 COMBINING LOW LINE
var fancyX = "x\u0305\u0332";
textarea = document.createElement('textarea');
document.body.appendChild(textarea);
textarea.value = fancyX + 'A'; // 4 characters, 2 grapheme cluster.
textarea.maxLength = 1;
textarea.focus();
shouldBeFalse('textarea.validity.tooLong');
eventSender.keyDown('backspace'); // Make the value dirty, 1 grapheme remains.
// Too long because there are three characters.
shouldBe('textarea.value.length', '3');
shouldBeTrue('textarea.validity.tooLong');

debug('');
debug('A value set by resetting a form doesn\'t make tooLong true.');
// Make a dirty textarea.
var parent = document.createElement('div');
document.body.appendChild(parent);
parent.innerHTML = '<form><textarea maxlength=2>abcdef</textarea></form>';
textarea = parent.firstChild.firstChild;
textarea.focus();
textarea.setSelectionRange(6, 6);
eventSender.keyDown('backspace');
shouldBeTrue('textarea.validity.tooLong');
parent.firstChild.reset();
shouldBe('textarea.value', '"abcdef"');
shouldBeFalse('textarea.validity.tooLong');

debug('');
debug('A value set by a child node change doesn\'t make tooLong true.');
parent.innerHTML = '<textarea maxlength=2>abc</textarea>';
textarea = parent.firstChild;
shouldBeFalse('textarea.validity.tooLong');
parent.firstChild.innerHTML = 'abcdef';
shouldBe('textarea.value', '"abcdef"');
shouldBeFalse('textarea.validity.tooLong');

debug('');
debug('minlength and maxlength together');
textarea.maxLength = 3;
textarea.minLength = 3;
textarea.value = 'abcde';
textarea.focus();
textarea.setSelectionRange(5, 5);
eventSender.keyDown('backspace');
shouldBeTrue('textarea.validity.tooLong');
shouldBeFalse('textarea.validity.tooShort');
eventSender.keyDown('backspace');
shouldBeFalse('textarea.validity.tooLong');
shouldBeFalse('textarea.validity.tooShort');
eventSender.keyDown('backspace');
shouldBeFalse('textarea.validity.tooLong');
shouldBeTrue('textarea.validity.tooShort');

debug('');
debug('minlength and maxlength clashing');
textarea.setAttribute('maxlength', '2');
textarea.setAttribute('minlength', '4');
textarea.value = 'abcde';
textarea.focus();
textarea.setSelectionRange(5, 5);
eventSender.keyDown('backspace');
shouldBeTrue('textarea.validity.tooLong');
shouldBeFalse('textarea.validity.tooShort');
eventSender.keyDown('backspace');
shouldBeTrue('textarea.validity.tooLong');
shouldBeTrue('textarea.validity.tooShort');
eventSender.keyDown('backspace');
shouldBeFalse('textarea.validity.tooLong');
shouldBeTrue('textarea.validity.tooShort');
eventSender.keyDown('backspace');
eventSender.keyDown('backspace');
shouldBeFalse('textarea.validity.tooLong');
shouldBeFalse('textarea.validity.tooShort');

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