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