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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=418756
https://bugzilla.mozilla.org/show_bug.cgi?id=617528
-->
<head>
<title>Test for Bug 418756 and 617528</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Mozilla bug
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=418756">418756</a>
and
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=617528">617528</a>
<p id="display"></p>
<div id="content">
<form id="f1">
</form>
<form id="f2">
</form>
<menu id="m1">
</menu>
<menu id="m2">
</menu>
</div>
<pre id="test">
<script class="testbody" type="text/javascript; version=1.7">
/** Test for Bug 418756 and 617528 **/
var group1;
var group2;
var group3;
var tags = ["input", "menuitem"];
for (let tag of tags) {
function bounce(node) {
let n = node.nextSibling;
let p = node.parentNode;
p.removeChild(node);
p.insertBefore(node, n);
}
var createdNodes = [];
function cleanup() {
for (let node of createdNodes) {
if (node.parentNode) {
node.parentNode.removeChild(node);
}
}
createdNodes = [];
}
var typeMapper = {
'c': 'checkbox',
'r': 'radio'
};
var id = 0;
// type can be 'c' for 'checkbox' and 'r' for 'radio'
function createNode(type, name, checked) {
let node = document.createElement(tag);
node.setAttribute("type", typeMapper[type]);
if (checked) {
node.setAttribute("checked", "checked");
}
node.setAttribute("id", type + (++id));
node.setAttribute(tag == "input" ? "name" : "radiogroup", name);
createdNodes.push(node);
return node;
}
var types = ['c', 'r'];
// First make sure that setting .checked makes .defaultChecked changes no
// longer affect .checked.
for (let type of types) {
let n = createNode(type, '', false);
is(n.defaultChecked, false, "Bogus defaultChecked on " + typeMapper[type]);
is(n.checked, false, "Bogus checked on " + typeMapper[type]);
n.defaultChecked = true;
is(n.defaultChecked, true, "Bogus defaultChecked on " + typeMapper[type] +
"after mutation");
is(n.checked, true, "Bogus checked on " + typeMapper[type] +
"after mutation");
n.checked = false;
is(n.defaultChecked, true, "Bogus defaultChecked on " + typeMapper[type] +
"after second mutation");
is(n.checked, false, "Bogus checked on " + typeMapper[type] +
"after second mutation");
n.defaultChecked = false;
is(n.defaultChecked, false, "Bogus defaultChecked on " + typeMapper[type] +
"after third mutation");
is(n.checked, false, "Bogus checked on " + typeMapper[type] +
"after third mutation");
n.defaultChecked = true;
is(n.defaultChecked, true, "Bogus defaultChecked on " + typeMapper[type] +
"after fourth mutation");
is(n.checked, false, "Bogus checked on " + typeMapper[type] +
"after fourth mutation");
}
cleanup();
// Now check that bouncing a control that's the only one of its kind has no
// effect
for (let type of types) {
let n = createNode(type, 'test1', true);
$(tag == "input" ? "f1" : "m1").appendChild(n);
n.checked = false;
n.defaultChecked = false;
bounce(n);
n.defaultChecked = true;
is(n.checked, false, "We set .checked on this " + typeMapper[type]);
}
cleanup();
// Now check that playing with a single radio in a group affects all
// other radios in the group (but not radios not in that group)
group1 = [ createNode('r', 'g1', false),
createNode('r', 'g1', false),
createNode('r', 'g1', false) ];
group2 = [ createNode('r', 'g2', false),
createNode('r', 'g2', false),
createNode('r', 'g2', false) ];
group3 = [ createNode('r', 'g1', false),
createNode('r', 'g1', false),
createNode('r', 'g1', false) ];
for (let g of group1) {
$(tag == "input" ? "f1" : "m1").appendChild(g);
}
for (let g of group2) {
$(tag == "input" ? "f1" : "m1").appendChild(g);
}
for (let g of group3) {
$(tag == "input" ? "f2" : "m2").appendChild(g);
}
for (let n of [1, 2, 3]) {
for (let g of window["group"+n]) {
is(g.defaultChecked, false,
"group" + n + "[" + window["group"+n].indexOf(g) +
"] defaultChecked wrong pass 1");
is(g.checked, false,
"group" + n + "[" + window["group"+n].indexOf(g) +
"] checkedhecked wrong pass 1");
}
}
group1[1].defaultChecked = true;
for (let n of [1, 2, 3]) {
for (let g of window["group"+n]) {
is(g.defaultChecked, n == 1 && group1.indexOf(g) == 1,
"group" + n + "[" + window["group"+n].indexOf(g) +
"] defaultChecked wrong pass 2");
is(g.checked, n == 1 && group1.indexOf(g) == 1,
"group" + n + "[" + window["group"+n].indexOf(g) +
"] checked wrong pass 2");
}
}
group1[0].defaultChecked = true;
for (let n of [1, 2, 3]) {
for (let g of window["group"+n]) {
is(g.defaultChecked, n == 1 && (group1.indexOf(g) == 1 ||
group1.indexOf(g) == 0),
"group" + n + "[" + window["group"+n].indexOf(g) +
"] defaultChecked wrong pass 3");
is(g.checked, n == 1 && group1.indexOf(g) == 0,
"group" + n + "[" + window["group"+n].indexOf(g) +
"] checked wrong pass 3");
}
}
group1[2].defaultChecked = true;
for (let n of [1, 2, 3]) {
for (let g of window["group"+n]) {
is(g.defaultChecked, n == 1,
"group" + n + "[" + window["group"+n].indexOf(g) +
"] defaultChecked wrong pass 4");
is(g.checked, n == 1 && group1.indexOf(g) == 2,
"group" + n + "[" + window["group"+n].indexOf(g) +
"] checked wrong pass 4");
}
}
var next = group1[1].nextSibling;
var p = group1[1].parentNode;
p.removeChild(group1[1]);
group1[1].defaultChecked = false;
group1[1].defaultChecked = true;
p.insertBefore(group1[1], next);
for (let n of [1, 2, 3]) {
for (let g of window["group"+n]) {
is(g.defaultChecked, n == 1,
"group" + n + "[" + window["group"+n].indexOf(g) +
"] defaultChecked wrong pass 5");
is(g.checked, n == 1 && group1.indexOf(g) == 1,
"group" + n + "[" + window["group"+n].indexOf(g) +
"] checked wrong pass 5");
}
}
for (let g of group1) {
g.defaultChecked = false;
}
for (let n of [1, 2, 3]) {
for (let g of window["group"+n]) {
is(g.defaultChecked, false,
"group" + n + "[" + window["group"+n].indexOf(g) +
"] defaultChecked wrong pass 6");
is(g.checked, false,
"group" + n + "[" + window["group"+n].indexOf(g) +
"] checkedhecked wrong pass 6");
}
}
group1[1].checked = true;
for (let n of [1, 2, 3]) {
for (let g of window["group"+n]) {
is(g.defaultChecked, false,
"group" + n + "[" + window["group"+n].indexOf(g) +
"] defaultChecked wrong pass 7");
is(g.checked, n == 1 && group1.indexOf(g) == 1,
"group" + n + "[" + window["group"+n].indexOf(g) +
"] checked wrong pass 7");
}
}
group1[0].defaultChecked = true;
for (let n of [1, 2, 3]) {
for (let g of window["group"+n]) {
is(g.defaultChecked, n == 1 && group1.indexOf(g) == 0,
"group" + n + "[" + window["group"+n].indexOf(g) +
"] defaultChecked wrong pass 8");
is(g.checked, n == 1 && group1.indexOf(g) == 1,
"group" + n + "[" + window["group"+n].indexOf(g) +
"] checked wrong pass 8");
}
}
group1[2].defaultChecked = true;
for (let n of [1, 2, 3]) {
for (let g of window["group"+n]) {
is(g.defaultChecked, n == 1 && (group1.indexOf(g) == 0 ||
group1.indexOf(g) == 2),
"group" + n + "[" + window["group"+n].indexOf(g) +
"] defaultChecked wrong pass 9");
is(g.checked, n == 1 && group1.indexOf(g) == 1,
"group" + n + "[" + window["group"+n].indexOf(g) +
"] checked wrong pass 9");
}
}
group1[1].parentNode.removeChild(group1[1]);
for (let n of [1, 2, 3]) {
for (let g of window["group"+n]) {
is(g.defaultChecked, n == 1 && (group1.indexOf(g) == 0 ||
group1.indexOf(g) == 2),
"group" + n + "[" + window["group"+n].indexOf(g) +
"] defaultChecked wrong pass 10");
is(g.checked, n == 1 && group1.indexOf(g) == 1,
"group" + n + "[" + window["group"+n].indexOf(g) +
"] checked wrong pass 10");
}
}
group1[2].checked = true;
for (let n of [1, 2, 3]) {
for (let g of window["group"+n]) {
is(g.defaultChecked, n == 1 && (group1.indexOf(g) == 0 ||
group1.indexOf(g) == 2),
"group" + n + "[" + window["group"+n].indexOf(g) +
"] defaultChecked wrong pass 11");
is(g.checked, n == 1 && (group1.indexOf(g) == 1 ||
group1.indexOf(g) == 2),
"group" + n + "[" + window["group"+n].indexOf(g) +
"] checked wrong pass 11");
}
}
group1[0].checked = true;
for (let n of [1, 2, 3]) {
for (let g of window["group"+n]) {
is(g.defaultChecked, n == 1 && (group1.indexOf(g) == 0 ||
group1.indexOf(g) == 2),
"group" + n + "[" + window["group"+n].indexOf(g) +
"] defaultChecked wrong pass 12");
is(g.checked, n == 1 && (group1.indexOf(g) == 1 ||
group1.indexOf(g) == 0),
"group" + n + "[" + window["group"+n].indexOf(g) +
"] checked wrong pass 12");
}
}
next = group2[1].nextSibling;
p = group2[1].parentNode;
p.removeChild(group2[1]);
p.insertBefore(group2[1], next);
group2[0].checked = true;
for (let n of [1, 2, 3]) {
for (let g of window["group"+n]) {
is(g.defaultChecked, n == 1 && (group1.indexOf(g) == 0 ||
group1.indexOf(g) == 2),
"group" + n + "[" + window["group"+n].indexOf(g) +
"] defaultChecked wrong pass 13");
is(g.checked, (n == 1 && (group1.indexOf(g) == 1 ||
group1.indexOf(g) == 0)) ||
(n == 2 && group2.indexOf(g) == 0),
"group" + n + "[" + window["group"+n].indexOf(g) +
"] checked wrong pass 13");
}
}
p.insertBefore(group2[1], next);
for (let n of [1, 2, 3]) {
for (let g of window["group"+n]) {
is(g.defaultChecked, n == 1 && (group1.indexOf(g) == 0 ||
group1.indexOf(g) == 2),
"group" + n + "[" + window["group"+n].indexOf(g) +
"] defaultChecked wrong pass 14");
is(g.checked, (n == 1 && (group1.indexOf(g) == 1 ||
group1.indexOf(g) == 0)) ||
(n == 2 && group2.indexOf(g) == 0),
"group" + n + "[" + window["group"+n].indexOf(g) +
"] checked wrong pass 14");
}
}
group2[1].defaultChecked = true;
for (let n of [1, 2, 3]) {
for (let g of window["group"+n]) {
is(g.defaultChecked, (n == 1 && (group1.indexOf(g) == 0 ||
group1.indexOf(g) == 2)) ||
(n == 2 && group2.indexOf(g) == 1),
"group" + n + "[" + window["group"+n].indexOf(g) +
"] defaultChecked wrong pass 15");
is(g.checked, (n == 1 && (group1.indexOf(g) == 1 ||
group1.indexOf(g) == 0)) ||
(n == 2 && group2.indexOf(g) == 0),
"group" + n + "[" + window["group"+n].indexOf(g) +
"] checked wrong pass 15");
}
}
cleanup();
}
</script>
</pre>
</body>
</html>
|