toolkit/content/tests/chrome/window_panel_focus.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial