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

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

Issue 11316121: Changes to make it easier to add elements. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 | « sdk/lib/html/templates/html/impl/impl_Element.darttemplate ('k') | no next file » | 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('append', () {
22 test('htmlelement', () { 22 test('htmlelement', () {
23 var el = new DivElement(); 23 var el = new DivElement();
24 el.addHtml('<span></span>'); 24 el.append(new SpanElement());
25 expect(el.children.length, equals(1)); 25 expect(el.children.length, equals(1));
26 var span = el.children[0]; 26 var span = el.children[0];
27 expect(span, isSpanElement); 27 expect(span, isSpanElement);
28 28
29 el.addHtml('<div></div>'); 29 el.append(new DivElement());
30 expect(el.children.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.children[0], equals(span)); 32 expect(el.children[0], equals(span));
33 expect(el.children[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.append(new SpanElement());
39 expect(fragment.children.length, equals(1)); 39 expect(fragment.children.length, equals(1));
40 expect(fragment.children[0], isSpanElement); 40 expect(fragment.children[0], isSpanElement);
41 }); 41 });
42 }); 42 });
43 43
44 group('addText', () { 44 group('appendHtml', () {
45 test('htmlelement', () { 45 test('htmlelement', () {
46 var el = new DivElement(); 46 var el = new DivElement();
47 el.addText('foo'); 47 el.appendHtml('<span></span>');
48 expect(el.children.length, equals(1));
49 var span = el.children[0];
50 expect(span, isSpanElement);
51
52 el.appendHtml('<div></div>');
53 expect(el.children.length, equals(2));
54 // Validate that the first item is still first.
55 expect(el.children[0], equals(span));
56 expect(el.children[1], isDivElement);
57 });
58
59 test('documentFragment', () {
60 var fragment = new DocumentFragment();
61 fragment.appendHtml('<span>something</span>');
62 expect(fragment.children.length, equals(1));
63 expect(fragment.children[0], isSpanElement);
64 });
65 });
66
67 group('appendText', () {
68 test('htmlelement', () {
69 var el = new DivElement();
70 el.appendText('foo');
48 // No children were created. 71 // No children were created.
49 expect(el.children.length, equals(0)); 72 expect(el.children.length, equals(0));
50 // One text node was added. 73 // One text node was added.
51 expect(el.nodes.length, equals(1)); 74 expect(el.nodes.length, equals(1));
52 }); 75 });
53 76
54 test('documentFragment', () { 77 test('documentFragment', () {
55 var fragment = new DocumentFragment(); 78 var fragment = new DocumentFragment();
56 fragment.addText('foo'); 79 fragment.appendText('foo');
57 // No children were created. 80 // No children were created.
58 expect(fragment.children.length, equals(0)); 81 expect(fragment.children.length, equals(0));
59 // One text node was added. 82 // One text node was added.
60 expect(fragment.nodes.length, equals(1)); 83 expect(fragment.nodes.length, equals(1));
61 }); 84 });
62 }); 85 });
63 86
64 group('insertAdjacentElement', () { 87 group('insertAdjacentElement', () {
65 test('beforebegin', () { 88 test('beforebegin', () {
66 var parent = new DivElement(); 89 var parent = new DivElement();
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 var child = new DivElement(); 219 var child = new DivElement();
197 parent.children.add(child); 220 parent.children.add(child);
198 221
199 parent.insertAdjacentText('beforeend', 'test'); 222 parent.insertAdjacentText('beforeend', 'test');
200 223
201 expect(parent.nodes.length, 2); 224 expect(parent.nodes.length, 2);
202 expect(parent.nodes[1], isText); 225 expect(parent.nodes[1], isText);
203 }); 226 });
204 }); 227 });
205 } 228 }
OLDNEW
« no previous file with comments | « sdk/lib/html/templates/html/impl/impl_Element.darttemplate ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698