diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/html/semantics/tabular-data/the-table-element | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/html/semantics/tabular-data/the-table-element')
12 files changed, 1166 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/caption-methods.html b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/caption-methods.html new file mode 100644 index 0000000000..a349ed2b77 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/caption-methods.html @@ -0,0 +1,276 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta charset="utf-8"> + <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> + <table id="table6" style="display:none"> + <caption id="caption6">caption 6</caption> + <tr> + <td>cell</td> + <td>cell</td> + </tr> + </table> + <table id="table7" style="display:none"> + <caption id="caption7">caption 7</caption> + <tbody id="tbody7"> + <tr> + <td>cell</td> + <td>cell</td> + </tr> + </tbody> + </table> + <table id="table10" style="display:none"> + <tbody> + <tr> + <td>cell</td> + <td>cell</td> + </tr> + </tbody> + <caption>caption 10</caption> + </table> + <table id="table11" style="display:none"> + <caption id="caption11">caption 11</caption> + </table> + <table id="table12" style="display:none"> + <caption>caption 1</caption> + <caption>caption 2</caption> + </table> + <table id="table13" style="display:none"> + </table> + <table id="table14" style="display:none"> + <tbody> + <tr> + <td>cell</td> + <td>cell</td> + </tr> + </tbody> + <caption id="caption14">caption 14</caption> + </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_dom("HierarchyRequestError", function() { + table5.caption = caption; + }); + + assert_not_equals(table5.caption, caption); + }, "Setting caption rethrows exception"); + + test(function() { + var table6 = document.getElementById("table6"); + var caption = document.getElementById("caption6"); + assert_equals(table6.caption, caption); + + var newCaption = document.createElement("caption"); + table6.caption = newCaption; + assert_equals(newCaption.parentNode, table6); + assert_equals(table6.firstChild, newCaption); + assert_equals(table6.caption, newCaption); + }, "Assigning a caption to table.caption") + + test(function() { + var table7 = document.getElementById("table7"); + var caption = document.getElementById("caption7"); + assert_equals(table7.caption, caption); + + table7.caption = null; + assert_equals(caption.parentNode, null); + assert_equals(table7.firstElementChild, document.getElementById("tbody7")); + assert_equals(table7.caption, null); + }, "Assigning null to table.caption") + + test(function() { + var table8 = document.createElement("table"); + var caption = document.createElement("captÄ°on"); + assert_throws_js(TypeError, function() { + table8.caption = caption; + }); + }, "Assigning a non-caption to table.caption") + + test(function() { + var table9 = document.createElement("table"); + var caption = document.createElementNS("http://www.example.com", "caption"); + assert_throws_js(TypeError, function() { + table9.caption = caption; + }); + }, "Assigning a foreign caption to table.caption") + + test(function() { + var table = document.createElement("table"); + var caption = document.createElement("caption"); + caption.innerHTML = "new caption"; + table.caption = caption; + + assert_equals(caption.parentNode, table); + assert_equals(table.firstChild, caption); + assert_equals(table.caption.innerHTML, "new caption"); + }, "Set table.caption when the table doesn't already have a caption") + + test(function() { + var table10 = document.getElementById("table10"); + var caption = document.createElement("caption"); + caption.innerHTML = "new caption"; + table10.caption = caption; + + assert_equals(caption.parentNode, table10); + assert_equals(table10.firstChild, caption); + assert_equals(table10.caption.innerHTML, "new caption"); + + var captions = table10.getElementsByTagName('caption'); + assert_equals(captions.length, 1); + }, "Set table.caption when the table has a caption child but with other siblings before it") + + test(function() { + var table11 = document.getElementById("table11"); + var caption = document.createElement("caption"); + caption.innerHTML = "new caption"; + table11.caption = caption; + + assert_equals(caption.parentNode, table11); + assert_equals(table11.firstChild, caption); + assert_equals(table11.caption.innerHTML, "new caption"); + + var captions = table11.getElementsByTagName('caption'); + assert_equals(captions.length, 1); + }, "Set table.caption when the table has a caption descendant") + + test(function() { + var table12 = document.getElementById("table12"); + var caption = document.createElement("caption"); + caption.innerHTML = "new caption"; + table12.caption = caption; + + assert_equals(caption.parentNode, table12); + assert_equals(table12.firstChild, caption); + assert_equals(table12.caption.innerHTML, "new caption"); + + var captions = table12.getElementsByTagName('caption'); + assert_equals(captions.length, 2); + assert_equals(captions[0].innerHTML, "new caption"); + assert_equals(captions[1].innerHTML, "caption 2"); + }, "Set table.caption when the table has two caption children") + + promise_test(async t => { + var table13 = document.getElementById("table13"); + var iframe = document.createElement("iframe"); + iframe.srcdoc = '<table><caption id="caption13">caption 13</caption></table>'; + document.body.appendChild(iframe); + + var iframeWatcher = new EventWatcher(t, iframe, "load"); + await iframeWatcher.wait_for("load"); + var caption = iframe.contentWindow.document.getElementById("caption13"); + table13.caption = caption; + + assert_equals(caption.parentNode, table13); + assert_equals(table13.firstChild, caption); + assert_equals(table13.caption.innerHTML, "caption 13"); + + var captions = table13.getElementsByTagName('caption'); + assert_equals(captions.length, 1); + }, "Assigning a caption has a different owner document to table.caption") + + test(function() { + var table14 = document.getElementById("table14"); + var caption = document.getElementById("caption14"); + table14.caption = caption; + + assert_equals(caption.parentNode, table14); + assert_equals(table14.firstChild, caption); + + var captions = table14.getElementsByTagName('caption'); + assert_equals(captions.length, 1); + }, "Assigning the caption already in the table to table.caption") + </script> +</body> +</html> diff --git a/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/createTBody.html b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/createTBody.html new file mode 100644 index 0000000000..6100aedfdf --- /dev/null +++ b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/createTBody.html @@ -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> diff --git a/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/delete-caption.html b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/delete-caption.html new file mode 100644 index 0000000000..6183fa98b8 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/delete-caption.html @@ -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> diff --git a/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/insertRow-method-01.html b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/insertRow-method-01.html new file mode 100644 index 0000000000..8ed7b5fad6 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/insertRow-method-01.html @@ -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_dom("INDEX_SIZE_ERR", function() { + table.insertRow(-2); + }) + assert_throws_dom("INDEX_SIZE_ERR", function() { + table.insertRow(2); + }) +}); +</script> diff --git a/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/insertRow-method-02.html b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/insertRow-method-02.html new file mode 100644 index 0000000000..410425fb1e --- /dev/null +++ b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/insertRow-method-02.html @@ -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> diff --git a/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/insertRow-method-03.html b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/insertRow-method-03.html new file mode 100644 index 0000000000..19c3ceb3c6 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/insertRow-method-03.html @@ -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> diff --git a/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/remove-row.html b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/remove-row.html new file mode 100644 index 0000000000..43a128c57e --- /dev/null +++ b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/remove-row.html @@ -0,0 +1,64 @@ +<!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_dom("IndexSizeError", function() { + el.deleteRow(-2) + }) +}, 'deleteRow function invalid argument'); +test(function() { + assert_throws_dom("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() { + assert_equals(el.rows.length, 3); + do { + var old_length = el.rows.length; + el.deleteRow(-1); + assert_equals(el.rows.length, old_length - 1); + } while (el.rows.length); +}, "check normal deleteRow bis"); + +test(function() { + assert_equals(el.rows.length, 0); + el.deleteRow(-1); +}, 'deleteRow(-1) with no rows'); + +test(function() { + assert_equals(el.rows.length, 0); + assert_throws_dom("IndexSizeError", function() { + el.deleteRow(0); + }); +}, 'deleteRow(0) with no rows'); +</script> diff --git a/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/tBodies.html b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/tBodies.html new file mode 100644 index 0000000000..128dbc9f7d --- /dev/null +++ b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/tBodies.html @@ -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> diff --git a/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/tFoot.html b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/tFoot.html new file mode 100644 index 0000000000..40220bc1e2 --- /dev/null +++ b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/tFoot.html @@ -0,0 +1,65 @@ +<!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_js(TypeError, function(){ + t.tFoot = document.createElement("div"); + }); + + assert_throws_dom("HierarchyRequestError", function(){ + t.tFoot = document.createElement("thead"); + }); +}) + +test(function () { + var table = document.createElementNS("http://www.w3.org/1999/xhtml", "foo:table") + var tfoot = table.createTFoot(); + + assert_equals(table.tFoot, tfoot); + assert_equals(tfoot.prefix, null); +}); +</script> diff --git a/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/tHead.html b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/tHead.html new file mode 100644 index 0000000000..fadebecd6f --- /dev/null +++ b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/tHead.html @@ -0,0 +1,74 @@ +<!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_js(TypeError, function(){ + t.tHead = document.createElement("div"); + }); + + assert_throws_dom("HierarchyRequestError", function(){ + t.tHead = document.createElement("tbody"); + }); + +}); + +test(function() { + var t2 = document.getElementById("t2"); + var t2thead = document.getElementById("t2thead"); + + assert_throws_dom("HierarchyRequestError", function() { + t2.tHead = t2thead; + }); +}); + +test(function () { + var table = document.createElementNS("http://www.w3.org/1999/xhtml", "foo:table") + var thead = table.createTHead(); + + assert_equals(table.tHead, thead); + assert_equals(thead.prefix, null); +}); +</script> diff --git a/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/table-insertRow.html b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/table-insertRow.html new file mode 100644 index 0000000000..8a9574ecdd --- /dev/null +++ b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/table-insertRow.html @@ -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> diff --git a/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/table-rows.html b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/table-rows.html new file mode 100644 index 0000000000..8bc23d5a7c --- /dev/null +++ b/testing/web-platform/tests/html/semantics/tabular-data/the-table-element/table-rows.html @@ -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> |