Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 <!DOCTYPE html>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=418368
5 -->
6 <head>
7 <title>nsIHyperLinkAccessible chrome tests</title>
8 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
10 <script type="application/javascript"
11 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
12 <script type="application/javascript"
13 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
15 <script type="application/javascript"
16 src="../common.js"></script>
17 <script type="application/javascript"
18 src="../role.js"></script>
19 <script type="application/javascript"
20 src="../states.js"></script>
21 <script type="application/javascript"
22 src="../events.js"></script>
24 <script type="application/javascript"
25 src="hyperlink.js"></script>
27 <script type="application/javascript">
28 function testThis(aID, aAcc, aRole, aAnchors, aName, aValid, aStartIndex,
29 aEndIndex)
30 {
31 testRole(aAcc, aRole);
32 is(aAcc.anchorCount, aAnchors, "Wrong number of anchors for ID "
33 + aID + "!");
34 is(aAcc.getAnchor(0).name, aName, "Wrong name for ID "
35 + aID + "!");
36 is(aAcc.valid, aValid, "No correct valid state for ID "
37 + aID + "!");
38 is(aAcc.startIndex, aStartIndex, "Wrong startIndex value for ID "
39 + aID + "!");
40 is(aAcc.endIndex, aEndIndex, "Wrong endIndex value for ID "
41 + aID + "!");
42 }
44 function testAction(aId, aAcc, aActionName)
45 {
46 var actionCount = aActionName ? 1 : 0;
47 is(aAcc.actionCount, actionCount,
48 "Wrong actions number for ID " + aId);
49 try {
50 is(aAcc.getActionName(0), aActionName,
51 "Wrong action name for ID " + aId);
52 } catch (e) {
53 if (actionCount)
54 ok(false, "Exception on action name getting for ID " + aId);
55 else
56 ok(true, "Correct action name for ID " + aId);
57 }
58 }
60 //gA11yEventDumpToConsole = true; // debug stuff
61 function doPreTest()
62 {
63 waitForImageMap("imgmap", doTest);
64 }
66 var gQueue = null;
67 function doTest()
68 {
69 //////////////////////////////////////////////////////////////////////////
70 // normal hyperlink
71 var normalHyperlinkAcc = getAccessible("NormalHyperlink",
72 [nsIAccessibleHyperLink]);
73 testThis("NormalHyperlink", normalHyperlinkAcc, ROLE_LINK, 1,
74 "Mozilla Foundation", true, 17, 18);
75 is(normalHyperlinkAcc.getURI(0).spec, "http://www.mozilla.org/",
76 "URI wrong for normalHyperlinkElement!");
77 testStates(normalHyperlinkAcc, STATE_LINKED, 0);
79 //////////////////////////////////////////////////////////////////////////
80 // ARIA hyperlink
81 var ariaHyperlinkAcc = getAccessible("AriaHyperlink",
82 [nsIAccessibleHyperLink]);
83 testThis("AriaHyperlink", ariaHyperlinkAcc, ROLE_LINK, 1,
84 "Mozilla Foundation Home", true, 30, 31);
85 testStates(ariaHyperlinkAcc, STATE_LINKED, 0);
86 testAction("AriaHyperlink", ariaHyperlinkAcc, "click");
88 //////////////////////////////////////////////////////////////////////////
89 // ARIA hyperlink with status invalid
90 var invalidAriaHyperlinkAcc = getAccessible("InvalidAriaHyperlink",
91 [nsIAccessibleHyperLink]);
92 is(invalidAriaHyperlinkAcc.valid, false, "Should not be valid!");
93 testStates(invalidAriaHyperlinkAcc, STATE_LINKED, 0);
95 //////////////////////////////////////////////////////////////////////////
96 // image map and its link children
98 var imageMapHyperlinkAcc = getAccessible("imgmap",
99 [nsIAccessibleHyperLink]);
100 testThis("imgmap", imageMapHyperlinkAcc, ROLE_IMAGE_MAP, 2, "b", true,
101 79, 80);
102 is(imageMapHyperlinkAcc.getURI(0).spec,
103 "http://www.bbc.co.uk/radio4/atoz/index.shtml#b", "URI wrong!");
104 is(imageMapHyperlinkAcc.getURI(1).spec,
105 "http://www.bbc.co.uk/radio4/atoz/index.shtml#a", "URI wrong!");
106 testStates(imageMapHyperlinkAcc, 0, 0);
108 var area1 = getAccessible(imageMapHyperlinkAcc.firstChild,
109 [nsIAccessibleHyperLink]);
110 testThis("Area1", area1, ROLE_LINK, 1, "b", true, 0, 1);
111 is(area1.getURI(0).spec,
112 "http://www.bbc.co.uk/radio4/atoz/index.shtml#b", "URI wrong!");
113 testStates(area1, (STATE_LINKED));
115 var area2 = getAccessible(area1.nextSibling,
116 [nsIAccessibleHyperLink]);
117 testThis("Area2", area2, ROLE_LINK, 1, "a", true, 1, 2);
118 is(area2.getURI(0).spec,
119 "http://www.bbc.co.uk/radio4/atoz/index.shtml#a", "URI wrong!");
120 testStates(area2, (STATE_LINKED));
122 //////////////////////////////////////////////////////////////////////////
123 // empty hyperlink
124 var EmptyHLAcc = getAccessible("emptyLink",
125 [nsIAccessibleHyperLink]);
126 testThis("emptyLink", EmptyHLAcc, ROLE_LINK, 1, null, true, 93, 94);
127 testStates(EmptyHLAcc, (STATE_FOCUSABLE | STATE_LINKED), 0);
128 testAction("emptyLink", EmptyHLAcc, "jump");
130 //////////////////////////////////////////////////////////////////////////
131 // normal hyperlink with embedded span
132 var hyperlinkWithSpanAcc = getAccessible("LinkWithSpan",
133 [nsIAccessibleHyperLink]);
134 testThis("LinkWithSpan", hyperlinkWithSpanAcc, ROLE_LINK, 1,
135 "Heise Online", true, 119, 120);
136 is(hyperlinkWithSpanAcc.getURI(0).spec, "http://www.heise.de/",
137 "URI wrong for hyperlinkElementWithSpan!");
138 testStates(hyperlinkWithSpanAcc, STATE_LINKED, 0);
139 testAction("LinkWithSpan", hyperlinkWithSpanAcc, "jump");
141 //////////////////////////////////////////////////////////////////////////
142 // Named anchor, should never have state_linked
143 var namedAnchorAcc = getAccessible("namedAnchor",
144 [nsIAccessibleHyperLink]);
145 testThis("namedAnchor", namedAnchorAcc, ROLE_LINK, 1,
146 "This should never be of state_linked", true, 196, 197);
147 testStates(namedAnchorAcc, STATE_SELECTABLE,
148 0, (STATE_FOCUSABLE | STATE_LINKED));
149 testAction("namedAnchor", namedAnchorAcc, "");
151 //////////////////////////////////////////////////////////////////////////
152 // No link (hasn't any attribute), should never have state_linked
153 var noLinkAcc = getAccessible("noLink",
154 [nsIAccessibleHyperLink]);
155 testThis("noLink", noLinkAcc, ROLE_LINK, 1,
156 "This should never be of state_linked", true, 254, 255);
157 testStates(noLinkAcc, 0, 0, (STATE_FOCUSABLE | STATE_LINKED));
158 testAction("noLink", noLinkAcc, "");
160 //////////////////////////////////////////////////////////////////////////
161 // Link with registered 'click' event, should have state_linked
162 var linkWithClickAcc = getAccessible("linkWithClick",
163 [nsIAccessibleHyperLink]);
164 testThis("linkWithClick", linkWithClickAcc, ROLE_LINK, 1,
165 "This should have state_linked", true, 292, 293);
166 testStates(linkWithClickAcc, STATE_LINKED, 0);
167 testAction("linkWithClick", linkWithClickAcc, "click");
169 //////////////////////////////////////////////////////////////////////////
170 // Maps to group links (bug 431615).
171 var linksMapAcc = getAccessible("linksmap");
173 //////////////////////////////////////////////////////////////////////////
174 // Link with title attribute, no name from the subtree (bug 438325).
175 var id = "linkWithTitleNoNameFromSubtree";
176 var linkAcc = getAccessible(id, [nsIAccessibleHyperLink]);
177 testThis(id, linkAcc, ROLE_LINK, 1, "Link with title", true, 344, 345);
178 testStates(linkAcc, STATE_LINKED, 0);
179 testAction(id, linkAcc, "jump");
181 //////////////////////////////////////////////////////////////////////////
182 // Link with title attribute, name from the subtree - onscreen name
183 // (bug 438325).
184 id = "linkWithTitleNameFromSubtree";
185 linkAcc = getAccessible(id, [nsIAccessibleHyperLink]);
186 testThis(id, linkAcc, ROLE_LINK, 1, "the name from subtree", true, 393,
187 394);
188 testStates(linkAcc, STATE_LINKED, 0);
189 testAction(id, linkAcc, "jump");
191 //////////////////////////////////////////////////////////////////////////
192 // Link with title attribute, name from the nested html:img (bug 438325).
193 id = "linkWithTitleNameFromImg";
194 linkAcc = getAccessible(id, [nsIAccessibleHyperLink]);
195 testThis(id, linkAcc, ROLE_LINK, 1, "The title for link", true, 447,
196 448);
197 testStates(linkAcc, STATE_LINKED, 0);
198 testAction(id, linkAcc, "jump");
200 //////////////////////////////////////////////////////////////////////////
201 // Link with label, no name from the subtree (bug 438325).
202 id = "linkWithLabelNoNameFromSubtree";
203 linkAcc = getAccessible(id, [nsIAccessibleHyperLink]);
204 testThis(id, linkAcc, ROLE_LINK, 1, "Link with label and nested image:",
205 true, 450, 451);
206 testStates(linkAcc, STATE_LINKED, 0);
207 testAction(id, linkAcc, "jump");
209 //////////////////////////////////////////////////////////////////////////
210 // Text accessible shouldn't implement nsIAccessibleHyperLink
211 var res = isAccessible(getNode("namedAnchor").firstChild,
212 [nsIAccessibleHyperLink]);
213 ok(!res, "Text accessible shouldn't implement nsIAccessibleHyperLink");
215 //////////////////////////////////////////////////////////////////////////
216 // Test focus
217 gQueue = new eventQueue();
219 gQueue.push(new focusLink("NormalHyperlink", true));
220 gQueue.push(new focusLink("AriaHyperlink", true));
221 gQueue.push(new focusLink("InvalidAriaHyperlink", false));
222 gQueue.push(new focusLink("LinkWithSpan", true));
224 gQueue.invoke(); // Will call SimpleTest.finish();
225 }
227 SimpleTest.waitForExplicitFinish();
228 addA11yLoadEvent(doPreTest);
229 </script>
231 </head>
232 <body><a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=418368">Mozilla Bug 418368</a
233 ><p id="display"></p
234 ><div id="content" style="display: none"></div
235 ><pre id="test">
236 </pre
237 ><br
238 >Simple link:<br
239 ><a id="NormalHyperlink" href="http://www.mozilla.org">Mozilla Foundation</a
240 ><br>ARIA link:<br
241 ><span id="AriaHyperlink" role="link"
242 onclick="window.open('http://www.mozilla.org/');"
243 tabindex="0">Mozilla Foundation Home</span
244 ><br
245 >Invalid, non-focusable hyperlink:<br
246 ><span id="InvalidAriaHyperlink" role="link" aria-invalid="true"
247 onclick="window.open('http:/www.mozilla.org/');">Invalid link</span
248 ><br>Image map:<br
249 ><map name="atoz_map"
250 ><area href="http://www.bbc.co.uk/radio4/atoz/index.shtml#b"
251 coords="17,0,30,14"
252 alt="b"
253 shape="rect"></area
254 ><area href="http://www.bbc.co.uk/radio4/atoz/index.shtml#a"
255 coords="0,0,13,14"
256 alt="a"
257 shape="rect"></area
258 ></map
259 ><img width="447" id="imgmap"
260 height="15"
261 usemap="#atoz_map"
262 src="../letters.gif"><br>Empty link:<br
263 ><a id="emptyLink" href=""><img src=""></a
264 ><br>Link with embedded span<br
265 ><a id="LinkWithSpan" href="http://www.heise.de/"><span lang="de">Heise Online</span></a
266 ><br>Named anchor, must not have "linked" state for it to be exposed correctly:<br
267 ><a id="namedAnchor" name="named_anchor">This should never be of state_linked</a
268 ><br>Link having no attributes, must not have "linked" state:<a id="noLink"
269 >This should never be of state_linked</a
270 ><br>Link with registered 'click' event: <a id="linkWithClick" onclick="var clicked = true;"
271 >This should have state_linked</a
272 ><br>Link with title attribute (no name from subtree): <a
273 id="linkWithTitleNoNameFromSubtree" href="http://www.heise.de/"
274 title="Link with title"><img src=""/></a
275 ><br>Link with title attribute (name from subtree): <a
276 id="linkWithTitleNameFromSubtree" href="http://www.heise.de/"
277 title="Link with title">the name from subtree</a
278 ><br>Link with title attribute (name from nested image): <a
279 id="linkWithTitleNameFromImg" href="http://www.heise.de/"
280 title="Link with title"><img src="" alt="The title for link"/></a
281 ><br><label for="linkWithLabelNoNameFromSubtree">Link with label and nested image: </label><a
282 id="linkWithLabelNoNameFromSubtree"
283 href="http://www.heise.de/"><img src=""/></a
284 ><br>Map that is used to group links (www.w3.org/TR/WCAG10-HTML-TECHS/#group-bypass), also see the bug 431615:<br
285 ><map id="linksmap" title="Site navigation"><ul
286 ><li><a href="http://mozilla.org">About the project</a></li
287 ><li><a href="http://mozilla.org">Sites and sounds</a></li
288 ></ul
289 ></map
290 ></body>
291 </html>