test_bug536891.html 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 type="application/javascript" 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. /** Test for Bug 536891 **/
  22. function checkNegativeMinMaxLength(element)
  23. {
  24. for(let type of ["min", "max"]) {
  25. /* value is set to -2 initially in the document, see above */
  26. is(element[type + "Length"], -1, "negative " + type + "Length should be considered invalid and represented as -1");
  27. // changing the property to an negative value should throw (see bug 536895).
  28. for(let value of [-15, -2147483648]) { // PR_INT32_MIN
  29. let threw = false;
  30. try {
  31. element[type + "Length"] = value;
  32. } catch(e) {
  33. threw = true;
  34. }
  35. is(threw, true, "setting " + type + "Length property to " + value + " should throw");
  36. }
  37. element[type + "Length"] = "non-numerical value";
  38. is(element[type + "Length"], 0, "setting " + type + "Length property to a non-numerical value should set it to zero");
  39. element.setAttribute(type + 'Length', -15);
  40. is(element[type + "Length"], -1, "negative " + type + "Length is not processed correctly when set dynamically");
  41. is(element.getAttribute(type + 'Length'), "-15", type + "Length attribute doesn't return the correct value");
  42. element.setAttribute(type + 'Length', 0);
  43. is(element[type + "Length"], 0, "zero " + type + "Length is not processed correctly");
  44. element.setAttribute(type + 'Length', 2147483647); // PR_INT32_MAX
  45. is(element[type + "Length"], 2147483647, "negative " + type + "Length is not processed correctly");
  46. element.setAttribute(type + 'Length', -2147483648); // PR_INT32_MIN
  47. is(element[type + "Length"], -1, "negative " + type + "Length is not processed correctly");
  48. element.setAttribute(type + 'Length', 'non-numerical-value');
  49. is(element[type + "Length"], -1, "non-numerical value should be considered invalid and represented as -1");
  50. }
  51. }
  52. /* TODO: correct behavior may be checked for email, telephone, url and search input types */
  53. checkNegativeMinMaxLength(document.getElementById('t'));
  54. checkNegativeMinMaxLength(document.getElementById('i'));
  55. checkNegativeMinMaxLength(document.getElementById('p'));
  56. </script>
  57. </pre>
  58. </body>
  59. </html>