|
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 title="Tests for focus on elements with anonymous focusable children" |
|
6 onload="setTimeout(runTests, 0);" |
|
7 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
8 |
|
9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
10 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
|
11 |
|
12 <label accesskey="a" control="menulist"/> |
|
13 <label accesskey="b" control="textbox"/> |
|
14 <label accesskey="c" control="scale"/> |
|
15 |
|
16 <menulist id="menulist" editable="true"> |
|
17 <menupopup> |
|
18 <menuitem label="One"/> |
|
19 </menupopup> |
|
20 </menulist> |
|
21 <textbox id="textbox"/> |
|
22 <scale id="scale"/> |
|
23 |
|
24 <script class="testbody" type="application/javascript"> |
|
25 <![CDATA[ |
|
26 |
|
27 SimpleTest.waitForExplicitFinish(); |
|
28 |
|
29 var gBlurs = 0, gFocuses = 0; |
|
30 var gExpectedBlur = ""; |
|
31 var gExpectedFocus = ""; |
|
32 |
|
33 function blurOccurred(event) { |
|
34 gBlurs++; |
|
35 is(event.originalTarget, gExpectedBlur, "blur " + gBlurs + "," + event.originalTarget.localName); |
|
36 } |
|
37 |
|
38 function focusOccurred(event) { |
|
39 gFocuses++; |
|
40 is(event.originalTarget, gExpectedFocus, "focus " + gFocuses + "," + event.originalTarget.localName); |
|
41 } |
|
42 |
|
43 function runTests() |
|
44 { |
|
45 addEventListener("focus", focusOccurred, true); |
|
46 addEventListener("blur", blurOccurred, true); |
|
47 |
|
48 gExpectedBlur = null; |
|
49 gExpectedFocus = $("menulist").inputField; |
|
50 $("menulist").focus(); |
|
51 |
|
52 gExpectedBlur = gExpectedFocus; |
|
53 gExpectedFocus = $("textbox").inputField; |
|
54 $("textbox").focus(); |
|
55 |
|
56 gExpectedBlur = gExpectedFocus; |
|
57 gExpectedFocus = document.getAnonymousNodes($("scale"))[0]; |
|
58 $("scale").focus(); |
|
59 |
|
60 var accessKeyDetails = (navigator.platform.indexOf("Mac") >= 0) ? |
|
61 { altKey: true, ctrlKey : true } : |
|
62 { altKey : true, shiftKey: true }; |
|
63 |
|
64 gExpectedBlur = document.getAnonymousNodes($("scale"))[0]; |
|
65 gExpectedFocus = $("menulist").inputField; |
|
66 synthesizeKey("a", accessKeyDetails); |
|
67 |
|
68 gExpectedBlur = gExpectedFocus; |
|
69 gExpectedFocus = $("textbox").inputField; |
|
70 synthesizeKey("b", accessKeyDetails); |
|
71 |
|
72 gExpectedBlur = gExpectedFocus; |
|
73 gExpectedFocus = document.getAnonymousNodes($("scale"))[0]; |
|
74 synthesizeKey("c", accessKeyDetails); |
|
75 |
|
76 if (navigator.platform.indexOf("Mac") == -1) { |
|
77 gExpectedBlur = gExpectedFocus; |
|
78 gExpectedFocus = $("textbox").inputField; |
|
79 synthesizeKey("VK_TAB", { shiftKey: true }); |
|
80 |
|
81 gExpectedBlur = gExpectedFocus; |
|
82 gExpectedFocus = $("menulist").inputField; |
|
83 synthesizeKey("VK_TAB", { shiftKey: true }); |
|
84 |
|
85 gExpectedBlur = gExpectedFocus; |
|
86 gExpectedFocus = $("textbox").inputField; |
|
87 synthesizeKey("VK_TAB", { }); |
|
88 |
|
89 gExpectedBlur = gExpectedFocus; |
|
90 gExpectedFocus = document.getAnonymousNodes($("scale"))[0]; |
|
91 synthesizeKey("VK_TAB", { }); |
|
92 |
|
93 is(gBlurs, 9, "correct number of blurs"); |
|
94 is(gFocuses, 10, "correct number of focuses"); |
|
95 } |
|
96 else { |
|
97 is(gBlurs, 5, "correct number of blurs"); |
|
98 is(gFocuses, 6, "correct number of focuses"); |
|
99 } |
|
100 |
|
101 removeEventListener("focus", focusOccurred, true); |
|
102 removeEventListener("blur", blurOccurred, true); |
|
103 |
|
104 SimpleTest.finish(); |
|
105 } |
|
106 |
|
107 ]]> |
|
108 </script> |
|
109 |
|
110 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
111 <p id="display"> |
|
112 </p> |
|
113 <div id="content" style="display: none"> |
|
114 </div> |
|
115 <pre id="test"> |
|
116 </pre> |
|
117 </body> |
|
118 |
|
119 </window> |