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

Side by Side Diff: tests/html/element_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/element_add_test.dart ('k') | tests/html/hidden_dom_1_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
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 ElementTest; 5 library ElementTest;
6 import '../../pkg/unittest/lib/unittest.dart'; 6 import '../../pkg/unittest/lib/unittest.dart';
7 import '../../pkg/unittest/lib/html_individual_config.dart'; 7 import '../../pkg/unittest/lib/html_individual_config.dart';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'dart:svg' as svg; 9 import 'dart:svg' as svg;
10 10
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 }); 83 });
84 84
85 test('client position synchronous', () { 85 test('client position synchronous', () {
86 final container = new Element.tag("div"); 86 final container = new Element.tag("div");
87 container.style.position = 'absolute'; 87 container.style.position = 'absolute';
88 container.style.top = '8px'; 88 container.style.top = '8px';
89 container.style.left = '8px'; 89 container.style.left = '8px';
90 final element = new Element.tag("div"); 90 final element = new Element.tag("div");
91 element.style.width = '200px'; 91 element.style.width = '200px';
92 element.style.height = '200px'; 92 element.style.height = '200px';
93 container.elements.add(element); 93 container.children.add(element);
94 document.body.elements.add(container); 94 document.body.children.add(container);
95 95
96 expect(element.clientWidth, greaterThan(100)); 96 expect(element.clientWidth, greaterThan(100));
97 expect(element.clientHeight, greaterThan(100)); 97 expect(element.clientHeight, greaterThan(100));
98 expect(element.offsetWidth, greaterThan(100)); 98 expect(element.offsetWidth, greaterThan(100));
99 expect(element.offsetHeight, greaterThan(100)); 99 expect(element.offsetHeight, greaterThan(100));
100 expect(element.scrollWidth, greaterThan(100)); 100 expect(element.scrollWidth, greaterThan(100));
101 expect(element.scrollHeight, greaterThan(100)); 101 expect(element.scrollHeight, greaterThan(100));
102 expect(element.getBoundingClientRect().left, 8); 102 expect(element.getBoundingClientRect().left, 8);
103 expect(element.getBoundingClientRect().top, 8); 103 expect(element.getBoundingClientRect().top, 8);
104 container.remove(); 104 container.remove();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 test('tbody', () => testConstructorHelper('tbody', 142 test('tbody', () => testConstructorHelper('tbody',
143 '<tbody><tr><td>foo</td></tr></tbody>', 'foo', 143 '<tbody><tr><td>foo</td></tr></tbody>', 'foo',
144 (element) => element is TableSectionElement)); 144 (element) => element is TableSectionElement));
145 test('tfoot', () => testConstructorHelper('tfoot', 145 test('tfoot', () => testConstructorHelper('tfoot',
146 '<tfoot><tr><td>foo</td></tr></tfoot>', 'foo', 146 '<tfoot><tr><td>foo</td></tr></tfoot>', 'foo',
147 (element) => element is TableSectionElement)); 147 (element) => element is TableSectionElement));
148 test('thead', () => testConstructorHelper('thead', 148 test('thead', () => testConstructorHelper('thead',
149 '<thead><tr><td>foo</td></tr></thead>', 'foo', 149 '<thead><tr><td>foo</td></tr></thead>', 'foo',
150 (element) => element is TableSectionElement)); 150 (element) => element is TableSectionElement));
151 }); 151 });
152 152
153 group('constructors', () { 153 group('constructors', () {
154 test('error', () { 154 test('error', () {
155 expect(() => new Element.html('<br/><br/>'), throwsArgumentError); 155 expect(() => new Element.html('<br/><br/>'), throwsArgumentError);
156 }); 156 });
157 157
158 test('.html has no parent', () => 158 test('.html has no parent', () =>
159 expect(new Element.html('<br/>').parent, isNull)); 159 expect(new Element.html('<br/>').parent, isNull));
160 160
161 test('a', () => testConstructorHelper('a', '<a>foo</a>', 'foo', 161 test('a', () => testConstructorHelper('a', '<a>foo</a>', 'foo',
162 (element) => element is AnchorElement)); 162 (element) => element is AnchorElement));
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 // TODO(jacobr): video tags cause tests to segfault when using dartium. 276 // TODO(jacobr): video tags cause tests to segfault when using dartium.
277 // b/5522106. 277 // b/5522106.
278 // test('video', () => testConstructorHelper('video', 278 // test('video', () => testConstructorHelper('video',
279 // '<video>foo</video>', 'foo', 279 // '<video>foo</video>', 'foo',
280 // (element) => element is VideoElement)); 280 // (element) => element is VideoElement));
281 // TODO(jacobr): this test is broken until Dartium fixes b/5521083 281 // TODO(jacobr): this test is broken until Dartium fixes b/5521083
282 // test('someunknown', () => testConstructorHelper('someunknown', 282 // test('someunknown', () => testConstructorHelper('someunknown',
283 // '<someunknown>foo</someunknown>', 'foo', 283 // '<someunknown>foo</someunknown>', 'foo',
284 // (element) => element is UnknownElement)); 284 // (element) => element is UnknownElement));
285 }); 285 });
286 286
287 group('eventListening', () { 287 group('eventListening', () {
288 test('eventListeners', () { 288 test('eventListeners', () {
289 final element = new Element.tag('div'); 289 final element = new Element.tag('div');
290 final on = element.on; 290 final on = element.on;
291 291
292 testEventHelper(on.abort, 'abort', 292 testEventHelper(on.abort, 'abort',
293 (listener) => Testing.addEventListener( 293 (listener) => Testing.addEventListener(
294 element, 'abort', listener, true)); 294 element, 'abort', listener, true));
295 testEventHelper(on.beforeCopy, 'beforecopy', 295 testEventHelper(on.beforeCopy, 'beforecopy',
296 (listener) => Testing.addEventListener( 296 (listener) => Testing.addEventListener(
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 attributes.remove('style'); 459 attributes.remove('style');
460 expect(attributes.length, 3); 460 expect(attributes.length, 3);
461 dataAttributes['foo3'] = 'baz3'; 461 dataAttributes['foo3'] = 'baz3';
462 expect(dataAttributes.length, 2); 462 expect(dataAttributes.length, 2);
463 expect(attributes.length, 4); 463 expect(attributes.length, 4);
464 attributes['style'] = 'width: 300px;'; 464 attributes['style'] = 'width: 300px;';
465 expect(attributes.length, 5); 465 expect(attributes.length, 5);
466 }); 466 });
467 }); 467 });
468 468
469 group('elements', () { 469 group('children', () {
470 test('is a subset of nodes', () { 470 test('is a subset of nodes', () {
471 var el = new Element.html("<div>Foo<br/><img/></div>"); 471 var el = new Element.html("<div>Foo<br/><img/></div>");
472 expect(el.nodes.length, 3); 472 expect(el.nodes.length, 3);
473 expect(el.elements.length, 2); 473 expect(el.children.length, 2);
474 expect(el.nodes[1], el.elements[0]); 474 expect(el.nodes[1], el.children[0]);
475 expect(el.nodes[2], el.elements[1]); 475 expect(el.nodes[2], el.children[1]);
476 }); 476 });
477 477
478 test('changes when an element is added to nodes', () { 478 test('changes when an element is added to nodes', () {
479 var el = new Element.html("<div>Foo<br/><img/></div>"); 479 var el = new Element.html("<div>Foo<br/><img/></div>");
480 el.nodes.add(new Element.tag('hr')); 480 el.nodes.add(new Element.tag('hr'));
481 expect(el.elements.length, 3); 481 expect(el.children.length, 3);
482 expect(el.elements[2], isHRElement); 482 expect(el.children[2], isHRElement);
483 expect(el.nodes[3], el.elements[2]); 483 expect(el.nodes[3], el.children[2]);
484 }); 484 });
485 485
486 test('changes nodes when an element is added', () { 486 test('changes nodes when an element is added', () {
487 var el = new Element.html("<div>Foo<br/><img/></div>"); 487 var el = new Element.html("<div>Foo<br/><img/></div>");
488 el.elements.add(new Element.tag('hr')); 488 el.children.add(new Element.tag('hr'));
489 expect(el.nodes.length, 4); 489 expect(el.nodes.length, 4);
490 expect(el.nodes[3], isHRElement); 490 expect(el.nodes[3], isHRElement);
491 expect(el.elements[2], el.nodes[3]); 491 expect(el.children[2], el.nodes[3]);
492 }); 492 });
493 493
494 test('last', () { 494 test('last', () {
495 var el = makeElementWithChildren(); 495 var el = makeElementWithChildren();
496 expect(el.elements.last, isInputElement); 496 expect(el.children.last, isInputElement);
497 }); 497 });
498 498
499 test('forEach', () { 499 test('forEach', () {
500 var els = []; 500 var els = [];
501 var el = makeElementWithChildren(); 501 var el = makeElementWithChildren();
502 el.elements.forEach((n) => els.add(n)); 502 el.children.forEach((n) => els.add(n));
503 expect(els[0], isBRElement); 503 expect(els[0], isBRElement);
504 expect(els[1], isImageElement); 504 expect(els[1], isImageElement);
505 expect(els[2], isInputElement); 505 expect(els[2], isInputElement);
506 }); 506 });
507 507
508 test('filter', () { 508 test('filter', () {
509 var filtered = makeElementWithChildren().elements. 509 var filtered = makeElementWithChildren().children.
510 filter((n) => n is ImageElement); 510 filter((n) => n is ImageElement);
511 expect(1, filtered.length); 511 expect(1, filtered.length);
512 expect(filtered[0], isImageElement); 512 expect(filtered[0], isImageElement);
513 expect(filtered, isElementList); 513 expect(filtered, isElementList);
514 }); 514 });
515 515
516 test('every', () { 516 test('every', () {
517 var el = makeElementWithChildren(); 517 var el = makeElementWithChildren();
518 expect(el.elements.every((n) => n is Element), isTrue); 518 expect(el.children.every((n) => n is Element), isTrue);
519 expect(el.elements.every((n) => n is InputElement), isFalse); 519 expect(el.children.every((n) => n is InputElement), isFalse);
520 }); 520 });
521 521
522 test('some', () { 522 test('some', () {
523 var el = makeElementWithChildren(); 523 var el = makeElementWithChildren();
524 expect(el.elements.some((n) => n is InputElement), isTrue); 524 expect(el.children.some((n) => n is InputElement), isTrue);
525 expect(el.elements.some((n) => n is svg.SvgElement), isFalse); 525 expect(el.children.some((n) => n is svg.SvgElement), isFalse);
526 }); 526 });
527 527
528 test('isEmpty', () { 528 test('isEmpty', () {
529 expect(makeElement().elements.isEmpty, isTrue); 529 expect(makeElement().children.isEmpty, isTrue);
530 expect(makeElementWithChildren().elements.isEmpty, isFalse); 530 expect(makeElementWithChildren().children.isEmpty, isFalse);
531 }); 531 });
532 532
533 test('length', () { 533 test('length', () {
534 expect(makeElement().elements.length, 0); 534 expect(makeElement().children.length, 0);
535 expect(makeElementWithChildren().elements.length, 3); 535 expect(makeElementWithChildren().children.length, 3);
536 }); 536 });
537 537
538 test('[]', () { 538 test('[]', () {
539 var el = makeElementWithChildren(); 539 var el = makeElementWithChildren();
540 expect(el.elements[0], isBRElement); 540 expect(el.children[0], isBRElement);
541 expect(el.elements[1], isImageElement); 541 expect(el.children[1], isImageElement);
542 expect(el.elements[2], isInputElement); 542 expect(el.children[2], isInputElement);
543 }); 543 });
544 544
545 test('[]=', () { 545 test('[]=', () {
546 var el = makeElementWithChildren(); 546 var el = makeElementWithChildren();
547 el.elements[1] = new Element.tag('hr'); 547 el.children[1] = new Element.tag('hr');
548 expect(el.elements[0], isBRElement); 548 expect(el.children[0], isBRElement);
549 expect(el.elements[1], isHRElement); 549 expect(el.children[1], isHRElement);
550 expect(el.elements[2], isInputElement); 550 expect(el.children[2], isInputElement);
551 }); 551 });
552 552
553 test('add', () { 553 test('add', () {
554 var el = makeElement(); 554 var el = makeElement();
555 el.elements.add(new Element.tag('hr')); 555 el.children.add(new Element.tag('hr'));
556 expect(el.elements.last, isHRElement); 556 expect(el.children.last, isHRElement);
557 }); 557 });
558 558
559 test('addLast', () { 559 test('addLast', () {
560 var el = makeElement(); 560 var el = makeElement();
561 el.elements.addLast(new Element.tag('hr')); 561 el.children.addLast(new Element.tag('hr'));
562 expect(el.elements.last, isHRElement); 562 expect(el.children.last, isHRElement);
563 }); 563 });
564 564
565 test('iterator', () { 565 test('iterator', () {
566 var els = []; 566 var els = [];
567 var el = makeElementWithChildren(); 567 var el = makeElementWithChildren();
568 for (var subel in el.elements) { 568 for (var subel in el.children) {
569 els.add(subel); 569 els.add(subel);
570 } 570 }
571 expect(els[0], isBRElement); 571 expect(els[0], isBRElement);
572 expect(els[1], isImageElement); 572 expect(els[1], isImageElement);
573 expect(els[2], isInputElement); 573 expect(els[2], isInputElement);
574 }); 574 });
575 575
576 test('addAll', () { 576 test('addAll', () {
577 var el = makeElementWithChildren(); 577 var el = makeElementWithChildren();
578 el.elements.addAll([ 578 el.children.addAll([
579 new Element.tag('span'), 579 new Element.tag('span'),
580 new Element.tag('a'), 580 new Element.tag('a'),
581 new Element.tag('h1') 581 new Element.tag('h1')
582 ]); 582 ]);
583 expect(el.elements[0], isBRElement); 583 expect(el.children[0], isBRElement);
584 expect(el.elements[1], isImageElement); 584 expect(el.children[1], isImageElement);
585 expect(el.elements[2], isInputElement); 585 expect(el.children[2], isInputElement);
586 expect(el.elements[3], isSpanElement); 586 expect(el.children[3], isSpanElement);
587 expect(el.elements[4], isAnchorElement); 587 expect(el.children[4], isAnchorElement);
588 expect(el.elements[5], isHeadingElement); 588 expect(el.children[5], isHeadingElement);
589 }); 589 });
590 590
591 test('clear', () { 591 test('clear', () {
592 var el = makeElementWithChildren(); 592 var el = makeElementWithChildren();
593 el.elements.clear(); 593 el.children.clear();
594 expect(el.elements, equals([])); 594 expect(el.children, equals([]));
595 }); 595 });
596 596
597 test('removeLast', () { 597 test('removeLast', () {
598 var el = makeElementWithChildren(); 598 var el = makeElementWithChildren();
599 expect(el.elements.removeLast(), isInputElement); 599 expect(el.children.removeLast(), isInputElement);
600 expect(el.elements.length, 2); 600 expect(el.children.length, 2);
601 expect(el.elements.removeLast(), isImageElement); 601 expect(el.children.removeLast(), isImageElement);
602 expect(el.elements.length, 1); 602 expect(el.children.length, 1);
603 }); 603 });
604 604
605 test('getRange', () { 605 test('getRange', () {
606 var el = makeElementWithChildren(); 606 var el = makeElementWithChildren();
607 expect(el.elements.getRange(1, 1), isElementList); 607 expect(el.children.getRange(1, 1), isElementList);
608 }); 608 });
609 }); 609 });
610 610
611 group('queryAll', () { 611 group('queryAll', () {
612 List<Element> getQueryAll() { 612 List<Element> getQueryAll() {
613 return new Element.html(""" 613 return new Element.html("""
614 <div> 614 <div>
615 <hr/> 615 <hr/>
616 <a class='q' href='http://dartlang.org'>Dart!</a> 616 <a class='q' href='http://dartlang.org'>Dart!</a>
617 <p> 617 <p>
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 testUnsupported('removeRange', () => getQueryAll().removeRange(0, 1)); 718 testUnsupported('removeRange', () => getQueryAll().removeRange(0, 1));
719 719
720 testUnsupported('insertangeRange', () => getQueryAll().insertRange(0, 1)); 720 testUnsupported('insertangeRange', () => getQueryAll().insertRange(0, 1));
721 721
722 testUnsupported('clear', () => getQueryAll().clear()); 722 testUnsupported('clear', () => getQueryAll().clear());
723 723
724 testUnsupported('removeLast', () => getQueryAll().removeLast()); 724 testUnsupported('removeLast', () => getQueryAll().removeLast());
725 }); 725 });
726 726
727 group('_ElementList', () { 727 group('_ElementList', () {
728 List<Element> makeElList() => makeElementWithChildren().elements; 728 List<Element> makeElList() => makeElementWithChildren().children;
729 729
730 test('filter', () { 730 test('filter', () {
731 var filtered = makeElList().filter((n) => n is ImageElement); 731 var filtered = makeElList().filter((n) => n is ImageElement);
732 expect(filtered.length, 1); 732 expect(filtered.length, 1);
733 expect(filtered[0], isImageElement); 733 expect(filtered[0], isImageElement);
734 expect(filtered, isElementList); 734 expect(filtered, isElementList);
735 }); 735 });
736 736
737 test('getRange', () { 737 test('getRange', () {
738 var range = makeElList().getRange(1, 2); 738 var range = makeElList().getRange(1, 2);
739 expect(range, isElementList); 739 expect(range, isElementList);
740 expect(range[0], isImageElement); 740 expect(range[0], isImageElement);
741 expect(range[1], isInputElement); 741 expect(range[1], isInputElement);
742 }); 742 });
743 }); 743 });
744 } 744 }
OLDNEW
« no previous file with comments | « tests/html/element_add_test.dart ('k') | tests/html/hidden_dom_1_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698