blob: efb90e37399d63fead51a3139974c7dd06a41362 [file] [log] [blame]
<p>This page tests that the <tt>maxlength</tt> attribute of the <tt>&lt;input&gt;</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>
<input id="input">
<pre id="log"></pre>
<script>
function log(msg)
{
document.getElementById("log").appendChild(document.createTextNode(msg + "\n"));
}
if (window.layoutTestController)
layoutTestController.dumpAsText();
var testString = "";
var input = document.getElementById("input");
function attempt(length, expected)
{
log("Attempting to insert " + length + " characters with maxLength = " + input.getAttribute("maxlength") + ".");
if (testString.length > length)
testString = "";
for (var i = testString.length; i < length; ++i)
testString += i % 10;
input.value = testString;
if (input.value.length == expected)
log("PASS");
else
log("FAIL: Expected " + expected + " characters to be inserted, but " + input.value.length + " characters were actually inserted.");
}
var implicitMaxLength = 524288;
var stringLengthsToTest = [0, 5, 100, 101, 200, 524287, 524288, 524289, 530000];
var maxLengthsToTest = ["-1", "100", "524288", "600000"];
for (var i = 0; i < stringLengthsToTest.length; ++i) {
var stringLength = stringLengthsToTest[i];
for (var j = 0; j < maxLengthsToTest.length; ++j) {
var maxLength = maxLengthsToTest[j];
input.setAttribute("maxlength", maxLength);
if (maxLength < 0 || maxLength > implicitMaxLength)
maxLength = implicitMaxLength;
var expected = Math.min(stringLength, maxLength);
attempt(stringLength, expected);
}
}
</script>