OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>HTMLTableElement.rows</title> |
| 3 <script src="../../../../../../resources/testharness.js"></script> |
| 4 <script src="../../../../../../resources/testharnessreport.js"></script> |
| 5 <div id="log"></div> |
| 6 <script> |
| 7 function assert_nodelist_equals(actual, expected) { |
| 8 assert_equals(actual.length, expected.length); |
| 9 |
| 10 for (var i = 0; i < actual.length; ++i) { |
| 11 assert_true(i in actual); |
| 12 assert_true(actual.hasOwnProperty(i), |
| 13 "property " + i + " expected to be present on the object"); |
| 14 assert_equals(actual.item(i), expected[i]); |
| 15 assert_equals(actual[i], expected[i]); |
| 16 } |
| 17 } |
| 18 |
| 19 function test_table_simple(group, table) { |
| 20 var foo1 = group.appendChild(document.createElement("tr")); |
| 21 foo1.id = "foo"; |
| 22 var bar1 = group.appendChild(document.createElement("tr")); |
| 23 bar1.id = "bar"; |
| 24 var foo2 = group.appendChild(document.createElement("tr")); |
| 25 foo2.id = "foo"; |
| 26 var bar2 = group.appendChild(document.createElement("tr")); |
| 27 bar2.id = "bar"; |
| 28 |
| 29 assert_true(table.rows instanceof HTMLCollection, "table.rows should be a HTML
Collection."); |
| 30 assert_nodelist_equals(table.rows, [foo1, bar1, foo2, bar2]); |
| 31 assert_equals(table.rows.foo, foo1); |
| 32 assert_equals(table.rows["foo"], foo1); |
| 33 assert_equals(table.rows.namedItem("foo"), foo1); |
| 34 assert_equals(table.rows.bar, bar1); |
| 35 assert_equals(table.rows["bar"], bar1); |
| 36 assert_equals(table.rows.namedItem("bar"), bar1); |
| 37 } |
| 38 test(function() { |
| 39 var table = document.createElement("table"); |
| 40 test_table_simple(table, table); |
| 41 }, "Children of table"); |
| 42 test(function() { |
| 43 var table = document.createElement("table"); |
| 44 var group = table.appendChild(document.createElement("thead")); |
| 45 test_table_simple(group, table); |
| 46 }, "Children of thead"); |
| 47 test(function() { |
| 48 var table = document.createElement("table"); |
| 49 var group = table.appendChild(document.createElement("tbody")); |
| 50 test_table_simple(group, table); |
| 51 }, "Children of tbody"); |
| 52 test(function() { |
| 53 var table = document.createElement("table"); |
| 54 var group = table.appendChild(document.createElement("tfoot")); |
| 55 test_table_simple(group, table); |
| 56 }, "Children of tfoot"); |
| 57 test(function() { |
| 58 var table = document.createElement("table"); |
| 59 var orphan1 = table.appendChild(document.createElement("tr")); |
| 60 orphan1.id = "orphan1"; |
| 61 var foot1 = table.appendChild(document.createElement("tfoot")); |
| 62 var orphan2 = table.appendChild(document.createElement("tr")); |
| 63 orphan2.id = "orphan2"; |
| 64 var foot2 = table.appendChild(document.createElement("tfoot")); |
| 65 var orphan3 = table.appendChild(document.createElement("tr")); |
| 66 orphan3.id = "orphan3"; |
| 67 var body1 = table.appendChild(document.createElement("tbody")); |
| 68 var orphan4 = table.appendChild(document.createElement("tr")); |
| 69 orphan4.id = "orphan4"; |
| 70 var body2 = table.appendChild(document.createElement("tbody")); |
| 71 var orphan5 = table.appendChild(document.createElement("tr")); |
| 72 orphan5.id = "orphan5"; |
| 73 var head1 = table.appendChild(document.createElement("thead")); |
| 74 var orphan6 = table.appendChild(document.createElement("tr")); |
| 75 orphan6.id = "orphan6"; |
| 76 var head2 = table.appendChild(document.createElement("thead")); |
| 77 var orphan7 = table.appendChild(document.createElement("tr")); |
| 78 orphan7.id = "orphan7"; |
| 79 |
| 80 var foot1row1 = foot1.appendChild(document.createElement("tr")); |
| 81 foot1row1.id = "foot1row1"; |
| 82 var foot1row2 = foot1.appendChild(document.createElement("tr")); |
| 83 foot1row2.id = "foot1row2"; |
| 84 var foot2row1 = foot2.appendChild(document.createElement("tr")); |
| 85 foot2row1.id = "foot2row1"; |
| 86 var foot2row2 = foot2.appendChild(document.createElement("tr")); |
| 87 foot2row2.id = "foot2row2"; |
| 88 |
| 89 var body1row1 = body1.appendChild(document.createElement("tr")); |
| 90 body1row1.id = "body1row1"; |
| 91 var body1row2 = body1.appendChild(document.createElement("tr")); |
| 92 body1row2.id = "body1row2"; |
| 93 var body2row1 = body2.appendChild(document.createElement("tr")); |
| 94 body2row1.id = "body2row1"; |
| 95 var body2row2 = body2.appendChild(document.createElement("tr")); |
| 96 body2row2.id = "body2row2"; |
| 97 |
| 98 var head1row1 = head1.appendChild(document.createElement("tr")); |
| 99 head1row1.id = "head1row1"; |
| 100 var head1row2 = head1.appendChild(document.createElement("tr")); |
| 101 head1row2.id = "head1row2"; |
| 102 var head2row1 = head2.appendChild(document.createElement("tr")); |
| 103 head2row1.id = "head2row1"; |
| 104 var head2row2 = head2.appendChild(document.createElement("tr")); |
| 105 head2row2.id = "head2row2"; |
| 106 |
| 107 // These elements should not end up in any collection. |
| 108 table.appendChild(document.createElement("div")) |
| 109 .appendChild(document.createElement("tr")); |
| 110 foot1.appendChild(document.createElement("div")) |
| 111 .appendChild(document.createElement("tr")); |
| 112 body1.appendChild(document.createElement("div")) |
| 113 .appendChild(document.createElement("tr")); |
| 114 head1.appendChild(document.createElement("div")) |
| 115 .appendChild(document.createElement("tr")); |
| 116 table.appendChild(document.createElementNS("http://example.com/test", "tr")); |
| 117 foot1.appendChild(document.createElementNS("http://example.com/test", "tr")); |
| 118 body1.appendChild(document.createElementNS("http://example.com/test", "tr")); |
| 119 head1.appendChild(document.createElementNS("http://example.com/test", "tr")); |
| 120 |
| 121 assert_true(table.rows instanceof HTMLCollection, "table.rows should be a HTML
Collection."); |
| 122 assert_nodelist_equals(table.rows, [ |
| 123 // thead |
| 124 head1row1, |
| 125 head1row2, |
| 126 head2row1, |
| 127 head2row2, |
| 128 |
| 129 // tbody + table |
| 130 orphan1, |
| 131 orphan2, |
| 132 orphan3, |
| 133 body1row1, |
| 134 body1row2, |
| 135 orphan4, |
| 136 body2row1, |
| 137 body2row2, |
| 138 orphan5, |
| 139 orphan6, |
| 140 orphan7, |
| 141 |
| 142 // tfoot |
| 143 foot1row1, |
| 144 foot1row2, |
| 145 foot2row1, |
| 146 foot2row2 |
| 147 ]); |
| 148 |
| 149 var ids = [ |
| 150 "orphan1", |
| 151 "orphan2", |
| 152 "orphan3", |
| 153 "orphan4", |
| 154 "orphan5", |
| 155 "orphan6", |
| 156 "orphan7", |
| 157 "foot1row1", |
| 158 "foot1row2", |
| 159 "foot2row1", |
| 160 "foot2row2", |
| 161 "body1row1", |
| 162 "body1row2", |
| 163 "body2row1", |
| 164 "body2row2", |
| 165 "head1row1", |
| 166 "head1row2", |
| 167 "head2row1", |
| 168 "head2row2" |
| 169 ]; |
| 170 ids.forEach(function(id) { |
| 171 assert_equals(table.rows.namedItem(id).id, id); |
| 172 assert_true(id in table.rows); |
| 173 assert_equals(table.rows[id].id, id); |
| 174 assert_true(id in table.rows); |
| 175 }); |
| 176 while (table.firstChild) { |
| 177 table.removeChild(table.firstChild); |
| 178 } |
| 179 ids.forEach(function(id) { |
| 180 assert_equals(table.rows.namedItem(id), null); |
| 181 assert_false(id in table.rows); |
| 182 assert_equals(table.rows[id], undefined); |
| 183 assert_false(id in table.rows); |
| 184 }); |
| 185 }, "Complicated case"); |
| 186 </script> |
OLD | NEW |