textarea-maxlength.html (1575B)
1 <!DOCTYPE html> 2 <html> 3 4 <head> 5 <title>textarea maxlength</title> 6 <link rel="author" title="tigercosmos" href="mailto:phy.tiger@gmail.com"> 7 <link rel=help href="https://html.spec.whatwg.org/multipage/#attr-textarea-maxlength"> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 </head> 11 12 <body> 13 14 <textarea id="none"></textarea> 15 <textarea id="negative" maxlength="-5"></textarea> 16 <textarea id="non-numeric" maxlength="not-a-number"></textarea> 17 <textarea id="assign-negative"></textarea> 18 <textarea id="assign-non-numeric"></textarea> 19 20 <script> 21 test( 22 function () { 23 assert_equals(document.getElementById("none").maxLength, -1); 24 }, "Unset maxlength is -1"); 25 26 test( 27 function () { 28 assert_equals(document.getElementById("negative").maxLength, -1); 29 }, "Negative maxlength is always -1"); 30 31 test( 32 function () { 33 assert_equals(document.getElementById("non-numeric").maxLength, -1); 34 }, "Non-numeric maxlength is -1"); 35 36 test( 37 function () { 38 assert_throws_dom("INDEX_SIZE_ERR", function () { 39 document.getElementById("assign-negative").maxLength = -5; 40 }); 41 }, "Assigning negative integer throws IndexSizeError"); 42 43 test( 44 function () { 45 document.getElementById("assign-non-numeric").maxLength = "not-a-number"; 46 assert_equals(document.getElementById("assign-non-numeric").maxLength, 0); 47 }, "Assigning non-numeric to maxlength sets maxlength to 0"); 48 </script> 49 </body> 50 51 </html>