blob: a770383a10aab1549d54e0fe218116634869f755 [file] [log] [blame]
<!DOCTYPE HTML>
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body id="a">
<script>
description("Test that different ways of changing an element's id all work properly.");
debug("\n1. Check id after parsing.");
shouldBe('document.getElementById("a")', 'document.body');
shouldBe('document.body.id', '"a"');
shouldBe('document.body.getAttributeNode("id").value', '"a"');
debug("\n2. Change Attr.value.");
document.body.getAttributeNode("id").value = "b";
shouldBe('document.getElementById("a")', 'null');
shouldBe('document.getElementById("b")', 'document.body');
shouldBe('document.body.getAttributeNode("id").value', '"b"');
debug("\n3. Change HTMLElement.id.");
document.body.id = "c";
shouldBe('document.getElementById("b")', 'null');
shouldBe('document.getElementById("c")', 'document.body');
shouldBe('document.body.getAttributeNode("id").value', '"c"');
debug("\n4. Change id attribute via setAttribute().");
document.body.setAttribute("id", "d");
shouldBe('document.getElementById("c")', 'null');
shouldBe('document.getElementById("d")', 'document.body');
shouldBe('document.body.getAttributeNode("id").value', '"d"');
debug("\n5. Change id attribute via setAttributeNS().");
document.body.setAttributeNS(null, "id", "e");
shouldBe('document.getElementById("d")', 'null');
shouldBe('document.getElementById("e")', 'document.body');
shouldBe('document.body.getAttributeNode("id").value', '"e"');
var attrNode = document.body.getAttributeNode("id");
debug("\n6. Change Attr.nodeValue.");
document.body.getAttributeNode("id").nodeValue = "f";
shouldBe('document.getElementById("e")', 'null');
shouldBe('document.getElementById("f")', 'document.body');
shouldBe('document.body.id', '"f"');
shouldBe('document.body.getAttribute("id")', '"f"');
shouldBe('attrNode.value', '"f"');
debug("\n12. Chnaging Attr.value.");
attrNode.value = "hi";
shouldBe('document.getElementById("i")', 'null');
shouldBe('document.getElementById("hi")', 'document.body');
shouldBe('document.body.id', '"hi"');
shouldBe('document.body.getAttribute("id")', '"hi"');
shouldBe('attrNode.value', '"hi"');
debug("\n21. Remove an Attr node.");
document.body.removeAttributeNode(attrNode);
shouldBe('document.body.id', '""');
shouldBe('document.getElementById("mn")', 'null');
shouldBe('document.body.getAttribute("id")', 'null');
shouldBe('document.body.getAttributeNode("id")', 'null');
debug("\n22. Add an Attr node.");
var attrNode = document.createAttribute("id");
attrNode.value = "o";
document.body.setAttributeNode(attrNode);
shouldBe('document.getElementById("o")', 'document.body');
shouldBe('document.body.id', '"o"');
shouldBe('document.body.getAttribute("id")', '"o"');
debug("\n23. Add an Attr node over an existing one.");
var attrNode = document.createAttribute("id");
attrNode.value = "p";
document.body.setAttributeNode(attrNode);
shouldBe('document.getElementById("o")', 'null');
shouldBe('document.getElementById("p")', 'document.body');
shouldBe('document.body.id', '"p"');
shouldBe('document.body.getAttribute("id")', '"p"');
</script>
</body>
</html>