Bug 1880216 - Migrate Fenix docs into Sphinx. r=owlish,geckoview-reviewers,android...
[gecko.git] / dom / html / test / test_bug535043.html
blob3eb046b3c55cf741360cba2e59c22b8253581867
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=535043
5 -->
6 <head>
7 <title>Test for Bug 535043</title>
8 <script src="/tests/SimpleTest/SimpleTest.js"></script>
9 <script src="/tests/SimpleTest/EventUtils.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=535043">Mozilla Bug 535043</a>
14 <p id="display"></p>
15 <div id="content">
16 <textarea></textarea>
17 <textarea maxlength="-1"></textarea>
18 <textarea maxlength="0"></textarea>
19 <textarea maxlength="2"></textarea>
20 </div>
21 <pre id="test">
22 <script type="text/javascript">
24 /** Test for Bug 535043 **/
25 function checkTextArea(textArea) {
26 textArea.value = '';
27 textArea.focus();
28 for (var j = 0; j < 3; j++) {
29 sendString("x");
31 var htmlMaxLength = textArea.getAttribute('maxlength');
32 var domMaxLength = textArea.maxLength;
33 if (htmlMaxLength == null) {
34 is(domMaxLength, -1,
35 'maxlength is unset but maxLength DOM attribute is not -1');
36 } else if (htmlMaxLength < 0) {
37 // Per the HTML5 spec, out-of-range values are supposed to translate to -1,
38 // not 0, but they don't?
39 is(domMaxLength, -1,
40 'maxlength is out of range but maxLength DOM attribute is not -1');
41 } else {
42 is(domMaxLength, parseInt(htmlMaxLength),
43 'maxlength in DOM does not match provided value');
45 if (textArea.maxLength == -1) {
46 is(textArea.value.length, 3,
47 'textarea with maxLength -1 should have no length limit');
48 } else {
49 is(textArea.value.length, textArea.maxLength, 'textarea has maxLength ' +
50 textArea.maxLength + ' but length ' + textArea.value.length );
54 SimpleTest.waitForFocus(function() {
55 var textAreas = document.getElementsByTagName('textarea');
56 for (var i = 0; i < textAreas.length; i++) {
57 checkTextArea(textAreas[i]);
60 textArea = textAreas[0];
61 testNums = [-42, -1, 0, 2];
62 for (var i = 0; i < testNums.length; i++) {
63 textArea.removeAttribute('maxlength');
65 var caught = false;
66 try {
67 textArea.maxLength = testNums[i];
68 } catch (e) {
69 caught = true;
71 if (testNums[i] < 0) {
72 ok(caught, 'Setting negative maxLength should throw exception');
73 } else {
74 ok(!caught, 'Setting nonnegative maxLength should not throw exception');
76 checkTextArea(textArea);
78 textArea.setAttribute('maxlength', testNums[i]);
79 checkTextArea(textArea);
82 SimpleTest.finish();
83 });
85 SimpleTest.waitForExplicitFinish();
87 </script>
88 </pre>
89 </body>
90 </html>