4 https://bugzilla.mozilla.org/show_bug.cgi?id=535043
7 <title>Test for Bug
535043</title>
8 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
9 <script src=
"/tests/SimpleTest/EventUtils.js"></script>
10 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
13 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=535043">Mozilla Bug
535043</a>
17 <textarea maxlength=
"-1"></textarea>
18 <textarea maxlength=
"0"></textarea>
19 <textarea maxlength=
"2"></textarea>
22 <script type=
"text/javascript">
24 /** Test for Bug 535043 **/
25 function checkTextArea(textArea
) {
28 for (var j
= 0; j
< 3; j
++) {
31 var htmlMaxLength
= textArea
.getAttribute('maxlength');
32 var domMaxLength
= textArea
.maxLength
;
33 if (htmlMaxLength
== null) {
35 'maxlength is unset but maxLength DOM attribute is not -1');
36 } else if (htmlMaxLength
< 0) {
37 // Per the HTML5 spec, out-of-range values are supposed to translate to -1,
38 // not 0, but they don't?
40 'maxlength is out of range but maxLength DOM attribute is not -1');
42 is(domMaxLength
, parseInt(htmlMaxLength
),
43 'maxlength in DOM does not match provided value');
45 if (textArea
.maxLength
== -1) {
46 is(textArea
.value
.length
, 3,
47 'textarea with maxLength -1 should have no length limit');
49 is(textArea
.value
.length
, textArea
.maxLength
, 'textarea has maxLength ' +
50 textArea
.maxLength
+ ' but length ' + textArea
.value
.length
);
54 SimpleTest
.waitForFocus(function() {
55 var textAreas
= document
.getElementsByTagName('textarea');
56 for (var i
= 0; i
< textAreas
.length
; i
++) {
57 checkTextArea(textAreas
[i
]);
60 textArea
= textAreas
[0];
61 testNums
= [-42, -1, 0, 2];
62 for (var i
= 0; i
< testNums
.length
; i
++) {
63 textArea
.removeAttribute('maxlength');
67 textArea
.maxLength
= testNums
[i
];
71 if (testNums
[i
] < 0) {
72 ok(caught
, 'Setting negative maxLength should throw exception');
74 ok(!caught
, 'Setting nonnegative maxLength should not throw exception');
76 checkTextArea(textArea
);
78 textArea
.setAttribute('maxlength', testNums
[i
]);
79 checkTextArea(textArea
);
85 SimpleTest
.waitForExplicitFinish();