gecko-dev/dom/html/test/test_checked.html

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

359 строки
11 KiB
HTML
Исходник Обычный вид История

2008-07-25 02:21:31 +04:00
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=418756
https://bugzilla.mozilla.org/show_bug.cgi?id=617528
2008-07-25 02:21:31 +04:00
-->
<head>
<title>Test for Bug 418756 and 617528</title>
<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>
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>
<menu id="m1">
</menu>
<menu id="m2">
</menu>
2008-07-25 02:21:31 +04:00
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
2008-07-25 02:21:31 +04:00
/** Test for Bug 418756 and 617528 **/
var group1;
var group2;
var group3;
var tags = ["input", "menuitem"];
for (let tag of tags) {
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);
}
var createdNodes = [];
2008-07-25 02:21:31 +04:00
function cleanup() {
for (let node of createdNodes) {
2008-07-25 02:21:31 +04:00
if (node.parentNode) {
node.remove();
}
}
createdNodes = [];
}
var typeMapper = {
2008-07-25 02:21:31 +04:00
'c': 'checkbox',
'r': 'radio'
};
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) {
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));
node.setAttribute(tag == "input" ? "name" : "radiogroup", name);
2008-07-25 02:21:31 +04:00
createdNodes.push(node);
return node;
}
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.
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
for (let type of types) {
2008-07-25 02:21:31 +04:00
let n = createNode(type, 'test1', true);
$(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)
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);
2008-07-25 02:21:31 +04:00
}
for (let g of group2) {
$(tag == "input" ? "f1" : "m1").appendChild(g);
2008-07-25 02:21:31 +04:00
}
for (let g of group3) {
$(tag == "input" ? "f2" : "m2").appendChild(g);
2008-07-25 02:21:31 +04: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;
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;
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;
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);
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");
}
}
for (let g of group1) {
2008-07-25 02:21:31 +04:00
g.defaultChecked = false;
}
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;
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;
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;
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();
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;
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;
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;
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);
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;
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();
}
2008-07-25 02:21:31 +04:00
</script>
</pre>
</body>
</html>