test_general.html (5871B)
1 <!DOCTYPE html> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=428248 5 --> 6 <head> 7 <title>nsIHyper>TextAccessible chrome tests</title> 8 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 9 10 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 11 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 12 13 <script type="application/javascript" 14 src="../common.js"></script> 15 <script type="application/javascript" 16 src="../events.js"></script> 17 18 <script type="application/javascript"> 19 var gParagraphAcc; 20 21 function testLinkIndexAtOffset(aID, aOffset, aIndex) { 22 var htAcc = getAccessible(aID, [nsIAccessibleHyperText]); 23 is(htAcc.getLinkIndexAtOffset(aOffset), aIndex, 24 "Wrong link index at offset " + aOffset + " for ID " + aID + "!"); 25 } 26 27 function testThis(aID, aCharIndex, aExpectedLinkIndex, aName) { 28 testLinkIndexAtOffset(gParagraphAcc, aCharIndex, aExpectedLinkIndex); 29 30 var linkAcc = gParagraphAcc.getLinkAt(aExpectedLinkIndex); 31 ok(linkAcc, "No accessible for link " + aID + "!"); 32 33 var linkIndex = gParagraphAcc.getLinkIndex(linkAcc); 34 is(linkIndex, aExpectedLinkIndex, "Wrong link index for " + aID + "!"); 35 36 // Just test the link's name to make sure we get the right one. 37 is(linkAcc.getAnchor(0).name, aName, "Wrong name for " + aID + "!"); 38 } 39 40 // gA11yEventDumpToConsole = true; 41 function doPreTest() { 42 waitForImageMap("imgmap", doTest); 43 } 44 45 function doTest() { 46 // Test link count 47 gParagraphAcc = getAccessible("testParagraph", [nsIAccessibleHyperText]); 48 is(gParagraphAcc.linkCount, 7, "Wrong link count for paragraph!"); 49 50 // normal hyperlink 51 testThis("NormalHyperlink", 14, 0, "Mozilla Foundation"); 52 53 // ARIA hyperlink 54 testThis("AriaHyperlink", 27, 1, "Mozilla Foundation Home"); 55 56 // ARIA hyperlink with status invalid 57 testThis("InvalidAriaHyperlink", 63, 2, "Invalid link"); 58 59 // image map, but not its link children. They are not part of hypertext. 60 testThis("imgmap", 76, 3, "b"); 61 62 // empty hyperlink 63 testThis("emptyLink", 90, 4, null); 64 65 // normal hyperlink with embedded span 66 testThis("LinkWithSpan", 116, 5, "Heise Online"); 67 68 // Named anchor 69 testThis("namedAnchor", 193, 6, null); 70 71 // Paragraph with link 72 var p2 = getAccessible("p2", [nsIAccessibleHyperText]); 73 var link = p2.getLinkAt(0); 74 is(link, p2.getChildAt(0), "Wrong link for p2"); 75 is(p2.linkCount, 1, "Wrong link count for p2"); 76 77 // getLinkIndexAtOffset, causes the offsets to be cached; 78 testLinkIndexAtOffset("p4", 0, 0); // 1st 'mozilla' link 79 testLinkIndexAtOffset("p4", 1, 1); // 2nd 'mozilla' link 80 testLinkIndexAtOffset("p4", 2, -1); // ' ' of ' te' text node 81 testLinkIndexAtOffset("p4", 3, -1); // 't' of ' te' text node 82 testLinkIndexAtOffset("p4", 5, -1); // 'x' of 'xt ' text node 83 testLinkIndexAtOffset("p4", 7, -1); // ' ' of 'xt ' text node 84 testLinkIndexAtOffset("p4", 8, 2); // 3d 'mozilla' link 85 testLinkIndexAtOffset("p4", 9, 2); // the end, latest link 86 87 // the second pass to make sure link indexes are calculated propertly from 88 // cached offsets. 89 testLinkIndexAtOffset("p4", 0, 0); // 1st 'mozilla' link 90 testLinkIndexAtOffset("p4", 1, 1); // 2nd 'mozilla' link 91 testLinkIndexAtOffset("p4", 2, -1); // ' ' of ' te' text node 92 testLinkIndexAtOffset("p4", 3, -1); // 't' of ' te' text node 93 testLinkIndexAtOffset("p4", 5, -1); // 'x' of 'xt ' text node 94 testLinkIndexAtOffset("p4", 7, -1); // ' ' of 'xt ' text node 95 testLinkIndexAtOffset("p4", 8, 2); // 3d 'mozilla' link 96 testLinkIndexAtOffset("p4", 9, 2); // the end, latest link 97 98 SimpleTest.finish(); 99 } 100 101 SimpleTest.waitForExplicitFinish(); 102 addA11yLoadEvent(doPreTest); 103 </script> 104 105 </head> 106 <body> 107 108 <a target="_blank" 109 title="Create tests for NSIAccessibleHyperlink interface" 110 href="https://bugzilla.mozilla.org/show_bug.cgi?id=418368"> 111 Mozilla Bug 418368 112 </a><br> 113 <p id="display"></p> 114 <div id="content" style="display: none"></div> 115 <pre id="test"> 116 </pre> 117 <p id="testParagraph"><br 118 >Simple link:<br 119 ><a id="NormalHyperlink" href="http://www.mozilla.org">Mozilla Foundation</a><br 120 >ARIA link:<br 121 ><span id="AriaHyperlink" role="link" 122 onclick="window.open('http://www.mozilla.org/');" 123 tabindex="0">Mozilla Foundation Home</span><br 124 >Invalid, non-focusable hyperlink:<br 125 ><span id="InvalidAriaHyperlink" role="link" aria-invalid="true" 126 onclick="window.open('http:/www.mozilla.org/');">Invalid link</span><br 127 >Image map:<br 128 ><map name="atoz_map"><area href="http://www.bbc.co.uk/radio4/atoz/index.shtml#b" 129 coords="17,0,30,14" 130 alt="b" 131 shape="rect"></area 132 ><area href="http://www.bbc.co.uk/radio4/atoz/index.shtml#a" 133 coords="0,0,13,14" 134 alt="a" 135 shape="rect"></area></map 136 ><img width="447" id="imgmap" 137 height="15" 138 usemap="#atoz_map" 139 src="../letters.gif"></img><br 140 >Empty link:<br 141 ><a id="emptyLink" href=""><img src=""></img></a><br 142 >Link with embedded span<br 143 ><a id="LinkWithSpan" href="http://www.heise.de/"><span lang="de">Heise Online</span></a><br 144 >Named anchor, must not have "linked" state for it to be exposed correctly:<br 145 ><a id="namedAnchor" name="named_anchor">This should never be of state_linked</a> 146 </p> 147 <p id="p2"><a href="http://mozilla.org">mozilla.org</a></p> 148 <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> 149 </body> 150 </html>