OLD | NEW |
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/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 expectLargeRect(ClientRect rect) { | 10 expectLargeRect(ClientRect rect) { |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 test('changes nodes when an element is added', () { | 490 test('changes nodes when an element is added', () { |
491 var el = new Element.html("<div>Foo<br/><img/></div>"); | 491 var el = new Element.html("<div>Foo<br/><img/></div>"); |
492 el.elements.add(new Element.tag('hr')); | 492 el.elements.add(new Element.tag('hr')); |
493 Expect.equals(4, el.nodes.length); | 493 Expect.equals(4, el.nodes.length); |
494 Expect.isTrue(el.nodes[3] is HRElement); | 494 Expect.isTrue(el.nodes[3] is HRElement); |
495 Expect.equals(el.elements[2], el.nodes[3]); | 495 Expect.equals(el.elements[2], el.nodes[3]); |
496 }); | 496 }); |
497 | 497 |
498 test('last', () { | 498 test('last', () { |
499 var el = makeElementWithChildren(); | 499 var el = makeElementWithChildren(); |
500 Expect.isTrue(el.elements.last() is InputElement); | 500 Expect.isTrue(el.elements.last is InputElement); |
501 }); | 501 }); |
502 | 502 |
503 test('forEach', () { | 503 test('forEach', () { |
504 var els = []; | 504 var els = []; |
505 var el = makeElementWithChildren(); | 505 var el = makeElementWithChildren(); |
506 el.elements.forEach((n) => els.add(n)); | 506 el.elements.forEach((n) => els.add(n)); |
507 Expect.isTrue(els[0] is BRElement); | 507 Expect.isTrue(els[0] is BRElement); |
508 Expect.isTrue(els[1] is ImageElement); | 508 Expect.isTrue(els[1] is ImageElement); |
509 Expect.isTrue(els[2] is InputElement); | 509 Expect.isTrue(els[2] is InputElement); |
510 }); | 510 }); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 var el = makeElementWithChildren(); | 550 var el = makeElementWithChildren(); |
551 el.elements[1] = new Element.tag('hr'); | 551 el.elements[1] = new Element.tag('hr'); |
552 Expect.isTrue(el.elements[0] is BRElement); | 552 Expect.isTrue(el.elements[0] is BRElement); |
553 Expect.isTrue(el.elements[1] is HRElement); | 553 Expect.isTrue(el.elements[1] is HRElement); |
554 Expect.isTrue(el.elements[2] is InputElement); | 554 Expect.isTrue(el.elements[2] is InputElement); |
555 }); | 555 }); |
556 | 556 |
557 test('add', () { | 557 test('add', () { |
558 var el = makeElement(); | 558 var el = makeElement(); |
559 el.elements.add(new Element.tag('hr')); | 559 el.elements.add(new Element.tag('hr')); |
560 Expect.isTrue(el.elements.last() is HRElement); | 560 Expect.isTrue(el.elements.last is HRElement); |
561 }); | 561 }); |
562 | 562 |
563 test('addLast', () { | 563 test('addLast', () { |
564 var el = makeElement(); | 564 var el = makeElement(); |
565 el.elements.addLast(new Element.tag('hr')); | 565 el.elements.addLast(new Element.tag('hr')); |
566 Expect.isTrue(el.elements.last() is HRElement); | 566 Expect.isTrue(el.elements.last is HRElement); |
567 }); | 567 }); |
568 | 568 |
569 test('iterator', () { | 569 test('iterator', () { |
570 var els = []; | 570 var els = []; |
571 var el = makeElementWithChildren(); | 571 var el = makeElementWithChildren(); |
572 for (var subel in el.elements) { | 572 for (var subel in el.elements) { |
573 els.add(subel); | 573 els.add(subel); |
574 } | 574 } |
575 Expect.isTrue(els[0] is BRElement); | 575 Expect.isTrue(els[0] is BRElement); |
576 Expect.isTrue(els[1] is ImageElement); | 576 Expect.isTrue(els[1] is ImageElement); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 | 629 |
630 List<Element> getEmptyQueryAll() => new Element.tag('div').queryAll('img'); | 630 List<Element> getEmptyQueryAll() => new Element.tag('div').queryAll('img'); |
631 | 631 |
632 void testUnsupported(String name, void f()) { | 632 void testUnsupported(String name, void f()) { |
633 test(name, () { | 633 test(name, () { |
634 Expect.throws(f, (e) => e is UnsupportedError); | 634 Expect.throws(f, (e) => e is UnsupportedError); |
635 }); | 635 }); |
636 } | 636 } |
637 | 637 |
638 test('last', () { | 638 test('last', () { |
639 Expect.isTrue(getQueryAll().last() is HRElement); | 639 Expect.isTrue(getQueryAll().last is HRElement); |
640 }); | 640 }); |
641 | 641 |
642 test('forEach', () { | 642 test('forEach', () { |
643 var els = []; | 643 var els = []; |
644 getQueryAll().forEach((el) => els.add(el)); | 644 getQueryAll().forEach((el) => els.add(el)); |
645 Expect.isTrue(els[0] is AnchorElement); | 645 Expect.isTrue(els[0] is AnchorElement); |
646 Expect.isTrue(els[1] is SpanElement); | 646 Expect.isTrue(els[1] is SpanElement); |
647 Expect.isTrue(els[2] is HRElement); | 647 Expect.isTrue(els[2] is HRElement); |
648 }); | 648 }); |
649 | 649 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 }); | 739 }); |
740 | 740 |
741 test('getRange', () { | 741 test('getRange', () { |
742 var range = makeElList().getRange(1, 2); | 742 var range = makeElList().getRange(1, 2); |
743 Expect.isTrue(range is List<Element>); | 743 Expect.isTrue(range is List<Element>); |
744 Expect.isTrue(range[0] is ImageElement); | 744 Expect.isTrue(range[0] is ImageElement); |
745 Expect.isTrue(range[1] is InputElement); | 745 Expect.isTrue(range[1] is InputElement); |
746 }); | 746 }); |
747 }); | 747 }); |
748 } | 748 } |
OLD | NEW |