summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/text/input-text-maxlength.html
blob: 9f09c301cedde04b8dc73820fbbb599b3f1420aa (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
<!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>

<input type="text" size="5" value="12345" maxlength="4" id="input1">
<input type="text" size="5" maxlength="4" value="12345" id="input2">
<input type="text" id="f" size="5" maxlength="4" value="123">
<input type="text" id="e" size="5" maxlength="4" value="123">
<input type="text" id="d" size="5" value="12345">
<input type="text" id="c" size="5" value="12345">
<input type="text" size="5" value="12x&#x305;&#x332;45" maxlength="4" id="input7">
<input type="text" size="5" maxlength="4" value="12x&#x305;&#x332;45" id="input8">
<input type="text" id="j" size="5" maxlength="4" value="123">
<input type="text" id="i" size="5" maxlength="4" value="123">
<input type="text" id="h" size="5" value="12x&#x305;&#x332;45">
<input type="text" id="g" size="5" value="12x&#x305;&#x332;45">

<script>
function domValueOf(id) {
    return document.getElementById(id).value;
}
function visibleValueOf(id) {
    var el = document.getElementById(id);
    el.focus();
    document.execCommand('SelectAll');
    return document.getSelection().toString();
}

var fancyX = "x" + String.fromCharCode(0x305) + String.fromCharCode(0x332);

debug('maxlength and value that violates it, maxlength first');
shouldBe('domValueOf("input1")', '"12345"');
shouldBe('visibleValueOf("input1")', '"12345"');

debug('maxlength and value that violates it, maxlength first');
shouldBe('domValueOf("input2")', '"12345"');
shouldBe('visibleValueOf("input2")', '"12345"');

debug('set value attribute that violates maxlength');
document.getElementById("f").setAttribute('value', '12345');
shouldBe('domValueOf("f")', '"12345"');
shouldBe('visibleValueOf("input2")', '"12345"');

debug('set value property that violates maxlength');
document.getElementById("e").value = '12345';
shouldBe('domValueOf("e")', '"12345"');
shouldBe('visibleValueOf("e")', '"12345"');

debug('set maxlength attribute that is smaller than initial value');
document.getElementById("d").setAttribute('maxlength', 4);
shouldBe('domValueOf("d")', '"12345"');
shouldBe('visibleValueOf("d")', '"12345"');

debug('set maxLength property that is smaller than initial value');
document.getElementById("c").maxLength = 4;
shouldBe('domValueOf("c")', '"12345"');
shouldBe('visibleValueOf("c")', '"12345"');

debug('maxlength and value that violates it, maxlength first');
shouldBe('domValueOf("input7")', '"12" + fancyX + "45"');
shouldBe('visibleValueOf("input7")', '"12" + fancyX + "45"');

debug('maxlength and value that violates it, value first');
shouldBe('domValueOf("input8")', '"12" + fancyX + "45"');
shouldBe('visibleValueOf("input8")', '"12" + fancyX + "45"');

debug('set value attribute that violates maxlength');
document.getElementById("j").setAttribute('value', '12' + fancyX + '45');
shouldBe('domValueOf("j")', '"12" + fancyX + "45"');
shouldBe('visibleValueOf("j")', '"12" + fancyX + "45"');

debug('set value property that violates maxlength');
document.getElementById("i").value = '12' + fancyX + '45';
shouldBe('domValueOf("i")', '"12" + fancyX + "45"');
shouldBe('visibleValueOf("i")', '"12" + fancyX + "45"');

debug('set maxlength attribute that is smaller than initial value');
document.getElementById("h").setAttribute('maxlength', 4);
shouldBe('domValueOf("h")', '"12" + fancyX + "45"');
shouldBe('visibleValueOf("h")', '"12" + fancyX + "45"');

debug('set maxLength property that is smaller than initial value');
document.getElementById("g").maxLength = 4;
shouldBe('domValueOf("g")', '"12" + fancyX + "45"');
shouldBe('visibleValueOf("g")', '"12" + fancyX + "45"');
</script>
</body>
</html>