1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <script src=
"../../resources/js-test.js"></script>
7 <p>This page tests that the
<tt>maxlength
</tt> attribute of the
<tt><input
></tt> element works correctly.
<a href=
"http://bugs.webkit.org/show_bug.cgi?id=14388">http://bugs.webkit.org/show_bug.cgi?id=
14388</a></p>
8 <div id=
"console"></div>
13 var implicitMaxLength
= 524288;
15 var input
= document
.getElementById("input");
17 function attempt(length
, expected
)
19 debug("Attempting to insert " + length
+ " characters with maxLength = " + input
.getAttribute("maxlength") + ".");
21 if (testString
.length
> length
)
24 for (var i
= testString
.length
; i
< length
; ++i
)
27 input
.value
= testString
;
28 if (input
.value
.length
== expected
)
31 testFailed("Expected " + domExpected
+ " characters to be inserted, but " + input
.value
.length
+ " characters were actually inserted.");
34 var stringLengthsToTest
= [0, 5, 100, 101, 200, 524287, 524288, 524289, 530000];
35 var maxLengthsToTest
= ["-1", "100", "524288", "600000"];
37 for (var i
= 0; i
< stringLengthsToTest
.length
; ++i
) {
38 var stringLength
= stringLengthsToTest
[i
];
39 for (var j
= 0; j
< maxLengthsToTest
.length
; ++j
) {
40 var maxLength
= maxLengthsToTest
[j
];
41 input
.setAttribute("maxlength", maxLength
);
42 var expected
= Math
.min(stringLength
, implicitMaxLength
);
43 attempt(stringLength
, expected
);
47 debug('Some tests for .maxLength property.');
48 input
= document
.createElement("input");
49 shouldBe("input.maxLength", "implicitMaxLength");
50 shouldThrow("input.maxLength = -1", '"IndexSizeError: Failed to set the \'maxLength\' property on \'HTMLInputElement\': The value provided (-1) is negative."');
51 input
.maxLength
= 100;
52 shouldBe("input.getAttribute('maxlength')", "'100'");