<!DOCTYPE HTML>
<html>
<head>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body id="a">
<script>
test(() => {
assert_equals(document.getElementById("a"), document.body);
assert_equals(document.body.id, "a");
assert_equals(document.body.getAttributeNode("id").value, "a");
}, "Test that different ways of changing an element's id all work properly, 1. Check id after parsing");
test(() => {
document.body.getAttributeNode("id").value = "b";
assert_equals(document.getElementById("a"), null);
assert_equals(document.getElementById("b"), document.body);
assert_equals(document.body.getAttributeNode("id").value, "b");
}, "Test that different ways of changing an element's id all work properly, 2. Change Attr.value");
test(() => {
document.body.id = "c";
assert_equals(document.getElementById("b"), null);
assert_equals(document.getElementById("c"), document.body);
assert_equals(document.body.getAttributeNode("id").value, "c");
}, "Test that different ways of changing an element's id all work properly, 3. Change HTMLElement.id");
test(() => {
document.body.setAttribute("id", "d");
assert_equals(document.getElementById("c"), null);
assert_equals(document.getElementById("d"), document.body);
assert_equals(document.body.getAttributeNode("id").value, "d");
}, "Test that different ways of changing an element's id all work properly, 4. Change id attribute via setAttribute()");
test(() => {
document.body.setAttributeNS(null, "id", "e");
assert_equals(document.getElementById("d"), null);
assert_equals(document.getElementById("e"), document.body);
assert_equals(document.body.getAttributeNode("id").value, "e");
}, "Test that different ways of changing an element's id all work properly, 5. Change id attribute via setAttributeNS()");
test(() => {
var attrNode = document.body.getAttributeNode("id");
document.body.getAttributeNode("id").nodeValue = "f";
assert_equals(document.getElementById("e"), null);
assert_equals(document.getElementById("f"), document.body);
assert_equals(document.body.id, "f");
assert_equals(document.body.getAttribute("id"), "f");
assert_equals(attrNode.value, "f");
}, "Test that different ways of changing an element's id all work properly, 6. Change Attr.nodeValue");
test(() => {
var attrNode = document.body.getAttributeNode("id");
attrNode.value = "hi";
assert_equals(document.getElementById("i"), null);
assert_equals(document.getElementById("hi"), document.body);
assert_equals(document.body.id, "hi");
assert_equals(document.body.getAttribute("id"), "hi");
assert_equals(attrNode.value, "hi");
}, "Test that different ways of changing an element's id all work properly, 12. Chnaging Attr.value");
test(() => {
var attrNode = document.body.getAttributeNode("id");
document.body.removeAttributeNode(attrNode);
assert_equals(document.body.id, "");
assert_equals(document.getElementById("mn"), null);
assert_equals(document.body.getAttribute("id"), null);
assert_equals(document.body.getAttributeNode("id"), null);
}, "Test that different ways of changing an element's id all work properly, 21. Remove an Attr node");
test(() => {
var attrNode = document.createAttribute("id");
attrNode.value = "o";
document.body.setAttributeNode(attrNode);
assert_equals(document.getElementById("o"), document.body);
assert_equals(document.body.id, "o");
assert_equals(document.body.getAttribute("id"), "o");
}, "Test that different ways of changing an element's id all work properly, 22. Add an Attr node");
test(() => {
var attrNode = document.createAttribute("id");
attrNode.value = "p";
document.body.setAttributeNode(attrNode);
assert_equals(document.getElementById("o"), null);
assert_equals(document.getElementById("p"), document.body);
assert_equals(document.body.id, "p");
assert_equals(document.body.getAttribute("id"), "p");
}, "Test that different ways of changing an element's id all work properly, 23. Add an Attr node over an existing one");
</script>
</body>
</html>