OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file |
| 4 |
| 5 #library('NodeListTest'); |
| 6 #import('../../lib/unittest/unittest.dart'); |
| 7 #import('../../lib/unittest/html_config.dart'); |
| 8 #import('dart:html'); |
| 9 |
| 10 main() { |
| 11 useHtmlConfiguration(); |
| 12 |
| 13 var div = new DivElement(); |
| 14 div.id = 'test'; |
| 15 document.body.nodes.add(div); |
| 16 |
| 17 div.nodes.addAll([ |
| 18 new DivElement(), |
| 19 new CanvasElement(), |
| 20 new DivElement(), |
| 21 new Text('Hello'), |
| 22 new DivElement(), |
| 23 new Text('World'), |
| 24 new CanvasElement()]); |
| 25 |
| 26 test('queryAll', () { |
| 27 List<Node> all = queryAll('*'); |
| 28 for (var e in all) { |
| 29 expect(e is Element, isTrue); |
| 30 } |
| 31 }); |
| 32 |
| 33 test('document.queryAll', () { |
| 34 List<Element> all1 = queryAll('*'); |
| 35 List<Element> all2 = document.queryAll('*'); |
| 36 expect(all1.length, equals(all2.length)); |
| 37 for (var i = 0; i < all1.length; ++i) { |
| 38 expect(all1[i], equals(all2[i])); |
| 39 } |
| 40 }); |
| 41 |
| 42 test('queryAll-canvas', () { |
| 43 List<CanvasElement> all = queryAll('canvas'); |
| 44 for (var e in all) { |
| 45 expect(e is CanvasElement, isTrue); |
| 46 } |
| 47 expect(all.length, equals(2)); |
| 48 }); |
| 49 |
| 50 test('queryAll-filter', () { |
| 51 List<Element> all = queryAll('*'); |
| 52 List<CanvasElement> canvases = all.filter((e) => e is CanvasElement); |
| 53 for (var e in canvases) { |
| 54 expect(e is CanvasElement, isTrue); |
| 55 } |
| 56 expect(canvases.length, equals(2)); |
| 57 }); |
| 58 |
| 59 test('node.queryAll', () { |
| 60 List<Element> list = div.queryAll('*'); |
| 61 expect(list.length, equals(5)); |
| 62 expect(list[0] is DivElement, isTrue); |
| 63 expect(list[1] is CanvasElement, isTrue); |
| 64 expect(list[2] is DivElement, isTrue); |
| 65 expect(list[3] is DivElement, isTrue); |
| 66 expect(list[4] is CanvasElement, isTrue); |
| 67 }); |
| 68 |
| 69 test('immutable', () { |
| 70 List<Element> list = div.queryAll('*'); |
| 71 int len = list.length; |
| 72 expect(() { list.add(new DivElement()); }, throwsException); |
| 73 expect(list.length, equals(len)); |
| 74 }); |
| 75 } |
OLD | NEW |