-
Notifications
You must be signed in to change notification settings - Fork 0
/
full_live_region_tests.js
334 lines (299 loc) · 9.95 KB
/
full_live_region_tests.js
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
322
323
324
325
326
327
328
329
330
331
332
333
334
// These are the different permutations of ARIA attributes to try.
var attrs = [
'role="alert"',
'aria-live="polite" aria-relevant="text additions" (default)',
'aria-live="polite" aria-relevant="additions"',
'aria-live="polite" aria-relevant="text"',
'aria-live="assertive" aria-relevant="text additions"'];
build();
var live_region_counter = 0;
addTests(
'alert',
'add new alert to page',
'<div></div>',
function(region) {
region.innerHTML = '<div role="alert">Alert ' + (++live_region_counter) + '.</div>';
});
addTests(
'alert',
'just changing the css position should not announce anything',
'<div ARIA-ATTRS>This is an alert.</div>',
function(region) {
region.style.position = 'absolute';
});
addTests(
'alert',
'changing the css position after deleting the alert text should not announce anything either',
'<div ARIA-ATTRS>This is an alert.</div>',
function(region) {
region.textContent = '';
region.style.position = 'absolute';
});
addTests(
'text',
'set textContent',
'<div ARIA-ATTRS></div>',
function(region) {
region.innerHTML = 'Live region succeeded ' + (++live_region_counter);
});
addTests(
'text',
'set textContent (repeat same text)',
'<div ARIA-ATTRS></div>',
function(region) {
region.innerHTML = 'Live region succeeded';
});
addTests(
'text',
'set textContent in inner div',
'<div ARIA-ATTRS><div id="setTextContentInInnerDiv"></div></div>',
function(region) {
document.getElementById('setTextContentInInnerDiv').innerHTML =
'Live region succeeded ' + (++live_region_counter);
});
addTests(
'text',
'set textContent in inner paragraph',
'<div ARIA-ATTRS><p id="setTextContentInInnerPara"></p></div>',
function(region) {
document.getElementById('setTextContentInInnerPara').innerHTML =
'Live region succeeded ' + (++live_region_counter);
});
addTests(
'text',
'set innerText replacing similar text',
'<div ARIA-ATTRS>Live region space</div>',
function(region) {
region.innerText = 'Live region succeeded ' + (++live_region_counter);
});
addTests(
'additions',
'append new div as child',
'<div ARIA-ATTRS></div>',
function(region) {
var msg = document.createElement('div');
var text = document.createTextNode('Live region succeeded ' + (++live_region_counter));
msg.appendChild(text);
region.appendChild(msg);
});
addTests(
'additions',
'append two new divs as children',
'<div ARIA-ATTRS></div>',
function(region) {
var msg = document.createElement('div');
var text = document.createTextNode('This live region has a first half ');
msg.appendChild(text);
region.appendChild(msg);
window.setTimeout(function() {
msg = document.createElement('div');
text = document.createTextNode('and a second half');
msg.appendChild(text);
region.appendChild(msg);
}, 50);
});
addTests(
'additions',
'add element to live region that already has content',
'<div ARIA-ATTRS><div>Live region failed.</div></div>',
function(region) {
var msg = document.createElement('div');
var text = document.createTextNode('Live region succeeded ' + (++live_region_counter));
msg.appendChild(text);
region.appendChild(msg);
});
addTests(
'additions',
'add element to atomic live region',
'<div ARIA-ATTRS aria-atomic="true">Live region s</div>',
function(region) {
var msg = document.createElement('span');
var text = document.createTextNode('ucceeded ' + (++live_region_counter));
msg.appendChild(text);
region.appendChild(msg);
});
addTests(
'additions',
'set textContent of two elements in an atomic live region',
'<div ARIA-ATTRS aria-atomic="true">' +
'<div id="atomic-a"></div>' +
'<div id="atomic-b">region</div>' +
'<div id="atomic-c"></div>' +
'</div>',
function(region) {
document.getElementById('atomic-a').textContent = 'Live';
document.getElementById('atomic-c').textContent = 'succeeded';
});
addTests(
'additions',
'set textContents of live region grandchild',
'<div ARIA-ATTRS>' +
'<div id="abc"></div>' +
'</div>',
function(region) {
document.getElementById('abc').textContent = 'Live region succeeded ' + (++ live_region_counter);
});
addTests(
'additions',
'change unrelated attribute in a live region, should not speak',
'<div id="foo15" ARIA-ATTRS>Live region failure' +
'</div>',
function(region) {
document.getElementById('foo15').className = 'cats-are-liquid';
});
addTests(
'additions',
'two live region changes, one second apart',
'<div ARIA-ATTRS id="first"></div>' +
'<div ARIA-ATTRS id="second"></div>',
function(region) {
document.getElementById('first').textContent =
'This utterance should be interrupted before it finishes';
setTimeout(function() {
document.getElementById('second').textContent = 'Live region succeeded ' + (++live_region_counter);
}, 1000);
});
addTests(
'additions',
'remove display none',
'<div ARIA-ATTRS><div style="display:none">Live region succeeded ' + (++live_region_counter) + '</div></div>',
function(region) {
region.firstElementChild.style.display = 'block';
});
addTests(
'additions',
'remove visibility hidden',
'<div ARIA-ATTRS><div style="visibility:hidden">Live region succeeded ' + (++live_region_counter) + '</div></div>',
function(region) {
region.firstElementChild.style.visibility = 'visible';
});
addTests(
'text',
'text node set data',
'<div ARIA-ATTRS>Live region failed.</div>',
function(region) {
region.firstChild.data = 'Live region succeeded ' + (++live_region_counter);
});
addTests(
'text',
'text node replaceData',
'<div ARIA-ATTRS>Live region failed.</div>',
function(region) {
region.firstChild.replaceData(12, 6, 'succeeded ' + (++live_region_counter));
});
addTests(
'additions',
'reparent div with existing text',
'<div ARIA-ATTRS></div>' +
'<div id="offscreen" style="position: absolute; left: -99999px;">' +
'Live region succeeded ' + (++live_region_counter) +
'</div>',
function(region) {
region.appendChild(document.getElementById('offscreen').firstChild);
});
addTests(
'additions',
'append img with alt text',
'<div ARIA-ATTRS></div>',
function(region) {
var img = document.createElement('img');
img.src = 'http://google.com/favicon.ico';
img.setAttribute('alt', 'Live region succeeded ' + (++live_region_counter));
region.appendChild(img);
});
addTests(
'text',
'change img alt text where img is contained within live region',
'<div ARIA-ATTRS>' +
'<img src="http://google.com/favicon.ico" alt="Live region failed.">' +
'</div>',
function(region) {
region.firstChild.setAttribute('alt', 'Live region succeeded ' + (++live_region_counter));
});
addTests(
'text',
'change img alt text where aria-live is on img itself',
'<div>' +
'<img ARIA-ATTRS src="http://google.com/favicon.ico" alt="Live region failed.">' +
'</div>',
function(region) {
region.firstChild.setAttribute('alt', 'Live region succeeded ' + (++live_region_counter));
});
addTests(
'additions',
'append button with inner text',
'<div ARIA-ATTRS></div>',
function(region) {
var b = document.createElement('button');
b.tabIndex = -1;
b.textContent = 'Live region succeeded ' + (++live_region_counter);
region.appendChild(b);
});
addTests(
'additions',
'append button with aria-label',
'<div ARIA-ATTRS></div>',
function(region) {
var b = document.createElement('button');
b.tabIndex = -1;
b.textContent = 'Live region failed.';
b.setAttribute('aria-label', 'Live region succeeded ' + (++live_region_counter));
region.appendChild(b);
});
addTests(
'text',
'change button\'s aria-label',
'<div ARIA-ATTRS>' +
'<button tabindex="-1" aria-label="Fail 2.">Fail 1.</button>' +
'</div>',
function(region) {
region.firstChild.setAttribute('aria-label', 'Live region succeeded ' + (++live_region_counter));
});
addTests(
'text',
'button which is itself a life region (as opposed to being inside of one)',
'<div><input type="button" value="Live region failed" tabindex="-1" ARIA-ATTRS>' +
'</div>',
function(region) {
region.firstChild.setAttribute('value', 'Live region succeeded ' + (++live_region_counter));
});
addTests(
'text',
'set focus to link 1, then modify live region.',
'<div ARIA-ATTRS></div>' +
'<div><a id="f1" href="#" tabindex="-1">Link 1</a></div>',
function(region) {
document.getElementById('f1').focus();
region.innerHTML = 'Live region succeeded ' + (++live_region_counter);
});
addTests(
'text',
'modify live region, then set focus to link 2.',
'<div ARIA-ATTRS></div>' +
'<div><a id="f2" href="#" tabindex="-1ZZ">Link 2</a></div>',
function(region) {
region.innerHTML = 'Live region succeeded ' + (++live_region_counter);
document.getElementById('f2').focus();
});
addTests(
'text',
'set focus to link 3, then modify live region after delay.',
'<div ARIA-ATTRS></div>' +
'<div><a id="f3" href="#">Link 3</a></div>',
function(region) {
document.getElementById('f3').focus();
setTimeout(function() {
region.innerHTML = 'Live region succeeded ' + (++live_region_counter);
}, 150);
});
addTests(
'text',
'modify live region, then set focus to link 4 after delay.',
'<div ARIA-ATTRS></div>' +
'<div><a id="f4" href="#">Link 4</a></div>',
function(region) {
region.innerHTML = 'Live region succeeded ' + (++live_region_counter);
setTimeout(function() {
document.getElementById('f4').focus();
}, 150);
});