This commit is contained in:
Boris Zbarsky 2008-07-24 15:21:31 -07:00
Родитель 7c367d2c04
Коммит ec44e362b9
1 изменённых файлов: 292 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,292 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=418756
-->
<head>
<title>Test for Bug 418756</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=418756">Mozilla Bug 418756</a>
<p id="display"></p>
<div id="content">
<form id="f1">
</form>
<form id="f2">
</form>
</div>
<pre id="test">
<script class="testbody" type="text/javascript; version=1.7">
/** Test for Bug 418756 **/
function bounce(node) {
let n = node.nextSibling;
let p = node.parentNode;
p.removeChild(node);
p.insertBefore(node, n);
}
let createdNodes = [];
function cleanup() {
for each (let node in createdNodes) {
if (node.parentNode) {
node.parentNode.removeChild(node);
}
}
createdNodes = [];
}
let typeMapper = {
'c': 'checkbox',
'r': 'radio'
};
let id = 0;
// type can be 'c' for 'checkbox' and 'r' for 'radio'
function createNode(type, name, checked) {
let node = document.createElement("input");
node.setAttribute("type", typeMapper[type]);
if (checked) {
node.setAttribute("checked", "checked");
}
node.setAttribute("id", type + (++id));
node.setAttribute("name", name);
createdNodes.push(node);
return node;
}
let types = ['c', 'r'];
// First make sure that setting .checked makes .defaultChecked changes no
// longer affect .checked.
for each (let type in 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 each (let type in types) {
let n = createNode(type, 'test1', true);
$("f1").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)
let group1 = [ createNode('r', 'g1', false),
createNode('r', 'g1', false),
createNode('r', 'g1', false) ];
let group2 = [ createNode('r', 'g2', false),
createNode('r', 'g2', false),
createNode('r', 'g2', false) ];
let group3 = [ createNode('r', 'g1', false),
createNode('r', 'g1', false),
createNode('r', 'g1', false) ];
for each (let g in group1) {
$("f1").appendChild(g);
}
for each (let g in group2) {
$("f1").appendChild(g);
}
for each (let g in group3) {
$("f2").appendChild(g);
}
for each (let n in [1, 2, 3]) {
for each (let g in 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 each (let n in [1, 2, 3]) {
for each (let g in 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 each (let n in [1, 2, 3]) {
for each (let g in 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 each (let n in [1, 2, 3]) {
for each (let g in 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 each (let n in [1, 2, 3]) {
for each (let g in 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 each(let g in group1) {
g.defaultChecked = false;
}
for each (let n in [1, 2, 3]) {
for each (let g in 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 each (let n in [1, 2, 3]) {
for each (let g in 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 each (let n in [1, 2, 3]) {
for each (let g in 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 each (let n in [1, 2, 3]) {
for each (let g in 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 each (let n in [1, 2, 3]) {
for each (let g in 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 each (let n in [1, 2, 3]) {
for each (let g in 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 each (let n in [1, 2, 3]) {
for each (let g in 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) == 0),
"group" + n + "[" + window["group"+n].indexOf(g) +
"] checked wrong pass 11");
}
}
cleanup();
</script>
</pre>
</body>
</html>