toolkit/content/tests/chrome/window_panel_focus.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/window_panel_focus.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,132 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     1.7 +
     1.8 +<window title="Panel Focus Tests"
     1.9 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.10 +
    1.11 +  <script type="application/javascript"
    1.12 +          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    1.13 +
    1.14 +<checkbox id="b1" label="Item 1"/>
    1.15 +
    1.16 +<!-- Focus should be in this order: 2 6 3 8 1 4 5 7 9 -->
    1.17 +<panel id="panel" norestorefocus="true" onpopupshown="panelShown()" onpopuphidden="panelHidden()">
    1.18 +  <button id="t1" label="Button One"/>
    1.19 +  <button id="t2" tabindex="1" label="Button Two" onblur="gButtonBlur++;"/>
    1.20 +  <button id="t3" tabindex="2" label="Button Three"/>
    1.21 +  <button id="t4" tabindex="0" label="Button Four"/>
    1.22 +  <button id="t5" label="Button Five"/>
    1.23 +  <button id="t6" tabindex="1" label="Button Six"/>
    1.24 +  <button id="t7" label="Button Seven"/>
    1.25 +  <button id="t8" tabindex="4" label="Button Eight"/>
    1.26 +  <button id="t9" label="Button Nine"/>
    1.27 +</panel>
    1.28 +
    1.29 +<panel id="noautofocusPanel" noautofocus="true"
    1.30 +       onpopupshown="noautofocusPanelShown()" onpopuphidden="noautofocusPanelHidden()">
    1.31 +  <textbox id="tb3"/>
    1.32 +</panel>
    1.33 +
    1.34 +<checkbox id="b2" label="Item 2" popup="panel" onblur="gButtonBlur++;"/>
    1.35 +
    1.36 +<script class="testbody" type="application/javascript">
    1.37 +<![CDATA[
    1.38 +
    1.39 +var gButtonBlur = 0;
    1.40 +
    1.41 +function showPanel()
    1.42 +{
    1.43 +  // click on the document so that the window has focus
    1.44 +  synthesizeMouse(document.documentElement, 1, 1, { });
    1.45 +
    1.46 +  // focus the button
    1.47 +  synthesizeKeyExpectEvent("VK_TAB", { }, $("b1"), "focus", "button focus");
    1.48 +  // tabbing again should skip the popup
    1.49 +  synthesizeKeyExpectEvent("VK_TAB", { }, $("b2"), "focus", "popup skipped in focus navigation");
    1.50 +
    1.51 +  $("panel").openPopup(null, "", 10, 10, false, false);
    1.52 +}
    1.53 +
    1.54 +function panelShown()
    1.55 +{
    1.56 +  // the focus on the button should have been removed when the popup was opened
    1.57 +  is(gButtonBlur, 1, "focus removed when popup opened");
    1.58 +
    1.59 +  // press tab numerous times to cycle through the buttons. The t2 button will
    1.60 +  // be blurred twice, so gButtonBlur will be 3 afterwards.
    1.61 +  synthesizeKeyExpectEvent("VK_TAB", { }, $("t2"), "focus", "tabindex 1");
    1.62 +  synthesizeKeyExpectEvent("VK_TAB", { }, $("t6"), "focus", "tabindex 2");
    1.63 +  synthesizeKeyExpectEvent("VK_TAB", { }, $("t3"), "focus", "tabindex 3");
    1.64 +  synthesizeKeyExpectEvent("VK_TAB", { }, $("t8"), "focus", "tabindex 4");
    1.65 +  synthesizeKeyExpectEvent("VK_TAB", { }, $("t1"), "focus", "tabindex 5");
    1.66 +  synthesizeKeyExpectEvent("VK_TAB", { }, $("t4"), "focus", "tabindex 6");
    1.67 +  synthesizeKeyExpectEvent("VK_TAB", { }, $("t5"), "focus", "tabindex 7");
    1.68 +  synthesizeKeyExpectEvent("VK_TAB", { }, $("t7"), "focus", "tabindex 8");
    1.69 +  synthesizeKeyExpectEvent("VK_TAB", { }, $("t9"), "focus", "tabindex 9");
    1.70 +  synthesizeKeyExpectEvent("VK_TAB", { }, $("t2"), "focus", "tabindex 10");
    1.71 +
    1.72 +  synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t9"), "focus", "back tabindex 1");
    1.73 +  synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t7"), "focus", "back tabindex 2");
    1.74 +  synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t5"), "focus", "back tabindex 3");
    1.75 +  synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t4"), "focus", "back tabindex 4");
    1.76 +  synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t1"), "focus", "back tabindex 5");
    1.77 +  synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t8"), "focus", "back tabindex 6");
    1.78 +  synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t3"), "focus", "back tabindex 7");
    1.79 +  synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t6"), "focus", "back tabindex 8");
    1.80 +  synthesizeKeyExpectEvent("VK_TAB", { shiftKey: true }, $("t2"), "focus", "back tabindex 9");
    1.81 +
    1.82 +  is(gButtonBlur, 3, "blur events fired within popup");
    1.83 +
    1.84 +  synthesizeKey("VK_ESCAPE", { });
    1.85 +}
    1.86 +
    1.87 +function ok(condition, message) {
    1.88 +  window.opener.wrappedJSObject.SimpleTest.ok(condition, message);
    1.89 +}
    1.90 +
    1.91 +function is(left, right, message) {
    1.92 +  window.opener.wrappedJSObject.SimpleTest.is(left, right, message);
    1.93 +}
    1.94 +
    1.95 +function panelHidden()
    1.96 +{
    1.97 +  // closing the popup should have blurred the focused element
    1.98 +  is(gButtonBlur, 4, "focus removed when popup closed");
    1.99 +
   1.100 +  // now that the panel is hidden, pressing tab should focus the elements in
   1.101 +  // the main window again
   1.102 +  synthesizeKeyExpectEvent("VK_TAB", { }, $("b1"), "focus", "focus after popup closed");
   1.103 +
   1.104 +  $("noautofocusPanel").openPopup(null, "", 10, 10, false, false);
   1.105 +}
   1.106 +
   1.107 +function noautofocusPanelShown()
   1.108 +{
   1.109 +  // with noautofocus="true", the focus should not be removed when the panel is
   1.110 +  // opened, so key events should still be fired at the checkbox.
   1.111 +  synthesizeKeyExpectEvent("VK_SPACE", { }, $("b1"), "command", "noautofocus");
   1.112 +  $("noautofocusPanel").hidePopup();
   1.113 +}
   1.114 +
   1.115 +function noautofocusPanelHidden()
   1.116 +{
   1.117 +  window.close();
   1.118 +  window.opener.wrappedJSObject.SimpleTest.finish();
   1.119 +}
   1.120 +
   1.121 +window.opener.wrappedJSObject.SimpleTest.waitForFocus(showPanel, window);
   1.122 +
   1.123 +]]>
   1.124 +</script>
   1.125 +
   1.126 +<body xmlns="http://www.w3.org/1999/xhtml">
   1.127 +<p id="display">
   1.128 +</p>
   1.129 +<div id="content" style="display: none">
   1.130 +</div>
   1.131 +<pre id="test">
   1.132 +</pre>
   1.133 +</body>
   1.134 +
   1.135 +</window>

mercurial