Bug 465573 - Add mochitests for ElementTraversal; r+sr=jonas

This commit is contained in:
Joel Maher 2008-12-02 14:05:15 +01:00
Родитель 4001c825fe
Коммит 3773cc68b0
6 изменённых файлов: 489 добавлений и 7 удалений

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

@ -261,7 +261,12 @@ _TEST_FILES = test_bug5141.html \
bug461735-post-redirect.js \
test_bug461735.html \
test_bug380418.html \
test_bug380418.html^headers^ \
test_bug380418.html^headers^ \
test_elementTraversal.html \
test_w3element_traversal.html \
test_w3element_traversal.xhtml \
test_w3element_traversal_svg.html \
w3element_traversal.svg
$(NULL)
# Disabled for now. Mochitest isn't reliable enough for these.

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

@ -23,26 +23,26 @@ text here
<script class="testbody" type="text/javascript">
var c = document.getElementById('content');
var cc = c.mozChildElements;
var cc = c.children;
var contents = ["span", "div", "p1", "p2", "abcde"];
function testContent() {
for(i = 0, e = c.firstElementChild; e; e = e.nextElementSibling, i++) {
is(e.textContent, contents[i], "wrong element contents");
is(e, c.mozChildElements[i], "wrong element");
is(e, c.mozChildElements.item(i), "wrong element");
is(e, c.children[i], "wrong element");
is(e, c.children.item(i), "wrong element");
}
is(i, contents.length, "wrong number of element siblings");
is(i, c.childElementCount, "wrong number of child elements");
is(i, c.mozChildElements.length, "wrong number of child elements");
is(i, c.children.length, "wrong number of child elements");
// Nuke all elements to retest the child list.
c.innerHTML = c.innerHTML;
for(i--, e = c.lastElementChild; e; e = e.previousElementSibling, i--) {
is(e.textContent, contents[i], "g element contents");
is(e, c.mozChildElements[i], "wrong element");
is(e, c.mozChildElements.item(i), "wrong element");
is(e, c.children[i], "wrong element");
is(e, c.children.item(i), "wrong element");
}
is(i, -1, "wrong number of element siblings");
}

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

@ -0,0 +1,149 @@
<!DOCTYPE HTML>
<html>
<!--
-->
<head>
<title>W3 Tests for Element Traversal - HTML</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>
<p id="parentEl_count">
<span id="first_element_child_count">
<span></span>
<span></span>
</span>
<span id="middle_element_child_count"></span>
<span id="last_element_child_count"></span>
</p>
<p id="parentEl_nochild">
</p>
<p id="parentEl_null">
</p>
<p id="parentEl_dynamicadd">
<span id="first_emement_child_add"></span>
</p>
<p id="parentEl_dynamicremove">
<span id="first_emement_child_remove"></span>
<span id="last_emement_child_remove"></span>
</p>
<p id="parentEl_fec">
<span id="first_element_child_fec"></span>
</p>
<p id="parentEl_lec">
<span id="first_element_child_lec"></span>
<span id="last_element_child_lec"></span>
</p>
<p id="parentEl_namespace">
<pickle:span id="first_element_child_namespace"></pickle:span>
</p>
<p id="parentEl_nes">
<span id="first_element_child_nes"></span>
<span id="last_element_child_nes"></span>
</p>
<p id="parentEl_pes">
<span id="first_element_child_pes"></span>
<span id="middle_element_child_pes"></span>
<span id="last_element_child_pes"></span>
</p>
<p id="parentEl_sibnull">
<span id="first_element_child_sibnull"></span>
</p>
<pre id="test">
<script class="testbody" type="text/javascript">
function runTest() {
//from et-childElementCount.html
var parentEl = document.getElementById("parentEl_count");
is(parentEl.childElementCount && 3, parentEl.childElementCount, "Child Element Count is mismatched");
//from et-childElementCount-nochild.html
var parentEl_nochild = document.getElementById("parentEl_nochild");
is(parentEl_nochild.childElementCount, 0, "Child Element count is not 0");
//from et-childElementCount-null.html
parentEl = document.getElementById("parentEl_null");
is(null == parentEl.firstElementChild, null == parentEl.lastElementChild, "firstElementChild or lastElementChild is not null");
//from et-dynamic-add.html
parentEl = document.getElementById("parentEl_dynamicadd");
var newChild = document.createElement("span")
parentEl.appendChild( newChild );
is(parentEl.childElementCount && 2, parentEl.childElementCount, "failed to add span element");
//from et-dynamic-remove.html
parentEl = document.getElementById("parentEl_dynamicremove");
var lec = parentEl.lastElementChild;
parentEl.removeChild( lec );
is(parentEl.childElementCount && 1, parentEl.childElementCount, "failed to remove span element");
//from et-firstElementChild.html
parentEl = document.getElementById("parentEl_fec");
var fec = parentEl.firstElementChild;
is(fec.nodeType, 1, "failed to get firstElementChild");
is(fec.getAttribute("id"), "first_element_child_fec", "failed to get firstElementChild");
isnot(fec, null, "failed to get firstElementChild");
//from et-lastElementChild.html
parentEl = document.getElementById("parentEl_lec");
var lec = parentEl.lastElementChild;
is(lec.nodeType, 1, "failed to get lastElementChild");
is(lec.getAttribute("id"), "last_element_child_lec", "failed to get lastElementChild");
isnot(lec, null, "failed to get lastElementChild");
//from et-namespace.html
parentEl = document.getElementById("parentEl_namespace");
var fec = parentEl.firstElementChild;
isnot(fec, null, "failed to get firstElementChild in namespace");
is(fec.getAttribute("id"), "first_element_child_namespace", "failed to get firstElementChild in namespace");
//from et-nextElementSibling.html
parentEl = document.getElementById("parentEl_nes");
var fec = parentEl.firstElementChild;
var nes = fec.nextElementSibling;
is(nes.nodeType, 1, "failed to get nextElementSibling");
is(nes.getAttribute("id"), "last_element_child_nes", "failed to get nextElementSibling");
isnot(nes, null, "failed to get nextElementSibling");
//from et-previousElementSibling.html
var lec = document.getElementById("last_element_child_pes");
var pes = lec.previousElementSibling;
is(pes.nodeType, 1, "failed to get previousElementSibling");
is(pes.getAttribute("id"), "middle_element_child_pes", "failed to get previousElementSibling");
isnot(pes, null, "failed to get previousElementSibling");
//from et-siblingElement-null.html
var fec = document.getElementById("first_element_child_sibnull");
var pes = fec.previousElementSibling;
var nes = fec.nextElementSibling;
is(pes, null, "got unexpected previousElementSibling");
is(nes, null, "got unexpected nextElementSibling");
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(runTest);
addLoadEvent(SimpleTest.finish)
</script>
</pre>
</body>
</html>

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

@ -0,0 +1,150 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:pickle="http://ns.example.org/pickle" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>W3 Tests for Element Traversal - XHTML</title>
<script type="text/javascript" src="/MochiKit/packed.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>
<p id="parentEl_count">
<span id="first_element_child_count">
<span></span>
<span></span>
</span>
<span id="middle_element_child_count"></span>
<span id="last_element_child_count"></span>
</p>
<p id="parentEl_nochild">
</p>
<p id="parentEl_null">
</p>
<p id="parentEl_dynamicadd">
<span id="first_emement_child_add"></span>
</p>
<p id="parentEl_dynamicremove">
<span id="first_emement_child_remove"></span>
<span id="last_emement_child_remove"></span>
</p>
<p id="parentEl_fec">
<span id="first_element_child_fec"></span>
</p>
<p id="parentEl_lec">
<span id="first_element_child_lec"></span>
<span id="last_element_child_lec"></span>
</p>
<div id="parentEl_namespace">
<pickle:dill />
</div>
<p id="parentEl_nes">
<span id="first_element_child_nes"></span>
<span id="last_element_child_nes"></span>
</p>
<p id="parentEl_pes">
<span id="first_element_child_pes"></span>
<span id="middle_element_child_pes"></span>
<span id="last_element_child_pes"></span>
</p>
<p id="parentEl_sibnull">
<span id="first_element_child_sibnull"></span>
</p>
<pre id="test">
<script class="testbody" type="text/javascript"><![CDATA[
function runTest() {
//from et-childElementCount.html
var parentEl = document.getElementById("parentEl_count");
is(parentEl.childElementCount && 3, parentEl.childElementCount, "Child Element Count is mismatched");
//from et-childElementCount-nochild.html
var parentEl_nochild = document.getElementById("parentEl_nochild");
is(parentEl_nochild.childElementCount, 0, "Child Element count is not 0");
//from et-childElementCount-null.html
parentEl = document.getElementById("parentEl_null");
is(null == parentEl.firstElementChild, null == parentEl.lastElementChild, "firstElementChild or lastElementChild is not null");
//from et-dynamic-add.html
parentEl = document.getElementById("parentEl_dynamicadd");
var newChild = document.createElement("span")
parentEl.appendChild( newChild );
is(parentEl.childElementCount && 2, parentEl.childElementCount, "failed to add span element");
//from et-dynamic-remove.html
parentEl = document.getElementById("parentEl_dynamicremove");
var lec = parentEl.lastElementChild;
parentEl.removeChild( lec );
is(parentEl.childElementCount && 1, parentEl.childElementCount, "failed to remove span element");
//from et-firstElementChild.html
parentEl = document.getElementById("parentEl_fec");
var fec = parentEl.firstElementChild;
is(fec.nodeType, 1, "failed to get firstElementChild");
is(fec.getAttribute("id"), "first_element_child_fec", "failed to get firstElementChild");
isnot(fec, null, "failed to get firstElementChild");
//from et-lastElementChild.html
parentEl = document.getElementById("parentEl_lec");
var lec = parentEl.lastElementChild;
is(lec.nodeType, 1, "failed to get lastElementChild");
is(lec.getAttribute("id"), "last_element_child_lec", "failed to get lastElementChild");
isnot(lec, null, "failed to get lastElementChild");
//from et-namespace.html
parentEl = document.getElementById("parentEl_namespace");
var nChild = parentEl.firstElementChild;
is(nChild && "dill", nChild.localName, "failed to get a namespace element");
//from et-nextElementSibling.html
parentEl = document.getElementById("parentEl_nes");
var fec = parentEl.firstElementChild;
var nes = fec.nextElementSibling;
is(nes.nodeType, 1, "failed to get nextElementSibling");
is(nes.getAttribute("id"), "last_element_child_nes", "failed to get nextElementSibling");
isnot(nes, null, "failed to get nextElementSibling");
//from et-previousElementSibling.html
var lec = document.getElementById("last_element_child_pes");
var pes = lec.previousElementSibling;
is(pes.nodeType, 1, "failed to get previousElementSibling");
is(pes.getAttribute("id"), "middle_element_child_pes", "failed to get previousElementSibling");
isnot(pes, null, "failed to get previousElementSibling");
//from et-siblingElement-null.html
var fec = document.getElementById("first_element_child_sibnull");
var pes = fec.previousElementSibling;
var nes = fec.nextElementSibling;
is(pes, null, "got unexpected previousElementSibling");
is(nes, null, "got unexpected nextElementSibling");
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(runTest);
addLoadEvent(SimpleTest.finish)
]]></script>
</pre>
</body>
</html>

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

@ -0,0 +1,108 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test for ElementTraversal via SVG</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<iframe id="svg" src="w3element_traversal.svg"></iframe>
<pre id="test">
<script class="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();
function run()
{
var doc = $("svg").contentDocument;
//et-namespace.svg
var parentEl = doc.getElementById("parentEl_namespace");
var nChild = parentEl.firstElementChild;
is(nChild && "dill", nChild.localName, "failed to get child with namespace")
//et-previousElementSibling.svg
var lec = doc.getElementById("last_element_child_pes");
var pes = lec.previousElementSibling;
isnot(pes, null, "previousElementSibling is null");
is(pes.nodeType, 1, "previousElementSibling returned the wrong node type");
is(pes.getAttribute("id"), "middle_element_child_pes", "previousElementSibling returned the wrong child");
//et-sibling_null.svg
var fec = doc.getElementById("first_element_child_sibnull");
var pes = fec.previousElementSibling;
var nes = fec.nextElementSibling;
is(pes, null, "previousElementSibling is not null");
is(nes, null, "nextElementSibling is not null");
//et-nextElementSibling.svg
fec = doc.getElementById("first_element_child_nes");
var nes = fec.nextElementSibling;
isnot(nes, null, "nextElementSibling returned NULL");
is(nes.nodeType, 1, "nextElementSibling returned wrong node type");
is(nes.getAttribute("id"), "last_element_child_nes", "nextElementSibling returned wrong node id");
//et-lastElementChild.svg
var parentEl = doc.getElementById("parentEl_lec");
var lec = parentEl.lastElementChild;
isnot(lec, null, "lastElementChild returned null");
is(lec.nodeType, 1, "lastElementChild returned wrong nodeType");
is(lec.getAttribute("id"), "last_element_child_lec", "lastElementChild returned wrong id");
//et-firstElementChild.svg
var parentEl = doc.getElementById("parentEl_fec");
var fec = parentEl.firstElementChild;
isnot(fec, null, "firstElementChild returned null");
is(fec.nodeType, 1, "firstElementChild returned wrong nodeType");
is(fec.getAttribute("id"), "first_element_child_fec", "firstElementChild returned wrong id");
//et-entity.svg
var parentEl = doc.getElementById("parentEl_entity");
var fec = parentEl.firstElementChild;
isnot(fec, null, "firstElementChild returned null");
is(fec.nodeType, 1, "firstElementChild returned wrong nodeType");
is(fec.getAttribute("id"), "first_element_child_entity", "firstElementChild returned wrong id");
//et-dynamic-remove.svg
var parentEl = doc.getElementById("parentEl_dynremove");
var lec = parentEl.lastElementChild;
parentEl.removeChild( lec );
is(parentEl.childElementCount && 1, parentEl.childElementCount, "failed to removeChild");
//et-dynamic-add.svg
var parentEl = doc.getElementById("parentEl_dynadd");
var newChild = doc.createElementNS("http://www.w3.org/2000/svg", "tspan");
parentEl.appendChild( newChild );
is(parentEl.childElementCount && 2, parentEl.childElementCount, "failed to appendChild");
//et-childElement-null.svg
var parentEl = doc.getElementById("parentEl_null");
var fec = parentEl.firstElementChild;
var lec = parentEl.lastElementChild;
is(fec, null, "expected null from firstElementChild");
is(lec, null, "expected null from lastElementChild");
//et-childElementCount.svg
var parentEl = doc.getElementById("parentEl_count");
is(parentEl.childElementCount && 3, parentEl.childElementCount, "got wrong childElementCount");
//et-childElementCount-nochild.svg
var parentEl = doc.getElementById("parentEl_nochild");
is(0, parentEl.childElementCount, "got wrong childElementCount");
SimpleTest.finish();
}
window.addEventListener("load", run, false);
</script>
</pre>
</body>
</html>

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

@ -0,0 +1,70 @@
<!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_entity'></tspan>">
]>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:pickle="http://ns.example.org/pickle"
version="1.1"
width="100%" height="100%" viewBox="0 0 400 400">
<text >
<tspan id="first_element_child_namespace"></tspan>
</text>
<g id="parentEl_namespace">
<pickle:dill />
</g>
<text id="parentEl_pes" >
<tspan id="first_element_child_pes"></tspan>
<tspan id="middle_element_child_pes"></tspan>
<tspan id="last_element_child_pes"></tspan>
</text>
<text id="parentEl" >
<tspan id="first_element_child_sibnull"></tspan>
</text>
<text id="parentEl_nes" >
<tspan id="first_element_child_nes"></tspan>
<tspan id="last_element_child_nes"></tspan>
</text>
<text id="parentEl_lec" >
<tspan id="first_element_child_lec"></tspan>
<tspan id="last_element_child_lec"></tspan>
</text>
<text id="parentEl_fec" >
<tspan id="first_element_child_fec"></tspan>
</text>
<text id="parentEl_entity" >&tree;</text>
<text id="parentEl_dynremove" >
<tspan id="first_element_child_dynremove"></tspan>
<tspan id="last_element_child_dynremove"></tspan>
</text>
<text id="parentEl_dynadd" >
<tspan id="first_element_child_dynadd"></tspan>
</text>
<text id="parentEl_null" ></text>
<text id="parentEl_count" >
<tspan id="first_element_child_count">
<tspan></tspan>
<tspan></tspan>
</tspan>
<tspan id="middle_element_child"></tspan>
<tspan id="last_element_child_count"></tspan>
</text>
<text id="parentEl_nochild"></text>
</svg>

После

Ширина:  |  Высота:  |  Размер: 1.7 KiB