1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
"use strict";
function testLinkIndexAtOffset(id, offset, index) {
let htAcc = getAccessible(id, [nsIAccessibleHyperText]);
is(
htAcc.getLinkIndexAtOffset(offset),
index,
"Wrong link index at offset " + offset + " for ID " + id + "!"
);
}
function testThis(
paragraph,
docURI,
id,
charIndex,
expectedLinkIndex,
expectedAnchors,
expectedURIs,
valid = true
) {
testLinkIndexAtOffset(paragraph, charIndex, expectedLinkIndex);
let linkAcc = paragraph.getLinkAt(expectedLinkIndex);
ok(linkAcc, "No accessible for link " + id + "!");
is(linkAcc.valid, valid, `${id} is valid.`);
let linkIndex = paragraph.getLinkIndex(linkAcc);
is(linkIndex, expectedLinkIndex, "Wrong link index for " + id + "!");
is(linkAcc.anchorCount, expectedAnchors.length, "Correct number of anchors");
for (let i = 0; i < expectedAnchors.length; i++) {
let uri = linkAcc.getURI(i);
is(
(uri ? uri.spec : "").replace(docURI, ""),
expectedURIs[i],
`Wrong anchor URI at ${i} for "${id}"`
);
is(
getAccessibleDOMNodeID(linkAcc.getAnchor(i)),
expectedAnchors[i],
`Wrong anchor at ${i} for "${id}"`
);
}
}
/**
* Test hyperlinks
*/
addAccessibleTask(
`
<p id="testParagraph"><br
>Simple link:<br
><a id="NormalHyperlink" href="https://www.mozilla.org">Mozilla Foundation</a><br
>ARIA link:<br
><span id="AriaHyperlink" role="link"
onclick="window.open('https://www.mozilla.org/');"
tabindex="0">Mozilla Foundation Home</span><br
>Invalid, non-focusable hyperlink:<br
><span id="InvalidAriaHyperlink" role="link" aria-invalid="true"
onclick="window.open('https:/www.mozilla.org/');">Invalid link</span><br
>Image map:<br
><map name="atoz_map"><area href="https://www.bbc.co.uk/radio4/atoz/index.shtml#b"
coords="17,0,30,14"
id="b"
shape="rect"></area
><area href="https://www.bbc.co.uk/radio4/atoz/index.shtml#a"
coords="0,0,13,14"
id="a"
shape="rect"></area></map
><img width="447" id="imgmap"
height="15"
usemap="#atoz_map"
src="../letters.gif"></img><br
>Empty link:<br
><a id="emptyLink" href=""><img src=""></img></a><br
>Link with embedded span<br
><a id="LinkWithSpan" href="https://www.heise.de/"><span lang="de">Heise Online</span></a><br
>Named anchor, must not have "linked" state for it to be exposed correctly:<br
><a id="namedAnchor" name="named_anchor">This should never be of state_linked</a>
</p>
`,
function (browser, accDoc) {
const paragraph = findAccessibleChildByID(accDoc, "testParagraph", [
nsIAccessibleHyperText,
]);
is(paragraph.linkCount, 7, "Wrong link count for paragraph!");
const docURI = accDoc.URL;
// normal hyperlink
testThis(
paragraph,
docURI,
"NormalHyperlink",
14,
0,
["NormalHyperlink"],
["https://www.mozilla.org/"]
);
// ARIA hyperlink
testThis(
paragraph,
docURI,
"AriaHyperlink",
27,
1,
["AriaHyperlink"],
[""]
);
// ARIA hyperlink with status invalid
testThis(
paragraph,
docURI,
"InvalidAriaHyperlink",
63,
2,
["InvalidAriaHyperlink"],
[""],
false
);
// image map, but not its link children. They are not part of hypertext.
testThis(
paragraph,
docURI,
"imgmap",
76,
3,
["b", "a"],
[
"https://www.bbc.co.uk/radio4/atoz/index.shtml#b",
"https://www.bbc.co.uk/radio4/atoz/index.shtml#a",
]
);
// empty hyperlink
testThis(paragraph, docURI, "emptyLink", 90, 4, ["emptyLink"], [""]);
// normal hyperlink with embedded span
testThis(
paragraph,
docURI,
"LinkWithSpan",
116,
5,
["LinkWithSpan"],
["https://www.heise.de/"]
);
// Named anchor
testThis(paragraph, docURI, "namedAnchor", 193, 6, ["namedAnchor"], [""]);
},
{
chrome: true,
topLevel: true,
iframe: true,
remoteIframe: true,
}
);
/**
* Test paragraph with link
*/
addAccessibleTask(
`
<p id="p"><a href="http://mozilla.org">mozilla.org</a></p>
`,
function (browser, accDoc) {
// Paragraph with link
const p = findAccessibleChildByID(accDoc, "p", [nsIAccessibleHyperText]);
const link = p.getLinkAt(0);
is(link, p.getChildAt(0), "Wrong link for p2");
is(p.linkCount, 1, "Wrong link count for p2");
},
{
chrome: true,
topLevel: true,
iframe: true,
remoteIframe: true,
}
);
/**
* Test paragraph with link
*/
addAccessibleTask(
`
<p id="p"><a href="www">mozilla</a><a href="www">mozilla</a><span> te</span><span>xt </span><a href="www">mozilla</a></p>
`,
function (browser, accDoc) {
// Paragraph with link
const p = findAccessibleChildByID(accDoc, "p", [nsIAccessibleHyperText]);
// getLinkIndexAtOffset, causes the offsets to be cached;
testLinkIndexAtOffset(p, 0, 0); // 1st 'mozilla' link
testLinkIndexAtOffset(p, 1, 1); // 2nd 'mozilla' link
testLinkIndexAtOffset(p, 2, -1); // ' ' of ' te' text node
testLinkIndexAtOffset(p, 3, -1); // 't' of ' te' text node
testLinkIndexAtOffset(p, 5, -1); // 'x' of 'xt ' text node
testLinkIndexAtOffset(p, 7, -1); // ' ' of 'xt ' text node
testLinkIndexAtOffset(p, 8, 2); // 3d 'mozilla' link
testLinkIndexAtOffset(p, 9, 2); // the end, latest link
// the second pass to make sure link indexes are calculated propertly from
// cached offsets.
testLinkIndexAtOffset(p, 0, 0); // 1st 'mozilla' link
testLinkIndexAtOffset(p, 1, 1); // 2nd 'mozilla' link
testLinkIndexAtOffset(p, 2, -1); // ' ' of ' te' text node
testLinkIndexAtOffset(p, 3, -1); // 't' of ' te' text node
testLinkIndexAtOffset(p, 5, -1); // 'x' of 'xt ' text node
testLinkIndexAtOffset(p, 7, -1); // ' ' of 'xt ' text node
testLinkIndexAtOffset(p, 8, 2); // 3d 'mozilla' link
testLinkIndexAtOffset(p, 9, 2); // the end, latest link
},
{
chrome: true,
topLevel: true,
iframe: true,
remoteIframe: true,
}
);
|