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

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

Issue 11413071: Deprecating Element.elements for Element.children. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Review feedback. Created 8 years, 1 month 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
« no previous file with comments | « tests/html/documentfragment_test.dart ('k') | tests/html/element_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 ElementAddTest; 5 library ElementAddTest;
6 import '../../pkg/unittest/lib/unittest.dart'; 6 import '../../pkg/unittest/lib/unittest.dart';
7 import '../../pkg/unittest/lib/html_config.dart'; 7 import '../../pkg/unittest/lib/html_config.dart';
8 import 'dart:html'; 8 import 'dart:html';
9 part 'util.dart'; 9 part 'util.dart';
10 10
11 main() { 11 main() {
12 useHtmlConfiguration(); 12 useHtmlConfiguration();
13 13
14 var isSpanElement = predicate((x) => x is SpanElement, 'is a SpanElemt'); 14 var isSpanElement = predicate((x) => x is SpanElement, 'is a SpanElemt');
15 var isDivElement = predicate((x) => x is DivElement, 'is a DivElement'); 15 var isDivElement = predicate((x) => x is DivElement, 'is a DivElement');
16 var isText = predicate((x) => x is Text, 'is a Text'); 16 var isText = predicate((x) => x is Text, 'is a Text');
17 17
18 void expectNoSuchMethod(void fn()) => 18 void expectNoSuchMethod(void fn()) =>
19 expect(fn, throwsNoSuchMethodError); 19 expect(fn, throwsNoSuchMethodError);
20 20
21 group('addHtml', () { 21 group('addHtml', () {
22 test('htmlelement', () { 22 test('htmlelement', () {
23 var el = new DivElement(); 23 var el = new DivElement();
24 el.addHtml('<span></span>'); 24 el.addHtml('<span></span>');
25 expect(el.elements.length, equals(1)); 25 expect(el.children.length, equals(1));
26 var span = el.elements[0]; 26 var span = el.children[0];
27 expect(span, isSpanElement); 27 expect(span, isSpanElement);
28 28
29 el.addHtml('<div></div>'); 29 el.addHtml('<div></div>');
30 expect(el.elements.length, equals(2)); 30 expect(el.children.length, equals(2));
31 // Validate that the first item is still first. 31 // Validate that the first item is still first.
32 expect(el.elements[0], equals(span)); 32 expect(el.children[0], equals(span));
33 expect(el.elements[1], isDivElement); 33 expect(el.children[1], isDivElement);
34 }); 34 });
35 35
36 test('documentFragment', () { 36 test('documentFragment', () {
37 var fragment = new DocumentFragment(); 37 var fragment = new DocumentFragment();
38 fragment.addHtml('<span>something</span>'); 38 fragment.addHtml('<span>something</span>');
39 expect(fragment.elements.length, equals(1)); 39 expect(fragment.children.length, equals(1));
40 expect(fragment.elements[0], isSpanElement); 40 expect(fragment.children[0], isSpanElement);
41 }); 41 });
42 }); 42 });
43 43
44 group('addText', () { 44 group('addText', () {
45 test('htmlelement', () { 45 test('htmlelement', () {
46 var el = new DivElement(); 46 var el = new DivElement();
47 el.addText('foo'); 47 el.addText('foo');
48 // No elements were created. 48 // No children were created.
49 expect(el.elements.length, equals(0)); 49 expect(el.children.length, equals(0));
50 // One text node was added. 50 // One text node was added.
51 expect(el.nodes.length, equals(1)); 51 expect(el.nodes.length, equals(1));
52 }); 52 });
53 53
54 test('documentFragment', () { 54 test('documentFragment', () {
55 var fragment = new DocumentFragment(); 55 var fragment = new DocumentFragment();
56 fragment.addText('foo'); 56 fragment.addText('foo');
57 // No elements were created. 57 // No children were created.
58 expect(fragment.elements.length, equals(0)); 58 expect(fragment.children.length, equals(0));
59 // One text node was added. 59 // One text node was added.
60 expect(fragment.nodes.length, equals(1)); 60 expect(fragment.nodes.length, equals(1));
61 }); 61 });
62 }); 62 });
63 63
64 group('insertAdjacentElement', () { 64 group('insertAdjacentElement', () {
65 test('beforebegin', () { 65 test('beforebegin', () {
66 var parent = new DivElement(); 66 var parent = new DivElement();
67 var child = new DivElement(); 67 var child = new DivElement();
68 var newChild = new SpanElement(); 68 var newChild = new SpanElement();
69 parent.elements.add(child); 69 parent.children.add(child);
70 70
71 child.insertAdjacentElement('beforebegin', newChild); 71 child.insertAdjacentElement('beforebegin', newChild);
72 72
73 expect(parent.elements.length, 2); 73 expect(parent.children.length, 2);
74 expect(parent.elements[0], isSpanElement); 74 expect(parent.children[0], isSpanElement);
75 }); 75 });
76 76
77 test('afterend', () { 77 test('afterend', () {
78 var parent = new DivElement(); 78 var parent = new DivElement();
79 var child = new DivElement(); 79 var child = new DivElement();
80 var newChild = new SpanElement(); 80 var newChild = new SpanElement();
81 parent.elements.add(child); 81 parent.children.add(child);
82 82
83 child.insertAdjacentElement('afterend', newChild); 83 child.insertAdjacentElement('afterend', newChild);
84 84
85 expect(parent.elements.length, 2); 85 expect(parent.children.length, 2);
86 expect(parent.elements[1], isSpanElement); 86 expect(parent.children[1], isSpanElement);
87 }); 87 });
88 88
89 test('afterbegin', () { 89 test('afterbegin', () {
90 var parent = new DivElement(); 90 var parent = new DivElement();
91 var child = new DivElement(); 91 var child = new DivElement();
92 var newChild = new SpanElement(); 92 var newChild = new SpanElement();
93 parent.elements.add(child); 93 parent.children.add(child);
94 94
95 parent.insertAdjacentElement('afterbegin', newChild); 95 parent.insertAdjacentElement('afterbegin', newChild);
96 96
97 expect(parent.elements.length, 2); 97 expect(parent.children.length, 2);
98 expect(parent.elements[0], isSpanElement); 98 expect(parent.children[0], isSpanElement);
99 }); 99 });
100 100
101 test('beforeend', () { 101 test('beforeend', () {
102 var parent = new DivElement(); 102 var parent = new DivElement();
103 var child = new DivElement(); 103 var child = new DivElement();
104 var newChild = new SpanElement(); 104 var newChild = new SpanElement();
105 parent.elements.add(child); 105 parent.children.add(child);
106 106
107 parent.insertAdjacentElement('beforeend', newChild); 107 parent.insertAdjacentElement('beforeend', newChild);
108 108
109 expect(parent.elements.length, 2); 109 expect(parent.children.length, 2);
110 expect(parent.elements[1], isSpanElement); 110 expect(parent.children[1], isSpanElement);
111 }); 111 });
112 }); 112 });
113 113
114 group('insertAdjacentHTML', () { 114 group('insertAdjacentHTML', () {
115 test('beforebegin', () { 115 test('beforebegin', () {
116 var parent = new DivElement(); 116 var parent = new DivElement();
117 var child = new DivElement(); 117 var child = new DivElement();
118 parent.elements.add(child); 118 parent.children.add(child);
119 119
120 child.insertAdjacentHTML('beforebegin', '<span></span>'); 120 child.insertAdjacentHTML('beforebegin', '<span></span>');
121 121
122 expect(parent.elements.length, 2); 122 expect(parent.children.length, 2);
123 expect(parent.elements[0], isSpanElement); 123 expect(parent.children[0], isSpanElement);
124 }); 124 });
125 125
126 test('afterend', () { 126 test('afterend', () {
127 var parent = new DivElement(); 127 var parent = new DivElement();
128 var child = new DivElement(); 128 var child = new DivElement();
129 parent.elements.add(child); 129 parent.children.add(child);
130 130
131 child.insertAdjacentHTML('afterend', '<span></span>'); 131 child.insertAdjacentHTML('afterend', '<span></span>');
132 132
133 expect(parent.elements.length, 2); 133 expect(parent.children.length, 2);
134 expect(parent.elements[1], isSpanElement); 134 expect(parent.children[1], isSpanElement);
135 }); 135 });
136 136
137 test('afterbegin', () { 137 test('afterbegin', () {
138 var parent = new DivElement(); 138 var parent = new DivElement();
139 var child = new DivElement(); 139 var child = new DivElement();
140 parent.elements.add(child); 140 parent.children.add(child);
141 141
142 parent.insertAdjacentHTML('afterbegin', '<span></span>'); 142 parent.insertAdjacentHTML('afterbegin', '<span></span>');
143 143
144 expect(parent.elements.length, 2); 144 expect(parent.children.length, 2);
145 expect(parent.elements[0], isSpanElement); 145 expect(parent.children[0], isSpanElement);
146 }); 146 });
147 147
148 test('beforeend', () { 148 test('beforeend', () {
149 var parent = new DivElement(); 149 var parent = new DivElement();
150 var child = new DivElement(); 150 var child = new DivElement();
151 parent.elements.add(child); 151 parent.children.add(child);
152 152
153 parent.insertAdjacentHTML('beforeend', '<span></span>'); 153 parent.insertAdjacentHTML('beforeend', '<span></span>');
154 154
155 expect(parent.elements.length, 2); 155 expect(parent.children.length, 2);
156 expect(parent.elements[1], isSpanElement); 156 expect(parent.children[1], isSpanElement);
157 }); 157 });
158 }); 158 });
159 159
160 group('insertAdjacentText', () { 160 group('insertAdjacentText', () {
161 test('beforebegin', () { 161 test('beforebegin', () {
162 var parent = new DivElement(); 162 var parent = new DivElement();
163 var child = new DivElement(); 163 var child = new DivElement();
164 parent.elements.add(child); 164 parent.children.add(child);
165 165
166 child.insertAdjacentText('beforebegin', 'test'); 166 child.insertAdjacentText('beforebegin', 'test');
167 167
168 expect(parent.nodes.length, 2); 168 expect(parent.nodes.length, 2);
169 expect(parent.nodes[0], isText); 169 expect(parent.nodes[0], isText);
170 }); 170 });
171 171
172 test('afterend', () { 172 test('afterend', () {
173 var parent = new DivElement(); 173 var parent = new DivElement();
174 var child = new DivElement(); 174 var child = new DivElement();
175 parent.elements.add(child); 175 parent.children.add(child);
176 176
177 child.insertAdjacentText('afterend', 'test'); 177 child.insertAdjacentText('afterend', 'test');
178 178
179 expect(parent.nodes.length, 2); 179 expect(parent.nodes.length, 2);
180 expect(parent.nodes[1], isText); 180 expect(parent.nodes[1], isText);
181 }); 181 });
182 182
183 test('afterbegin', () { 183 test('afterbegin', () {
184 var parent = new DivElement(); 184 var parent = new DivElement();
185 var child = new DivElement(); 185 var child = new DivElement();
186 parent.elements.add(child); 186 parent.children.add(child);
187 187
188 parent.insertAdjacentText('afterbegin', 'test'); 188 parent.insertAdjacentText('afterbegin', 'test');
189 189
190 expect(parent.nodes.length, 2); 190 expect(parent.nodes.length, 2);
191 expect(parent.nodes[0], isText); 191 expect(parent.nodes[0], isText);
192 }); 192 });
193 193
194 test('beforeend', () { 194 test('beforeend', () {
195 var parent = new DivElement(); 195 var parent = new DivElement();
196 var child = new DivElement(); 196 var child = new DivElement();
197 parent.elements.add(child); 197 parent.children.add(child);
198 198
199 parent.insertAdjacentText('beforeend', 'test'); 199 parent.insertAdjacentText('beforeend', 'test');
200 200
201 expect(parent.nodes.length, 2); 201 expect(parent.nodes.length, 2);
202 expect(parent.nodes[1], isText); 202 expect(parent.nodes[1], isText);
203 }); 203 });
204 }); 204 });
205 } 205 }
OLDNEW
« no previous file with comments | « tests/html/documentfragment_test.dart ('k') | tests/html/element_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698