element: implement parenteNode accessors

This commit is contained in:
Pierre Tachoire
2023-12-13 13:38:24 +01:00
parent c732b7496c
commit d1f8555c1e
28 changed files with 639 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>Null test</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of firstElementChild and lastChildElement returning null</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle" font-weight="bold">Test</text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl")
assert_equals(parentEl.firstElementChild, null)
assert_equals(parentEl.lastElementChild, null)
})
]]></h:script>
</svg>

After

Width:  |  Height:  |  Size: 787 B

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Null Test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of firstElementChild and lastChildElement returning null</h1>
<div id="log"></div>
<p id="parentEl" style="font-weight:bold;">Test.</p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl")
assert_equals(parentEl.firstElementChild, null)
assert_equals(parentEl.lastElementChild, null)
})
]]></script>
</body>
</html>

View File

@@ -0,0 +1,15 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Null test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of firstElementChild and lastChildElement returning null</h1>
<div id="log"></div>
<p id="parentEl" style="font-weight:bold;">Test.</p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl")
assert_equals(parentEl.firstElementChild, null)
assert_equals(parentEl.lastElementChild, null)
})
</script>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>Dynamic Adding of Elements</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of Dynamic Adding of Elements</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle">The result of this test is
<tspan id="first_element_child" font-weight="bold">unknown.</tspan></text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var newChild = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
parentEl.appendChild(newChild);
assert_equals(parentEl.childElementCount, 2)
})
]]></h:script>
</svg>

After

Width:  |  Height:  |  Size: 913 B

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Dynamic Adding of Elements</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of Dynamic Adding of Elements</h1>
<div id="log"></div>
<p id="parentEl">The result of this test is
<span id="first_element_child" style="font-weight:bold;">logged above.</span></p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var newChild = document.createElement("span");
parentEl.appendChild(newChild);
assert_equals(parentEl.childElementCount, 2)
})
]]></script>
</body>
</html>

View File

@@ -0,0 +1,17 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Dynamic Adding of Elements</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of Dynamic Adding of Elements</h1>
<div id="log"></div>
<p id="parentEl">The result of this test is
<span id="first_element_child" style="font-weight:bold;">logged above.</span></p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl");
var newChild = document.createElement("span");
parentEl.appendChild(newChild);
assert_equals(parentEl.childElementCount, 2)
})
</script>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>Dynamic Removal of Elements</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of Dynamic Removal of Elements</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle">The result of this test is
<tspan id="first_element_child" font-weight="bold">unknown.</tspan><tspan id="last_element_child"> </tspan></text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var lec = parentEl.lastElementChild;
parentEl.removeChild(lec);
assert_equals(parentEl.childElementCount, 1)
})
]]></h:script>
</svg>

After

Width:  |  Height:  |  Size: 907 B

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Dynamic Removal of Elements</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of Removal Adding of Elements</h1>
<div id="log"></div>
<p id="parentEl">The result of this test is
<span id="first_element_child" style="font-weight:bold;">logged above.</span><span id="last_element_child"> </span></p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var lec = parentEl.lastElementChild;
parentEl.removeChild(lec);
assert_equals(parentEl.childElementCount, 1)
})
]]></script>
</body>
</html>

View File

@@ -0,0 +1,17 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Dynamic Removal of Elements</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of Dynamic Removal of Elements</h1>
<div id="log"></div>
<p id="parentEl">The result of this test is
<span id="first_element_child" style="font-weight:bold;">unknown.</span><span id="last_element_child"> </span></p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl");
var lec = parentEl.lastElementChild;
parentEl.removeChild(lec);
assert_equals(parentEl.childElementCount, 1)
})
</script>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>childElementCount</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of childElementCount with No Child Element Nodes</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle" font-weight="bold">Test</text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl")
assert_equals(parentEl.childElementCount, 0)
})
]]></h:script>
</svg>

After

Width:  |  Height:  |  Size: 735 B

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>childElementCount without Child Element Nodes</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of childElementCount with No Child Element Nodes</h1>
<div id="log"></div>
<p id="parentEl" style="font-weight:bold;">Test.</p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl")
assert_equals(parentEl.childElementCount, 0)
})
]]></script>
</body>
</html>

View File

@@ -0,0 +1,14 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>childElementCount without Child Element Nodes</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of childElementCount with No Child Element Nodes</h1>
<div id="log"></div>
<p id="parentEl" style="font-weight:bold;">Test.</p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl")
assert_equals(parentEl.childElementCount, 0)
})
</script>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>childElementCount</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of childElementCount</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle">The result of <tspan id="first_element_child"><tspan>this</tspan> <tspan>test</tspan></tspan> is
<tspan id="middle_element_child" font-weight="bold">unknown.</tspan>
<tspan id="last_element_child" style="display:none;">fnord</tspan> </text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl")
assert_true("childElementCount" in parentEl)
assert_equals(parentEl.childElementCount, 3)
})
]]></h:script>
</svg>

After

Width:  |  Height:  |  Size: 967 B

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>childElementCount</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of childElementCount</h1>
<div id="log"></div>
<p id="parentEl">The result of <span id="first_element_child"><span>this</span> <span>test</span></span> is
<span id="middle_element_child" style="font-weight:bold;">unknown.</span>
<span id="last_element_child" style="display:none;">fnord</span> </p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl")
assert_true("childElementCount" in parentEl)
assert_equals(parentEl.childElementCount, 3)
})
]]></script>
</body>
</html>

View File

@@ -0,0 +1,20 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>childElementCount</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of childElementCount</h1>
<div id="log"></div>
<p id="parentEl">The result of <span id="first_element_child"><span>this</span> <span>test</span></span> is
<span id="middle_element_child" style="font-weight:bold;">given above.</span>
<span id="last_element_child" style="display:none;">fnord</span> </p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl")
assert_true("childElementCount" in parentEl)
assert_equals(parentEl.childElementCount, 3)
})
</script>

View File

@@ -0,0 +1,58 @@
<!DOCTYPE html>
<title>HTMLCollection edge cases</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<div id="test"><img><img id=foo><img id=foo><img name="bar"></div>
<script>
setup(function() {
// Add some non-HTML elements in there to test what happens with those.
var container = document.getElementById("test");
var child = document.createElementNS("", "img");
child.setAttribute("id", "baz");
container.appendChild(child);
child = document.createElementNS("", "img");
child.setAttribute("name", "qux");
container.appendChild(child);
});
test(function() {
var container = document.getElementById("test");
var result = container.children.item("foo");
assert_true(result instanceof Element, "Expected an Element.");
assert_false(result.hasAttribute("id"), "Expected the IDless Element.")
})
test(function() {
var container = document.getElementById("test");
var list = container.children;
var result = [];
for (var p in list) {
if (list.hasOwnProperty(p)) {
result.push(p);
}
}
assert_array_equals(result, ['0', '1', '2', '3', '4', '5']);
result = Object.getOwnPropertyNames(list);
assert_array_equals(result, ['0', '1', '2', '3', '4', '5', 'foo', 'bar', 'baz']);
// Mapping of exposed names to their indices in the list.
var exposedNames = { 'foo': 1, 'bar': 3, 'baz': 4 };
for (var exposedName in exposedNames) {
assert_true(exposedName in list);
assert_true(list.hasOwnProperty(exposedName));
assert_equals(list[exposedName], list.namedItem(exposedName));
assert_equals(list[exposedName], list.item(exposedNames[exposedName]));
assert_true(list[exposedName] instanceof Element);
}
var unexposedNames = ['qux'];
for (var unexposedName of unexposedNames) {
assert_false(unexposedName in list);
assert_false(list.hasOwnProperty(unexposedName));
assert_equals(list[unexposedName], undefined);
assert_equals(list.namedItem(unexposedName), null);
}
});
</script>

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
[
<!ENTITY tree "<span id='first_element_child' style='font-weight:bold;'>unknown.</span>">
]>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Entity References</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of Entity References</h1>
<div id="log"></div>
<p id="parentEl">The result of this test is &tree;</p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl")
var fec = parentEl.firstElementChild;
assert_true(!!fec)
assert_equals(fec.nodeType, 1)
assert_equals(fec.getAttribute("id"), "first_element_child")
})
]]></script>
</body>
</html>

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
[
<!ENTITY tree "<tspan id='first_element_child' font-weight='bold'>unknown.</tspan>">
]>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>Entity References</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of Entity References</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle">The result of this test is &tree;</text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl")
var fec = parentEl.firstElementChild;
assert_true(!!fec)
assert_equals(fec.nodeType, 1)
assert_equals(fec.getAttribute("id"), "first_element_child")
})
]]></h:script>
</svg>

After

Width:  |  Height:  |  Size: 1015 B

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:pickle="http://ns.example.org/pickle"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>firstElementChild with namespaces</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of firstElementChild with namespaces</text>
<g id="parentEl">
<pickle:dill id="first_element_child"/>
</g>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var fec = parentEl.firstElementChild;
assert_true(!!fec)
assert_equals(fec.nodeType, 1)
assert_equals(fec.getAttribute("id"), "first_element_child")
assert_equals(fec.localName, "dill")
})
]]></h:script>
</svg>

After

Width:  |  Height:  |  Size: 888 B

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:pickle="http://ns.example.org/pickle">
<head>
<title>firstElementChild with namespaces</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of firstElementChild with namespaces</h1>
<div id="parentEl">
<pickle:dill id="first_element_child"/>
</div>
<div id="log"></div>
<p id="parentEl">The result of this test is
<span id="first_element_child" style="font-weight:bold;">logged above.</span></p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var fec = parentEl.firstElementChild;
assert_true(!!fec)
assert_equals(fec.nodeType, 1)
assert_equals(fec.getAttribute("id"), "first_element_child")
assert_equals(fec.localName, "dill")
})
]]></script>
</body>
</html>

View File

@@ -0,0 +1,21 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>firstElementChild with namespaces</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of firstElementChild with namespaces</h1>
<div id="log"></div>
<p id="parentEl">The result of this test is a unknown.</p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl")
var el = document.createElementNS("http://ns.example.org/pickle", "pickle:dill")
el.setAttribute("id", "first_element_child")
parentEl.appendChild(el)
var fec = parentEl.firstElementChild
assert_true(!!fec)
assert_equals(fec.nodeType, 1)
assert_equals(fec.getAttribute("id"), "first_element_child")
assert_equals(fec.localName, "dill")
})
</script>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>firstElementChild</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of firstElementChild</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle">The result of this test is
<tspan id="first_element_child" font-weight="bold">unknown.</tspan></text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var fec = parentEl.firstElementChild;
assert_true(!!fec)
assert_equals(fec.nodeType, 1)
assert_equals(fec.getAttribute("id"), "first_element_child")
})
]]></h:script>
</svg>

After

Width:  |  Height:  |  Size: 889 B

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>firstElementChild</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of firstElementChild</h1>
<div id="log"></div>
<p id="parentEl">The result of this test is
<span id="first_element_child" style="font-weight:bold;">logged above.</span></p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var fec = parentEl.firstElementChild;
assert_true(!!fec)
assert_equals(fec.nodeType, 1)
assert_equals(fec.getAttribute("id"), "first_element_child")
})
]]></script>
</body>
</html>

View File

@@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>firstElementChild</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of firstElementChild</h1>
<div id="log"></div>
<p id="parentEl">The result of this test is
<span id="first_element_child" style="font-weight:bold;">logged above.</span></p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl");
var fec = parentEl.firstElementChild;
assert_true(!!fec)
assert_equals(fec.nodeType, 1)
assert_equals(fec.getAttribute("id"), "first_element_child")
})
</script>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:h="http://www.w3.org/1999/xhtml"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<title>lastElementChild</title>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<text x="200" y="40" font-size="25" fill="black" text-anchor="middle">Test of lastElementChild</text>
<text id="parentEl" x="200" y="70" font-size="20" fill="black" text-anchor="middle">The result of <tspan id="first_element_child">this test</tspan> is <tspan id="last_element_child" font-weight="bold">not</tspan> known.</text>
<h:script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var lec = parentEl.lastElementChild;
assert_true(!!lec)
assert_equals(lec.nodeType, 1)
assert_equals(lec.getAttribute("id"), "last_element_child")
})
]]></h:script>
</svg>

After

Width:  |  Height:  |  Size: 926 B

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>firstElementChild</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>Test of firstElementChild</h1>
<div id="log"></div>
<p id="parentEl">The result of <span id="first_element_child">this test</span> is <span id="last_element_child" style="font-weight:bold;">logged</span> above.</p>
<script><![CDATA[
test(function() {
var parentEl = document.getElementById("parentEl");
var lec = parentEl.lastElementChild;
assert_true(!!lec)
assert_equals(lec.nodeType, 1)
assert_equals(lec.getAttribute("id"), "last_element_child")
})
]]></script>
</body>
</html>

View File

@@ -0,0 +1,17 @@
<!DOCTYPE HTML>
<meta charset=utf-8>
<title>lastElementChild</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<h1>Test of lastElementChild</h1>
<div id="log"></div>
<p id="parentEl">The result of <span id="first_element_child">this test</span> is <span id="last_element_child" style="font-weight:bold;">logged</span> above.</p>
<script>
test(function() {
var parentEl = document.getElementById("parentEl");
var lec = parentEl.lastElementChild;
assert_true(!!lec)
assert_equals(lec.nodeType, 1)
assert_equals(lec.getAttribute("id"), "last_element_child")
})
</script>