| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library ElementTest; | 5 library ElementTest; |
| 6 import '../../pkg/unittest/lib/unittest.dart'; | 6 import '../../pkg/unittest/lib/unittest.dart'; |
| 7 import '../../pkg/unittest/lib/html_individual_config.dart'; | 7 import '../../pkg/unittest/lib/html_individual_config.dart'; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:html'; | 9 import 'dart:html'; |
| 10 import 'dart:svg' as svg; | 10 import 'dart:svg' as svg; |
| 11 import 'utils.dart'; | |
| 12 | 11 |
| 13 expectLargeRect(Rect rect) { | 12 expectLargeRect(Rect rect) { |
| 14 expect(rect.top, 0); | 13 expect(rect.top, 0); |
| 15 expect(rect.left, 0); | 14 expect(rect.left, 0); |
| 16 expect(rect.width, greaterThan(100)); | 15 expect(rect.width, greaterThan(100)); |
| 17 expect(rect.height, greaterThan(100)); | 16 expect(rect.height, greaterThan(100)); |
| 18 expect(rect.bottom, rect.top + rect.height); | 17 expect(rect.bottom, rect.top + rect.height); |
| 19 expect(rect.right, rect.left + rect.width); | 18 expect(rect.right, rect.left + rect.width); |
| 20 } | 19 } |
| 21 | 20 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 expect(element.getBoundingClientRect().top, 8); | 76 expect(element.getBoundingClientRect().top, 8); |
| 78 | 77 |
| 79 expect(element.documentOffset.x, 9); | 78 expect(element.documentOffset.x, 9); |
| 80 expect(element.documentOffset.y, 8); | 79 expect(element.documentOffset.y, 8); |
| 81 container.remove(); | 80 container.remove(); |
| 82 }); | 81 }); |
| 83 }); | 82 }); |
| 84 | 83 |
| 85 group('constructors', () { | 84 group('constructors', () { |
| 86 test('error', () { | 85 test('error', () { |
| 87 expect(() => new Element.html('<br/><br/>'), throwsStateError); | 86 expect(() => new Element.html('<br/><br/>'), throwsArgumentError); |
| 88 }); | 87 }); |
| 89 | 88 |
| 90 test('.html has no parent', () => | 89 test('.html has no parent', () => |
| 91 expect(new Element.html('<br/>').parent, isNull)); | 90 expect(new Element.html('<br/>').parent, isNull)); |
| 92 | 91 |
| 93 test('.html table', () { | 92 test('.html table', () { |
| 94 // http://developers.whatwg.org/tabular-data.html#tabular-data | 93 // http://developers.whatwg.org/tabular-data.html#tabular-data |
| 95 var node = new Element.html(''' | 94 var node = new Element.html(''' |
| 96 <table> | 95 <table> |
| 97 <caption>Characteristics with positive and negative sides</caption> | 96 <caption>Characteristics with positive and negative sides</caption> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 117 'Characteristics with positive and negative sides'); | 116 'Characteristics with positive and negative sides'); |
| 118 expect(node.tHead.rows.length, 1); | 117 expect(node.tHead.rows.length, 1); |
| 119 expect(node.tHead.rows[0].cells.length, 3); | 118 expect(node.tHead.rows[0].cells.length, 3); |
| 120 expect(node.tBodies.length, 1); | 119 expect(node.tBodies.length, 1); |
| 121 expect(node.tBodies[0].rows.length, 2); | 120 expect(node.tBodies[0].rows.length, 2); |
| 122 expect(node.tBodies[0].rows[1].cells.map((c) => c.innerHtml), | 121 expect(node.tBodies[0].rows[1].cells.map((c) => c.innerHtml), |
| 123 [' Failing\n ', ' Grade\n ', ' Passing\n']); | 122 [' Failing\n ', ' Grade\n ', ' Passing\n']); |
| 124 }); | 123 }); |
| 125 | 124 |
| 126 test('.html caption', () { | 125 test('.html caption', () { |
| 127 var table = new TableElement(); | 126 var node = new Element.html('<caption><p>Table 1.'); |
| 128 var node = table.createFragment('<caption><p>Table 1.').nodes.single; | |
| 129 expect(node, predicate((x) => x is TableCaptionElement, | 127 expect(node, predicate((x) => x is TableCaptionElement, |
| 130 'is a TableCaptionElement')); | 128 'is a TableCaptionElement')); |
| 131 expect(node.tagName, 'CAPTION'); | 129 expect(node.tagName, 'CAPTION'); |
| 132 expect(node.parent, isNull); | 130 expect(node.parent, isNull); |
| 133 expect(node.innerHtml, '<p>Table 1.</p>'); | 131 expect(node.innerHtml, '<p>Table 1.</p>'); |
| 134 }); | 132 }); |
| 135 | 133 |
| 136 test('.html colgroup', () { | 134 test('.html colgroup', () { |
| 137 var table = new TableElement(); | 135 var node = new Element.html('<colgroup> <col> <col> <col>'); |
| 138 var node = | |
| 139 table.createFragment('<colgroup> <col> <col> <col>').nodes.single; | |
| 140 expect(node, predicate((x) => x is TableColElement, | 136 expect(node, predicate((x) => x is TableColElement, |
| 141 'is a TableColElement')); | 137 'is a TableColElement')); |
| 142 expect(node.tagName, 'COLGROUP'); | 138 expect(node.tagName, 'COLGROUP'); |
| 143 expect(node.parent, isNull); | 139 expect(node.parent, isNull); |
| 144 expect(node.innerHtml, ' <col> <col> <col>'); | 140 expect(node.innerHtml, ' <col> <col> <col>'); |
| 145 }); | 141 }); |
| 146 | 142 |
| 143 test('.html col', () { |
| 144 var node = new Element.html('<col span="2">'); |
| 145 expect(node, predicate((x) => x is TableColElement, |
| 146 'is a TableColElement')); |
| 147 expect(node.tagName, 'COL'); |
| 148 expect(node.parent, isNull); |
| 149 expect(node.outerHtml, '<col span="2">'); |
| 150 }); |
| 151 |
| 147 test('.html tbody', () { | 152 test('.html tbody', () { |
| 148 var innerHtml = '<tr><td headers="n r1">Sad</td><td>Happy</td></tr>'; | 153 var innerHtml = '<tr><td headers="n r1">Sad</td><td>Happy</td></tr>'; |
| 149 var table = new TableElement(); | 154 var node = new Element.html('<tbody>$innerHtml'); |
| 150 var node = table.createFragment('<tbody>$innerHtml').nodes.single; | |
| 151 expect(node, predicate((x) => x is TableSectionElement, | 155 expect(node, predicate((x) => x is TableSectionElement, |
| 152 'is a TableSectionElement')); | 156 'is a TableSectionElement')); |
| 153 expect(node.tagName, 'TBODY'); | 157 expect(node.tagName, 'TBODY'); |
| 154 expect(node.parent, isNull); | 158 expect(node.parent, isNull); |
| 155 expect(node.rows.length, 1); | 159 expect(node.rows.length, 1); |
| 156 expect(node.rows[0].cells.length, 2); | 160 expect(node.rows[0].cells.length, 2); |
| 157 expect(node.innerHtml, innerHtml); | 161 expect(node.innerHtml, innerHtml); |
| 158 }); | 162 }); |
| 159 | 163 |
| 160 test('.html thead', () { | 164 test('.html thead', () { |
| 161 var innerHtml = '<tr><th id="n">Negative</th><th>Positive</th></tr>'; | 165 var innerHtml = '<tr><th id="n">Negative</th><th>Positive</th></tr>'; |
| 162 var table = new TableElement(); | 166 var node = new Element.html('<thead>$innerHtml'); |
| 163 var node = table.createFragment('<thead>$innerHtml').nodes.single; | |
| 164 expect(node, predicate((x) => x is TableSectionElement, | 167 expect(node, predicate((x) => x is TableSectionElement, |
| 165 'is a TableSectionElement')); | 168 'is a TableSectionElement')); |
| 166 expect(node.tagName, 'THEAD'); | 169 expect(node.tagName, 'THEAD'); |
| 167 expect(node.parent, isNull); | 170 expect(node.parent, isNull); |
| 168 expect(node.rows.length, 1); | 171 expect(node.rows.length, 1); |
| 169 expect(node.rows[0].cells.length, 2); | 172 expect(node.rows[0].cells.length, 2); |
| 170 expect(node.innerHtml, innerHtml); | 173 expect(node.innerHtml, innerHtml); |
| 171 }); | 174 }); |
| 172 | 175 |
| 173 test('.html tfoot', () { | 176 test('.html tfoot', () { |
| 174 var innerHtml = '<tr><th>percentage</th><td>34.3%</td></tr>'; | 177 var innerHtml = '<tr><th>percentage</th><td>34.3%</td></tr>'; |
| 175 var table = new TableElement(); | 178 var node = new Element.html('<tfoot>$innerHtml'); |
| 176 var node = table.createFragment('<tfoot>$innerHtml').nodes.single; | |
| 177 expect(node, predicate((x) => x is TableSectionElement, | 179 expect(node, predicate((x) => x is TableSectionElement, |
| 178 'is a TableSectionElement')); | 180 'is a TableSectionElement')); |
| 179 expect(node.tagName, 'TFOOT'); | 181 expect(node.tagName, 'TFOOT'); |
| 180 expect(node.parent, isNull); | 182 expect(node.parent, isNull); |
| 181 expect(node.rows.length, 1); | 183 expect(node.rows.length, 1); |
| 182 expect(node.rows[0].cells.length, 2); | 184 expect(node.rows[0].cells.length, 2); |
| 183 expect(node.innerHtml, innerHtml); | 185 expect(node.innerHtml, innerHtml); |
| 184 }); | 186 }); |
| 185 | 187 |
| 186 test('.html tr', () { | 188 test('.html tr', () { |
| 187 var table = new TableElement(); | 189 var node = new Element.html('<tr><td>foo<td>bar'); |
| 188 var tBody = table.createTBody(); | |
| 189 var node = tBody.createFragment('<tr><td>foo<td>bar').nodes.single; | |
| 190 expect(node, predicate((x) => x is TableRowElement, | 190 expect(node, predicate((x) => x is TableRowElement, |
| 191 'is a TableRowElement')); | 191 'is a TableRowElement')); |
| 192 expect(node.tagName, 'TR'); | 192 expect(node.tagName, 'TR'); |
| 193 expect(node.parent, isNull); | 193 expect(node.parent, isNull); |
| 194 expect(node.cells.map((c) => c.innerHtml), ['foo', 'bar']); | 194 expect(node.cells.map((c) => c.innerHtml), ['foo', 'bar']); |
| 195 }); | 195 }); |
| 196 | 196 |
| 197 test('.html td', () { | 197 test('.html td', () { |
| 198 var table = new TableElement(); | 198 var node = new Element.html('<td>foobar'); |
| 199 var tBody = table.createTBody(); | |
| 200 var tRow = tBody.addRow(); | |
| 201 var node = tRow.createFragment('<td>foobar').nodes.single; | |
| 202 expect(node, predicate((x) => x is TableCellElement, | 199 expect(node, predicate((x) => x is TableCellElement, |
| 203 'is a TableCellElement')); | 200 'is a TableCellElement')); |
| 204 expect(node.tagName, 'TD'); | 201 expect(node.tagName, 'TD'); |
| 205 expect(node.parent, isNull); | 202 expect(node.parent, isNull); |
| 206 expect(node.innerHtml, 'foobar'); | 203 expect(node.innerHtml, 'foobar'); |
| 207 }); | 204 }); |
| 208 | 205 |
| 209 test('.html th', () { | 206 test('.html th', () { |
| 210 var table = new TableElement(); | 207 var node = new Element.html('<th>foobar'); |
| 211 var tBody = table.createTBody(); | |
| 212 var tRow = tBody.addRow(); | |
| 213 var node = tRow.createFragment('<th>foobar').nodes.single; | |
| 214 expect(node, predicate((x) => x is TableCellElement, | 208 expect(node, predicate((x) => x is TableCellElement, |
| 215 'is a TableCellElement')); | 209 'is a TableCellElement')); |
| 216 expect(node.tagName, 'TH'); | 210 expect(node.tagName, 'TH'); |
| 217 expect(node.parent, isNull); | 211 expect(node.parent, isNull); |
| 218 expect(node.innerHtml, 'foobar'); | 212 expect(node.innerHtml, 'foobar'); |
| 219 }); | 213 }); |
| 220 }); | 214 }); |
| 221 | 215 |
| 222 group('eventListening', () { | 216 group('eventListening', () { |
| 223 test('streams', () { | 217 test('streams', () { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 e2.click(); | 297 e2.click(); |
| 304 expect(firedEvent2, true); | 298 expect(firedEvent2, true); |
| 305 }); | 299 }); |
| 306 }); | 300 }); |
| 307 | 301 |
| 308 group('attributes', () { | 302 group('attributes', () { |
| 309 test('manipulation', () { | 303 test('manipulation', () { |
| 310 final element = new Element.html( | 304 final element = new Element.html( |
| 311 '''<div class="foo" style="overflow: hidden" data-foo="bar" | 305 '''<div class="foo" style="overflow: hidden" data-foo="bar" |
| 312 data-foo2="bar2" dir="rtl"> | 306 data-foo2="bar2" dir="rtl"> |
| 313 </div>''', treeSanitizer: new NullTreeSanitizer()); | 307 </div>'''); |
| 314 final attributes = element.attributes; | 308 final attributes = element.attributes; |
| 315 expect(attributes['class'], 'foo'); | 309 expect(attributes['class'], 'foo'); |
| 316 expect(attributes['style'], startsWith('overflow: hidden')); | 310 expect(attributes['style'], startsWith('overflow: hidden')); |
| 317 expect(attributes['data-foo'], 'bar'); | 311 expect(attributes['data-foo'], 'bar'); |
| 318 expect(attributes['data-foo2'], 'bar2'); | 312 expect(attributes['data-foo2'], 'bar2'); |
| 319 expect(attributes.length, 5); | 313 expect(attributes.length, 5); |
| 320 expect(element.dataset.length, 2); | 314 expect(element.dataset.length, 2); |
| 321 element.dataset['foo'] = 'baz'; | 315 element.dataset['foo'] = 'baz'; |
| 322 expect(element.dataset['foo'], 'baz'); | 316 expect(element.dataset['foo'], 'baz'); |
| 323 expect(attributes['data-foo'], 'baz'); | 317 expect(attributes['data-foo'], 'baz'); |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 | 885 |
| 892 test('sublist', () { | 886 test('sublist', () { |
| 893 var range = makeElementList().sublist(1, 3); | 887 var range = makeElementList().sublist(1, 3); |
| 894 expect(range.length, 2); | 888 expect(range.length, 2); |
| 895 expect(range[0], isBRElement); | 889 expect(range[0], isBRElement); |
| 896 expect(range[1], isBRElement); | 890 expect(range[1], isBRElement); |
| 897 }); | 891 }); |
| 898 | 892 |
| 899 }); | 893 }); |
| 900 } | 894 } |
| OLD | NEW |