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

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

Issue 13852008: Removing redundant collection methods from DOM collections. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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 | « sdk/lib/html/html_common/filtered_element_list.dart ('k') | tests/html/node_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:async'; 8 import 'dart:async';
9 import 'dart:html'; 9 import 'dart:html';
10 import 'dart:svg' as svg; 10 import 'dart:svg' as svg;
11 11
12 expectLargeRect(Rect rect) { 12 expectLargeRect(Rect rect) {
13 expect(rect.top, 0); 13 expect(rect.top, 0);
14 expect(rect.left, 0); 14 expect(rect.left, 0);
15 expect(rect.width, greaterThan(100)); 15 expect(rect.width, greaterThan(100));
16 expect(rect.height, greaterThan(100)); 16 expect(rect.height, greaterThan(100));
17 expect(rect.bottom, rect.top + rect.height); 17 expect(rect.bottom, rect.top + rect.height);
18 expect(rect.right, rect.left + rect.width); 18 expect(rect.right, rect.left + rect.width);
19 } 19 }
20 20
21 void testUnsupported(String name, void f()) {
22 test(name, () {
23 expect(f, throwsUnsupportedError);
24 });
25 }
26
21 main() { 27 main() {
22 useHtmlIndividualConfiguration(); 28 useHtmlIndividualConfiguration();
23 29
24 var isHRElement = predicate((x) => x is HRElement, 'is a HRElement'); 30 var isHRElement = predicate((x) => x is HRElement, 'is a HRElement');
25 var isBRElement = predicate((x) => x is BRElement, 'is a BRElement'); 31 var isBRElement = predicate((x) => x is BRElement, 'is a BRElement');
26 var isInputElement = 32 var isInputElement =
27 predicate((x) => x is InputElement, 'is an InputElement'); 33 predicate((x) => x is InputElement, 'is an InputElement');
28 var isImageElement = 34 var isImageElement =
29 predicate((x) => x is ImageElement, 'is an ImageElement'); 35 predicate((x) => x is ImageElement, 'is an ImageElement');
30 var isSpanElement = predicate((x) => x is SpanElement, 'is a SpanElement'); 36 var isSpanElement = predicate((x) => x is SpanElement, 'is a SpanElement');
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 expect(el.children.removeLast(), isInputElement); 487 expect(el.children.removeLast(), isInputElement);
482 expect(el.children.length, 2); 488 expect(el.children.length, 2);
483 expect(el.children.removeLast(), isImageElement); 489 expect(el.children.removeLast(), isImageElement);
484 expect(el.children.length, 1); 490 expect(el.children.length, 1);
485 }); 491 });
486 492
487 test('sublist', () { 493 test('sublist', () {
488 var el = makeElementWithChildren(); 494 var el = makeElementWithChildren();
489 expect(el.children.sublist(1, 2), isElementList); 495 expect(el.children.sublist(1, 2), isElementList);
490 }); 496 });
497
498 test('getRange', () {
499 var el = makeElementWithChildren();
500 expect(el.children.getRange(1, 2).length, 1);
501 });
502
503 testUnsupported('sort', () {
504 var l = makeElementWithChildren().children;
505 l.sort();
506 });
507
508 testUnsupported('setRange', () {
509 var l = makeElementWithChildren().children;
510 l.setRange(0, 0, []);
511 });
512
513 testUnsupported('replaceRange', () {
514 var l = makeElementWithChildren().children;
515 l.replaceRange(0, 0, []);
516 });
517
518 testUnsupported('removeRange', () {
519 var l = makeElementWithChildren().children;
520 l.removeRange(0, 1);
521 });
522
523 testUnsupported('insertAll', () {
524 var l = makeElementWithChildren().children;
525 l.insertAll(0, []);
526 });
491 }); 527 });
492 528
493 group('matches', () { 529 group('matches', () {
494 test('matches', () { 530 test('matches', () {
495 var element = new DivElement(); 531 var element = new DivElement();
496 element.classes.add('test'); 532 element.classes.add('test');
497 533
498 expect(element.matches('div'), true); 534 expect(element.matches('div'), true);
499 expect(element.matches('span'), false); 535 expect(element.matches('span'), false);
500 expect(element.matches('.test'), true); 536 expect(element.matches('.test'), true);
(...skipping 10 matching lines...) Expand all
511 <span class='q'>Hello</span>, 547 <span class='q'>Hello</span>,
512 <em>world</em>! 548 <em>world</em>!
513 </p> 549 </p>
514 <hr class='q'/> 550 <hr class='q'/>
515 </div> 551 </div>
516 """).queryAll('.q'); 552 """).queryAll('.q');
517 } 553 }
518 554
519 List<Element> getEmptyQueryAll() => new Element.tag('div').queryAll('img'); 555 List<Element> getEmptyQueryAll() => new Element.tag('div').queryAll('img');
520 556
521 void testUnsupported(String name, void f()) {
522 test(name, () {
523 expect(f, throwsUnsupportedError);
524 });
525 }
526
527 test('last', () { 557 test('last', () {
528 expect(getQueryAll().last, isHRElement); 558 expect(getQueryAll().last, isHRElement);
529 }); 559 });
530 560
531 test('forEach', () { 561 test('forEach', () {
532 var els = []; 562 var els = [];
533 getQueryAll().forEach((el) => els.add(el)); 563 getQueryAll().forEach((el) => els.add(el));
534 expect(els[0], isAnchorElement); 564 expect(els[0], isAnchorElement);
535 expect(els[1], isSpanElement); 565 expect(els[1], isSpanElement);
536 expect(els[2], isHRElement); 566 expect(els[2], isHRElement);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 testUnsupported('addAll', () { 627 testUnsupported('addAll', () {
598 getQueryAll().addAll([ 628 getQueryAll().addAll([
599 new Element.tag('span'), 629 new Element.tag('span'),
600 new Element.tag('a'), 630 new Element.tag('a'),
601 new Element.tag('h1') 631 new Element.tag('h1')
602 ]); 632 ]);
603 }); 633 });
604 634
605 testUnsupported('sort', () => getQueryAll().sort((a1, a2) => true)); 635 testUnsupported('sort', () => getQueryAll().sort((a1, a2) => true));
606 636
607 testUnsupported('setRange', () => getQueryAll().setRange(0, 0, [])); 637 testUnsupported('setRange', () {
638 getQueryAll().setRange(0, 1, [new BRElement()]);
639 });
608 640
609 testUnsupported('removeRange', () => getQueryAll().removeRange(0, 1)); 641 testUnsupported('removeRange', () => getQueryAll().removeRange(0, 1));
610 642
611 testUnsupported('clear', () => getQueryAll().clear()); 643 testUnsupported('clear', () => getQueryAll().clear());
612 644
613 testUnsupported('removeLast', () => getQueryAll().removeLast()); 645 testUnsupported('removeLast', () => getQueryAll().removeLast());
614 }); 646 });
615 647
616 group('functional', () { 648 group('functional', () {
617 test('toString', () { 649 test('toString', () {
(...skipping 25 matching lines...) Expand all
643 }); 675 });
644 676
645 test('sublist', () { 677 test('sublist', () {
646 var range = makeElList().sublist(1, 3); 678 var range = makeElList().sublist(1, 3);
647 expect(range, isElementList); 679 expect(range, isElementList);
648 expect(range[0], isImageElement); 680 expect(range[0], isImageElement);
649 expect(range[1], isInputElement); 681 expect(range[1], isInputElement);
650 }); 682 });
651 }); 683 });
652 } 684 }
OLDNEW
« no previous file with comments | « sdk/lib/html/html_common/filtered_element_list.dart ('k') | tests/html/node_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698