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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
/* 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 http://mozilla.org/MPL/2.0/. */
"use strict";
/* import-globals-from ../../mochitest/role.js */
/* import-globals-from ../../mochitest/states.js */
loadScripts(
{ name: "role.js", dir: MOCHITESTS_DIR },
{ name: "states.js", dir: MOCHITESTS_DIR }
);
function getChildRoles(parent) {
return parent
.getAttributeValue("AXChildren")
.map(c => c.getAttributeValue("AXRole"));
}
function getLinkedTitles(element) {
return element
.getAttributeValue("AXLinkedUIElements")
.map(c => c.getAttributeValue("AXTitle"));
}
/**
* Test radio group
*/
addAccessibleTask(
`<div role="radiogroup" id="radioGroup">
<div role="radio"
id="radioGroupItem1">
Regular crust
</div>
<div role="radio"
id="radioGroupItem2">
Deep dish
</div>
<div role="radio"
id="radioGroupItem3">
Thin crust
</div>
</div>`,
async (browser, accDoc) => {
let item1 = getNativeInterface(accDoc, "radioGroupItem1");
let item2 = getNativeInterface(accDoc, "radioGroupItem2");
let item3 = getNativeInterface(accDoc, "radioGroupItem3");
let titleList = ["Regular crust", "Deep dish", "Thin crust"];
Assert.deepEqual(
titleList,
[item1, item2, item3].map(c => c.getAttributeValue("AXTitle")),
"Title list matches"
);
let linkedElems = item1.getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 3, "Item 1 has three linked UI elems");
Assert.deepEqual(
getLinkedTitles(item1),
titleList,
"Item one has correctly ordered linked elements"
);
linkedElems = item2.getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 3, "Item 2 has three linked UI elems");
Assert.deepEqual(
getLinkedTitles(item2),
titleList,
"Item two has correctly ordered linked elements"
);
linkedElems = item3.getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 3, "Item 3 has three linked UI elems");
Assert.deepEqual(
getLinkedTitles(item3),
titleList,
"Item three has correctly ordered linked elements"
);
}
);
/**
* Test dynamic add to a radio group
*/
addAccessibleTask(
`<div role="radiogroup" id="radioGroup">
<div role="radio"
id="radioGroupItem1">
Option One
</div>
</div>`,
async (browser, accDoc) => {
let item1 = getNativeInterface(accDoc, "radioGroupItem1");
let linkedElems = item1.getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 1, "Item 1 has one linked UI elem");
is(
linkedElems[0].getAttributeValue("AXTitle"),
item1.getAttributeValue("AXTitle"),
"Item 1 is first element"
);
let reorder = waitForEvent(EVENT_REORDER, "radioGroup");
await SpecialPowers.spawn(browser, [], () => {
let d = content.document.createElement("div");
d.setAttribute("role", "radio");
content.document.getElementById("radioGroup").appendChild(d);
});
await reorder;
let radioGroup = getNativeInterface(accDoc, "radioGroup");
let groupMembers = radioGroup.getAttributeValue("AXChildren");
is(groupMembers.length, 2, "Radio group has two members");
let item2 = groupMembers[1];
item1 = getNativeInterface(accDoc, "radioGroupItem1");
let titleList = ["Option One", ""];
Assert.deepEqual(
titleList,
[item1, item2].map(c => c.getAttributeValue("AXTitle")),
"Title list matches"
);
linkedElems = item1.getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 2, "Item 1 has two linked UI elems");
Assert.deepEqual(
getLinkedTitles(item1),
titleList,
"Item one has correctly ordered linked elements"
);
linkedElems = item2.getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 2, "Item 2 has two linked UI elems");
Assert.deepEqual(
getLinkedTitles(item2),
titleList,
"Item two has correctly ordered linked elements"
);
}
);
/**
* Test input[type=radio] for single group
*/
addAccessibleTask(
`<input type="radio" id="cat" name="animal"><label for="cat">Cat</label>
<input type="radio" id="dog" name="animal"><label for="dog">Dog</label>
<input type="radio" id="catdog" name="animal"><label for="catdog">CatDog</label>`,
async (browser, accDoc) => {
let cat = getNativeInterface(accDoc, "cat");
let dog = getNativeInterface(accDoc, "dog");
let catdog = getNativeInterface(accDoc, "catdog");
let titleList = ["Cat", "Dog", "CatDog"];
Assert.deepEqual(
titleList,
[cat, dog, catdog].map(x => x.getAttributeValue("AXTitle")),
"Title list matches"
);
let linkedElems = cat.getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 3, "Cat has three linked UI elems");
Assert.deepEqual(
getLinkedTitles(cat),
titleList,
"Cat has correctly ordered linked elements"
);
linkedElems = dog.getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 3, "Dog has three linked UI elems");
Assert.deepEqual(
getLinkedTitles(dog),
titleList,
"Dog has correctly ordered linked elements"
);
linkedElems = catdog.getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 3, "Catdog has three linked UI elems");
Assert.deepEqual(
getLinkedTitles(catdog),
titleList,
"catdog has correctly ordered linked elements"
);
}
);
/**
* Test input[type=radio] for different groups
*/
addAccessibleTask(
`<input type="radio" id="cat" name="one"><label for="cat">Cat</label>
<input type="radio" id="dog" name="two"><label for="dog">Dog</label>
<input type="radio" id="catdog"><label for="catdog">CatDog</label>`,
async (browser, accDoc) => {
let cat = getNativeInterface(accDoc, "cat");
let dog = getNativeInterface(accDoc, "dog");
let catdog = getNativeInterface(accDoc, "catdog");
let linkedElems = cat.getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 1, "Cat has one linked UI elem");
is(
linkedElems[0].getAttributeValue("AXTitle"),
cat.getAttributeValue("AXTitle"),
"Cat is only element"
);
linkedElems = dog.getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 1, "Dog has one linked UI elem");
is(
linkedElems[0].getAttributeValue("AXTitle"),
dog.getAttributeValue("AXTitle"),
"Dog is only element"
);
linkedElems = catdog.getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 0, "Catdog has no linked UI elem");
}
);
/**
* Test input[type=radio] for single group across DOM
*/
addAccessibleTask(
`<input type="radio" id="cat" name="animal"><label for="cat">Cat</label>
<div>
<span>
<input type="radio" id="dog" name="animal"><label for="dog">Dog</label>
</span>
</div>
<div>
<input type="radio" id="catdog" name="animal"><label for="catdog">CatDog</label>
</div>`,
async (browser, accDoc) => {
let cat = getNativeInterface(accDoc, "cat");
let dog = getNativeInterface(accDoc, "dog");
let catdog = getNativeInterface(accDoc, "catdog");
let titleList = ["Cat", "Dog", "CatDog"];
Assert.deepEqual(
titleList,
[cat, dog, catdog].map(x => x.getAttributeValue("AXTitle")),
"Title list matches"
);
let linkedElems = cat.getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 3, "Cat has three linked UI elems");
Assert.deepEqual(
getLinkedTitles(cat),
titleList,
"cat has correctly ordered linked elements"
);
linkedElems = dog.getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 3, "Dog has three linked UI elems");
Assert.deepEqual(
getLinkedTitles(dog),
titleList,
"dog has correctly ordered linked elements"
);
linkedElems = catdog.getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 3, "Catdog has three linked UI elems");
Assert.deepEqual(
getLinkedTitles(catdog),
titleList,
"catdog has correctly ordered linked elements"
);
}
);
/**
* Test dynamic add of input[type=radio] in a single group
*/
addAccessibleTask(
`<div id="container"><input type="radio" id="cat" name="animal"></div>`,
async (browser, accDoc) => {
let cat = getNativeInterface(accDoc, "cat");
let container = getNativeInterface(accDoc, "container");
let containerChildren = container.getAttributeValue("AXChildren");
is(containerChildren.length, 1, "container has one button");
is(
containerChildren[0].getAttributeValue("AXRole"),
"AXRadioButton",
"Container child is radio button"
);
let linkedElems = cat.getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 1, "Cat has 1 linked UI elem");
is(
linkedElems[0].getAttributeValue("AXTitle"),
cat.getAttributeValue("AXTitle"),
"Cat is first element"
);
let reorder = waitForEvent(EVENT_REORDER, "container");
await SpecialPowers.spawn(browser, [], () => {
let input = content.document.createElement("input");
input.setAttribute("type", "radio");
input.setAttribute("name", "animal");
content.document.getElementById("container").appendChild(input);
});
await reorder;
container = getNativeInterface(accDoc, "container");
containerChildren = container.getAttributeValue("AXChildren");
is(containerChildren.length, 2, "container has two children");
Assert.deepEqual(
getChildRoles(container),
["AXRadioButton", "AXRadioButton"],
"Both children are radio buttons"
);
linkedElems = containerChildren[0].getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 2, "Cat has 2 linked elements");
linkedElems = containerChildren[1].getAttributeValue("AXLinkedUIElements");
is(linkedElems.length, 2, "New button has 2 linked elements");
}
);
|