Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: tests/html/xmldocument_test.dart

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

Powered by Google App Engine
This is Rietveld 408576698