/toolkit/content/tests/chrome/window_panel_focus.xul

http://github.com/zpao/v8monkey · Unknown · 134 lines · 106 code · 28 blank · 0 comment · 0 complexity · 25699c26bf7f83bc9865ad8c6f54cc27 MD5 · raw file

  1. <?xml version="1.0"?>
  2. <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
  3. <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
  4. <window title="Panel Focus Tests"
  5. xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  6. <script type="application/javascript"
  7. src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
  8. <title>Panel Focus Tests</title>
  9. <checkbox id="b1" label="Item 1"/>
  10. <!-- Focus should be in this order: 2 6 3 8 1 4 5 7 9 -->
  11. <panel id="panel" norestorefocus="true" onpopupshown="panelShown()" onpopuphidden="panelHidden()">
  12. <button id="t1" label="Button One"/>
  13. <button id="t2" tabindex="1" label="Button Two" onblur="gButtonBlur++;"/>
  14. <button id="t3" tabindex="2" label="Button Three"/>
  15. <button id="t4" tabindex="0" label="Button Four"/>
  16. <button id="t5" label="Button Five"/>
  17. <button id="t6" tabindex="1" label="Button Six"/>
  18. <button id="t7" label="Button Seven"/>
  19. <button id="t8" tabindex="4" label="Button Eight"/>
  20. <button id="t9" label="Button Nine"/>
  21. </panel>
  22. <panel id="noautofocusPanel" noautofocus="true"
  23. onpopupshown="noautofocusPanelShown()" onpopuphidden="noautofocusPanelHidden()">
  24. <textbox id="tb3"/>
  25. </panel>
  26. <checkbox id="b2" label="Item 2" popup="panel" onblur="gButtonBlur++;"/>
  27. <script class="testbody" type="application/javascript">
  28. <![CDATA[
  29. var gButtonBlur = 0;
  30. function showPanel()
  31. {
  32. // click on the document so that the window has focus
  33. synthesizeMouse(document.documentElement, 1, 1, { });
  34. // focus the button
  35. synthesizeKeyExpectEvent("VK_TAB", { }, $("b1"), "focus", "button focus");
  36. // tabbing again should skip the popup
  37. synthesizeKeyExpectEvent("VK_TAB", { }, $("b2"), "focus", "popup skipped in focus navigation");
  38. $("panel").openPopup(null, "", 10, 10, false, false);
  39. }
  40. function panelShown()
  41. {
  42. // the focus on the button should have been removed when the popup was opened
  43. is(gButtonBlur, 1, "focus removed when popup opened");
  44. // press tab numerous times to cycle through the buttons. The t2 button will
  45. // be blurred twice, so gButtonBlur will be 3 afterwards.
  46. synthesizeKeyExpectEvent("VK_TAB", { }, $("t2"), "focus", "tabindex 1");
  47. synthesizeKeyExpectEvent("VK_TAB", { }, $("t6"), "focus", "tabindex 2");
  48. synthesizeKeyExpectEvent("VK_TAB", { }, $("t3"), "focus", "tabindex 3");
  49. synthesizeKeyExpectEvent("VK_TAB", { }, $("t8"), "focus", "tabindex 4");
  50. synthesizeKeyExpectEvent("VK_TAB", { }, $("t1"), "focus", "tabindex 5");
  51. synthesizeKeyExpectEvent("VK_TAB", { }, $("t4"), "focus", "tabindex 6");
  52. synthesizeKeyExpectEvent("VK_TAB", { }, $("t5"), "focus", "tabindex 7");
  53. synthesizeKeyExpectEvent("VK_TAB", { }, $("t7"), "focus", "tabindex 8");
  54. synthesizeKeyExpectEvent("VK_TAB", { }, $("t9"), "focus", "tabindex 9");
  55. synthesizeKeyExpectEvent("VK_TAB", { }, $("t2"), "focus", "tabindex 10");
  56. synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t9"), "focus", "back tabindex 1");
  57. synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t7"), "focus", "back tabindex 2");
  58. synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t5"), "focus", "back tabindex 3");
  59. synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t4"), "focus", "back tabindex 4");
  60. synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t1"), "focus", "back tabindex 5");
  61. synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t8"), "focus", "back tabindex 6");
  62. synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t3"), "focus", "back tabindex 7");
  63. synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t6"), "focus", "back tabindex 8");
  64. synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t2"), "focus", "back tabindex 9");
  65. is(gButtonBlur, 3, "blur events fired within popup");
  66. synthesizeKey("VK_ESCAPE", { });
  67. }
  68. function ok(condition, message) {
  69. window.opener.wrappedJSObject.SimpleTest.ok(condition, message);
  70. }
  71. function is(left, right, message) {
  72. window.opener.wrappedJSObject.SimpleTest.is(left, right, message);
  73. }
  74. function panelHidden()
  75. {
  76. // closing the popup should have blurred the focused element
  77. is(gButtonBlur, 4, "focus removed when popup closed");
  78. // now that the panel is hidden, pressing tab should focus the elements in
  79. // the main window again
  80. synthesizeKeyExpectEvent("VK_TAB", { }, $("b1"), "focus", "focus after popup closed");
  81. $("noautofocusPanel").openPopup(null, "", 10, 10, false, false);
  82. }
  83. function noautofocusPanelShown()
  84. {
  85. // with noautofocus="true", the focus should not be removed when the panel is
  86. // opened, so key events should still be fired at the checkbox.
  87. synthesizeKeyExpectEvent("VK_SPACE", { }, $("b1"), "command", "noautofocus");
  88. $("noautofocusPanel").hidePopup();
  89. }
  90. function noautofocusPanelHidden()
  91. {
  92. window.close();
  93. window.opener.wrappedJSObject.SimpleTest.finish();
  94. }
  95. window.opener.wrappedJSObject.SimpleTest.waitForFocus(showPanel, window);
  96. ]]>
  97. </script>
  98. <body xmlns="http://www.w3.org/1999/xhtml">
  99. <p id="display">
  100. </p>
  101. <div id="content" style="display: none">
  102. </div>
  103. <pre id="test">
  104. </pre>
  105. </body>
  106. </window>