toolkit/content/tests/chrome/test_dialogfocus.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 width="500" height="600"
     6         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     8 <script type="application/javascript"
     9         src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    10 <script type="application/javascript"
    11         src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    13 <button id="test" label="Test"/>
    15 <body xmlns="http://www.w3.org/1999/xhtml">
    16 <p id="display"></p>
    17 <div id="content" style="display: none">
    18 </div>
    19 <pre id="test">
    20 </pre>
    21 </body>
    23 <script>
    24 <![CDATA[
    26 SimpleTest.waitForExplicitFinish();
    27 SimpleTest.requestCompleteLog();
    29 var expected = [ "one", "_extra2", "tab", "one", "tabbutton2", "tabbutton", "two", "textbox-yes", "one" ];
    30 // non-Mac will always focus the default button if any of the dialog buttons
    31 // would be focused
    32 if (navigator.platform.indexOf("Mac") == -1)
    33   expected[1] = "_accept";
    35 var step = 0;
    36 var fullKeyboardAccess = false;
    38 function startTest()
    39 {
    40   var testButton = document.getElementById("test");
    41   synthesizeKey("VK_TAB", { });
    42   fullKeyboardAccess = (document.activeElement == testButton);
    43   info("We " + (fullKeyboardAccess ? "have" : "don't have") + " full keyboard access");
    44   runTest();
    45 }
    47 function runTest()
    48 {
    49   step++;
    50   info("runTest(), step = " + step + ", expected = " + expected[step - 1]);
    51   if (step > expected.length || (!fullKeyboardAccess && step == 2)) {
    52     info("finishing");
    53     SimpleTest.finish();
    54     return;
    55   }
    57   var expectedFocus = expected[step - 1];
    58   var win = window.openDialog("dialog_dialogfocus.xul", "_new", "chrome,dialog", step);
    60   function checkDialogFocus(event)
    61   {
    62     info("checkDialogFocus()");
    63     // if full keyboard access is not on, just skip the tests
    64     var match = false;
    65     if (fullKeyboardAccess) {
    66       if (!(event.target instanceof Element)) {
    67         info("target not an Element");
    68         return;
    69       }
    71       if (expectedFocus == "textbox-yes")
    72         match = (win.document.activeElement == win.document.getElementById(expectedFocus).inputField);
    73       else if (expectedFocus[0] == "_")
    74         match = (win.document.activeElement.dlgType == expectedFocus.substring(1));
    75       else
    76         match = (win.document.activeElement.id == expectedFocus);
    77       info("match = " + match);
    78       if (!match)
    79         return;
    80     }
    81     else {
    82       match = (win.document.activeElement == win.document.documentElement);
    83       info("match = " + match);
    84     }
    86     win.removeEventListener("focus", checkDialogFocus, true);
    87     ok(match, "focus step " + step);
    89     win.close();
    90     SimpleTest.waitForFocus(runTest, window);
    91   }
    93   win.addEventListener("focus", checkDialogFocus, true);
    94 }
    96 SimpleTest.waitForFocus(startTest, window);
    98 ]]>
   100 </script>
   102 </window>

mercurial