Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: tests/html/node_test.dart

Issue 12374060: Adding Node.insertAllBefore (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 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:html'; 8 import 'dart:html';
9 import 'dart:svg' as svg; 9 import 'dart:svg' as svg;
10 10
11 Node makeNode() => new Element.tag('div'); 11 Node makeNode() => new Element.tag('div');
12 Node makeNodeWithChildren() => 12 Node makeNodeWithChildren() =>
13 new Element.html("<div>Foo<br/><!--baz--></div>"); 13 new Element.html("<div>Foo<br/><!--baz--></div>");
14 14
15 main() { 15 main() {
16 useHtmlIndividualConfiguration(); 16 useHtmlIndividualConfiguration();
17 17
18 var isText = predicate((x) => x is Text, 'is a Text'); 18 var isText = predicate((x) => x is Text, 'is a Text');
19 var isComment = predicate((x) => x is Comment, 'is a Comment'); 19 var isComment = predicate((x) => x is Comment, 'is a Comment');
20 var isBRElement = predicate((x) => x is BRElement, 'is a BRElement'); 20 var isBRElement = predicate((x) => x is BRElement, 'is a BRElement');
21 var isHRElement = predicate((x) => x is HRElement, 'is a HRElement'); 21 var isHRElement = predicate((x) => x is HRElement, 'is a HRElement');
22 var isNodeList = predicate((x) => x is List<Node>, 'is a List<Node>'); 22 var isNodeList = predicate((x) => x is List<Node>, 'is a List<Node>');
23 var isImageElement = 23 var isImageElement =
24 predicate((x) => x is ImageElement, 'is an ImageElement'); 24 predicate((x) => x is ImageElement, 'is an ImageElement');
25 var isInputElement = 25 var isInputElement =
26 predicate((x) => x is InputElement, 'is an InputElement'); 26 predicate((x) => x is InputElement, 'is an InputElement');
27 27
28 test('replaceWith', () { 28 group('functional', () {
29 final node = makeNodeWithChildren(); 29 test('replaceWith', () {
30 final subnode = node.nodes[1]; 30 final node = makeNodeWithChildren();
31 final out = subnode.replaceWith(new Text('Bar')); 31 final subnode = node.nodes[1];
32 expect(out, equals(subnode), reason: '#replaceWith should be chainable'); 32 final out = subnode.replaceWith(new Text('Bar'));
33 expect(node.nodes.length, 3); 33 expect(out, equals(subnode), reason: '#replaceWith should be chainable');
34 expect(node.nodes[0], isText); 34 expect(node.nodes.length, 3);
35 expect(node.nodes[0].text, 'Foo'); 35 expect(node.nodes[0], isText);
36 expect(node.nodes[1], isText); 36 expect(node.nodes[0].text, 'Foo');
37 expect(node.nodes[1].text, 'Bar'); 37 expect(node.nodes[1], isText);
38 expect(node.nodes[2], isComment); 38 expect(node.nodes[1].text, 'Bar');
39 }); 39 expect(node.nodes[2], isComment);
40 });
40 41
41 test('remove', () { 42 test('remove', () {
42 final node = makeNodeWithChildren(); 43 final node = makeNodeWithChildren();
43 final subnode = node.nodes[1]; 44 final subnode = node.nodes[1];
44 subnode.remove(); 45 subnode.remove();
45 expect(node.nodes.length, 2); 46 expect(node.nodes.length, 2);
46 expect(node.nodes[0], isText); 47 expect(node.nodes[0], isText);
47 expect(node.nodes[1], isComment); 48 expect(node.nodes[1], isComment);
48 }); 49 });
49 50
50 test('contains', () { 51 test('contains', () {
51 final Node node = new Element.html("<div>Foo<span>Bar</span></div>"); 52 final Node node = new Element.html("<div>Foo<span>Bar</span></div>");
52 expect(node.contains(node.nodes.first), isTrue); 53 expect(node.contains(node.nodes.first), isTrue);
53 expect(node.contains(node.nodes[1].nodes.first), isTrue); 54 expect(node.contains(node.nodes[1].nodes.first), isTrue);
54 expect(node.contains(new Text('Foo')), isFalse); 55 expect(node.contains(new Text('Foo')), isFalse);
56 });
57
58 test('insertAllBefore', () {
59 var node = makeNodeWithChildren();
60 var b = new DivElement();
61 b.nodes.addAll([
62 new HRElement(),
63 new ImageElement(),
64 new InputElement()
65 ]);
66 node.insertAllBefore(b.nodes, node.nodes[1]);
67 expect(node.nodes[0], isText);
68 expect(node.nodes[1], isHRElement);
69 expect(node.nodes[2], isImageElement);
70 expect(node.nodes[3], isInputElement);
71 expect(node.nodes[4], isBRElement);
72 expect(node.nodes[5], isComment);
73
74 var nodes = [
75 new HRElement(),
76 new ImageElement(),
77 new InputElement()
78 ];
79 node.insertAllBefore(nodes, node.nodes[5]);
80
81 expect(node.nodes[0], isText);
82 expect(node.nodes[1], isHRElement);
83 expect(node.nodes[2], isImageElement);
84 expect(node.nodes[3], isInputElement);
85 expect(node.nodes[4], isBRElement);
86 expect(node.nodes[5], isHRElement);
87 expect(node.nodes[6], isImageElement);
88 expect(node.nodes[7], isInputElement);
89 expect(node.nodes[8], isComment);
90 });
55 }); 91 });
56 92
57 group('nodes', () { 93 group('nodes', () {
58 test('is a NodeList', () { 94 test('is a NodeList', () {
59 expect(makeNodeWithChildren().nodes, isNodeList); 95 expect(makeNodeWithChildren().nodes, isNodeList);
60 }); 96 });
61 97
62 test('first', () { 98 test('first', () {
63 var node = makeNodeWithChildren(); 99 var node = makeNodeWithChildren();
64 expect(node.nodes.first, isText); 100 expect(node.nodes.first, isText);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 }); 251 });
216 252
217 test('getRange', () { 253 test('getRange', () {
218 var range = makeNodeList().getRange(1, 2); 254 var range = makeNodeList().getRange(1, 2);
219 expect(range, isNodeList); 255 expect(range, isNodeList);
220 expect(range[0], isBRElement); 256 expect(range[0], isBRElement);
221 expect(range[1], isComment); 257 expect(range[1], isComment);
222 }); 258 });
223 }); 259 });
224 } 260 }
OLDNEW
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tools/dom/templates/html/impl/impl_Node.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698