Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / forms / input-maxlength.html
blob4d180916089e198b0e119bcdd63abbe1d9eb673a
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>&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>
8 <div id="console"></div>
10 <input id="input">
12 <script>
13 var implicitMaxLength = 524288;
14 var testString = "";
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)
22 testString = "";
24 for (var i = testString.length; i < length; ++i)
25 testString += i % 10;
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.");
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'");
53 </script>
54 </body>
55 </html>