PageRenderTime 17ms CodeModel.GetById 8ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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