toolkit/content/tests/chrome/test_dialogfocus.xul

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:0c5d712a4357
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 width="500" height="600"
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/SimpleTest.js"/>
10 <script type="application/javascript"
11 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
12
13 <button id="test" label="Test"/>
14
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>
22
23 <script>
24 <![CDATA[
25
26 SimpleTest.waitForExplicitFinish();
27 SimpleTest.requestCompleteLog();
28
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";
34
35 var step = 0;
36 var fullKeyboardAccess = false;
37
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 }
46
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 }
56
57 var expectedFocus = expected[step - 1];
58 var win = window.openDialog("dialog_dialogfocus.xul", "_new", "chrome,dialog", step);
59
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 }
70
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 }
85
86 win.removeEventListener("focus", checkDialogFocus, true);
87 ok(match, "focus step " + step);
88
89 win.close();
90 SimpleTest.waitForFocus(runTest, window);
91 }
92
93 win.addEventListener("focus", checkDialogFocus, true);
94 }
95
96 SimpleTest.waitForFocus(startTest, window);
97
98 ]]>
99
100 </script>
101
102 </window>

mercurial