OLD | NEW |
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('NodeListTest'); | 5 #library('NodeListTest'); |
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 main() { | 10 main() { |
11 useHtmlConfiguration(); | 11 useHtmlConfiguration(); |
12 | 12 |
| 13 var isElement = new isInstanceOf<Element>('Element'); |
| 14 var isCanvasElement = new isInstanceOf<CanvasElement>('CanvasElement'); |
| 15 var isDivElement = new isInstanceOf<DivElement>('DivElement'); |
| 16 |
13 var div = new DivElement(); | 17 var div = new DivElement(); |
14 div.id = 'test'; | 18 div.id = 'test'; |
15 document.body.nodes.add(div); | 19 document.body.nodes.add(div); |
16 | 20 |
17 div.nodes.addAll([ | 21 div.nodes.addAll([ |
18 new DivElement(), | 22 new DivElement(), |
19 new CanvasElement(), | 23 new CanvasElement(), |
20 new DivElement(), | 24 new DivElement(), |
21 new Text('Hello'), | 25 new Text('Hello'), |
22 new DivElement(), | 26 new DivElement(), |
23 new Text('World'), | 27 new Text('World'), |
24 new CanvasElement()]); | 28 new CanvasElement()]); |
25 | 29 |
26 test('queryAll', () { | 30 test('queryAll', () { |
27 List<Node> all = queryAll('*'); | 31 List<Node> all = queryAll('*'); |
28 for (var e in all) { | 32 for (var e in all) { |
29 expect(e is Element, isTrue); | 33 expect(e, isElement); |
30 } | 34 } |
31 }); | 35 }); |
32 | 36 |
33 test('document.queryAll', () { | 37 test('document.queryAll', () { |
34 List<Element> all1 = queryAll('*'); | 38 List<Element> all1 = queryAll('*'); |
35 List<Element> all2 = document.queryAll('*'); | 39 List<Element> all2 = document.queryAll('*'); |
36 expect(all1.length, equals(all2.length)); | 40 expect(all1.length, equals(all2.length)); |
37 for (var i = 0; i < all1.length; ++i) { | 41 for (var i = 0; i < all1.length; ++i) { |
38 expect(all1[i], equals(all2[i])); | 42 expect(all1[i], equals(all2[i])); |
39 } | 43 } |
40 }); | 44 }); |
41 | 45 |
42 test('queryAll-canvas', () { | 46 test('queryAll-canvas', () { |
43 List<CanvasElement> all = queryAll('canvas'); | 47 List<CanvasElement> all = queryAll('canvas'); |
44 for (var e in all) { | 48 for (var e in all) { |
45 expect(e is CanvasElement, isTrue); | 49 expect(e, isCanvasElement); |
46 } | 50 } |
47 expect(all.length, equals(2)); | 51 expect(all.length, equals(2)); |
48 }); | 52 }); |
49 | 53 |
50 test('queryAll-contains', () { | 54 test('queryAll-contains', () { |
51 List<Element> all = queryAll('*'); | 55 List<Element> all = queryAll('*'); |
52 for (var e in all) { | 56 for (var e in all) { |
53 expect(all.contains(e), isTrue); | 57 expect(all.contains(e), isTrue); |
54 } | 58 } |
55 }); | 59 }); |
56 | 60 |
57 test('queryAll-filter', () { | 61 test('queryAll-filter', () { |
58 List<Element> all = queryAll('*'); | 62 List<Element> all = queryAll('*'); |
59 List<CanvasElement> canvases = all.filter((e) => e is CanvasElement); | 63 List<CanvasElement> canvases = all.filter((e) => e is CanvasElement); |
60 for (var e in canvases) { | 64 for (var e in canvases) { |
61 expect(e is CanvasElement, isTrue); | 65 expect(e is CanvasElement, isTrue); |
62 } | 66 } |
63 expect(canvases.length, equals(2)); | 67 expect(canvases.length, equals(2)); |
64 }); | 68 }); |
65 | 69 |
66 test('node.queryAll', () { | 70 test('node.queryAll', () { |
67 List<Element> list = div.queryAll('*'); | 71 List<Element> list = div.queryAll('*'); |
68 expect(list.length, equals(5)); | 72 expect(list.length, equals(5)); |
69 expect(list[0] is DivElement, isTrue); | 73 expect(list[0], isDivElement); |
70 expect(list[1] is CanvasElement, isTrue); | 74 expect(list[1], isCanvasElement); |
71 expect(list[2] is DivElement, isTrue); | 75 expect(list[2], isDivElement); |
72 expect(list[3] is DivElement, isTrue); | 76 expect(list[3], isDivElement); |
73 expect(list[4] is CanvasElement, isTrue); | 77 expect(list[4], isCanvasElement); |
74 }); | 78 }); |
75 | 79 |
76 test('immutable', () { | 80 test('immutable', () { |
77 List<Element> list = div.queryAll('*'); | 81 List<Element> list = div.queryAll('*'); |
78 int len = list.length; | 82 int len = list.length; |
79 expect(() { list.add(new DivElement()); }, throwsUnsupportedError); | 83 expect(() { list.add(new DivElement()); }, throwsUnsupportedError); |
80 expect(list.length, equals(len)); | 84 expect(list.length, equals(len)); |
81 }); | 85 }); |
82 } | 86 } |
OLD | NEW |