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