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 NodeTest; | 5 library NodeTest; |
| 6 |
6 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
7 import 'package:unittest/html_individual_config.dart'; | 8 import 'package:unittest/html_individual_config.dart'; |
8 import 'dart:html'; | 9 import 'dart:html'; |
9 import 'dart:svg' as svg; | 10 import 'dart:svg' as svg; |
10 | 11 |
11 Node makeNode() => new Element.tag('div'); | 12 Node makeNode() => new Element.tag('div'); |
12 Node makeNodeWithChildren() => | 13 Node makeNodeWithChildren() => |
13 new Element.html("<div>Foo<br/><!--baz--></div>"); | 14 new Element.html("<div>Foo<br/><!--baz--></div>"); |
14 | 15 |
15 void testUnsupported(String name, void f()) { | 16 void testUnsupported(String name, void f()) { |
16 test(name, () { | 17 test(name, () { |
17 expect(f, throwsUnsupportedError); | 18 expect(f, throwsUnsupportedError); |
18 }); | 19 }); |
19 } | 20 } |
20 | 21 |
21 main() { | 22 main() { |
22 useHtmlIndividualConfiguration(); | 23 useHtmlIndividualConfiguration(); |
23 | 24 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 new Element.html("<div>Foo<span><div>Bar<div></span></div>"); | 75 new Element.html("<div>Foo<span><div>Bar<div></span></div>"); |
75 // IE10 returns false for contains of nodes. | 76 // IE10 returns false for contains of nodes. |
76 //expect(node.contains(node.nodes.first), isTrue); | 77 //expect(node.contains(node.nodes.first), isTrue); |
77 expect(node.contains(node.nodes[1].nodes.first), isTrue); | 78 expect(node.contains(node.nodes[1].nodes.first), isTrue); |
78 expect(node.contains(new Text('Foo')), isFalse); | 79 expect(node.contains(new Text('Foo')), isFalse); |
79 }); | 80 }); |
80 | 81 |
81 test('insertAllBefore', () { | 82 test('insertAllBefore', () { |
82 var node = makeNodeWithChildren(); | 83 var node = makeNodeWithChildren(); |
83 var b = new DivElement(); | 84 var b = new DivElement(); |
84 b.nodes.addAll([ | 85 b.nodes.addAll([new HRElement(), new ImageElement(), new InputElement()]); |
85 new HRElement(), | |
86 new ImageElement(), | |
87 new InputElement() | |
88 ]); | |
89 node.insertAllBefore(b.nodes, node.nodes[1]); | 86 node.insertAllBefore(b.nodes, node.nodes[1]); |
90 expect(node.nodes[0], isText); | 87 expect(node.nodes[0], isText); |
91 expect(node.nodes[1], isHRElement); | 88 expect(node.nodes[1], isHRElement); |
92 expect(node.nodes[2], isImageElement); | 89 expect(node.nodes[2], isImageElement); |
93 expect(node.nodes[3], isInputElement); | 90 expect(node.nodes[3], isInputElement); |
94 expect(node.nodes[4], isBRElement); | 91 expect(node.nodes[4], isBRElement); |
95 expect(node.nodes[5], isComment); | 92 expect(node.nodes[5], isComment); |
96 | 93 |
97 var nodes = [ | 94 var nodes = [new HRElement(), new ImageElement(), new InputElement()]; |
98 new HRElement(), | |
99 new ImageElement(), | |
100 new InputElement() | |
101 ]; | |
102 node.insertAllBefore(nodes, node.nodes[5]); | 95 node.insertAllBefore(nodes, node.nodes[5]); |
103 | 96 |
104 expect(node.nodes[0], isText); | 97 expect(node.nodes[0], isText); |
105 expect(node.nodes[1], isHRElement); | 98 expect(node.nodes[1], isHRElement); |
106 expect(node.nodes[2], isImageElement); | 99 expect(node.nodes[2], isImageElement); |
107 expect(node.nodes[3], isInputElement); | 100 expect(node.nodes[3], isInputElement); |
108 expect(node.nodes[4], isBRElement); | 101 expect(node.nodes[4], isBRElement); |
109 expect(node.nodes[5], isHRElement); | 102 expect(node.nodes[5], isHRElement); |
110 expect(node.nodes[6], isImageElement); | 103 expect(node.nodes[6], isImageElement); |
111 expect(node.nodes[7], isInputElement); | 104 expect(node.nodes[7], isInputElement); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 }); | 273 }); |
281 | 274 |
282 test('sublist', () { | 275 test('sublist', () { |
283 var node = makeNodeWithChildren(); | 276 var node = makeNodeWithChildren(); |
284 expect(node.nodes.sublist(1, 3), isNodeList); | 277 expect(node.nodes.sublist(1, 3), isNodeList); |
285 }); | 278 }); |
286 | 279 |
287 test('insertAll', () { | 280 test('insertAll', () { |
288 var node = makeNodeWithChildren(); | 281 var node = makeNodeWithChildren(); |
289 var b = new DivElement(); | 282 var b = new DivElement(); |
290 b.nodes.addAll([ | 283 b.nodes.addAll([new HRElement(), new ImageElement(), new InputElement()]); |
291 new HRElement(), | |
292 new ImageElement(), | |
293 new InputElement() | |
294 ]); | |
295 node.nodes.insertAll(1, b.nodes); | 284 node.nodes.insertAll(1, b.nodes); |
296 expect(node.nodes[0], isText); | 285 expect(node.nodes[0], isText); |
297 expect(node.nodes[1], isHRElement); | 286 expect(node.nodes[1], isHRElement); |
298 expect(node.nodes[2], isImageElement); | 287 expect(node.nodes[2], isImageElement); |
299 expect(node.nodes[3], isInputElement); | 288 expect(node.nodes[3], isInputElement); |
300 expect(node.nodes[4], isBRElement); | 289 expect(node.nodes[4], isBRElement); |
301 expect(node.nodes[5], isComment); | 290 expect(node.nodes[5], isComment); |
302 | 291 |
303 var nodes = [ | 292 var nodes = [new HRElement(), new ImageElement(), new InputElement()]; |
304 new HRElement(), | |
305 new ImageElement(), | |
306 new InputElement() | |
307 ]; | |
308 node.nodes.insertAll(5, nodes); | 293 node.nodes.insertAll(5, nodes); |
309 | 294 |
310 expect(node.nodes[0], isText); | 295 expect(node.nodes[0], isText); |
311 expect(node.nodes[1], isHRElement); | 296 expect(node.nodes[1], isHRElement); |
312 expect(node.nodes[2], isImageElement); | 297 expect(node.nodes[2], isImageElement); |
313 expect(node.nodes[3], isInputElement); | 298 expect(node.nodes[3], isInputElement); |
314 expect(node.nodes[4], isBRElement); | 299 expect(node.nodes[4], isBRElement); |
315 expect(node.nodes[5], isHRElement); | 300 expect(node.nodes[5], isHRElement); |
316 expect(node.nodes[6], isImageElement); | 301 expect(node.nodes[6], isImageElement); |
317 expect(node.nodes[7], isInputElement); | 302 expect(node.nodes[7], isInputElement); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 }); | 336 }); |
352 | 337 |
353 test('TreeWalker', () { | 338 test('TreeWalker', () { |
354 var root = makeNodeWithChildren(); | 339 var root = makeNodeWithChildren(); |
355 var treeWalker = new TreeWalker(root, NodeFilter.SHOW_COMMENT); | 340 var treeWalker = new TreeWalker(root, NodeFilter.SHOW_COMMENT); |
356 expect(treeWalker.nextNode(), isComment); | 341 expect(treeWalker.nextNode(), isComment); |
357 expect(treeWalker.nextNode(), isNull); | 342 expect(treeWalker.nextNode(), isNull); |
358 }); | 343 }); |
359 }); | 344 }); |
360 } | 345 } |
OLD | NEW |