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/xmlelement_test.dart

Issue 11413071: Deprecating Element.elements for Element.children. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Review feedback. 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
« no previous file with comments | « tests/html/xmldocument_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 XMLElementTest; 5 library XMLElementTest;
6 import '../../pkg/unittest/lib/unittest.dart'; 6 import '../../pkg/unittest/lib/unittest.dart';
7 import '../../pkg/unittest/lib/html_config.dart'; 7 import '../../pkg/unittest/lib/html_config.dart';
8 import 'dart:html'; 8 import 'dart:html';
9 9
10 main() { 10 main() {
11 useHtmlConfiguration(); 11 useHtmlConfiguration();
12 12
13 var isXMLElement = predicate((x) => x is XMLElement, 'is an XMLElement'); 13 var isXMLElement = predicate((x) => x is XMLElement, 'is an XMLElement');
14 14
15 XMLElement makeElement() => new XMLElement.xml("<xml><foo/><bar/></xml>"); 15 XMLElement makeElement() => new XMLElement.xml("<xml><foo/><bar/></xml>");
16 16
17 makeElementWithParent() { 17 makeElementWithParent() {
18 final parent = new XMLElement.xml( 18 final parent = new XMLElement.xml(
19 "<parent><before/><xml><foo/><bar/></xml><after/></parent>"); 19 "<parent><before/><xml><foo/><bar/></xml><after/></parent>");
20 return parent.elements[1]; 20 return parent.children[1];
21 } 21 }
22 22
23 group('constructors', () { 23 group('constructors', () {
24 group('.xml', () { 24 group('.xml', () {
25 test('with a well-formed document', () { 25 test('with a well-formed document', () {
26 final el = makeElement(); 26 final el = makeElement();
27 expect(el, isXMLElement); 27 expect(el, isXMLElement);
28 expect(el.elements[0].tagName, 'foo'); 28 expect(el.children[0].tagName, 'foo');
29 expect(el.elements[1].tagName, 'bar'); 29 expect(el.children[1].tagName, 'bar');
30 }); 30 });
31 31
32 test('with too many nodes', () { 32 test('with too many nodes', () {
33 expect(() => new XMLElement.xml("<xml></xml>foo"), throwsArgumentError); 33 expect(() => new XMLElement.xml("<xml></xml>foo"), throwsArgumentError);
34 }); 34 });
35 35
36 test('with a parse error', () { 36 test('with a parse error', () {
37 expect(() => new XMLElement.xml("<xml></xml>>"), throwsArgumentError); 37 expect(() => new XMLElement.xml("<xml></xml>>"), throwsArgumentError);
38 }); 38 });
39 39
40 test('with a PARSERERROR tag', () { 40 test('with a PARSERERROR tag', () {
41 final el = new XMLElement.xml("<xml><parsererror /></xml>"); 41 final el = new XMLElement.xml("<xml><parsererror /></xml>");
42 expect('parsererror', el.elements[0].tagName, 'parsererror'); 42 expect('parsererror', el.children[0].tagName, 'parsererror');
43 }); 43 });
44 44
45 test('has no parent', () => 45 test('has no parent', () =>
46 expect(new XMLElement.xml('<foo/>').parent), isNull); 46 expect(new XMLElement.xml('<foo/>').parent), isNull);
47 }); 47 });
48 48
49 test('.tag', () { 49 test('.tag', () {
50 final el = new XMLElement.tag('foo'); 50 final el = new XMLElement.tag('foo');
51 expect(el, isXMLElement); 51 expect(el, isXMLElement);
52 expect(el.tagName, 'foo'); 52 expect(el.tagName, 'foo');
53 }); 53 });
54 }); 54 });
55 55
56 // FilteredElementList is tested more thoroughly in DocumentFragmentTests. 56 // FilteredElementList is tested more thoroughly in DocumentFragmentTests.
57 group('elements', () { 57 group('children', () {
58 test('filters out non-element nodes', () { 58 test('filters out non-element nodes', () {
59 final el = new XMLElement.xml("<xml>1<a/><b/>2<c/>3<d/></xml>"); 59 final el = new XMLElement.xml("<xml>1<a/><b/>2<c/>3<d/></xml>");
60 expect(el.elements.map((e) => e.tagName), ["a", "b", "c", "d"]); 60 expect(el.children.map((e) => e.tagName), ["a", "b", "c", "d"]);
61 }); 61 });
62 62
63 test('overwrites nodes when set', () { 63 test('overwrites nodes when set', () {
64 final el = new XMLElement.xml("<xml>1<a/><b/>2<c/>3<d/></xml>"); 64 final el = new XMLElement.xml("<xml>1<a/><b/>2<c/>3<d/></xml>");
65 el.elements = [new XMLElement.tag('x'), new XMLElement.tag('y')]; 65 el.children = [new XMLElement.tag('x'), new XMLElement.tag('y')];
66 expect(el.outerHTML, "<xml><x></x><y></y></xml>"); 66 expect(el.outerHTML, "<xml><x></x><y></y></xml>");
67 }); 67 });
68 }); 68 });
69 69
70 group('classes', () { 70 group('classes', () {
71 XMLElement makeElementWithClasses() => 71 XMLElement makeElementWithClasses() =>
72 new XMLElement.xml("<xml class='foo bar baz'></xml>"); 72 new XMLElement.xml("<xml class='foo bar baz'></xml>");
73 73
74 Set<String> makeClassSet() => makeElementWithClasses().classes; 74 Set<String> makeClassSet() => makeElementWithClasses().classes;
75 75
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 expect( 443 expect(
444 el.insertAdjacentElement("afterEnd", new XMLElement.tag("b")), isNull); 444 el.insertAdjacentElement("afterEnd", new XMLElement.tag("b")), isNull);
445 expect(el.innerHTML, "<foo></foo><bar></bar>"); 445 expect(el.innerHTML, "<foo></foo><bar></bar>");
446 }); 446 });
447 447
448 test('beforeBegin with parent inserts the element', () { 448 test('beforeBegin with parent inserts the element', () {
449 final el = makeElementWithParent(); 449 final el = makeElementWithParent();
450 final newEl = new XMLElement.tag("b"); 450 final newEl = new XMLElement.tag("b");
451 expect(el.insertAdjacentElement("beforeBegin", newEl), newEl); 451 expect(el.insertAdjacentElement("beforeBegin", newEl), newEl);
452 expect(el.innerHTML, "<foo></foo><bar></bar>"); 452 expect(el.innerHTML, "<foo></foo><bar></bar>");
453 expect(el.parent.innerHTML, 453 expect(el.parent.innerHTML,
454 "<before></before><b></b><xml><foo></foo><bar></bar>" 454 "<before></before><b></b><xml><foo></foo><bar></bar>"
455 "</xml><after></after>"); 455 "</xml><after></after>");
456 }); 456 });
457 457
458 test('afterEnd with parent inserts the element', () { 458 test('afterEnd with parent inserts the element', () {
459 final el = makeElementWithParent(); 459 final el = makeElementWithParent();
460 final newEl = new XMLElement.tag("b"); 460 final newEl = new XMLElement.tag("b");
461 expect(el.insertAdjacentElement("afterEnd", newEl), newEl); 461 expect(el.insertAdjacentElement("afterEnd", newEl), newEl);
462 expect(el.innerHTML, "<foo></foo><bar></bar>"); 462 expect(el.innerHTML, "<foo></foo><bar></bar>");
463 expect(el.parent.innerHTML, 463 expect(el.parent.innerHTML,
464 "<before></before><xml><foo></foo><bar></bar></xml><b>" 464 "<before></before><xml><foo></foo><bar></bar></xml><b>"
465 "</b><after></after>"); 465 "</b><after></after>");
466 }); 466 });
467 467
468 test('afterBegin inserts the element', () { 468 test('afterBegin inserts the element', () {
469 final el = makeElement(); 469 final el = makeElement();
470 final newEl = new XMLElement.tag("b"); 470 final newEl = new XMLElement.tag("b");
471 expect(el.insertAdjacentElement("afterBegin", newEl), newEl); 471 expect(el.insertAdjacentElement("afterBegin", newEl), newEl);
472 expect(el.innerHTML, "<b></b><foo></foo><bar></bar>"); 472 expect(el.innerHTML, "<b></b><foo></foo><bar></bar>");
473 }); 473 });
(...skipping 16 matching lines...) Expand all
490 test('afterEnd with no parent does nothing', () { 490 test('afterEnd with no parent does nothing', () {
491 final el = makeElement(); 491 final el = makeElement();
492 el.insertAdjacentText("afterEnd", "foo"); 492 el.insertAdjacentText("afterEnd", "foo");
493 expect(el.innerHTML, "<foo></foo><bar></bar>"); 493 expect(el.innerHTML, "<foo></foo><bar></bar>");
494 }); 494 });
495 495
496 test('beforeBegin with parent inserts the text', () { 496 test('beforeBegin with parent inserts the text', () {
497 final el = makeElementWithParent(); 497 final el = makeElementWithParent();
498 el.insertAdjacentText("beforeBegin", "foo"); 498 el.insertAdjacentText("beforeBegin", "foo");
499 expect(el.innerHTML, "<foo></foo><bar></bar>"); 499 expect(el.innerHTML, "<foo></foo><bar></bar>");
500 expect(el.parent.innerHTML, 500 expect(el.parent.innerHTML,
501 "<before></before>foo<xml><foo></foo><bar></bar></xml>" 501 "<before></before>foo<xml><foo></foo><bar></bar></xml>"
502 "<after></after>"); 502 "<after></after>");
503 }); 503 });
504 504
505 test('afterEnd with parent inserts the text', () { 505 test('afterEnd with parent inserts the text', () {
506 final el = makeElementWithParent(); 506 final el = makeElementWithParent();
507 el.insertAdjacentText("afterEnd", "foo"); 507 el.insertAdjacentText("afterEnd", "foo");
508 expect(el.innerHTML, "<foo></foo><bar></bar>"); 508 expect(el.innerHTML, "<foo></foo><bar></bar>");
509 expect(el.parent.innerHTML, 509 expect(el.parent.innerHTML,
510 "<before></before><xml><foo></foo><bar></bar></xml>foo" 510 "<before></before><xml><foo></foo><bar></bar></xml>foo"
511 "<after></after>"); 511 "<after></after>");
512 }); 512 });
513 513
514 test('afterBegin inserts the text', () { 514 test('afterBegin inserts the text', () {
515 final el = makeElement(); 515 final el = makeElement();
516 el.insertAdjacentText("afterBegin", "foo"); 516 el.insertAdjacentText("afterBegin", "foo");
517 expect(el.innerHTML, "foo<foo></foo><bar></bar>"); 517 expect(el.innerHTML, "foo<foo></foo><bar></bar>");
518 }); 518 });
519 519
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 makeElement().rect.then( 572 makeElement().rect.then(
573 expectAsync1(ElementRect rect) { 573 expectAsync1(ElementRect rect) {
574 expectEmptyRect(rect.client); 574 expectEmptyRect(rect.client);
575 expectEmptyRect(rect.offset); 575 expectEmptyRect(rect.offset);
576 expectEmptyRect(rect.scroll); 576 expectEmptyRect(rect.scroll);
577 expectEmptyRect(rect.bounding); 577 expectEmptyRect(rect.bounding);
578 expect(rect.clientRects.isEmpty, isTrue); 578 expect(rect.clientRects.isEmpty, isTrue);
579 })); 579 }));
580 }); 580 });
581 } 581 }
OLDNEW
« no previous file with comments | « tests/html/xmldocument_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698