tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug535043.html (2574B)


      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">
     23 
     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");
     30  }
     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');
     44  }
     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 );
     51  }
     52 }
     53 
     54 SimpleTest.waitForFocus(function() {
     55  var textAreas = document.getElementsByTagName('textarea');
     56  for (var i = 0; i < textAreas.length; i++) {
     57    checkTextArea(textAreas[i]);
     58  }
     59 
     60  textArea = textAreas[0];
     61  testNums = [-42, -1, 0, 2];
     62  for (var i = 0; i < testNums.length; i++) {
     63    textArea.removeAttribute('maxlength');
     64 
     65    var caught = false;
     66    try {
     67      textArea.maxLength = testNums[i];
     68    } catch (e) {
     69      caught = true;
     70    }
     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');
     75    }
     76    checkTextArea(textArea);
     77 
     78    textArea.setAttribute('maxlength', testNums[i]);
     79    checkTextArea(textArea);
     80  }
     81 
     82  SimpleTest.finish();
     83 });
     84 
     85 SimpleTest.waitForExplicitFinish();
     86 
     87 </script>
     88 </pre>
     89 </body>
     90 </html>