OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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('XMLElementTest'); | 5 #library('XMLElementTest'); |
6 #import('../../pkg/unittest/unittest.dart'); | 6 #import('../../pkg/unittest/unittest.dart'); |
7 #import('../../pkg/unittest/html_config.dart'); | 7 #import('../../pkg/unittest/html_config.dart'); |
8 #import('dart:html'); | 8 #import('dart:html'); |
9 | 9 |
10 main() { | 10 main() { |
11 useHtmlConfiguration(); | 11 useHtmlConfiguration(); |
12 | 12 |
| 13 var isXMLElement = predicate((x) => x is XMLElement, 'is an XMLElement'); |
| 14 |
13 XMLElement makeElement() => new XMLElement.xml("<xml><foo/><bar/></xml>"); | 15 XMLElement makeElement() => new XMLElement.xml("<xml><foo/><bar/></xml>"); |
14 | 16 |
15 makeElementWithParent() { | 17 makeElementWithParent() { |
16 final parent = new XMLElement.xml( | 18 final parent = new XMLElement.xml( |
17 "<parent><before/><xml><foo/><bar/></xml><after/></parent>"); | 19 "<parent><before/><xml><foo/><bar/></xml><after/></parent>"); |
18 return parent.elements[1]; | 20 return parent.elements[1]; |
19 } | 21 } |
20 | 22 |
21 group('constructors', () { | 23 group('constructors', () { |
22 group('.xml', () { | 24 group('.xml', () { |
23 test('with a well-formed document', () { | 25 test('with a well-formed document', () { |
24 final el = makeElement(); | 26 final el = makeElement(); |
25 Expect.isTrue(el is XMLElement); | 27 expect(el, isXMLElement); |
26 Expect.equals('foo', el.elements[0].tagName); | 28 expect(el.elements[0].tagName, 'foo'); |
27 Expect.equals('bar', el.elements[1].tagName); | 29 expect(el.elements[1].tagName, 'bar'); |
28 }); | 30 }); |
29 | 31 |
30 test('with too many nodes', () { | 32 test('with too many nodes', () { |
31 Expect.throws(() => new XMLElement.xml("<xml></xml>foo"), | 33 expect(() => new XMLElement.xml("<xml></xml>foo"), throwsArgumentError); |
32 (e) => e is ArgumentError); | |
33 }); | 34 }); |
34 | 35 |
35 test('with a parse error', () { | 36 test('with a parse error', () { |
36 Expect.throws(() => new XMLElement.xml("<xml></xml>>"), | 37 expect(() => new XMLElement.xml("<xml></xml>>"), throwsArgumentError); |
37 (e) => e is ArgumentError); | |
38 }); | 38 }); |
39 | 39 |
40 test('with a PARSERERROR tag', () { | 40 test('with a PARSERERROR tag', () { |
41 final el = new XMLElement.xml("<xml><parsererror /></xml>"); | 41 final el = new XMLElement.xml("<xml><parsererror /></xml>"); |
42 Expect.equals('parsererror', el.elements[0].tagName); | 42 expect('parsererror', el.elements[0].tagName, 'parsererror'); |
43 }); | 43 }); |
44 | 44 |
45 test('has no parent', () => | 45 test('has no parent', () => |
46 Expect.isNull(new XMLElement.xml('<foo/>').parent)); | 46 expect(new XMLElement.xml('<foo/>').parent), isNull); |
47 }); | 47 }); |
48 | 48 |
49 test('.tag', () { | 49 test('.tag', () { |
50 final el = new XMLElement.tag('foo'); | 50 final el = new XMLElement.tag('foo'); |
51 Expect.isTrue(el is XMLElement); | 51 expect(el, isXMLElement); |
52 Expect.equals('foo', el.tagName); | 52 expect(el.tagName, 'foo'); |
53 }); | 53 }); |
54 }); | 54 }); |
55 | 55 |
56 // FilteredElementList is tested more thoroughly in DocumentFragmentTests. | 56 // FilteredElementList is tested more thoroughly in DocumentFragmentTests. |
57 group('elements', () { | 57 group('elements', () { |
58 test('filters out non-element nodes', () { | 58 test('filters out non-element nodes', () { |
59 final el = new XMLElement.xml("<xml>1<a/><b/>2<c/>3<d/></xml>"); | 59 final el = new XMLElement.xml("<xml>1<a/><b/>2<c/>3<d/></xml>"); |
60 Expect.listEquals(["a", "b", "c", "d"], el.elements.map((e) => e.tagName))
; | 60 expect(el.elements.map((e) => e.tagName), ["a", "b", "c", "d"]); |
61 }); | 61 }); |
62 | 62 |
63 test('overwrites nodes when set', () { | 63 test('overwrites nodes when set', () { |
64 final el = new XMLElement.xml("<xml>1<a/><b/>2<c/>3<d/></xml>"); | 64 final el = new XMLElement.xml("<xml>1<a/><b/>2<c/>3<d/></xml>"); |
65 el.elements = [new XMLElement.tag('x'), new XMLElement.tag('y')]; | 65 el.elements = [new XMLElement.tag('x'), new XMLElement.tag('y')]; |
66 Expect.equals("<xml><x></x><y></y></xml>", el.outerHTML); | 66 expect(el.outerHTML, "<xml><x></x><y></y></xml>"); |
67 }); | 67 }); |
68 }); | 68 }); |
69 | 69 |
70 group('classes', () { | 70 group('classes', () { |
71 XMLElement makeElementWithClasses() => | 71 XMLElement makeElementWithClasses() => |
72 new XMLElement.xml("<xml class='foo bar baz'></xml>"); | 72 new XMLElement.xml("<xml class='foo bar baz'></xml>"); |
73 | 73 |
74 Set<String> makeClassSet() => makeElementWithClasses().classes; | 74 Set<String> makeClassSet() => makeElementWithClasses().classes; |
75 | 75 |
76 test('affects the "class" attribute', () { | 76 test('affects the "class" attribute', () { |
77 final el = makeElementWithClasses(); | 77 final el = makeElementWithClasses(); |
78 el.classes.add('qux'); | 78 el.classes.add('qux'); |
79 Expect.setEquals(['foo', 'bar', 'baz', 'qux'], | 79 expect(el.attributes['class'].split(' '), |
80 el.attributes['class'].split(' ')); | 80 unorderedEquals(['foo', 'bar', 'baz', 'qux'])); |
81 }); | 81 }); |
82 | 82 |
83 test('is affected by the "class" attribute', () { | 83 test('is affected by the "class" attribute', () { |
84 final el = makeElementWithClasses(); | 84 final el = makeElementWithClasses(); |
85 el.attributes['class'] = 'foo qux'; | 85 el.attributes['class'] = 'foo qux'; |
86 Expect.setEquals(['foo', 'qux'], el.classes); | 86 expect(el.classes, unorderedEquals(['foo', 'qux'])); |
87 }); | 87 }); |
88 | 88 |
89 test('classes=', () { | 89 test('classes=', () { |
90 final el = makeElementWithClasses(); | 90 final el = makeElementWithClasses(); |
91 el.classes = ['foo', 'qux']; | 91 el.classes = ['foo', 'qux']; |
92 Expect.setEquals(['foo', 'qux'], el.classes); | 92 expect(el.classes, unorderedEquals(['foo', 'qux'])); |
93 Expect.setEquals(['foo', 'qux'], el.attributes['class'].split(' ')); | 93 expect(el.attributes['class'].split(' '), |
| 94 unorderedEquals(['foo', 'qux'])); |
94 }); | 95 }); |
95 | 96 |
96 test('toString', () { | 97 test('toString', () { |
97 Expect.setEquals(['foo', 'bar', 'baz'], | 98 expect(makeClassSet().toString().split(' '), |
98 makeClassSet().toString().split(' ')); | 99 unorderedEquals(['foo', 'bar', 'baz'])); |
99 Expect.equals('', makeElement().classes.toString()); | 100 expect(makeElement().classes.toString(), ''); |
100 }); | 101 }); |
101 | 102 |
102 test('forEach', () { | 103 test('forEach', () { |
103 final classes = <String>[]; | 104 final classes = <String>[]; |
104 makeClassSet().forEach(classes.add); | 105 makeClassSet().forEach(classes.add); |
105 Expect.setEquals(['foo', 'bar', 'baz'], classes); | 106 expect(classes, unorderedEquals(['foo', 'bar', 'baz'])); |
106 }); | 107 }); |
107 | 108 |
108 test('iterator', () { | 109 test('iterator', () { |
109 final classes = <String>[]; | 110 final classes = <String>[]; |
110 for (var el in makeClassSet()) { | 111 for (var el in makeClassSet()) { |
111 classes.add(el); | 112 classes.add(el); |
112 } | 113 } |
113 Expect.setEquals(['foo', 'bar', 'baz'], classes); | 114 expect(classes, unorderedEquals(['foo', 'bar', 'baz'])); |
114 }); | 115 }); |
115 | 116 |
116 test('map', () { | 117 test('map', () { |
117 Expect.setEquals(['FOO', 'BAR', 'BAZ'], | 118 expect(makeClassSet().map((c) => c.toUpperCase()), |
118 makeClassSet().map((c) => c.toUpperCase())); | 119 unorderedEquals(['FOO', 'BAR', 'BAZ'])); |
119 }); | 120 }); |
120 | 121 |
121 test('filter', () { | 122 test('filter', () { |
122 Expect.setEquals(['bar', 'baz'], | 123 expect(makeClassSet().filter((c) => c.contains('a')), |
123 makeClassSet().filter((c) => c.contains('a'))); | 124 unorderedEquals(['bar', 'baz'])); |
124 }); | 125 }); |
125 | 126 |
126 test('every', () { | 127 test('every', () { |
127 Expect.isTrue(makeClassSet().every((c) => c is String)); | 128 expect(makeClassSet().every((c) => c is String), isTrue); |
128 Expect.isFalse( | 129 expect(makeClassSet().every((c) => c.contains('a')), isFalse); |
129 makeClassSet().every((c) => c.contains('a'))); | |
130 }); | 130 }); |
131 | 131 |
132 test('some', () { | 132 test('some', () { |
133 Expect.isTrue( | 133 expect(makeClassSet().some((c) => c.contains('a')), isTrue); |
134 makeClassSet().some((c) => c.contains('a'))); | 134 expect(makeClassSet().some((c) => c is num), isFalse); |
135 Expect.isFalse(makeClassSet().some((c) => c is num)); | |
136 }); | 135 }); |
137 | 136 |
138 test('isEmpty', () { | 137 test('isEmpty', () { |
139 Expect.isFalse(makeClassSet().isEmpty); | 138 expect(makeClassSet().isEmpty, isFalse); |
140 Expect.isTrue(makeElement().classes.isEmpty); | 139 expect(makeElement().classes.isEmpty, isTrue); |
141 }); | 140 }); |
142 | 141 |
143 test('length', () { | 142 test('length', () { |
144 Expect.equals(3, makeClassSet().length); | 143 expect(makeClassSet().length, 3); |
145 Expect.equals(0, makeElement().classes.length); | 144 expect(makeElement().classes.length, 0); |
146 }); | 145 }); |
147 | 146 |
148 test('contains', () { | 147 test('contains', () { |
149 Expect.isTrue(makeClassSet().contains('foo')); | 148 expect(makeClassSet().contains('foo'), isTrue); |
150 Expect.isFalse(makeClassSet().contains('qux')); | 149 expect(makeClassSet().contains('qux'), isFalse); |
151 }); | 150 }); |
152 | 151 |
153 test('add', () { | 152 test('add', () { |
154 final classes = makeClassSet(); | 153 final classes = makeClassSet(); |
155 classes.add('qux'); | 154 classes.add('qux'); |
156 Expect.setEquals(['foo', 'bar', 'baz', 'qux'], classes); | 155 expect(classes, unorderedEquals(['foo', 'bar', 'baz', 'qux'])); |
157 | 156 |
158 classes.add('qux'); | 157 classes.add('qux'); |
159 final list = new List.from(classes); | 158 final list = new List.from(classes); |
160 list.sort((a, b) => a.compareTo(b)); | 159 list.sort((a, b) => a.compareTo(b)); |
161 Expect.listEquals(['bar', 'baz', 'foo', 'qux'], list, | 160 expect(list, ['bar', 'baz', 'foo', 'qux'], |
162 "The class set shouldn't have duplicate elements."); | 161 reason: "The class set shouldn't have duplicate elements."); |
163 }); | 162 }); |
164 | 163 |
165 test('remove', () { | 164 test('remove', () { |
166 final classes = makeClassSet(); | 165 final classes = makeClassSet(); |
167 classes.remove('bar'); | 166 classes.remove('bar'); |
168 Expect.setEquals(['foo', 'baz'], classes); | 167 expect(classes, unorderedEquals(['foo', 'baz'])); |
169 classes.remove('qux'); | 168 classes.remove('qux'); |
170 Expect.setEquals(['foo', 'baz'], classes); | 169 expect(classes, unorderedEquals(['foo', 'baz'])); |
171 }); | 170 }); |
172 | 171 |
173 test('addAll', () { | 172 test('addAll', () { |
174 final classes = makeClassSet(); | 173 final classes = makeClassSet(); |
175 classes.addAll(['bar', 'qux', 'bip']); | 174 classes.addAll(['bar', 'qux', 'bip']); |
176 Expect.setEquals(['foo', 'bar', 'baz', 'qux', 'bip'], classes); | 175 expect(classes, unorderedEquals(['foo', 'bar', 'baz', 'qux', 'bip'])); |
177 }); | 176 }); |
178 | 177 |
179 test('removeAll', () { | 178 test('removeAll', () { |
180 final classes = makeClassSet(); | 179 final classes = makeClassSet(); |
181 classes.removeAll(['bar', 'baz', 'qux']); | 180 classes.removeAll(['bar', 'baz', 'qux']); |
182 Expect.setEquals(['foo'], classes); | 181 expect(classes, ['foo']); |
183 }); | 182 }); |
184 | 183 |
185 test('isSubsetOf', () { | 184 test('isSubsetOf', () { |
186 final classes = makeClassSet(); | 185 final classes = makeClassSet(); |
187 Expect.isTrue(classes.isSubsetOf(['foo', 'bar', 'baz'])); | 186 expect(classes.isSubsetOf(['foo', 'bar', 'baz']), isTrue); |
188 Expect.isTrue(classes.isSubsetOf(['foo', 'bar', 'baz', 'qux'])); | 187 expect(classes.isSubsetOf(['foo', 'bar', 'baz', 'qux']), isTrue); |
189 Expect.isFalse(classes.isSubsetOf(['foo', 'bar', 'qux'])); | 188 expect(classes.isSubsetOf(['foo', 'bar', 'qux']), isFalse); |
190 }); | 189 }); |
191 | 190 |
192 test('containsAll', () { | 191 test('containsAll', () { |
193 final classes = makeClassSet(); | 192 final classes = makeClassSet(); |
194 Expect.isTrue(classes.containsAll(['foo', 'baz'])); | 193 expect(classes.containsAll(['foo', 'baz']), isTrue); |
195 Expect.isFalse(classes.containsAll(['foo', 'qux'])); | 194 expect(classes.containsAll(['foo', 'qux']), isFalse); |
196 }); | 195 }); |
197 | 196 |
198 test('intersection', () { | 197 test('intersection', () { |
199 final classes = makeClassSet(); | 198 final classes = makeClassSet(); |
200 Expect.setEquals(['foo', 'baz'], | 199 expect(classes.intersection(['foo', 'qux', 'baz']), |
201 classes.intersection(['foo', 'qux', 'baz'])); | 200 unorderedEquals(['foo', 'baz'])); |
202 }); | 201 }); |
203 | 202 |
204 test('clear', () { | 203 test('clear', () { |
205 final classes = makeClassSet(); | 204 final classes = makeClassSet(); |
206 classes.clear(); | 205 classes.clear(); |
207 Expect.setEquals([], classes); | 206 expect(classes, []); |
208 }); | 207 }); |
209 }); | 208 }); |
210 | 209 |
211 test("no-op methods don't throw errors", () { | 210 test("no-op methods don't throw errors", () { |
212 final el = makeElement(); | 211 final el = makeElement(); |
213 el.on.click.add((e) => null); | 212 el.on.click.add((e) => null); |
214 el.blur(); | 213 el.blur(); |
215 el.focus(); | 214 el.focus(); |
216 el.scrollByLines(2); | 215 el.scrollByLines(2); |
217 el.scrollByPages(2); | 216 el.scrollByPages(2); |
218 el.scrollIntoView(); | 217 el.scrollIntoView(); |
219 }); | 218 }); |
220 | 219 |
221 group('properties that map to attributes', () { | 220 group('properties that map to attributes', () { |
222 group('contentEditable', () { | 221 group('contentEditable', () { |
223 test('get', () { | 222 test('get', () { |
224 final el = makeElement(); | 223 final el = makeElement(); |
225 Expect.equals('inherit', el.contentEditable); | 224 expect(el.contentEditable, 'inherit'); |
226 el.attributes['contentEditable'] = 'foo'; | 225 el.attributes['contentEditable'] = 'foo'; |
227 Expect.equals('foo', el.contentEditable); | 226 expect(el.contentEditable, 'foo'); |
228 }); | 227 }); |
229 | 228 |
230 test('set', () { | 229 test('set', () { |
231 final el = makeElement(); | 230 final el = makeElement(); |
232 el.contentEditable = 'foo'; | 231 el.contentEditable = 'foo'; |
233 Expect.equals('foo', el.attributes['contentEditable']); | 232 expect(el.attributes['contentEditable'], 'foo'); |
234 }); | 233 }); |
235 | 234 |
236 test('isContentEditable', () { | 235 test('isContentEditable', () { |
237 final el = makeElement(); | 236 final el = makeElement(); |
238 Expect.isFalse(el.isContentEditable); | 237 expect(el.isContentEditable, isFalse); |
239 el.contentEditable = 'true'; | 238 el.contentEditable = 'true'; |
240 Expect.isFalse(el.isContentEditable); | 239 expect(el.isContentEditable, isFalse); |
241 }); | 240 }); |
242 }); | 241 }); |
243 | 242 |
244 group('draggable', () { | 243 group('draggable', () { |
245 test('get', () { | 244 test('get', () { |
246 final el = makeElement(); | 245 final el = makeElement(); |
247 Expect.isFalse(el.draggable); | 246 expect(el.draggable, isFalse); |
248 el.attributes['draggable'] = 'true'; | 247 el.attributes['draggable'] = 'true'; |
249 Expect.isTrue(el.draggable); | 248 expect(el.draggable, isTrue); |
250 el.attributes['draggable'] = 'foo'; | 249 el.attributes['draggable'] = 'foo'; |
251 Expect.isFalse(el.draggable); | 250 expect(el.draggable, isFalse); |
252 }); | 251 }); |
253 | 252 |
254 test('set', () { | 253 test('set', () { |
255 final el = makeElement(); | 254 final el = makeElement(); |
256 el.draggable = true; | 255 el.draggable = true; |
257 Expect.equals('true', el.attributes['draggable']); | 256 expect(el.attributes['draggable'], 'true'); |
258 el.draggable = false; | 257 el.draggable = false; |
259 Expect.equals('false', el.attributes['draggable']); | 258 expect(el.attributes['draggable'], 'false'); |
260 }); | 259 }); |
261 }); | 260 }); |
262 | 261 |
263 group('spellcheck', () { | 262 group('spellcheck', () { |
264 test('get', () { | 263 test('get', () { |
265 final el = makeElement(); | 264 final el = makeElement(); |
266 Expect.isFalse(el.spellcheck); | 265 expect(el.spellcheck, isFalse); |
267 el.attributes['spellcheck'] = 'true'; | 266 el.attributes['spellcheck'] = 'true'; |
268 Expect.isTrue(el.spellcheck); | 267 expect(el.spellcheck, isTrue); |
269 el.attributes['spellcheck'] = 'foo'; | 268 el.attributes['spellcheck'] = 'foo'; |
270 Expect.isFalse(el.spellcheck); | 269 expect(el.spellcheck, isFalse); |
271 }); | 270 }); |
272 | 271 |
273 test('set', () { | 272 test('set', () { |
274 final el = makeElement(); | 273 final el = makeElement(); |
275 el.spellcheck = true; | 274 el.spellcheck = true; |
276 Expect.equals('true', el.attributes['spellcheck']); | 275 expect(el.attributes['spellcheck'], 'true'); |
277 el.spellcheck = false; | 276 el.spellcheck = false; |
278 Expect.equals('false', el.attributes['spellcheck']); | 277 expect(el.attributes['spellcheck'], 'false'); |
279 }); | 278 }); |
280 }); | 279 }); |
281 | 280 |
282 group('hidden', () { | 281 group('hidden', () { |
283 test('get', () { | 282 test('get', () { |
284 final el = makeElement(); | 283 final el = makeElement(); |
285 Expect.isFalse(el.hidden); | 284 expect(el.hidden, isFalse); |
286 el.attributes['hidden'] = ''; | 285 el.attributes['hidden'] = ''; |
287 Expect.isTrue(el.hidden); | 286 expect(el.hidden, isTrue); |
288 }); | 287 }); |
289 | 288 |
290 test('set', () { | 289 test('set', () { |
291 final el = makeElement(); | 290 final el = makeElement(); |
292 el.hidden = true; | 291 el.hidden = true; |
293 Expect.equals('', el.attributes['hidden']); | 292 expect(el.attributes['hidden'], ''); |
294 el.hidden = false; | 293 el.hidden = false; |
295 Expect.isFalse(el.attributes.containsKey('hidden')); | 294 expect(el.attributes.containsKey('hidden'), isFalse); |
296 }); | 295 }); |
297 }); | 296 }); |
298 | 297 |
299 group('tabIndex', () { | 298 group('tabIndex', () { |
300 test('get', () { | 299 test('get', () { |
301 final el = makeElement(); | 300 final el = makeElement(); |
302 Expect.equals(0, el.tabIndex); | 301 expect(el.tabIndex, 0); |
303 el.attributes['tabIndex'] = '2'; | 302 el.attributes['tabIndex'] = '2'; |
304 Expect.equals(2, el.tabIndex); | 303 expect(el.tabIndex, 2); |
305 el.attributes['tabIndex'] = 'foo'; | 304 el.attributes['tabIndex'] = 'foo'; |
306 Expect.equals(0, el.tabIndex); | 305 expect(el.tabIndex, 0); |
307 }); | 306 }); |
308 | 307 |
309 test('set', () { | 308 test('set', () { |
310 final el = makeElement(); | 309 final el = makeElement(); |
311 el.tabIndex = 15; | 310 el.tabIndex = 15; |
312 Expect.equals('15', el.attributes['tabIndex']); | 311 expect(el.attributes['tabIndex'], '15'); |
313 }); | 312 }); |
314 }); | 313 }); |
315 | 314 |
316 group('id', () { | 315 group('id', () { |
317 test('get', () { | 316 test('get', () { |
318 final el = makeElement(); | 317 final el = makeElement(); |
319 Expect.equals('', el.id); | 318 expect(el.id, ''); |
320 el.attributes['id'] = 'foo'; | 319 el.attributes['id'] = 'foo'; |
321 Expect.equals('foo', el.id); | 320 expect(el.id, 'foo'); |
322 }); | 321 }); |
323 | 322 |
324 test('set', () { | 323 test('set', () { |
325 final el = makeElement(); | 324 final el = makeElement(); |
326 el.id = 'foo'; | 325 el.id = 'foo'; |
327 Expect.equals('foo', el.attributes['id']); | 326 expect(el.attributes['id'], 'foo'); |
328 }); | 327 }); |
329 }); | 328 }); |
330 | 329 |
331 group('title', () { | 330 group('title', () { |
332 test('get', () { | 331 test('get', () { |
333 final el = makeElement(); | 332 final el = makeElement(); |
334 Expect.equals('', el.title); | 333 expect(el.title, ''); |
335 el.attributes['title'] = 'foo'; | 334 el.attributes['title'] = 'foo'; |
336 Expect.equals('foo', el.title); | 335 expect(el.title, 'foo'); |
337 }); | 336 }); |
338 | 337 |
339 test('set', () { | 338 test('set', () { |
340 final el = makeElement(); | 339 final el = makeElement(); |
341 el.title = 'foo'; | 340 el.title = 'foo'; |
342 Expect.equals('foo', el.attributes['title']); | 341 expect(el.attributes['title'], 'foo'); |
343 }); | 342 }); |
344 }); | 343 }); |
345 | 344 |
346 group('webkitdropzone', () { | 345 group('webkitdropzone', () { |
347 test('get', () { | 346 test('get', () { |
348 final el = makeElement(); | 347 final el = makeElement(); |
349 Expect.equals('', el.webkitdropzone); | 348 expect(el.webkitdropzone, ''); |
350 el.attributes['webkitdropzone'] = 'foo'; | 349 el.attributes['webkitdropzone'] = 'foo'; |
351 Expect.equals('foo', el.webkitdropzone); | 350 expect(el.webkitdropzone, 'foo'); |
352 }); | 351 }); |
353 | 352 |
354 test('set', () { | 353 test('set', () { |
355 final el = makeElement(); | 354 final el = makeElement(); |
356 el.webkitdropzone = 'foo'; | 355 el.webkitdropzone = 'foo'; |
357 Expect.equals('foo', el.attributes['webkitdropzone']); | 356 expect(el.attributes['webkitdropzone'], 'foo'); |
358 }); | 357 }); |
359 }); | 358 }); |
360 | 359 |
361 group('lang', () { | 360 group('lang', () { |
362 test('get', () { | 361 test('get', () { |
363 final el = makeElement(); | 362 final el = makeElement(); |
364 Expect.equals('', el.lang); | 363 expect(el.lang, ''); |
365 el.attributes['lang'] = 'foo'; | 364 el.attributes['lang'] = 'foo'; |
366 Expect.equals('foo', el.lang); | 365 expect(el.lang, 'foo'); |
367 }); | 366 }); |
368 | 367 |
369 test('set', () { | 368 test('set', () { |
370 final el = makeElement(); | 369 final el = makeElement(); |
371 el.lang = 'foo'; | 370 el.lang = 'foo'; |
372 Expect.equals('foo', el.attributes['lang']); | 371 expect(el.attributes['lang'], 'foo'); |
373 }); | 372 }); |
374 }); | 373 }); |
375 | 374 |
376 group('dir', () { | 375 group('dir', () { |
377 test('get', () { | 376 test('get', () { |
378 final el = makeElement(); | 377 final el = makeElement(); |
379 Expect.equals('', el.dir); | 378 expect(el.dir, ''); |
380 el.attributes['dir'] = 'foo'; | 379 el.attributes['dir'] = 'foo'; |
381 Expect.equals('foo', el.dir); | 380 expect(el.dir, 'foo'); |
382 }); | 381 }); |
383 | 382 |
384 test('set', () { | 383 test('set', () { |
385 final el = makeElement(); | 384 final el = makeElement(); |
386 el.dir = 'foo'; | 385 el.dir = 'foo'; |
387 Expect.equals('foo', el.attributes['dir']); | 386 expect(el.attributes['dir'], 'foo'); |
388 }); | 387 }); |
389 }); | 388 }); |
390 }); | 389 }); |
391 | 390 |
392 test('set innerHTML', () { | 391 test('set innerHTML', () { |
393 final el = makeElement(); | 392 final el = makeElement(); |
394 el.innerHTML = "<foo>Bar<baz/></foo>"; | 393 el.innerHTML = "<foo>Bar<baz/></foo>"; |
395 Expect.equals(1, el.nodes.length); | 394 expect(el.nodes.length, 1); |
396 final node = el.nodes[0]; | 395 final node = el.nodes[0]; |
397 Expect.isTrue(node is XMLElement); | 396 expect(node, isXMLElement); |
398 Expect.equals('foo', node.tagName); | 397 expect(node.tagName, 'foo'); |
399 Expect.equals('Bar', node.nodes[0].text); | 398 expect(node.nodes[0].text, 'Bar'); |
400 Expect.equals('baz', node.nodes[1].tagName); | 399 expect(node.nodes[1].tagName, 'baz'); |
401 }); | 400 }); |
402 | 401 |
403 test('get innerHTML/outerHTML', () { | 402 test('get innerHTML/outerHTML', () { |
404 final el = makeElement(); | 403 final el = makeElement(); |
405 Expect.equals("<foo></foo><bar></bar>", el.innerHTML); | 404 expect(el.innerHTML, "<foo></foo><bar></bar>"); |
406 el.nodes.clear(); | 405 el.nodes.clear(); |
407 el.nodes.addAll([new Text("foo"), new XMLElement.xml("<a>bar</a>")]); | 406 el.nodes.addAll([new Text("foo"), new XMLElement.xml("<a>bar</a>")]); |
408 Expect.equals("foo<a>bar</a>", el.innerHTML); | 407 expect(el.innerHTML, "foo<a>bar</a>"); |
409 Expect.equals("<xml>foo<a>bar</a></xml>", el.outerHTML); | 408 expect(el.outerHTML, "<xml>foo<a>bar</a></xml>"); |
410 }); | 409 }); |
411 | 410 |
412 test('query', () { | 411 test('query', () { |
413 final el = makeElement(); | 412 final el = makeElement(); |
414 Expect.equals("foo", el.query('foo').tagName); | 413 expect(el.query('foo').tagName, 'foo'); |
415 Expect.isNull(el.query('baz')); | 414 expect(el.query('baz'), isNull); |
416 }); | 415 }); |
417 | 416 |
418 test('queryAll', () { | 417 test('queryAll', () { |
419 final el = new XMLElement.xml( | 418 final el = new XMLElement.xml( |
420 "<xml><foo id='f1' /><bar><foo id='f2' /></bar></xml>"); | 419 "<xml><foo id='f1' /><bar><foo id='f2' /></bar></xml>"); |
421 Expect.listEquals(["f1", "f2"], el.queryAll('foo').map((e) => e.id)); | 420 expect(el.queryAll('foo').map((e) => e.id), ['f1', 'f2']); |
422 Expect.listEquals([], el.queryAll('baz')); | 421 expect(el.queryAll('baz'), []); |
423 }); | 422 }); |
424 | 423 |
425 // TODO(nweiz): re-enable this when matchesSelector works cross-browser. | 424 // TODO(nweiz): re-enable this when matchesSelector works cross-browser. |
426 // | 425 // |
427 // test('matchesSelector', () { | 426 // test('matchesSelector', () { |
428 // final el = makeElement(); | 427 // final el = makeElement(); |
429 // Expect.isTrue(el.matchesSelector('*')); | 428 // expect(el.matchesSelector('*'), isTrue); |
430 // Expect.isTrue(el.matchesSelector('xml')); | 429 // expect(el.matchesSelector('xml'), isTrue); |
431 // Expect.isFalse(el.matchesSelector('html')); | 430 // expect(el.matchesSelector('html'), isFalse); |
432 // }); | 431 // }); |
433 | 432 |
434 group('insertAdjacentElement', () { | 433 group('insertAdjacentElement', () { |
435 test('beforeBegin with no parent does nothing', () { | 434 test('beforeBegin with no parent does nothing', () { |
436 final el = makeElement(); | 435 final el = makeElement(); |
437 Expect.isNull( | 436 expect(el.insertAdjacentElement("beforeBegin", new XMLElement.tag("b")), |
438 el.insertAdjacentElement("beforeBegin", new XMLElement.tag("b"))); | 437 isNull); |
439 Expect.equals("<foo></foo><bar></bar>", el.innerHTML); | 438 expect(el.innerHTML, "<foo></foo><bar></bar>"); |
440 }); | 439 }); |
441 | 440 |
442 test('afterEnd with no parent does nothing', () { | 441 test('afterEnd with no parent does nothing', () { |
443 final el = makeElement(); | 442 final el = makeElement(); |
444 Expect.isNull( | 443 expect( |
445 el.insertAdjacentElement("afterEnd", new XMLElement.tag("b"))); | 444 el.insertAdjacentElement("afterEnd", new XMLElement.tag("b")), isNull); |
446 Expect.equals("<foo></foo><bar></bar>", el.innerHTML); | 445 expect(el.innerHTML, "<foo></foo><bar></bar>"); |
447 }); | 446 }); |
448 | 447 |
449 test('beforeBegin with parent inserts the element', () { | 448 test('beforeBegin with parent inserts the element', () { |
450 final el = makeElementWithParent(); | 449 final el = makeElementWithParent(); |
451 final newEl = new XMLElement.tag("b"); | 450 final newEl = new XMLElement.tag("b"); |
452 Expect.equals(newEl, el.insertAdjacentElement("beforeBegin", newEl)); | 451 expect(el.insertAdjacentElement("beforeBegin", newEl), newEl); |
453 Expect.equals("<foo></foo><bar></bar>", el.innerHTML); | 452 expect(el.innerHTML, "<foo></foo><bar></bar>"); |
454 Expect.equals("<before></before><b></b><xml><foo></foo><bar></bar>" + | 453 expect(el.parent.innerHTML, |
455 "</xml><after></after>", el.parent.innerHTML); | 454 "<before></before><b></b><xml><foo></foo><bar></bar>" |
| 455 "</xml><after></after>"); |
456 }); | 456 }); |
457 | 457 |
458 test('afterEnd with parent inserts the element', () { | 458 test('afterEnd with parent inserts the element', () { |
459 final el = makeElementWithParent(); | 459 final el = makeElementWithParent(); |
460 final newEl = new XMLElement.tag("b"); | 460 final newEl = new XMLElement.tag("b"); |
461 Expect.equals(newEl, el.insertAdjacentElement("afterEnd", newEl)); | 461 expect(el.insertAdjacentElement("afterEnd", newEl), newEl); |
462 Expect.equals("<foo></foo><bar></bar>", el.innerHTML); | 462 expect(el.innerHTML, "<foo></foo><bar></bar>"); |
463 Expect.equals("<before></before><xml><foo></foo><bar></bar></xml><b>" + | 463 expect(el.parent.innerHTML, |
464 "</b><after></after>", el.parent.innerHTML); | 464 "<before></before><xml><foo></foo><bar></bar></xml><b>" |
| 465 "</b><after></after>"); |
465 }); | 466 }); |
466 | 467 |
467 test('afterBegin inserts the element', () { | 468 test('afterBegin inserts the element', () { |
468 final el = makeElement(); | 469 final el = makeElement(); |
469 final newEl = new XMLElement.tag("b"); | 470 final newEl = new XMLElement.tag("b"); |
470 Expect.equals(newEl, el.insertAdjacentElement("afterBegin", newEl)); | 471 expect(el.insertAdjacentElement("afterBegin", newEl), newEl); |
471 Expect.equals("<b></b><foo></foo><bar></bar>", el.innerHTML); | 472 expect(el.innerHTML, "<b></b><foo></foo><bar></bar>"); |
472 }); | 473 }); |
473 | 474 |
474 test('beforeEnd inserts the element', () { | 475 test('beforeEnd inserts the element', () { |
475 final el = makeElement(); | 476 final el = makeElement(); |
476 final newEl = new XMLElement.tag("b"); | 477 final newEl = new XMLElement.tag("b"); |
477 Expect.equals(newEl, el.insertAdjacentElement("beforeEnd", newEl)); | 478 expect(el.insertAdjacentElement("beforeEnd", newEl), newEl); |
478 Expect.equals("<foo></foo><bar></bar><b></b>", el.innerHTML); | 479 expect(el.innerHTML, "<foo></foo><bar></bar><b></b>"); |
479 }); | 480 }); |
480 }); | 481 }); |
481 | 482 |
482 group('insertAdjacentText', () { | 483 group('insertAdjacentText', () { |
483 test('beforeBegin with no parent does nothing', () { | 484 test('beforeBegin with no parent does nothing', () { |
484 final el = makeElement(); | 485 final el = makeElement(); |
485 el.insertAdjacentText("beforeBegin", "foo"); | 486 el.insertAdjacentText("beforeBegin", "foo"); |
486 Expect.equals("<foo></foo><bar></bar>", el.innerHTML); | 487 expect(el.innerHTML, "<foo></foo><bar></bar>"); |
487 }); | 488 }); |
488 | 489 |
489 test('afterEnd with no parent does nothing', () { | 490 test('afterEnd with no parent does nothing', () { |
490 final el = makeElement(); | 491 final el = makeElement(); |
491 el.insertAdjacentText("afterEnd", "foo"); | 492 el.insertAdjacentText("afterEnd", "foo"); |
492 Expect.equals("<foo></foo><bar></bar>", el.innerHTML); | 493 expect(el.innerHTML, "<foo></foo><bar></bar>"); |
493 }); | 494 }); |
494 | 495 |
495 test('beforeBegin with parent inserts the text', () { | 496 test('beforeBegin with parent inserts the text', () { |
496 final el = makeElementWithParent(); | 497 final el = makeElementWithParent(); |
497 el.insertAdjacentText("beforeBegin", "foo"); | 498 el.insertAdjacentText("beforeBegin", "foo"); |
498 Expect.equals("<foo></foo><bar></bar>", el.innerHTML); | 499 expect(el.innerHTML, "<foo></foo><bar></bar>"); |
499 Expect.equals("<before></before>foo<xml><foo></foo><bar></bar></xml>" + | 500 expect(el.parent.innerHTML, |
500 "<after></after>", el.parent.innerHTML); | 501 "<before></before>foo<xml><foo></foo><bar></bar></xml>" |
| 502 "<after></after>"); |
501 }); | 503 }); |
502 | 504 |
503 test('afterEnd with parent inserts the text', () { | 505 test('afterEnd with parent inserts the text', () { |
504 final el = makeElementWithParent(); | 506 final el = makeElementWithParent(); |
505 el.insertAdjacentText("afterEnd", "foo"); | 507 el.insertAdjacentText("afterEnd", "foo"); |
506 Expect.equals("<foo></foo><bar></bar>", el.innerHTML); | 508 expect(el.innerHTML, "<foo></foo><bar></bar>"); |
507 Expect.equals("<before></before><xml><foo></foo><bar></bar></xml>foo" + | 509 expect(el.parent.innerHTML, |
508 "<after></after>", el.parent.innerHTML); | 510 "<before></before><xml><foo></foo><bar></bar></xml>foo" |
| 511 "<after></after>"); |
509 }); | 512 }); |
510 | 513 |
511 test('afterBegin inserts the text', () { | 514 test('afterBegin inserts the text', () { |
512 final el = makeElement(); | 515 final el = makeElement(); |
513 el.insertAdjacentText("afterBegin", "foo"); | 516 el.insertAdjacentText("afterBegin", "foo"); |
514 Expect.equals("foo<foo></foo><bar></bar>", el.innerHTML); | 517 expect(el.innerHTML, "foo<foo></foo><bar></bar>"); |
515 }); | 518 }); |
516 | 519 |
517 test('beforeEnd inserts the text', () { | 520 test('beforeEnd inserts the text', () { |
518 final el = makeElement(); | 521 final el = makeElement(); |
519 el.insertAdjacentText("beforeEnd", "foo"); | 522 el.insertAdjacentText("beforeEnd", "foo"); |
520 Expect.equals("<foo></foo><bar></bar>foo", el.innerHTML); | 523 expect(el.innerHTML, "<foo></foo><bar></bar>foo"); |
521 }); | 524 }); |
522 }); | 525 }); |
523 | 526 |
524 group('insertAdjacentHTML', () { | 527 group('insertAdjacentHTML', () { |
525 test('beforeBegin with no parent does nothing', () { | 528 test('beforeBegin with no parent does nothing', () { |
526 final el = makeElement(); | 529 final el = makeElement(); |
527 el.insertAdjacentHTML("beforeBegin", "foo<b/>"); | 530 el.insertAdjacentHTML("beforeBegin", "foo<b/>"); |
528 Expect.equals("<foo></foo><bar></bar>", el.innerHTML); | 531 expect(el.innerHTML, "<foo></foo><bar></bar>"); |
529 }); | 532 }); |
530 | 533 |
531 test('afterEnd with no parent does nothing', () { | 534 test('afterEnd with no parent does nothing', () { |
532 final el = makeElement(); | 535 final el = makeElement(); |
533 el.insertAdjacentHTML("afterEnd", "<b/>foo"); | 536 el.insertAdjacentHTML("afterEnd", "<b/>foo"); |
534 Expect.equals("<foo></foo><bar></bar>", el.innerHTML); | 537 expect(el.innerHTML, "<foo></foo><bar></bar>"); |
535 }); | 538 }); |
536 | 539 |
537 test('beforeBegin with parent inserts the HTML', () { | 540 test('beforeBegin with parent inserts the HTML', () { |
538 final el = makeElementWithParent(); | 541 final el = makeElementWithParent(); |
539 el.insertAdjacentHTML("beforeBegin", "foo<b/>"); | 542 el.insertAdjacentHTML("beforeBegin", "foo<b/>"); |
540 Expect.equals("<foo></foo><bar></bar>", el.innerHTML); | 543 expect(el.innerHTML, "<foo></foo><bar></bar>"); |
541 Expect.equals("<before></before>foo<b></b><xml><foo></foo><bar></bar>" + | 544 expect(el.parent.innerHTML, |
542 "</xml><after></after>", el.parent.innerHTML); | 545 "<before></before>foo<b></b><xml><foo></foo><bar></bar>" |
| 546 "</xml><after></after>"); |
543 }); | 547 }); |
544 | 548 |
545 test('afterEnd with parent inserts the HTML', () { | 549 test('afterEnd with parent inserts the HTML', () { |
546 final el = makeElementWithParent(); | 550 final el = makeElementWithParent(); |
547 el.insertAdjacentHTML("afterEnd", "foo<b/>"); | 551 el.insertAdjacentHTML("afterEnd", "foo<b/>"); |
548 Expect.equals("<foo></foo><bar></bar>", el.innerHTML); | 552 expect(el.innerHTML, "<foo></foo><bar></bar>"); |
549 Expect.equals("<before></before><xml><foo></foo><bar></bar></xml>foo" + | 553 expect(el.parent.innerHTML, |
550 "<b></b><after></after>", el.parent.innerHTML); | 554 "<before></before><xml><foo></foo><bar></bar></xml>foo" |
| 555 "<b></b><after></after>"); |
551 }); | 556 }); |
552 | 557 |
553 test('afterBegin inserts the HTML', () { | 558 test('afterBegin inserts the HTML', () { |
554 final el = makeElement(); | 559 final el = makeElement(); |
555 el.insertAdjacentHTML("afterBegin", "foo<b/>"); | 560 el.insertAdjacentHTML("afterBegin", "foo<b/>"); |
556 Expect.equals("foo<b></b><foo></foo><bar></bar>", el.innerHTML); | 561 expect(el.innerHTML, "foo<b></b><foo></foo><bar></bar>"); |
557 }); | 562 }); |
558 | 563 |
559 test('beforeEnd inserts the HTML', () { | 564 test('beforeEnd inserts the HTML', () { |
560 final el = makeElement(); | 565 final el = makeElement(); |
561 el.insertAdjacentHTML("beforeEnd", "<b/>foo"); | 566 el.insertAdjacentHTML("beforeEnd", "<b/>foo"); |
562 Expect.equals("<foo></foo><bar></bar><b></b>foo", el.innerHTML); | 567 expect(el.innerHTML, "<foo></foo><bar></bar><b></b>foo"); |
563 }); | 568 }); |
564 }); | 569 }); |
565 | 570 |
566 test('default rect values', () { | 571 test('default rect values', () { |
567 makeElement().rect.then( | 572 makeElement().rect.then( |
568 expectAsync1(ElementRect rect) { | 573 expectAsync1(ElementRect rect) { |
569 expectEmptyRect(rect.client); | 574 expectEmptyRect(rect.client); |
570 expectEmptyRect(rect.offset); | 575 expectEmptyRect(rect.offset); |
571 expectEmptyRect(rect.scroll); | 576 expectEmptyRect(rect.scroll); |
572 expectEmptyRect(rect.bounding); | 577 expectEmptyRect(rect.bounding); |
573 Expect.isTrue(rect.clientRects.isEmpty); | 578 expect(rect.clientRects.isEmpty, isTrue); |
574 })); | 579 })); |
575 }); | 580 }); |
576 } | 581 } |
OLD | NEW |