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