2008-07-25 02:21:31 +04:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=418756
|
2011-08-08 21:31:32 +04:00
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=617528
|
2008-07-25 02:21:31 +04:00
|
|
|
-->
|
|
|
|
<head>
|
2011-08-08 21:31:32 +04:00
|
|
|
<title>Test for Bug 418756 and 617528</title>
|
2019-04-16 06:53:28 +03:00
|
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
2008-07-25 02:21:31 +04:00
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
2011-08-08 21:31:32 +04:00
|
|
|
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>
|
2008-07-25 02:21:31 +04:00
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content">
|
|
|
|
<form id="f1">
|
|
|
|
</form>
|
|
|
|
<form id="f2">
|
|
|
|
</form>
|
2011-08-08 21:31:32 +04:00
|
|
|
<menu id="m1">
|
|
|
|
</menu>
|
|
|
|
<menu id="m2">
|
|
|
|
</menu>
|
2008-07-25 02:21:31 +04:00
|
|
|
</div>
|
|
|
|
<pre id="test">
|
2018-01-09 19:00:49 +03:00
|
|
|
<script class="testbody" type="text/javascript">
|
2008-07-25 02:21:31 +04:00
|
|
|
|
2011-08-08 21:31:32 +04:00
|
|
|
/** Test for Bug 418756 and 617528 **/
|
2015-10-07 15:03:21 +03:00
|
|
|
var group1;
|
|
|
|
var group2;
|
|
|
|
var group3;
|
2011-08-08 21:31:32 +04:00
|
|
|
|
2015-10-07 15:03:21 +03:00
|
|
|
var tags = ["input", "menuitem"];
|
2015-10-18 20:00:50 +03:00
|
|
|
for (let tag of tags) {
|
2011-08-08 21:31:32 +04:00
|
|
|
|
2008-07-25 02:21:31 +04:00
|
|
|
function bounce(node) {
|
|
|
|
let n = node.nextSibling;
|
|
|
|
let p = node.parentNode;
|
|
|
|
p.removeChild(node);
|
|
|
|
p.insertBefore(node, n);
|
|
|
|
}
|
|
|
|
|
2015-10-07 15:03:21 +03:00
|
|
|
var createdNodes = [];
|
2008-07-25 02:21:31 +04:00
|
|
|
|
|
|
|
function cleanup() {
|
2015-10-18 20:00:50 +03:00
|
|
|
for (let node of createdNodes) {
|
2008-07-25 02:21:31 +04:00
|
|
|
if (node.parentNode) {
|
|
|
|
node.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
createdNodes = [];
|
|
|
|
}
|
|
|
|
|
2015-10-07 15:03:21 +03:00
|
|
|
var typeMapper = {
|
2008-07-25 02:21:31 +04:00
|
|
|
'c': 'checkbox',
|
|
|
|
'r': 'radio'
|
|
|
|
};
|
|
|
|
|
2015-10-07 15:03:21 +03:00
|
|
|
var id = 0;
|
2008-07-25 02:21:31 +04:00
|
|
|
|
|
|
|
// type can be 'c' for 'checkbox' and 'r' for 'radio'
|
|
|
|
function createNode(type, name, checked) {
|
2011-08-08 21:31:32 +04:00
|
|
|
let node = document.createElement(tag);
|
2008-07-25 02:21:31 +04:00
|
|
|
node.setAttribute("type", typeMapper[type]);
|
|
|
|
if (checked) {
|
|
|
|
node.setAttribute("checked", "checked");
|
|
|
|
}
|
|
|
|
node.setAttribute("id", type + (++id));
|
2011-08-08 21:31:32 +04:00
|
|
|
node.setAttribute(tag == "input" ? "name" : "radiogroup", name);
|
2008-07-25 02:21:31 +04:00
|
|
|
createdNodes.push(node);
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2015-10-07 15:03:21 +03:00
|
|
|
var types = ['c', 'r'];
|
2008-07-25 02:21:31 +04:00
|
|
|
|
|
|
|
// First make sure that setting .checked makes .defaultChecked changes no
|
|
|
|
// longer affect .checked.
|
2015-10-18 20:00:50 +03:00
|
|
|
for (let type of types) {
|
2008-07-25 02:21:31 +04:00
|
|
|
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
|
2015-10-18 20:00:50 +03:00
|
|
|
for (let type of types) {
|
2008-07-25 02:21:31 +04:00
|
|
|
let n = createNode(type, 'test1', true);
|
2011-08-08 21:31:32 +04:00
|
|
|
$(tag == "input" ? "f1" : "m1").appendChild(n);
|
2008-07-25 02:21:31 +04:00
|
|
|
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)
|
2011-08-08 21:31:32 +04:00
|
|
|
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) ];
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let g of group1) {
|
2011-08-08 21:31:32 +04:00
|
|
|
$(tag == "input" ? "f1" : "m1").appendChild(g);
|
2008-07-25 02:21:31 +04:00
|
|
|
}
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let g of group2) {
|
2011-08-08 21:31:32 +04:00
|
|
|
$(tag == "input" ? "f1" : "m1").appendChild(g);
|
2008-07-25 02:21:31 +04:00
|
|
|
}
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let g of group3) {
|
2011-08-08 21:31:32 +04:00
|
|
|
$(tag == "input" ? "f2" : "m2").appendChild(g);
|
2008-07-25 02:21:31 +04:00
|
|
|
}
|
|
|
|
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let n of [1, 2, 3]) {
|
|
|
|
for (let g of window["group"+n]) {
|
2008-07-25 02:21:31 +04:00
|
|
|
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;
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let n of [1, 2, 3]) {
|
|
|
|
for (let g of window["group"+n]) {
|
2008-07-25 02:21:31 +04:00
|
|
|
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;
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let n of [1, 2, 3]) {
|
|
|
|
for (let g of window["group"+n]) {
|
2008-07-25 02:21:31 +04:00
|
|
|
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;
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let n of [1, 2, 3]) {
|
|
|
|
for (let g of window["group"+n]) {
|
2008-07-25 02:21:31 +04:00
|
|
|
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);
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let n of [1, 2, 3]) {
|
|
|
|
for (let g of window["group"+n]) {
|
2008-07-25 02:21:31 +04:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let g of group1) {
|
2008-07-25 02:21:31 +04:00
|
|
|
g.defaultChecked = false;
|
|
|
|
}
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let n of [1, 2, 3]) {
|
|
|
|
for (let g of window["group"+n]) {
|
2008-07-25 02:21:31 +04:00
|
|
|
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;
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let n of [1, 2, 3]) {
|
|
|
|
for (let g of window["group"+n]) {
|
2008-07-25 02:21:31 +04:00
|
|
|
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;
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let n of [1, 2, 3]) {
|
|
|
|
for (let g of window["group"+n]) {
|
2008-07-25 02:21:31 +04:00
|
|
|
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;
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let n of [1, 2, 3]) {
|
|
|
|
for (let g of window["group"+n]) {
|
2008-07-25 02:21:31 +04:00
|
|
|
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].remove();
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let n of [1, 2, 3]) {
|
|
|
|
for (let g of window["group"+n]) {
|
2008-07-25 02:21:31 +04:00
|
|
|
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;
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let n of [1, 2, 3]) {
|
|
|
|
for (let g of window["group"+n]) {
|
2008-07-25 02:21:31 +04:00
|
|
|
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;
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let n of [1, 2, 3]) {
|
|
|
|
for (let g of window["group"+n]) {
|
2008-07-25 02:21:31 +04:00
|
|
|
is(g.defaultChecked, n == 1 && (group1.indexOf(g) == 0 ||
|
|
|
|
group1.indexOf(g) == 2),
|
|
|
|
"group" + n + "[" + window["group"+n].indexOf(g) +
|
2008-07-25 02:28:12 +04:00
|
|
|
"] defaultChecked wrong pass 12");
|
2008-07-25 02:21:31 +04:00
|
|
|
is(g.checked, n == 1 && (group1.indexOf(g) == 1 ||
|
|
|
|
group1.indexOf(g) == 0),
|
|
|
|
"group" + n + "[" + window["group"+n].indexOf(g) +
|
2008-07-25 02:28:12 +04:00
|
|
|
"] 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;
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let n of [1, 2, 3]) {
|
|
|
|
for (let g of window["group"+n]) {
|
2008-07-25 02:28:12 +04:00
|
|
|
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);
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let n of [1, 2, 3]) {
|
|
|
|
for (let g of window["group"+n]) {
|
2008-07-25 02:28:12 +04:00
|
|
|
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;
|
2015-06-05 12:23:08 +03:00
|
|
|
for (let n of [1, 2, 3]) {
|
|
|
|
for (let g of window["group"+n]) {
|
2008-07-25 02:28:12 +04:00
|
|
|
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");
|
2008-07-25 02:21:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup();
|
2011-08-08 21:31:32 +04:00
|
|
|
|
|
|
|
}
|
2008-07-25 02:21:31 +04:00
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|