-
Notifications
You must be signed in to change notification settings - Fork 0
/
text_content_tests.js
188 lines (167 loc) · 5.47 KB
/
text_content_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
// These are the different permutations of ARIA attributes to try.
var attrs = [
'alert',
'aria-live="polite" aria-relevant="text additions" (default)'];
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(
'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',
'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);
});