tor-browser

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

test_bug536891.html (2768B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=536891
      5 -->
      6 <head>
      7  <title>Test for Bug 536891</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     10 </head>
     11 <body>
     12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=536891">Mozilla Bug 536891</a>
     13 <p id="display"></p>
     14 <div id="content" style="display: none">
     15 <textarea id="t" maxlength="-2" minlength="-2"></textarea>
     16 <input id="i" type="text" maxlength="-2" minlength="-2">
     17 <input id="p" type="password" maxlength="-2" minlength="-2">
     18 </div>
     19 <pre id="test">
     20 <script type="application/javascript">
     21 
     22 /** Test for Bug 536891 */
     23 
     24 function checkNegativeMinMaxLength(element)
     25 {
     26  for(let type of ["min", "max"]) {
     27    /* value is set to -2 initially in the document, see above */
     28    is(element[type + "Length"], -1, "negative " + type + "Length should be considered invalid and represented as -1");
     29 
     30    // changing the property to an negative value should throw (see bug 536895).
     31    for(let value of [-15, -2147483648]) { // PR_INT32_MIN
     32      let threw = false;
     33      try {
     34        element[type + "Length"] = value;
     35      } catch(e) {
     36        threw = true;
     37      }
     38      is(threw, true, "setting " + type + "Length property to " + value + " should throw");
     39    }
     40    element[type + "Length"] = "non-numerical value";
     41    is(element[type + "Length"], 0, "setting " + type + "Length property to a non-numerical value should set it to zero");
     42 
     43 
     44    element.setAttribute(type + 'Length', -15);
     45    is(element[type + "Length"], -1, "negative " + type + "Length is not processed correctly when set dynamically");
     46    is(element.getAttribute(type + 'Length'), "-15", type + "Length attribute doesn't return the correct value");
     47 
     48    element.setAttribute(type + 'Length', 0);
     49    is(element[type + "Length"], 0, "zero " + type + "Length is not processed correctly");
     50    element.setAttribute(type + 'Length', 2147483647); // PR_INT32_MAX 
     51    is(element[type + "Length"], 2147483647, "negative " + type + "Length is not processed correctly");
     52    element.setAttribute(type + 'Length', -2147483648);  // PR_INT32_MIN
     53    is(element[type + "Length"], -1, "negative " + type + "Length is not processed correctly");
     54    element.setAttribute(type + 'Length', 'non-numerical-value');
     55    is(element[type + "Length"], -1, "non-numerical value should be considered invalid and represented as -1");
     56  }
     57 }
     58 
     59 /* TODO: correct behavior may be checked for email, telephone, url and search input types */
     60 checkNegativeMinMaxLength(document.getElementById('t'));
     61 checkNegativeMinMaxLength(document.getElementById('i'));
     62 checkNegativeMinMaxLength(document.getElementById('p'));
     63 
     64 </script>
     65 </pre>
     66 </body>
     67 </html>