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
|
<!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 <input> elements.');
var input = document.createElement('input');
document.body.appendChild(input);
debug('No maxlength and no value');
shouldBeFalse('input.validity.tooLong');
debug('');
debug('Non-dirty value');
input.setAttribute('value', 'abcde');
input.maxLength = 3;
shouldBe('input.value.length', '5');
shouldBeFalse('input.validity.tooLong');
input.setAttribute('value', 'abcdef');
shouldBe('input.value.length', '6');
shouldBeFalse('input.validity.tooLong');
debug('');
debug('Dirty value and longer than maxLength');
input = document.createElement('input');
document.body.appendChild(input);
input.setAttribute('value', 'abcde');
input.maxLength = 3;
input.focus();
input.setSelectionRange(5, 5); // Move the cursor at the end.
eventSender.keyDown('backspace');
shouldBe('input.value.length', '4');
shouldBeTrue('input.validity.tooLong');
// Make the value <=maxLength.
eventSender.keyDown('backspace');
shouldBeFalse('input.validity.tooLong');
debug('');
debug('Sets a value via DOM property');
input.maxLength = 3;
input.value = 'abcde';
shouldBeFalse('input.validity.tooLong');
debug('');
debug('Disabling makes the control valid');
input.focus();
input.setSelectionRange(5, 5); // Move the cursor at the end.
eventSender.keyDown('backspace');
shouldBeTrue('input.validity.tooLong');
shouldBeFalse('input.disabled = true; input.validity.tooLong');
shouldBeTrue('input.disabled = false; input.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";
input = document.createElement('input');
document.body.appendChild(input);
input.value = fancyX + 'A'; // 4 characters, 2 grapheme clusters.
input.maxLength = 1;
input.focus();
shouldBeFalse('input.validity.tooLong');
eventSender.keyDown('backspace'); // Make the value dirty, 1 grapheme remains.
// Too long because there are three characters.
shouldBe('input.value.length', '3');
shouldBeTrue('input.validity.tooLong');
debug('');
debug('Change the type with a too long value');
input.maxLength = 3;
input.value = 'abcde';
input.type = 'search';
input.focus();
input.setSelectionRange(5, 5);
eventSender.keyDown('backspace');
shouldBeTrue('input.validity.tooLong');
shouldBeFalse('input.type = "number"; input.validity.tooLong');
input.type = "text";
debug('');
debug('minlength and maxlength together');
input.maxLength = 3;
input.minLength = 3;
input.value = 'abcde';
input.focus();
input.setSelectionRange(5, 5);
eventSender.keyDown('backspace');
shouldBeTrue('input.validity.tooLong');
shouldBeFalse('input.validity.tooShort');
eventSender.keyDown('backspace');
shouldBeFalse('input.validity.tooLong');
shouldBeFalse('input.validity.tooShort');
eventSender.keyDown('backspace');
shouldBeFalse('input.validity.tooLong');
shouldBeTrue('input.validity.tooShort');
debug('');
debug('minlength and maxlength clashing');
input.setAttribute('maxlength', '2');
input.setAttribute('minlength', '4');
input.value = 'abcde';
input.focus();
input.setSelectionRange(5, 5);
eventSender.keyDown('backspace');
shouldBeTrue('input.validity.tooLong');
shouldBeFalse('input.validity.tooShort');
eventSender.keyDown('backspace');
shouldBeTrue('input.validity.tooLong');
shouldBeTrue('input.validity.tooShort');
eventSender.keyDown('backspace');
shouldBeFalse('input.validity.tooLong');
shouldBeTrue('input.validity.tooShort');
eventSender.keyDown('backspace');
eventSender.keyDown('backspace');
shouldBeFalse('input.validity.tooLong');
shouldBeFalse('input.validity.tooShort');
</script>
</body>
</html>
|