|
1 <html> |
|
2 |
|
3 <head> |
|
4 <title>Accessible name testing on focus</title> |
|
5 |
|
6 <link rel="stylesheet" type="text/css" |
|
7 href="chrome://mochikit/content/tests/SimpleTest/test.css" /> |
|
8 |
|
9 <script type="application/javascript" |
|
10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
11 <script type="application/javascript" |
|
12 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
|
13 |
|
14 <script type="application/javascript" |
|
15 src="../common.js"></script> |
|
16 <script type="application/javascript" |
|
17 src="../events.js"></script> |
|
18 |
|
19 <script type="application/javascript"> |
|
20 /** |
|
21 * Checker for invokers. |
|
22 */ |
|
23 function actionChecker(aID, aDescription) |
|
24 { |
|
25 this.__proto__ = new invokerChecker(EVENT_FOCUS, aID); |
|
26 |
|
27 this.check = function actionChecker_check(aEvent) |
|
28 { |
|
29 var target = aEvent.accessible; |
|
30 is(target.description, aDescription, |
|
31 "Wrong description for " + prettyName(target)); |
|
32 } |
|
33 } |
|
34 |
|
35 var gFocusHandler = { |
|
36 handleEvent: function gFocusHandler_handleEvent(aEvent) { |
|
37 var elm = aEvent.target; |
|
38 if (elm.nodeType != nsIDOMNode.ELEMENT_NODE) |
|
39 return; |
|
40 |
|
41 gTooltipElm.style.display = "block"; |
|
42 |
|
43 elm.setAttribute("aria-describedby", "tooltip"); |
|
44 } |
|
45 }; |
|
46 |
|
47 var gBlurHandler = { |
|
48 handleEvent: function gBlurHandler_handleEvent(aEvent) { |
|
49 gTooltipElm.style.display = "none"; |
|
50 |
|
51 var elm = aEvent.target; |
|
52 if (elm.nodeType == nsIDOMNode.ELEMENT_NODE) |
|
53 elm.removeAttribute("aria-describedby"); |
|
54 } |
|
55 }; |
|
56 |
|
57 /** |
|
58 * Do tests. |
|
59 */ |
|
60 |
|
61 // gA11yEventDumpID = "eventdump"; // debug stuff |
|
62 //gA11yEventDumpToConsole = true; |
|
63 |
|
64 var gQueue = null; |
|
65 |
|
66 var gButtonElm = null; |
|
67 var gTextboxElm = null; |
|
68 var gTooltipElm = null; |
|
69 |
|
70 function doTests() |
|
71 { |
|
72 gButtonElm = getNode("button"); |
|
73 gTextboxElm = getNode("textbox"); |
|
74 gTooltipElm = getNode("tooltip"); |
|
75 |
|
76 gButtonElm.addEventListener("focus", gFocusHandler, false); |
|
77 gButtonElm.addEventListener("blur", gBlurHandler, false); |
|
78 gTextboxElm.addEventListener("focus", gFocusHandler, false); |
|
79 gTextboxElm.addEventListener("blur", gBlurHandler, false); |
|
80 |
|
81 // The aria-describedby is changed on DOM focus. Accessible description |
|
82 // should be updated when a11y focus is fired. |
|
83 gQueue = new eventQueue(nsIAccessibleEvent.EVENT_FOCUS); |
|
84 gQueue.onFinish = function() |
|
85 { |
|
86 gButtonElm.removeEventListener("focus", gFocusHandler, false); |
|
87 gButtonElm.removeEventListener("blur", gBlurHandler, false); |
|
88 gTextboxElm.removeEventListener("focus", gFocusHandler, false); |
|
89 gTextboxElm.removeEventListener("blur", gBlurHandler, false); |
|
90 } |
|
91 |
|
92 var descr = "It's a tooltip"; |
|
93 gQueue.push(new synthFocus("button", new actionChecker("button", descr))); |
|
94 gQueue.push(new synthTab("textbox", new actionChecker("textbox", descr))); |
|
95 |
|
96 gQueue.invoke(); // Will call SimpleTest.finish(); |
|
97 } |
|
98 |
|
99 SimpleTest.waitForExplicitFinish(); |
|
100 addA11yLoadEvent(doTests); |
|
101 </script> |
|
102 </head> |
|
103 |
|
104 <body> |
|
105 |
|
106 <a target="_blank" |
|
107 href="https://bugzilla.mozilla.org/show_bug.cgi?id=520709" |
|
108 title="mochitest to ensure name/description are updated on a11y focus if they were changed on DOM focus"> |
|
109 Mozilla Bug 520709 |
|
110 </a> |
|
111 <p id="display"></p> |
|
112 <div id="content" style="display: none"></div> |
|
113 <pre id="test"> |
|
114 </pre> |
|
115 |
|
116 <div id="tooltip" style="display: none" aria-hidden="true">It's a tooltip</div> |
|
117 <button id="button">button</button> |
|
118 <input id="textbox"> |
|
119 |
|
120 <div id="eventdump"></div> |
|
121 </body> |
|
122 </html> |