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.

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

mercurial