1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/tests/mochitest/hypertext/test_general.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,156 @@ 1.4 +<!DOCTYPE html> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=428248 1.8 +--> 1.9 +<head> 1.10 + <title>nsIHyper>TextAccessible 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="../events.js"></script> 1.22 + 1.23 + <script type="application/javascript"> 1.24 + var gParagraphAcc; 1.25 + 1.26 + function testLinkIndexAtOffset(aID, aOffset, aIndex) 1.27 + { 1.28 + var htAcc = getAccessible(aID, [nsIAccessibleHyperText]); 1.29 + is(htAcc.getLinkIndexAtOffset(aOffset), aIndex, 1.30 + "Wrong link index at offset " + aOffset + " for ID " + aID + "!"); 1.31 + } 1.32 + 1.33 + function testThis(aID, aCharIndex, aExpectedLinkIndex, aName) 1.34 + { 1.35 + testLinkIndexAtOffset(gParagraphAcc, aCharIndex, aExpectedLinkIndex); 1.36 + 1.37 + var linkAcc = gParagraphAcc.getLinkAt(aExpectedLinkIndex); 1.38 + ok(linkAcc, "No accessible for link " + aID + "!"); 1.39 + 1.40 + var linkIndex = gParagraphAcc.getLinkIndex(linkAcc); 1.41 + is(linkIndex, aExpectedLinkIndex, "Wrong link index for " + aID + "!"); 1.42 + 1.43 + // Just test the link's name to make sure we get the right one. 1.44 + is(linkAcc.getAnchor(0).name, aName, "Wrong name for " + aID + "!"); 1.45 + } 1.46 + 1.47 + //gA11yEventDumpToConsole = true; 1.48 + function doPreTest() 1.49 + { 1.50 + waitForImageMap("imgmap", doTest); 1.51 + } 1.52 + 1.53 + function doTest() 1.54 + { 1.55 + // Test link count 1.56 + gParagraphAcc = getAccessible("testParagraph", [nsIAccessibleHyperText]); 1.57 + is(gParagraphAcc.linkCount, 7, "Wrong link count for paragraph!"); 1.58 + 1.59 + // normal hyperlink 1.60 + testThis("NormalHyperlink", 14, 0, "Mozilla Foundation"); 1.61 + 1.62 + // ARIA hyperlink 1.63 + testThis("AriaHyperlink", 27, 1, "Mozilla Foundation Home"); 1.64 + 1.65 + // ARIA hyperlink with status invalid 1.66 + testThis("InvalidAriaHyperlink", 63, 2, "Invalid link"); 1.67 + 1.68 + // image map, but not its link children. They are not part of hypertext. 1.69 + testThis("imgmap", 76, 3, "b"); 1.70 + 1.71 + // empty hyperlink 1.72 + testThis("emptyLink", 90, 4, null); 1.73 + 1.74 + // normal hyperlink with embedded span 1.75 + testThis("LinkWithSpan", 116, 5, "Heise Online"); 1.76 + 1.77 + // Named anchor 1.78 + testThis("namedAnchor", 193, 6, "This should never be of state_linked"); 1.79 + 1.80 + // Paragraph with link 1.81 + var p2 = getAccessible("p2", [nsIAccessibleHyperText]); 1.82 + var link = p2.getLinkAt(0); 1.83 + is(link, p2.getChildAt(0), "Wrong link for p2"); 1.84 + is(p2.linkCount, 1, "Wrong link count for p2"); 1.85 + 1.86 + // getLinkIndexAtOffset, causes the offsets to be cached; 1.87 + testLinkIndexAtOffset("p4", 0, 0); // 1st 'mozilla' link 1.88 + testLinkIndexAtOffset("p4", 1, 1); // 2nd 'mozilla' link 1.89 + testLinkIndexAtOffset("p4", 2, -1); // ' ' of ' te' text node 1.90 + testLinkIndexAtOffset("p4", 3, -1); // 't' of ' te' text node 1.91 + testLinkIndexAtOffset("p4", 5, -1); // 'x' of 'xt ' text node 1.92 + testLinkIndexAtOffset("p4", 7, -1); // ' ' of 'xt ' text node 1.93 + testLinkIndexAtOffset("p4", 8, 2); // 3d 'mozilla' link 1.94 + testLinkIndexAtOffset("p4", 9, 2); // the end, latest link 1.95 + 1.96 + // the second pass to make sure link indexes are calculated propertly from 1.97 + // cached offsets. 1.98 + testLinkIndexAtOffset("p4", 0, 0); // 1st 'mozilla' link 1.99 + testLinkIndexAtOffset("p4", 1, 1); // 2nd 'mozilla' link 1.100 + testLinkIndexAtOffset("p4", 2, -1); // ' ' of ' te' text node 1.101 + testLinkIndexAtOffset("p4", 3, -1); // 't' of ' te' text node 1.102 + testLinkIndexAtOffset("p4", 5, -1); // 'x' of 'xt ' text node 1.103 + testLinkIndexAtOffset("p4", 7, -1); // ' ' of 'xt ' text node 1.104 + testLinkIndexAtOffset("p4", 8, 2); // 3d 'mozilla' link 1.105 + testLinkIndexAtOffset("p4", 9, 2); // the end, latest link 1.106 + 1.107 + SimpleTest.finish(); 1.108 + } 1.109 + 1.110 + SimpleTest.waitForExplicitFinish(); 1.111 + addA11yLoadEvent(doPreTest); 1.112 + </script> 1.113 + 1.114 +</head> 1.115 +<body> 1.116 + 1.117 + <a target="_blank" 1.118 + title="Create tests for NSIAccessibleHyperlink interface" 1.119 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=418368"> 1.120 + Mozilla Bug 418368 1.121 + </a><br> 1.122 + <p id="display"></p> 1.123 + <div id="content" style="display: none"></div> 1.124 + <pre id="test"> 1.125 + </pre> 1.126 + <p id="testParagraph"><br 1.127 + >Simple link:<br 1.128 + ><a id="NormalHyperlink" href="http://www.mozilla.org">Mozilla Foundation</a><br 1.129 + >ARIA link:<br 1.130 + ><span id="AriaHyperlink" role="link" 1.131 + onclick="window.open('http://www.mozilla.org/');" 1.132 + tabindex="0">Mozilla Foundation Home</span><br 1.133 + >Invalid, non-focusable hyperlink:<br 1.134 + ><span id="InvalidAriaHyperlink" role="link" aria-invalid="true" 1.135 + onclick="window.open('http:/www.mozilla.org/');">Invalid link</span><br 1.136 + >Image map:<br 1.137 + ><map name="atoz_map"><area href="http://www.bbc.co.uk/radio4/atoz/index.shtml#b" 1.138 + coords="17,0,30,14" 1.139 + alt="b" 1.140 + shape="rect"></area 1.141 + ><area href="http://www.bbc.co.uk/radio4/atoz/index.shtml#a" 1.142 + coords="0,0,13,14" 1.143 + alt="a" 1.144 + shape="rect"></area></map 1.145 + ><img width="447" id="imgmap" 1.146 + height="15" 1.147 + usemap="#atoz_map" 1.148 + src="../letters.gif"></img><br 1.149 + >Empty link:<br 1.150 + ><a id="emptyLink" href=""><img src=""></img></a><br 1.151 + >Link with embedded span<br 1.152 + ><a id="LinkWithSpan" href="http://www.heise.de/"><span lang="de">Heise Online</span></a><br 1.153 + >Named anchor, must not have "linked" state for it to be exposed correctly:<br 1.154 + ><a id="namedAnchor" name="named_anchor">This should never be of state_linked</a> 1.155 + </p> 1.156 + <p id="p2"><a href="http://mozilla.org">mozilla.org</a></p> 1.157 + <p id="p4"><a href="www">mozilla</a><a href="www">mozilla</a><span> te</span><span>xt </span><a href="www">mozilla</a></p> 1.158 +</body> 1.159 +</html>