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

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

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

Powered by Google App Engine
This is Rietveld 408576698