import FIREFOX_52_6_0esr_RELEASE from mozilla-esr52 hg repo

This commit is contained in:
Roy Tam 2018-01-19 03:59:58 +08:00
commit dcd9973243
150858 changed files with 23884658 additions and 0 deletions

View file

@ -0,0 +1,100 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Creating and deleting captions</title>
<link rel="author" title="Erika Navara" href="mailto:edoyle@microsoft.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#the-table-element" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-table-createcaption" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-table-deletecaption" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<table id="table0" style="display:none">
</table>
<table id="table1" style="display:none">
<caption id="caption1">caption</caption>
<tr>
<td>cell</td>
<td>cell</td>
</tr>
</table>
<table id="table2" style="display:none">
<foo:caption>caption</foo:caption>
<tr>
<td>cell</td>
<td>cell</td>
</tr>
</table>
<table id="table3" style="display:none">
<caption id="caption3">caption 3</caption>
<tr>
<td>cell</td>
<td>cell</td>
</tr>
</table>
<table id="table4" style="display:none">
</table>
<table id="table5" style="display:none">
</table>
<script>
test(function () {
var table0 = document.getElementById('table0');
var caption = document.createElementNS("foo", "caption");
table0.appendChild(caption);
var table0FirstNode = table0.firstChild;
var testCaption = table0.createCaption();
assert_not_equals(testCaption, table0FirstNode);
assert_equals(testCaption, table0.firstChild);
}, "createCaption method creates new caption if existing caption is not in html namespace")
test(function () {
var table1 = document.getElementById('table1');
var testCaption = table1.createCaption();
var table1FirstCaption = table1.caption;
assert_equals(testCaption, table1FirstCaption);
}, "createCaption method returns the first caption element child of the table")
test(function () {
var table2 = document.getElementById('table2');
var test2Caption = table2.createCaption();
var table2FirstNode = table2.firstChild;
assert_true(test2Caption instanceof HTMLTableCaptionElement);
assert_equals(table2FirstNode, test2Caption);
}, "createCaption method creates a new caption and inserts it as the first node of the table element")
test(function () {
var table = document.createElement('table');
assert_equals(table.createCaption(), table.createCaption());
}, "createCaption will not create new caption if one exists")
test(function () {
var table = document.createElementNS("http://www.w3.org/1999/xhtml", "foo:table")
var caption = table.createCaption();
assert_equals(caption.prefix, null);
}, "createCaption will not copy table's prefix")
test(function () {
var table3 = document.getElementById('table3');
assert_equals(table3.caption.textContent, "caption 3");
table3.deleteCaption();
assert_equals(table3.caption, null);
}, "deleteCaption method removes the first caption element child of the table element")
test(function () {
var table4 = document.getElementById('table4');
var caption = document.createElementNS("foo", "caption");
table4.appendChild(caption);
table4.deleteCaption();
assert_equals(caption.parentNode, table4);
}, "deleteCaption method not remove caption that is not in html namespace")
test(function() {
var table5 = document.getElementById('table5');
var caption = document.createElement('caption');
caption.appendChild(table5)
// Node cannot be inserted at the specified point in the hierarchy
assert_throws("HierarchyRequestError", function() {
table5.caption = caption;
});
assert_not_equals(table5.caption, caption);
}, "Setting caption rethrows exception");
</script>
</body>
</html>

View file

@ -0,0 +1,10 @@
[
{
"id": "table-descriptions-techniques",
"original_id": "table-descriptions-techniques"
},
{
"id": "table-layout-techniques",
"original_id": "table-layout-techniques"
}
]

View file

@ -0,0 +1,173 @@
<!doctype html>
<meta charset=utf-8>
<title>HTMLTableElement.createTBody</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
<script>
function assert_tbody(tbody) {
assert_equals(tbody.localName, "tbody");
assert_equals(tbody.namespaceURI, htmlNS);
assert_equals(tbody.prefix, null);
}
var htmlNS = "http://www.w3.org/1999/xhtml";
test(function() {
var table = document.createElement("table");
var tbody = table.createTBody();
assert_equals(table.firstChild, tbody);
assert_tbody(tbody);
}, "No child nodes");
test(function() {
var table = document.createElement("table");
var before = table.appendChild(document.createElement("tbody"));
assert_array_equals(table.childNodes, [before]);
var tbody = table.createTBody();
assert_array_equals(table.childNodes, [before, tbody]);
assert_tbody(tbody);
}, "One tbody child node");
test(function() {
var table = document.createElement("table");
var before1 = table.appendChild(document.createElement("tbody"));
var before2 = table.appendChild(document.createElement("tbody"));
assert_array_equals(table.childNodes, [before1, before2]);
var tbody = table.createTBody();
assert_array_equals(table.childNodes, [before1, before2, tbody]);
assert_tbody(tbody);
}, "Two tbody child nodes");
test(function() {
var table = document.createElement("table");
var before1 = table.appendChild(document.createElement("thead"));
var before2 = table.appendChild(document.createElement("tbody"));
assert_array_equals(table.childNodes, [before1, before2]);
var tbody = table.createTBody();
assert_array_equals(table.childNodes, [before1, before2, tbody]);
assert_tbody(tbody);
}, "A thead and a tbody child node");
test(function() {
var table = document.createElement("table");
var before1 = table.appendChild(document.createElement("tfoot"));
var before2 = table.appendChild(document.createElement("tbody"));
assert_array_equals(table.childNodes, [before1, before2]);
var tbody = table.createTBody();
assert_array_equals(table.childNodes, [before1, before2, tbody]);
assert_tbody(tbody);
}, "A tfoot and a tbody child node");
test(function() {
var table = document.createElement("table");
var before = table.appendChild(document.createElement("tbody"));
var after = table.appendChild(document.createElement("thead"));
assert_array_equals(table.childNodes, [before, after]);
var tbody = table.createTBody();
assert_array_equals(table.childNodes, [before, tbody, after]);
assert_tbody(tbody);
}, "A tbody and a thead child node");
test(function() {
var table = document.createElement("table");
var before = table.appendChild(document.createElement("tbody"));
var after = table.appendChild(document.createElement("tfoot"));
assert_array_equals(table.childNodes, [before, after]);
var tbody = table.createTBody();
assert_array_equals(table.childNodes, [before, tbody, after]);
assert_tbody(tbody);
}, "A tbody and a tfoot child node");
test(function() {
var table = document.createElement("table");
var before1 = table.appendChild(document.createElement("tbody"));
var before2 = table.appendChild(document.createElement("tbody"));
var after = table.appendChild(document.createElement("div"));
assert_array_equals(table.childNodes, [before1, before2, after]);
var tbody = table.createTBody();
assert_array_equals(table.childNodes, [before1, before2, tbody, after]);
assert_tbody(tbody);
}, "Two tbody child nodes and a div");
test(function() {
var table = document.createElement("table");
var before = table.appendChild(document.createElement("tbody"));
var after = table.appendChild(document.createElementNS("x", "tbody"));
assert_array_equals(table.childNodes, [before, after]);
var tbody = table.createTBody();
assert_array_equals(table.childNodes, [before, tbody, after]);
assert_tbody(tbody);
}, "One HTML and one namespaced tbody child node");
test(function() {
var table = document.createElement("table");
var before1 = table.appendChild(document.createElement("tbody"));
var before2 = before1.appendChild(document.createElement("tbody"));
assert_array_equals(table.childNodes, [before1]);
var tbody = table.createTBody();
assert_array_equals(table.childNodes, [before1, tbody]);
assert_tbody(tbody);
}, "Two nested tbody child nodes");
test(function() {
var table = document.createElement("table");
var before1 = table.appendChild(document.createElement("thead"));
var before2 = before1.appendChild(document.createElement("tbody"));
assert_array_equals(table.childNodes, [before1]);
var tbody = table.createTBody();
assert_array_equals(table.childNodes, [before1, tbody]);
assert_tbody(tbody);
}, "A tbody node inside a thead child node");
test(function() {
var table = document.createElement("table");
var before1 = table.appendChild(document.createElement("tfoot"));
var before2 = before1.appendChild(document.createElement("tbody"));
assert_array_equals(table.childNodes, [before1]);
var tbody = table.createTBody();
assert_array_equals(table.childNodes, [before1, tbody]);
assert_tbody(tbody);
}, "A tbody node inside a tfoot child node");
test(function() {
var table = document.createElement("table");
var before = table.appendChild(document.createElement("tbody"));
var after1 = table.appendChild(document.createElement("thead"));
var after2 = after1.appendChild(document.createElement("tbody"));
assert_array_equals(table.childNodes, [before, after1]);
var tbody = table.createTBody();
assert_array_equals(table.childNodes, [before, tbody, after1]);
assert_tbody(tbody);
}, "A tbody node inside a thead child node after a tbody child node");
test(function() {
var table = document.createElement("table");
var before = table.appendChild(document.createElement("tbody"));
var after1 = table.appendChild(document.createElement("tfoot"));
var after2 = after1.appendChild(document.createElement("tbody"));
assert_array_equals(table.childNodes, [before, after1]);
var tbody = table.createTBody();
assert_array_equals(table.childNodes, [before, tbody, after1]);
assert_tbody(tbody);
}, "A tbody node inside a tfoot child node after a tbody child node");
test(function() {
var table = document.createElementNS(htmlNS, "foo:table");
var tbody = table.createTBody();
assert_equals(tbody.prefix, null);
}, "A prefixed table creates tbody without prefix");
</script>

View file

@ -0,0 +1,94 @@
<!DOCTYPE HTML>
<html>
<head>
<title>deleteCaption()</title>
<link rel="author" title="Ben Boyle" href="mailto:benjamins.boyle@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-table-deletecaption" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<table id="one-caption">
<caption>Fixture table caption</caption>
</table>
<table id="two-captions">
<caption>Fixture table caption</caption>
<caption>A second caption element</caption>
</table>
<table id="zero-captions"></table>
<table id="descendent-caption">
<tr>
<td>
<table>
<caption>Nested caption</caption>
</table>
</td>
</tr>
</table>
<script>
// The deleteCaption() method must remove the first caption element child of the table element, if any.
// https://html.spec.whatwgorg/multipage/tables.html#dom-table-deletecaption
test(function() {
var table = document.getElementById('one-caption');
table.deleteCaption();
assert_equals(table.getElementsByTagName('caption').length, 0, 'caption was removed');
}, 'deleteCaption() delete only caption on table');
test(function() {
var table = document.getElementById('one-caption');
var result;
result = table.deleteCaption();
// does .deleteCaption() have a return value?
assert_equals(result, undefined, '.deleteCaption() returns undefined');
}, 'deleteCaption() returns undefined');
test(function() {
var table = document.getElementById('two-captions');
table.deleteCaption();
assert_equals(table.getElementsByTagName('caption').length, 1, '1 caption (of 2) was removed');
assert_equals(table.getElementsByTagName('caption')[0].textContent, 'A second caption element', 'The first caption was removed');
// removing the only caption
table.deleteCaption();
assert_equals(table.getElementsByTagName('caption').length, 0, 'last caption was removed');
}, 'deleteCaption()');
test(function() {
var table = document.getElementById('zero-captions');
// removing a caption when none exists
table.deleteCaption();
assert_equals(table.getElementsByTagName('caption').length, 0, 'no exceptions using .deleteCaption() on a table without any captions');
}, 'deleteCaption() does not throw any exceptions when called on a table without a caption');
test(function() {
var table = document.getElementById( 'descendent-caption' );
table.deleteCaption();
assert_equals(table.getElementsByTagName('caption').length, 1, 'descendent caption was not deleted');
}, 'deleteCaption() does not delete captions in descendent tables');
test(function() {
var table = document.getElementById('zero-captions');
var caption;
caption = document.createElementNS('http://www.w3.org/2000/svg', 'caption');
table.insertBefore(caption, table.firstChild);
assert_equals(table.getElementsByTagName('caption').length, 1, 'SVG:caption is created');
table.deleteCaption();
assert_equals(table.getElementsByTagName('caption').length, 1, 'SVG:caption is not deleted');
}, 'deleteCaption() handles captions from different namespaces');
</script>
</body>
</html>

View file

@ -0,0 +1,24 @@
<!DOCTYPE html>
<title>insertRow(): INDEX_SIZE_ERR</title>
<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-table-insertrow">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<div id="test">
<table>
<tr>
<td>
</table>
</div>
<script>
test(function() {
var table = document.getElementById("test").getElementsByTagName("table")[0];
assert_throws("INDEX_SIZE_ERR", function() {
table.insertRow(-2);
})
assert_throws("INDEX_SIZE_ERR", function() {
table.insertRow(2);
})
});
</script>

View file

@ -0,0 +1,34 @@
<!DOCTYPE html>
<title>insertRow(): Empty table</title>
<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-table-insertrow">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<div id="test">
<table></table>
</div>
<script>
var HTML = "http://www.w3.org/1999/xhtml";
test(function() {
var table = document.getElementById("test").getElementsByTagName("table")[0];
test(function() {
assert_equals(table.childNodes.length, 0);
assert_equals(table.rows.length, 0);
}, "table should start out empty")
var tr;
test(function() {
tr = table.insertRow(0);
assert_equals(tr.localName, "tr");
assert_equals(tr.namespaceURI, HTML);
}, "insertRow should insert a tr element")
var tbody = tr.parentNode;
test(function() {
assert_equals(tbody.localName, "tbody");
assert_equals(tbody.namespaceURI, HTML);
assert_equals(tbody.parentNode, table);
}, "insertRow should insert a tbody element")
});
</script>

View file

@ -0,0 +1,32 @@
<!DOCTYPE html>
<title>insertRow(): non-empty table</title>
<link rel="author" title="g-k" href="mailto:greg.guthe@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#dom-table-insertrow">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<div id="test">
<table>
<tbody><tr id="first"></tr><tr id="second"></tr></tbody>
</table>
</div>
<script>
var HTML = "http://www.w3.org/1999/xhtml";
test(function() {
var table = document.getElementById("test").getElementsByTagName("table")[0];
test(function() {
assert_equals(table.childNodes.length, 3);
assert_equals(table.rows.length, 2);
}, "table should start out with two rows")
var tr;
test(function() {
tr = table.insertRow(1);
assert_equals(tr.localName, "tr");
assert_equals(tr.namespaceURI, HTML);
assert_equals(table.getElementsByTagName("tr")[0].id, "first");
assert_equals(table.getElementsByTagName("tr")[1].id, "");
assert_equals(table.getElementsByTagName("tr")[2].id, "second");
}, "insertRow should insert a tr element before the second row")
});
</script>

View file

@ -0,0 +1,50 @@
<!doctype html>
<meta charset="utf-8">
<title>Delete Row tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<table id="element">
<thead>
<th>First column</th>
<th>Second column</th>
</thead>
<tbody>
<tr>
<td>1.1</td>
<td>1.2</td>
</tr>
<tr>
<td>2.1</td>
<td>2.2</td>
</tr>
</tbody>
</table>
<script>
var el = document.getElementById('element');
test(function() {
assert_throws("IndexSizeError", function() {
el.deleteRow(-2)
})
}, 'deleteRow function invalid argument');
test(function() {
assert_throws("IndexSizeError", function() {
el.deleteRow(el.rows.length)
})
}, 'deleteRow function invalid argument bis');
test(function() {
var old_length = el.rows.length;
el.insertRow(-1);
el.deleteRow(-1);
assert_equals(old_length, el.rows.length);
}, "check normal deleteRow");
test(function() {
while (el.rows.length > 1) {
el.deleteRow(-1);
}
assert_equals(1, el.rows.length);
}, "check normal deleteRow bis");
</script>

View file

@ -0,0 +1,40 @@
<!DOCTYPE html>
<title>HTMLTableElement.tBodies</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
test(function() {
var text =
'<html xmlns="http://www.w3.org/1999/xhtml">' +
' <head>' +
' <title>Virtual Library</title>' +
' </head>' +
' <body>' +
' <table id="mytable" border="1">' +
' <tbody>' +
' <tr><td>Cell 1</td><td>Cell 2</td></tr>' +
' <tr><td>Cell 3</td><td>Cell 4</td></tr>' +
' </tbody>' +
' </table>' +
' </body>' +
'</html>';
var parser = new DOMParser();
var doc = parser.parseFromString(text, "text/xml");
// import <table>
var table = doc.documentElement.getElementsByTagName('table')[0];
var mytable = document.body.appendChild(document.importNode(table, true));
assert_equals(mytable.tBodies.length, 1);
var tbody = document.createElement('tbody');
mytable.appendChild(tbody);
var tr = tbody.insertRow(-1);
tr.insertCell(-1).appendChild(document.createTextNode('Cell 5'));
tr.insertCell(-1).appendChild(document.createTextNode('Cell 6'));
assert_equals(mytable.tBodies.length, 2);
assert_equals(mytable.rows.length, 3);
assert_equals(tr.rowIndex, 2);
});
</script>

View file

@ -0,0 +1,57 @@
<!doctype html>
<meta charset="utf-8">
<title>tFoot tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<table id="t">
<caption id="tcaption"></caption><thead id="thead"></thead><tbody id="tbody1"></tbody><tbody id="tbody2"></tbody><tfoot id="tfoot1"></tfoot><tfoot id="tfoot2"></tfoot><tfoot id="tfoot3"></tfoot></table>
<script>
test(function() {
var t = document.getElementById("t");
var tfoot1 = document.getElementById("tfoot1");
assert_equals(t.tFoot, tfoot1);
var tfoot2 = document.getElementById("tfoot2");
t.tFoot = null;
assert_equals(t.tFoot, tfoot2);
var tfoot3 = document.getElementById("tfoot3");
t.deleteTFoot();
assert_equals(t.tFoot, tfoot3);
var tfoot = t.createTFoot();
assert_equals(t.tFoot, tfoot);
assert_equals(tfoot, tfoot3);
t.deleteTFoot();
assert_equals(t.tFoot, null);
var tbody2 = document.getElementById("tbody2");
tfoot = t.createTFoot();
assert_equals(t.tFoot, tfoot);
assert_equals(t.tFoot.previousSibling, tbody2);
assert_equals(t.tFoot.nextSibling, null);
t.deleteTFoot();
assert_equals(t.tFoot, null);
t.tFoot = tfoot;
assert_equals(t.tFoot, tfoot);
assert_equals(t.tFoot.previousSibling, tbody2);
assert_equals(t.tFoot.nextSibling, null);
assert_throws(new TypeError(), function(){
t.tFoot = document.createElement("div");
});
assert_throws("HierarchyRequestError", function(){
t.tFoot = document.createElement("thead");
});
})
</script>

View file

@ -0,0 +1,66 @@
<!doctype html>
<meta charset="utf-8">
<title>tHead tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<table id="t">
<caption id="tcaption"></caption><thead id="thead1"></thead><thead id="thead2"></thead><thead id="thead3"></thead><tbody id="tbody1"></tbody><tbody id="tbody2"></tbody><tfoot id="tfoot"></tfoot>
</table>
<table>
<thead id="t2thead">
<td>
<table id="t2">
</table>
</table>
<script>
test(function() {
var t = document.getElementById("t");
var thead1 = document.getElementById("thead1");
assert_equals(t.tHead, thead1);
var thead2 = document.getElementById("thead2");
t.tHead = null;
assert_equals(t.tHead, thead2);
var thead3 = document.getElementById("thead3");
t.deleteTHead();
assert_equals(t.tHead, thead3);
var thead = t.createTHead();
assert_equals(t.tHead, thead);
assert_equals(thead, thead3);
t.deleteTHead();
assert_equals(t.tHead, null);
var tcaption = document.getElementById("tcaption");
var tbody1 = document.getElementById("tbody1");
thead = t.createTHead();
assert_equals(t.tHead, thead);
assert_equals(t.tHead.previousSibling, tcaption);
assert_equals(t.tHead.nextSibling, tbody1);
assert_throws(new TypeError(), function(){
t.tHead = document.createElement("div");
});
assert_throws("HierarchyRequestError", function(){
t.tHead = document.createElement("tbody");
});
});
test(function() {
var t2 = document.getElementById("t2");
var t2thead = document.getElementById("t2thead");
assert_throws("HierarchyRequestError", function() {
t2.tHead = t2thead;
});
});
</script>

View file

@ -0,0 +1,56 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>HTMLTableElement.insertRow</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
test(function() {
var HTMLNS = "http://www.w3.org/1999/xhtml"
var parentEl = document.createElementNS(HTMLNS, "html:table")
assert_equals(parentEl.namespaceURI, HTMLNS, "Parent should be in the HTML namespace")
assert_equals(parentEl.prefix, "html", "Parent prefix should be html")
assert_equals(parentEl.localName, "table", "Parent local name should be table")
assert_equals(parentEl.tagName, "HTML:TABLE", "Parent tag name should be HTML:TABLE")
var row = parentEl.insertRow(-1)
assert_equals(row.namespaceURI, HTMLNS, "Row should be in the HTML namespace")
assert_equals(row.prefix, null, "Row prefix should be null")
assert_equals(row.localName, "tr", "Row local name should be tr")
assert_equals(row.tagName, "TR", "Row tag name should be TR")
var body = row.parentNode
assert_equals(body.namespaceURI, HTMLNS, "Body should be in the HTML namespace")
assert_equals(body.prefix, null, "Body prefix should be null")
assert_equals(body.localName, "tbody", "Body local name should be tr")
assert_equals(body.tagName, "TBODY", "Body tag name should be TR")
assert_array_equals(parentEl.childNodes, [body])
assert_array_equals(body.childNodes, [row])
assert_array_equals(parentEl.rows, [row])
}, "insertRow should not copy prefixes")
test(function() {
var table = document.createElement("table")
var head = table.appendChild(document.createElement("thead"))
assert_array_equals(table.rows, [])
var row = table.insertRow(-1)
var body = row.parentNode
assert_array_equals(table.childNodes, [head, body])
assert_array_equals(head.childNodes, [])
assert_array_equals(body.childNodes, [row])
assert_array_equals(table.rows, [row])
}, "insertRow should insert into a tbody, not into a thead, if table.rows is empty")
test(function() {
var table = document.createElement("table")
var foot = table.appendChild(document.createElement("tfoot"))
assert_array_equals(table.rows, [])
var row = table.insertRow(-1)
var body = row.parentNode
assert_array_equals(table.childNodes, [foot, body])
assert_array_equals(foot.childNodes, [])
assert_array_equals(body.childNodes, [row])
assert_array_equals(table.rows, [row])
}, "insertRow should insert into a tbody, not into a tfoot, if table.rows is empty")
</script>

View file

@ -0,0 +1,234 @@
<!DOCTYPE html>
<title>HTMLTableElement.rows</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
function assert_nodelist_equals(actual, expected) {
assert_equals(actual.length, expected.length);
for (var i = 0; i < actual.length; ++i) {
assert_true(i in actual);
assert_true(actual.hasOwnProperty(i),
"property " + i + " expected to be present on the object");
assert_equals(actual.item(i), expected[i]);
assert_equals(actual[i], expected[i]);
}
}
function test_table_simple(group, table) {
var foo1 = group.appendChild(document.createElement("tr"));
foo1.id = "foo";
var bar1 = group.appendChild(document.createElement("tr"));
bar1.id = "bar";
var foo2 = group.appendChild(document.createElement("tr"));
foo2.id = "foo";
var bar2 = group.appendChild(document.createElement("tr"));
bar2.id = "bar";
assert_true(table.rows instanceof HTMLCollection, "table.rows should be a HTMLCollection.");
assert_nodelist_equals(table.rows, [foo1, bar1, foo2, bar2]);
assert_equals(table.rows.foo, foo1);
assert_equals(table.rows["foo"], foo1);
assert_equals(table.rows.namedItem("foo"), foo1);
assert_equals(table.rows.bar, bar1);
assert_equals(table.rows["bar"], bar1);
assert_equals(table.rows.namedItem("bar"), bar1);
assert_array_equals(Object.getOwnPropertyNames(table.rows), [
"0",
"1",
"2",
"3",
"foo",
"bar"
]);
}
test(function() {
var table = document.createElement("table");
test_table_simple(table, table);
}, "Children of table");
test(function() {
var table = document.createElement("table");
var group = table.appendChild(document.createElement("thead"));
test_table_simple(group, table);
}, "Children of thead");
test(function() {
var table = document.createElement("table");
var group = table.appendChild(document.createElement("tbody"));
test_table_simple(group, table);
}, "Children of tbody");
test(function() {
var table = document.createElement("table");
var group = table.appendChild(document.createElement("tfoot"));
test_table_simple(group, table);
}, "Children of tfoot");
test(function() {
var table = document.createElement("table");
var orphan1 = table.appendChild(document.createElement("tr"));
orphan1.id = "orphan1";
var foot1 = table.appendChild(document.createElement("tfoot"));
var orphan2 = table.appendChild(document.createElement("tr"));
orphan2.id = "orphan2";
var foot2 = table.appendChild(document.createElement("tfoot"));
var orphan3 = table.appendChild(document.createElement("tr"));
orphan3.id = "orphan3";
var body1 = table.appendChild(document.createElement("tbody"));
var orphan4 = table.appendChild(document.createElement("tr"));
orphan4.id = "orphan4";
var body2 = table.appendChild(document.createElement("tbody"));
var orphan5 = table.appendChild(document.createElement("tr"));
orphan5.id = "orphan5";
var head1 = table.appendChild(document.createElement("thead"));
var orphan6 = table.appendChild(document.createElement("tr"));
orphan6.id = "orphan6";
var head2 = table.appendChild(document.createElement("thead"));
var orphan7 = table.appendChild(document.createElement("tr"));
orphan7.id = "orphan7";
var foot1row1 = foot1.appendChild(document.createElement("tr"));
foot1row1.id = "foot1row1";
var foot1row2 = foot1.appendChild(document.createElement("tr"));
foot1row2.id = "foot1row2";
var foot2row1 = foot2.appendChild(document.createElement("tr"));
foot2row1.id = "foot2row1";
var foot2row2 = foot2.appendChild(document.createElement("tr"));
foot2row2.id = "foot2row2";
var body1row1 = body1.appendChild(document.createElement("tr"));
body1row1.id = "body1row1";
var body1row2 = body1.appendChild(document.createElement("tr"));
body1row2.id = "body1row2";
var body2row1 = body2.appendChild(document.createElement("tr"));
body2row1.id = "body2row1";
var body2row2 = body2.appendChild(document.createElement("tr"));
body2row2.id = "body2row2";
var head1row1 = head1.appendChild(document.createElement("tr"));
head1row1.id = "head1row1";
var head1row2 = head1.appendChild(document.createElement("tr"));
head1row2.id = "head1row2";
var head2row1 = head2.appendChild(document.createElement("tr"));
head2row1.id = "head2row1";
var head2row2 = head2.appendChild(document.createElement("tr"));
head2row2.id = "head2row2";
// These elements should not end up in any collection.
table.appendChild(document.createElement("div"))
.appendChild(document.createElement("tr"));
foot1.appendChild(document.createElement("div"))
.appendChild(document.createElement("tr"));
body1.appendChild(document.createElement("div"))
.appendChild(document.createElement("tr"));
head1.appendChild(document.createElement("div"))
.appendChild(document.createElement("tr"));
table.appendChild(document.createElementNS("http://example.com/test", "tr"));
foot1.appendChild(document.createElementNS("http://example.com/test", "tr"));
body1.appendChild(document.createElementNS("http://example.com/test", "tr"));
head1.appendChild(document.createElementNS("http://example.com/test", "tr"));
assert_true(table.rows instanceof HTMLCollection, "table.rows should be a HTMLCollection.");
assert_nodelist_equals(table.rows, [
// thead
head1row1,
head1row2,
head2row1,
head2row2,
// tbody + table
orphan1,
orphan2,
orphan3,
body1row1,
body1row2,
orphan4,
body2row1,
body2row2,
orphan5,
orphan6,
orphan7,
// tfoot
foot1row1,
foot1row2,
foot2row1,
foot2row2
]);
assert_array_equals(Object.getOwnPropertyNames(table.rows), [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"head1row1",
"head1row2",
"head2row1",
"head2row2",
"orphan1",
"orphan2",
"orphan3",
"body1row1",
"body1row2",
"orphan4",
"body2row1",
"body2row2",
"orphan5",
"orphan6",
"orphan7",
"foot1row1",
"foot1row2",
"foot2row1",
"foot2row2"
]);
var ids = [
"orphan1",
"orphan2",
"orphan3",
"orphan4",
"orphan5",
"orphan6",
"orphan7",
"foot1row1",
"foot1row2",
"foot2row1",
"foot2row2",
"body1row1",
"body1row2",
"body2row1",
"body2row2",
"head1row1",
"head1row2",
"head2row1",
"head2row2"
];
ids.forEach(function(id) {
assert_equals(table.rows.namedItem(id).id, id);
assert_true(id in table.rows);
assert_equals(table.rows[id].id, id);
assert_true(id in table.rows);
});
while (table.firstChild) {
table.removeChild(table.firstChild);
}
ids.forEach(function(id) {
assert_equals(table.rows.namedItem(id), null);
assert_false(id in table.rows);
assert_equals(table.rows[id], undefined);
assert_false(id in table.rows);
});
}, "Complicated case");
</script>