test_bug622597.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=622597
  5. -->
  6. <head>
  7. <title>Test for Bug 622597</title>
  8. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <script type="application/javascript" 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=622597">Mozilla Bug 622597</a>
  14. <p id="display"></p>
  15. <div id="content">
  16. <form>
  17. <input required>
  18. <textarea required></textarea>
  19. <select required><option>foo</option><option value="">bar</option></select>
  20. <button>submit</button>
  21. </form>
  22. </div>
  23. <pre id="test">
  24. <script type="application/javascript">
  25. /** Test for Bug 622597 **/
  26. var form = document.forms[0];
  27. var input = form.elements[0];
  28. var textarea = form.elements[1];
  29. var select = form.elements[2];
  30. var button = form.elements[3];
  31. function checkPseudoClasses(aElement, aValid, aInvalid)
  32. {
  33. is(aElement.matches(":-moz-ui-valid"), aValid,
  34. aValid ? aElement + " should match :-moz-ui-valid"
  35. : aElement + " should not match :-moz-ui-valid");
  36. is(aElement.matches(":-moz-ui-invalid"), aInvalid,
  37. aInvalid ? aElement + " should match :-moz-ui-invalid"
  38. : aElement + " should not match :-moz-ui-invalid");
  39. if (aValid && aInvalid) {
  40. ok(false,
  41. aElement + " should not match :-moz-ui-valid AND :-moz-ui-invalid");
  42. }
  43. }
  44. select.addEventListener("focus", function() {
  45. select.removeEventListener("focus", arguments.callee, false);
  46. SimpleTest.executeSoon(function() {
  47. form.noValidate = false;
  48. SimpleTest.executeSoon(function() {
  49. checkPseudoClasses(select, false, true);
  50. SimpleTest.finish();
  51. });
  52. });
  53. }, false);
  54. textarea.addEventListener("focus", function() {
  55. textarea.removeEventListener("focus", arguments.callee, false);
  56. SimpleTest.executeSoon(function() {
  57. form.noValidate = false;
  58. SimpleTest.executeSoon(function() {
  59. checkPseudoClasses(textarea, false, true);
  60. form.noValidate = true;
  61. select.selectedIndex = 1;
  62. select.focus();
  63. });
  64. });
  65. }, false);
  66. input.addEventListener("invalid", function() {
  67. input.removeEventListener("invalid", arguments.callee, false);
  68. input.addEventListener("focus", function() {
  69. input.removeEventListener("focus", arguments.callee, false);
  70. SimpleTest.executeSoon(function() {
  71. form.noValidate = false;
  72. SimpleTest.executeSoon(function() {
  73. checkPseudoClasses(input, false, true);
  74. form.noValidate = true;
  75. textarea.value = '';
  76. textarea.focus();
  77. });
  78. });
  79. }, false);
  80. SimpleTest.executeSoon(function() {
  81. form.noValidate = true;
  82. input.blur();
  83. input.value = '';
  84. input.focus();
  85. });
  86. }, false);
  87. button.addEventListener("focus", function() {
  88. button.removeEventListener("focus", arguments.callee, false);
  89. SimpleTest.executeSoon(function() {
  90. synthesizeKey("VK_RETURN", {});
  91. });
  92. }, false);
  93. SimpleTest.waitForExplicitFinish();
  94. SimpleTest.waitForFocus(function() {
  95. button.focus();
  96. });
  97. </script>
  98. </pre>
  99. </body>
  100. </html>