test_focus_disabled.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=375008
  5. -->
  6. <head>
  7. <meta charset="utf-8">
  8. <title>Test for Bug 375008</title>
  9. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  10. <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  11. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  12. </head>
  13. <body>
  14. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=375008">Mozilla Bug 375008</a>
  15. <p id="display"></p>
  16. <div id="content">
  17. <div id='not-focusable'>
  18. <!-- Disabled elements -->
  19. <button hidden disabled>foo</button>
  20. <input hidden disabled>
  21. <fieldset hidden disabled>foo</fieldset>
  22. <select hidden disabled><option>foo</option></select>
  23. <textarea hidden disabled></textarea>
  24. <optgroup hidden disabled><option>foo</option></optgroup>
  25. <option hidden disabled>foo</option>
  26. </div>
  27. <div id='focusable'>
  28. <button hidden>foo</button>
  29. <input hidden>
  30. <select hidden><option>foo</option></select>
  31. <textarea hidden></textarea>
  32. <!-- Those elements are not focusable by default. -->
  33. <fieldset tabindex=1 hidden>foo</fieldset>
  34. <optgroup tabindex=1 hidden><option>foo</option></optgroup>
  35. <option tabindex=1 hidden>foo</option>
  36. </div>
  37. <!-- Hidden elements, they have a frame but focus will go through them. -->
  38. <div id='hidden' style='visibility: hidden;'>
  39. <button hidden>foo</button>
  40. <input hidden>
  41. <fieldset hidden>foo</fieldset>
  42. <select hidden><option>foo</option></select>
  43. <textarea hidden></textarea>
  44. <optgroup hidden><option>foo</option></optgroup>
  45. <option hidden>foo</option>
  46. </div>
  47. <div>
  48. <input id='witness'>
  49. </div>
  50. </div>
  51. <pre id="test">
  52. <script type="application/javascript">
  53. /** Test for Bug 375008 **/
  54. /*
  55. * This test is divided in three parts:
  56. * - cases where focus isn't doable but blur should not happen;
  57. * - cases where focus is doable;
  58. * - cases where focus isn't doable but blur should still happen.
  59. */
  60. SimpleTest.waitForExplicitFinish();
  61. SimpleTest.waitForFocus(function() {
  62. // On Mac, this preference needs to be turned on to be able to focus all the
  63. // form controls we want to focus.
  64. SpecialPowers.pushPrefEnv({"set": [[ "accessibility.mouse_focuses_formcontrol", true ]]},
  65. runTest);
  66. });
  67. function runTest()
  68. {
  69. var witness = document.getElementById('witness');
  70. witness.focus();
  71. var notFocusableElements = document.getElementById('not-focusable').children;
  72. for (var i=0; i<notFocusableElements.length; ++i) {
  73. var element = notFocusableElements[i];
  74. element.hidden = false;
  75. synthesizeMouseAtCenter(element, {});
  76. is(document.activeElement, witness,
  77. "[" + element.tagName + "] witness should still be focused");
  78. // Cleanup.
  79. element.hidden = true;
  80. witness.focus();
  81. }
  82. var focusableElements = document.getElementById('focusable').children;
  83. for (var i=0; i<focusableElements.length; ++i) {
  84. var element = focusableElements[i];
  85. element.hidden = false;
  86. synthesizeMouseAtCenter(element, {});
  87. is(document.activeElement, element, "focus should have moved to " + element);
  88. // Cleanup.
  89. element.hidden = true;
  90. witness.focus();
  91. }
  92. var hiddenElements = document.getElementById('hidden').children;
  93. for (var i=0; i<hiddenElements.length; ++i) {
  94. var element = hiddenElements[i];
  95. element.hidden = false;
  96. synthesizeMouseAtCenter(element, {});
  97. is(document.activeElement, document.body,
  98. "focus should have moved to the body");
  99. // Cleanup.
  100. element.hidden = true;
  101. witness.focus();
  102. }
  103. SimpleTest.finish();
  104. }
  105. </script>
  106. </pre>
  107. </body>
  108. </html>