1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/tests/mochitest/hyperlink/test_general.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,291 @@ 1.4 +<!DOCTYPE html> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=418368 1.8 +--> 1.9 +<head> 1.10 + <title>nsIHyperLinkAccessible chrome tests</title> 1.11 + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 1.12 + 1.13 + <script type="application/javascript" 1.14 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.15 + <script type="application/javascript" 1.16 + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.17 + 1.18 + <script type="application/javascript" 1.19 + src="../common.js"></script> 1.20 + <script type="application/javascript" 1.21 + src="../role.js"></script> 1.22 + <script type="application/javascript" 1.23 + src="../states.js"></script> 1.24 + <script type="application/javascript" 1.25 + src="../events.js"></script> 1.26 + 1.27 + <script type="application/javascript" 1.28 + src="hyperlink.js"></script> 1.29 + 1.30 + <script type="application/javascript"> 1.31 + function testThis(aID, aAcc, aRole, aAnchors, aName, aValid, aStartIndex, 1.32 + aEndIndex) 1.33 + { 1.34 + testRole(aAcc, aRole); 1.35 + is(aAcc.anchorCount, aAnchors, "Wrong number of anchors for ID " 1.36 + + aID + "!"); 1.37 + is(aAcc.getAnchor(0).name, aName, "Wrong name for ID " 1.38 + + aID + "!"); 1.39 + is(aAcc.valid, aValid, "No correct valid state for ID " 1.40 + + aID + "!"); 1.41 + is(aAcc.startIndex, aStartIndex, "Wrong startIndex value for ID " 1.42 + + aID + "!"); 1.43 + is(aAcc.endIndex, aEndIndex, "Wrong endIndex value for ID " 1.44 + + aID + "!"); 1.45 + } 1.46 + 1.47 + function testAction(aId, aAcc, aActionName) 1.48 + { 1.49 + var actionCount = aActionName ? 1 : 0; 1.50 + is(aAcc.actionCount, actionCount, 1.51 + "Wrong actions number for ID " + aId); 1.52 + try { 1.53 + is(aAcc.getActionName(0), aActionName, 1.54 + "Wrong action name for ID " + aId); 1.55 + } catch (e) { 1.56 + if (actionCount) 1.57 + ok(false, "Exception on action name getting for ID " + aId); 1.58 + else 1.59 + ok(true, "Correct action name for ID " + aId); 1.60 + } 1.61 + } 1.62 + 1.63 + //gA11yEventDumpToConsole = true; // debug stuff 1.64 + function doPreTest() 1.65 + { 1.66 + waitForImageMap("imgmap", doTest); 1.67 + } 1.68 + 1.69 + var gQueue = null; 1.70 + function doTest() 1.71 + { 1.72 + ////////////////////////////////////////////////////////////////////////// 1.73 + // normal hyperlink 1.74 + var normalHyperlinkAcc = getAccessible("NormalHyperlink", 1.75 + [nsIAccessibleHyperLink]); 1.76 + testThis("NormalHyperlink", normalHyperlinkAcc, ROLE_LINK, 1, 1.77 + "Mozilla Foundation", true, 17, 18); 1.78 + is(normalHyperlinkAcc.getURI(0).spec, "http://www.mozilla.org/", 1.79 + "URI wrong for normalHyperlinkElement!"); 1.80 + testStates(normalHyperlinkAcc, STATE_LINKED, 0); 1.81 + 1.82 + ////////////////////////////////////////////////////////////////////////// 1.83 + // ARIA hyperlink 1.84 + var ariaHyperlinkAcc = getAccessible("AriaHyperlink", 1.85 + [nsIAccessibleHyperLink]); 1.86 + testThis("AriaHyperlink", ariaHyperlinkAcc, ROLE_LINK, 1, 1.87 + "Mozilla Foundation Home", true, 30, 31); 1.88 + testStates(ariaHyperlinkAcc, STATE_LINKED, 0); 1.89 + testAction("AriaHyperlink", ariaHyperlinkAcc, "click"); 1.90 + 1.91 + ////////////////////////////////////////////////////////////////////////// 1.92 + // ARIA hyperlink with status invalid 1.93 + var invalidAriaHyperlinkAcc = getAccessible("InvalidAriaHyperlink", 1.94 + [nsIAccessibleHyperLink]); 1.95 + is(invalidAriaHyperlinkAcc.valid, false, "Should not be valid!"); 1.96 + testStates(invalidAriaHyperlinkAcc, STATE_LINKED, 0); 1.97 + 1.98 + ////////////////////////////////////////////////////////////////////////// 1.99 + // image map and its link children 1.100 + 1.101 + var imageMapHyperlinkAcc = getAccessible("imgmap", 1.102 + [nsIAccessibleHyperLink]); 1.103 + testThis("imgmap", imageMapHyperlinkAcc, ROLE_IMAGE_MAP, 2, "b", true, 1.104 + 79, 80); 1.105 + is(imageMapHyperlinkAcc.getURI(0).spec, 1.106 + "http://www.bbc.co.uk/radio4/atoz/index.shtml#b", "URI wrong!"); 1.107 + is(imageMapHyperlinkAcc.getURI(1).spec, 1.108 + "http://www.bbc.co.uk/radio4/atoz/index.shtml#a", "URI wrong!"); 1.109 + testStates(imageMapHyperlinkAcc, 0, 0); 1.110 + 1.111 + var area1 = getAccessible(imageMapHyperlinkAcc.firstChild, 1.112 + [nsIAccessibleHyperLink]); 1.113 + testThis("Area1", area1, ROLE_LINK, 1, "b", true, 0, 1); 1.114 + is(area1.getURI(0).spec, 1.115 + "http://www.bbc.co.uk/radio4/atoz/index.shtml#b", "URI wrong!"); 1.116 + testStates(area1, (STATE_LINKED)); 1.117 + 1.118 + var area2 = getAccessible(area1.nextSibling, 1.119 + [nsIAccessibleHyperLink]); 1.120 + testThis("Area2", area2, ROLE_LINK, 1, "a", true, 1, 2); 1.121 + is(area2.getURI(0).spec, 1.122 + "http://www.bbc.co.uk/radio4/atoz/index.shtml#a", "URI wrong!"); 1.123 + testStates(area2, (STATE_LINKED)); 1.124 + 1.125 + ////////////////////////////////////////////////////////////////////////// 1.126 + // empty hyperlink 1.127 + var EmptyHLAcc = getAccessible("emptyLink", 1.128 + [nsIAccessibleHyperLink]); 1.129 + testThis("emptyLink", EmptyHLAcc, ROLE_LINK, 1, null, true, 93, 94); 1.130 + testStates(EmptyHLAcc, (STATE_FOCUSABLE | STATE_LINKED), 0); 1.131 + testAction("emptyLink", EmptyHLAcc, "jump"); 1.132 + 1.133 + ////////////////////////////////////////////////////////////////////////// 1.134 + // normal hyperlink with embedded span 1.135 + var hyperlinkWithSpanAcc = getAccessible("LinkWithSpan", 1.136 + [nsIAccessibleHyperLink]); 1.137 + testThis("LinkWithSpan", hyperlinkWithSpanAcc, ROLE_LINK, 1, 1.138 + "Heise Online", true, 119, 120); 1.139 + is(hyperlinkWithSpanAcc.getURI(0).spec, "http://www.heise.de/", 1.140 + "URI wrong for hyperlinkElementWithSpan!"); 1.141 + testStates(hyperlinkWithSpanAcc, STATE_LINKED, 0); 1.142 + testAction("LinkWithSpan", hyperlinkWithSpanAcc, "jump"); 1.143 + 1.144 + ////////////////////////////////////////////////////////////////////////// 1.145 + // Named anchor, should never have state_linked 1.146 + var namedAnchorAcc = getAccessible("namedAnchor", 1.147 + [nsIAccessibleHyperLink]); 1.148 + testThis("namedAnchor", namedAnchorAcc, ROLE_LINK, 1, 1.149 + "This should never be of state_linked", true, 196, 197); 1.150 + testStates(namedAnchorAcc, STATE_SELECTABLE, 1.151 + 0, (STATE_FOCUSABLE | STATE_LINKED)); 1.152 + testAction("namedAnchor", namedAnchorAcc, ""); 1.153 + 1.154 + ////////////////////////////////////////////////////////////////////////// 1.155 + // No link (hasn't any attribute), should never have state_linked 1.156 + var noLinkAcc = getAccessible("noLink", 1.157 + [nsIAccessibleHyperLink]); 1.158 + testThis("noLink", noLinkAcc, ROLE_LINK, 1, 1.159 + "This should never be of state_linked", true, 254, 255); 1.160 + testStates(noLinkAcc, 0, 0, (STATE_FOCUSABLE | STATE_LINKED)); 1.161 + testAction("noLink", noLinkAcc, ""); 1.162 + 1.163 + ////////////////////////////////////////////////////////////////////////// 1.164 + // Link with registered 'click' event, should have state_linked 1.165 + var linkWithClickAcc = getAccessible("linkWithClick", 1.166 + [nsIAccessibleHyperLink]); 1.167 + testThis("linkWithClick", linkWithClickAcc, ROLE_LINK, 1, 1.168 + "This should have state_linked", true, 292, 293); 1.169 + testStates(linkWithClickAcc, STATE_LINKED, 0); 1.170 + testAction("linkWithClick", linkWithClickAcc, "click"); 1.171 + 1.172 + ////////////////////////////////////////////////////////////////////////// 1.173 + // Maps to group links (bug 431615). 1.174 + var linksMapAcc = getAccessible("linksmap"); 1.175 + 1.176 + ////////////////////////////////////////////////////////////////////////// 1.177 + // Link with title attribute, no name from the subtree (bug 438325). 1.178 + var id = "linkWithTitleNoNameFromSubtree"; 1.179 + var linkAcc = getAccessible(id, [nsIAccessibleHyperLink]); 1.180 + testThis(id, linkAcc, ROLE_LINK, 1, "Link with title", true, 344, 345); 1.181 + testStates(linkAcc, STATE_LINKED, 0); 1.182 + testAction(id, linkAcc, "jump"); 1.183 + 1.184 + ////////////////////////////////////////////////////////////////////////// 1.185 + // Link with title attribute, name from the subtree - onscreen name 1.186 + // (bug 438325). 1.187 + id = "linkWithTitleNameFromSubtree"; 1.188 + linkAcc = getAccessible(id, [nsIAccessibleHyperLink]); 1.189 + testThis(id, linkAcc, ROLE_LINK, 1, "the name from subtree", true, 393, 1.190 + 394); 1.191 + testStates(linkAcc, STATE_LINKED, 0); 1.192 + testAction(id, linkAcc, "jump"); 1.193 + 1.194 + ////////////////////////////////////////////////////////////////////////// 1.195 + // Link with title attribute, name from the nested html:img (bug 438325). 1.196 + id = "linkWithTitleNameFromImg"; 1.197 + linkAcc = getAccessible(id, [nsIAccessibleHyperLink]); 1.198 + testThis(id, linkAcc, ROLE_LINK, 1, "The title for link", true, 447, 1.199 + 448); 1.200 + testStates(linkAcc, STATE_LINKED, 0); 1.201 + testAction(id, linkAcc, "jump"); 1.202 + 1.203 + ////////////////////////////////////////////////////////////////////////// 1.204 + // Link with label, no name from the subtree (bug 438325). 1.205 + id = "linkWithLabelNoNameFromSubtree"; 1.206 + linkAcc = getAccessible(id, [nsIAccessibleHyperLink]); 1.207 + testThis(id, linkAcc, ROLE_LINK, 1, "Link with label and nested image:", 1.208 + true, 450, 451); 1.209 + testStates(linkAcc, STATE_LINKED, 0); 1.210 + testAction(id, linkAcc, "jump"); 1.211 + 1.212 + ////////////////////////////////////////////////////////////////////////// 1.213 + // Text accessible shouldn't implement nsIAccessibleHyperLink 1.214 + var res = isAccessible(getNode("namedAnchor").firstChild, 1.215 + [nsIAccessibleHyperLink]); 1.216 + ok(!res, "Text accessible shouldn't implement nsIAccessibleHyperLink"); 1.217 + 1.218 + ////////////////////////////////////////////////////////////////////////// 1.219 + // Test focus 1.220 + gQueue = new eventQueue(); 1.221 + 1.222 + gQueue.push(new focusLink("NormalHyperlink", true)); 1.223 + gQueue.push(new focusLink("AriaHyperlink", true)); 1.224 + gQueue.push(new focusLink("InvalidAriaHyperlink", false)); 1.225 + gQueue.push(new focusLink("LinkWithSpan", true)); 1.226 + 1.227 + gQueue.invoke(); // Will call SimpleTest.finish(); 1.228 + } 1.229 + 1.230 + SimpleTest.waitForExplicitFinish(); 1.231 + addA11yLoadEvent(doPreTest); 1.232 + </script> 1.233 + 1.234 +</head> 1.235 +<body><a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=418368">Mozilla Bug 418368</a 1.236 + ><p id="display"></p 1.237 + ><div id="content" style="display: none"></div 1.238 + ><pre id="test"> 1.239 + </pre 1.240 + ><br 1.241 + >Simple link:<br 1.242 + ><a id="NormalHyperlink" href="http://www.mozilla.org">Mozilla Foundation</a 1.243 + ><br>ARIA link:<br 1.244 + ><span id="AriaHyperlink" role="link" 1.245 + onclick="window.open('http://www.mozilla.org/');" 1.246 + tabindex="0">Mozilla Foundation Home</span 1.247 + ><br 1.248 + >Invalid, non-focusable hyperlink:<br 1.249 + ><span id="InvalidAriaHyperlink" role="link" aria-invalid="true" 1.250 + onclick="window.open('http:/www.mozilla.org/');">Invalid link</span 1.251 + ><br>Image map:<br 1.252 + ><map name="atoz_map" 1.253 + ><area href="http://www.bbc.co.uk/radio4/atoz/index.shtml#b" 1.254 + coords="17,0,30,14" 1.255 + alt="b" 1.256 + shape="rect"></area 1.257 + ><area href="http://www.bbc.co.uk/radio4/atoz/index.shtml#a" 1.258 + coords="0,0,13,14" 1.259 + alt="a" 1.260 + shape="rect"></area 1.261 + ></map 1.262 + ><img width="447" id="imgmap" 1.263 + height="15" 1.264 + usemap="#atoz_map" 1.265 + src="../letters.gif"><br>Empty link:<br 1.266 + ><a id="emptyLink" href=""><img src=""></a 1.267 + ><br>Link with embedded span<br 1.268 + ><a id="LinkWithSpan" href="http://www.heise.de/"><span lang="de">Heise Online</span></a 1.269 + ><br>Named anchor, must not have "linked" state for it to be exposed correctly:<br 1.270 + ><a id="namedAnchor" name="named_anchor">This should never be of state_linked</a 1.271 + ><br>Link having no attributes, must not have "linked" state:<a id="noLink" 1.272 + >This should never be of state_linked</a 1.273 + ><br>Link with registered 'click' event: <a id="linkWithClick" onclick="var clicked = true;" 1.274 + >This should have state_linked</a 1.275 + ><br>Link with title attribute (no name from subtree): <a 1.276 + id="linkWithTitleNoNameFromSubtree" href="http://www.heise.de/" 1.277 + title="Link with title"><img src=""/></a 1.278 + ><br>Link with title attribute (name from subtree): <a 1.279 + id="linkWithTitleNameFromSubtree" href="http://www.heise.de/" 1.280 + title="Link with title">the name from subtree</a 1.281 + ><br>Link with title attribute (name from nested image): <a 1.282 + id="linkWithTitleNameFromImg" href="http://www.heise.de/" 1.283 + title="Link with title"><img src="" alt="The title for link"/></a 1.284 + ><br><label for="linkWithLabelNoNameFromSubtree">Link with label and nested image: </label><a 1.285 + id="linkWithLabelNoNameFromSubtree" 1.286 + href="http://www.heise.de/"><img src=""/></a 1.287 + ><br>Map that is used to group links (www.w3.org/TR/WCAG10-HTML-TECHS/#group-bypass), also see the bug 431615:<br 1.288 + ><map id="linksmap" title="Site navigation"><ul 1.289 + ><li><a href="http://mozilla.org">About the project</a></li 1.290 + ><li><a href="http://mozilla.org">Sites and sounds</a></li 1.291 + ></ul 1.292 + ></map 1.293 +></body> 1.294 +</html>