| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | |
| 2 <html> | |
| 3 <head> | |
| 4 <script src="../../../resources/js-test.js"></script> | |
| 5 </head> | |
| 6 <body> | |
| 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> | |
| 9 | |
| 10 <input id="input"> | |
| 11 | |
| 12 <script> | |
| 13 var implicitMaxLength = 524288; | |
| 14 var testString = ""; | |
| 15 var input = document.getElementById("input"); | |
| 16 | |
| 17 function attempt(length, expected) | |
| 18 { | |
| 19 debug("Attempting to insert " + length + " characters with maxLength = "
+ input.getAttribute("maxlength") + "."); | |
| 20 | |
| 21 if (testString.length > length) | |
| 22 testString = ""; | |
| 23 | |
| 24 for (var i = testString.length; i < length; ++i) | |
| 25 testString += i % 10; | |
| 26 | |
| 27 input.value = testString; | |
| 28 if (input.value.length == expected) | |
| 29 testPassed(""); | |
| 30 else | |
| 31 testFailed("Expected " + domExpected + " characters to be inserted,
but " + input.value.length + " characters were actually inserted."); | |
| 32 } | |
| 33 | |
| 34 var stringLengthsToTest = [0, 5, 100, 101, 200, 524287, 524288, 524289, 5300
00]; | |
| 35 var maxLengthsToTest = ["-1", "100", "524288", "600000"]; | |
| 36 | |
| 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); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 debug('Some tests for .maxLength property.'); | |
| 48 input = document.createElement("input"); | |
| 49 input.maxLength = 100; | |
| 50 shouldBe("input.getAttribute('maxlength')", "'100'"); | |
| 51 </script> | |
| 52 </body> | |
| 53 </html> | |
| OLD | NEW |