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