| 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'; |
| 11 | 12 |
| 12 expectLargeRect(Rect rect) { | 13 expectLargeRect(Rect rect) { |
| 13 expect(rect.top, 0); | 14 expect(rect.top, 0); |
| 14 expect(rect.left, 0); | 15 expect(rect.left, 0); |
| 15 expect(rect.width, greaterThan(100)); | 16 expect(rect.width, greaterThan(100)); |
| 16 expect(rect.height, greaterThan(100)); | 17 expect(rect.height, greaterThan(100)); |
| 17 expect(rect.bottom, rect.top + rect.height); | 18 expect(rect.bottom, rect.top + rect.height); |
| 18 expect(rect.right, rect.left + rect.width); | 19 expect(rect.right, rect.left + rect.width); |
| 19 } | 20 } |
| 20 | 21 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 expect(element.scrollWidth, greaterThan(100)); | 74 expect(element.scrollWidth, greaterThan(100)); |
| 74 expect(element.scrollHeight, greaterThan(100)); | 75 expect(element.scrollHeight, greaterThan(100)); |
| 75 expect(element.getBoundingClientRect().left, 8); | 76 expect(element.getBoundingClientRect().left, 8); |
| 76 expect(element.getBoundingClientRect().top, 8); | 77 expect(element.getBoundingClientRect().top, 8); |
| 77 container.remove(); | 78 container.remove(); |
| 78 }); | 79 }); |
| 79 }); | 80 }); |
| 80 | 81 |
| 81 group('constructors', () { | 82 group('constructors', () { |
| 82 test('error', () { | 83 test('error', () { |
| 83 expect(() => new Element.html('<br/><br/>'), throwsArgumentError); | 84 expect(() => new Element.html('<br/><br/>'), throwsStateError); |
| 84 }); | 85 }); |
| 85 | 86 |
| 86 test('.html has no parent', () => | 87 test('.html has no parent', () => |
| 87 expect(new Element.html('<br/>').parent, isNull)); | 88 expect(new Element.html('<br/>').parent, isNull)); |
| 88 | 89 |
| 89 test('.html table', () { | 90 test('.html table', () { |
| 90 // http://developers.whatwg.org/tabular-data.html#tabular-data | 91 // http://developers.whatwg.org/tabular-data.html#tabular-data |
| 91 var node = new Element.html(''' | 92 var node = new Element.html(''' |
| 92 <table> | 93 <table> |
| 93 <caption>Characteristics with positive and negative sides</caption> | 94 <caption>Characteristics with positive and negative sides</caption> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 113 'Characteristics with positive and negative sides'); | 114 'Characteristics with positive and negative sides'); |
| 114 expect(node.tHead.rows.length, 1); | 115 expect(node.tHead.rows.length, 1); |
| 115 expect(node.tHead.rows[0].cells.length, 3); | 116 expect(node.tHead.rows[0].cells.length, 3); |
| 116 expect(node.tBodies.length, 1); | 117 expect(node.tBodies.length, 1); |
| 117 expect(node.tBodies[0].rows.length, 2); | 118 expect(node.tBodies[0].rows.length, 2); |
| 118 expect(node.tBodies[0].rows[1].cells.map((c) => c.innerHtml), | 119 expect(node.tBodies[0].rows[1].cells.map((c) => c.innerHtml), |
| 119 [' Failing\n ', ' Grade\n ', ' Passing\n']); | 120 [' Failing\n ', ' Grade\n ', ' Passing\n']); |
| 120 }); | 121 }); |
| 121 | 122 |
| 122 test('.html caption', () { | 123 test('.html caption', () { |
| 123 var node = new Element.html('<caption><p>Table 1.'); | 124 var table = new TableElement(); |
| 125 var node = table.createFragment('<caption><p>Table 1.').nodes.single; |
| 124 expect(node, predicate((x) => x is TableCaptionElement, | 126 expect(node, predicate((x) => x is TableCaptionElement, |
| 125 'is a TableCaptionElement')); | 127 'is a TableCaptionElement')); |
| 126 expect(node.tagName, 'CAPTION'); | 128 expect(node.tagName, 'CAPTION'); |
| 127 expect(node.parent, isNull); | 129 expect(node.parent, isNull); |
| 128 expect(node.innerHtml, '<p>Table 1.</p>'); | 130 expect(node.innerHtml, '<p>Table 1.</p>'); |
| 129 }); | 131 }); |
| 130 | 132 |
| 131 test('.html colgroup', () { | 133 test('.html colgroup', () { |
| 132 var node = new Element.html('<colgroup> <col> <col> <col>'); | 134 var table = new TableElement(); |
| 135 var node = |
| 136 table.createFragment('<colgroup> <col> <col> <col>').nodes.single; |
| 133 expect(node, predicate((x) => x is TableColElement, | 137 expect(node, predicate((x) => x is TableColElement, |
| 134 'is a TableColElement')); | 138 'is a TableColElement')); |
| 135 expect(node.tagName, 'COLGROUP'); | 139 expect(node.tagName, 'COLGROUP'); |
| 136 expect(node.parent, isNull); | 140 expect(node.parent, isNull); |
| 137 expect(node.innerHtml, ' <col> <col> <col>'); | 141 expect(node.innerHtml, ' <col> <col> <col>'); |
| 138 }); | 142 }); |
| 139 | 143 |
| 140 test('.html col', () { | |
| 141 var node = new Element.html('<col span="2">'); | |
| 142 expect(node, predicate((x) => x is TableColElement, | |
| 143 'is a TableColElement')); | |
| 144 expect(node.tagName, 'COL'); | |
| 145 expect(node.parent, isNull); | |
| 146 expect(node.outerHtml, '<col span="2">'); | |
| 147 }); | |
| 148 | |
| 149 test('.html tbody', () { | 144 test('.html tbody', () { |
| 150 var innerHtml = '<tr><td headers="n r1">Sad</td><td>Happy</td></tr>'; | 145 var innerHtml = '<tr><td headers="n r1">Sad</td><td>Happy</td></tr>'; |
| 151 var node = new Element.html('<tbody>$innerHtml'); | 146 var table = new TableElement(); |
| 147 var node = table.createFragment('<tbody>$innerHtml').nodes.single; |
| 152 expect(node, predicate((x) => x is TableSectionElement, | 148 expect(node, predicate((x) => x is TableSectionElement, |
| 153 'is a TableSectionElement')); | 149 'is a TableSectionElement')); |
| 154 expect(node.tagName, 'TBODY'); | 150 expect(node.tagName, 'TBODY'); |
| 155 expect(node.parent, isNull); | 151 expect(node.parent, isNull); |
| 156 expect(node.rows.length, 1); | 152 expect(node.rows.length, 1); |
| 157 expect(node.rows[0].cells.length, 2); | 153 expect(node.rows[0].cells.length, 2); |
| 158 expect(node.innerHtml, innerHtml); | 154 expect(node.innerHtml, innerHtml); |
| 159 }); | 155 }); |
| 160 | 156 |
| 161 test('.html thead', () { | 157 test('.html thead', () { |
| 162 var innerHtml = '<tr><th id="n">Negative</th><th>Positive</th></tr>'; | 158 var innerHtml = '<tr><th id="n">Negative</th><th>Positive</th></tr>'; |
| 163 var node = new Element.html('<thead>$innerHtml'); | 159 var table = new TableElement(); |
| 160 var node = table.createFragment('<thead>$innerHtml').nodes.single; |
| 164 expect(node, predicate((x) => x is TableSectionElement, | 161 expect(node, predicate((x) => x is TableSectionElement, |
| 165 'is a TableSectionElement')); | 162 'is a TableSectionElement')); |
| 166 expect(node.tagName, 'THEAD'); | 163 expect(node.tagName, 'THEAD'); |
| 167 expect(node.parent, isNull); | 164 expect(node.parent, isNull); |
| 168 expect(node.rows.length, 1); | 165 expect(node.rows.length, 1); |
| 169 expect(node.rows[0].cells.length, 2); | 166 expect(node.rows[0].cells.length, 2); |
| 170 expect(node.innerHtml, innerHtml); | 167 expect(node.innerHtml, innerHtml); |
| 171 }); | 168 }); |
| 172 | 169 |
| 173 test('.html tfoot', () { | 170 test('.html tfoot', () { |
| 174 var innerHtml = '<tr><th>percentage</th><td>34.3%</td></tr>'; | 171 var innerHtml = '<tr><th>percentage</th><td>34.3%</td></tr>'; |
| 175 var node = new Element.html('<tfoot>$innerHtml'); | 172 var table = new TableElement(); |
| 173 var node = table.createFragment('<tfoot>$innerHtml').nodes.single; |
| 176 expect(node, predicate((x) => x is TableSectionElement, | 174 expect(node, predicate((x) => x is TableSectionElement, |
| 177 'is a TableSectionElement')); | 175 'is a TableSectionElement')); |
| 178 expect(node.tagName, 'TFOOT'); | 176 expect(node.tagName, 'TFOOT'); |
| 179 expect(node.parent, isNull); | 177 expect(node.parent, isNull); |
| 180 expect(node.rows.length, 1); | 178 expect(node.rows.length, 1); |
| 181 expect(node.rows[0].cells.length, 2); | 179 expect(node.rows[0].cells.length, 2); |
| 182 expect(node.innerHtml, innerHtml); | 180 expect(node.innerHtml, innerHtml); |
| 183 }); | 181 }); |
| 184 | 182 |
| 185 test('.html tr', () { | 183 test('.html tr', () { |
| 186 var node = new Element.html('<tr><td>foo<td>bar'); | 184 var table = new TableElement(); |
| 185 var tBody = table.createTBody(); |
| 186 var node = tBody.createFragment('<tr><td>foo<td>bar').nodes.single; |
| 187 expect(node, predicate((x) => x is TableRowElement, | 187 expect(node, predicate((x) => x is TableRowElement, |
| 188 'is a TableRowElement')); | 188 'is a TableRowElement')); |
| 189 expect(node.tagName, 'TR'); | 189 expect(node.tagName, 'TR'); |
| 190 expect(node.parent, isNull); | 190 expect(node.parent, isNull); |
| 191 expect(node.cells.map((c) => c.innerHtml), ['foo', 'bar']); | 191 expect(node.cells.map((c) => c.innerHtml), ['foo', 'bar']); |
| 192 }); | 192 }); |
| 193 | 193 |
| 194 test('.html td', () { | 194 test('.html td', () { |
| 195 var node = new Element.html('<td>foobar'); | 195 var table = new TableElement(); |
| 196 var tBody = table.createTBody(); |
| 197 var tRow = tBody.addRow(); |
| 198 var node = tRow.createFragment('<td>foobar').nodes.single; |
| 196 expect(node, predicate((x) => x is TableCellElement, | 199 expect(node, predicate((x) => x is TableCellElement, |
| 197 'is a TableCellElement')); | 200 'is a TableCellElement')); |
| 198 expect(node.tagName, 'TD'); | 201 expect(node.tagName, 'TD'); |
| 199 expect(node.parent, isNull); | 202 expect(node.parent, isNull); |
| 200 expect(node.innerHtml, 'foobar'); | 203 expect(node.innerHtml, 'foobar'); |
| 201 }); | 204 }); |
| 202 | 205 |
| 203 test('.html th', () { | 206 test('.html th', () { |
| 204 var node = new Element.html('<th>foobar'); | 207 var table = new TableElement(); |
| 208 var tBody = table.createTBody(); |
| 209 var tRow = tBody.addRow(); |
| 210 var node = tRow.createFragment('<th>foobar').nodes.single; |
| 205 expect(node, predicate((x) => x is TableCellElement, | 211 expect(node, predicate((x) => x is TableCellElement, |
| 206 'is a TableCellElement')); | 212 'is a TableCellElement')); |
| 207 expect(node.tagName, 'TH'); | 213 expect(node.tagName, 'TH'); |
| 208 expect(node.parent, isNull); | 214 expect(node.parent, isNull); |
| 209 expect(node.innerHtml, 'foobar'); | 215 expect(node.innerHtml, 'foobar'); |
| 210 }); | 216 }); |
| 211 }); | 217 }); |
| 212 | 218 |
| 213 group('eventListening', () { | 219 group('eventListening', () { |
| 214 test('streams', () { | 220 test('streams', () { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 e.click(); | 289 e.click(); |
| 284 expect(firedEvent, true); | 290 expect(firedEvent, true); |
| 285 }); | 291 }); |
| 286 }); | 292 }); |
| 287 | 293 |
| 288 group('attributes', () { | 294 group('attributes', () { |
| 289 test('manipulation', () { | 295 test('manipulation', () { |
| 290 final element = new Element.html( | 296 final element = new Element.html( |
| 291 '''<div class="foo" style="overflow: hidden" data-foo="bar" | 297 '''<div class="foo" style="overflow: hidden" data-foo="bar" |
| 292 data-foo2="bar2" dir="rtl"> | 298 data-foo2="bar2" dir="rtl"> |
| 293 </div>'''); | 299 </div>''', treeSanitizer: new NullTreeSanitizer()); |
| 294 final attributes = element.attributes; | 300 final attributes = element.attributes; |
| 295 expect(attributes['class'], 'foo'); | 301 expect(attributes['class'], 'foo'); |
| 296 expect(attributes['style'], startsWith('overflow: hidden')); | 302 expect(attributes['style'], startsWith('overflow: hidden')); |
| 297 expect(attributes['data-foo'], 'bar'); | 303 expect(attributes['data-foo'], 'bar'); |
| 298 expect(attributes['data-foo2'], 'bar2'); | 304 expect(attributes['data-foo2'], 'bar2'); |
| 299 expect(attributes.length, 5); | 305 expect(attributes.length, 5); |
| 300 expect(element.dataset.length, 2); | 306 expect(element.dataset.length, 2); |
| 301 element.dataset['foo'] = 'baz'; | 307 element.dataset['foo'] = 'baz'; |
| 302 expect(element.dataset['foo'], 'baz'); | 308 expect(element.dataset['foo'], 'baz'); |
| 303 expect(attributes['data-foo'], 'baz'); | 309 expect(attributes['data-foo'], 'baz'); |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 }); | 725 }); |
| 720 | 726 |
| 721 test('sublist', () { | 727 test('sublist', () { |
| 722 var range = makeElList().sublist(1, 3); | 728 var range = makeElList().sublist(1, 3); |
| 723 expect(range, isElementList); | 729 expect(range, isElementList); |
| 724 expect(range[0], isImageElement); | 730 expect(range[0], isImageElement); |
| 725 expect(range[1], isInputElement); | 731 expect(range[1], isInputElement); |
| 726 }); | 732 }); |
| 727 }); | 733 }); |
| 728 } | 734 } |
| OLD | NEW |