| 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/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; |
| (...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 | 813 |
| 814 var firedEvent5 = false; | 814 var firedEvent5 = false; |
| 815 queryAll(':root').onClick.matches('.e').listen((event) { | 815 queryAll(':root').onClick.matches('.e').listen((event) { |
| 816 firedEvent5 = true; | 816 firedEvent5 = true; |
| 817 }); | 817 }); |
| 818 expect(firedEvent5, false); | 818 expect(firedEvent5, false); |
| 819 query('.i').click(); | 819 query('.i').click(); |
| 820 expect(firedEvent5, true); | 820 expect(firedEvent5, true); |
| 821 }); | 821 }); |
| 822 }); | 822 }); |
| 823 |
| 824 group('ElementList', () { |
| 825 // Tests for methods on the DOM class 'NodeList'. |
| 826 // |
| 827 // There are two interesting things that are checked here from the viewpoint |
| 828 // of the dart2js implementation of a 'native' class: |
| 829 // |
| 830 // 1. Some methods are implementated from by 'Object' or 'Interceptor'; |
| 831 // some of these tests simply check that a method can be called. |
| 832 // 2. Some methods are implemented by mixins. |
| 833 |
| 834 ElementList makeElementList() => |
| 835 (new Element.html("<div>Foo<br/><!--baz--><br/><br/></div>")) |
| 836 .queryAll('br'); |
| 837 |
| 838 test('hashCode', () { |
| 839 var nodes = makeElementList(); |
| 840 var hash = nodes.hashCode; |
| 841 final int N = 1000; |
| 842 int matchCount = 0; |
| 843 for (int i = 0; i < N; i++) { |
| 844 if (makeElementList().hashCode == hash) matchCount++; |
| 845 } |
| 846 expect(matchCount, lessThan(N)); |
| 847 }); |
| 848 |
| 849 test('operator==', () { |
| 850 var a = [makeElementList(), makeElementList(), null]; |
| 851 for (int i = 0; i < a.length; i++) { |
| 852 for (int j = 0; j < a.length; j++) { |
| 853 expect(i == j, a[i] == a[j]); |
| 854 } |
| 855 } |
| 856 }); |
| 857 |
| 858 test('runtimeType', () { |
| 859 var nodes1 = makeElementList(); |
| 860 var nodes2 = makeElementList(); |
| 861 var type1 = nodes1.runtimeType; |
| 862 var type2 = nodes2.runtimeType; |
| 863 expect(type1 == type2, true); |
| 864 String name = '$type1'; |
| 865 if (name.length > 3) { |
| 866 expect(name.contains('ElementList'), true); |
| 867 } |
| 868 }); |
| 869 |
| 870 test('first', () { |
| 871 var nodes = makeElementList(); |
| 872 expect(nodes.first, isBRElement); |
| 873 }); |
| 874 |
| 875 test('last', () { |
| 876 var nodes = makeElementList(); |
| 877 expect(nodes.last, isBRElement); |
| 878 }); |
| 879 |
| 880 test('where', () { |
| 881 var filtered = makeElementList().where((n) => n is BRElement).toList(); |
| 882 expect(filtered.length, 3); |
| 883 expect(filtered[0], isBRElement); |
| 884 }); |
| 885 |
| 886 test('sublist', () { |
| 887 var range = makeElementList().sublist(1, 3); |
| 888 expect(range.length, 2); |
| 889 expect(range[0], isBRElement); |
| 890 expect(range[1], isBRElement); |
| 891 }); |
| 892 |
| 893 }); |
| 823 } | 894 } |
| OLD | NEW |