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

Side by Side Diff: pkg/dev_compiler/test/codegen/lib/html/custom_elements_test.dart

Issue 2413073002: Start cleaning up the HTML tests. (Closed)
Patch Set: Unfork expect.dart. Created 4 years, 2 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 custom_elements_test; 5 library custom_elements_test;
6 import 'dart:async'; 6 import 'dart:async';
7 import 'dart:html'; 7 import 'dart:html';
8 import 'package:unittest/html_individual_config.dart'; 8 import 'package:unittest/html_individual_config.dart';
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 import 'utils.dart'; 10 import 'utils.dart';
(...skipping 30 matching lines...) Expand all
41 main() { 41 main() {
42 useHtmlIndividualConfiguration(); 42 useHtmlIndividualConfiguration();
43 43
44 setUp(() => customElementsReady); 44 setUp(() => customElementsReady);
45 45
46 group('register', () { 46 group('register', () {
47 test('register', () { 47 test('register', () {
48 var tag = nextTag; 48 var tag = nextTag;
49 document.registerElement(tag, CustomType); 49 document.registerElement(tag, CustomType);
50 50
51 var element = new Element.tag(tag); 51 var element = new Element.tag(tag) as CustomType;
52 expect(element, isNotNull); 52 expect(element, isNotNull);
53 expect(element is CustomType, isTrue); 53 expect(element is CustomType, isTrue);
54 expect(element.createdCalled, isTrue); 54 expect(element.createdCalled, isTrue);
55 }); 55 });
56 56
57 test('register twice', () { 57 test('register twice', () {
58 var tag = nextTag; 58 var tag = nextTag;
59 document.registerElement(tag, CustomType); 59 document.registerElement(tag, CustomType);
60 expect(() { 60 expect(() {
61 document.registerElement(tag, CustomType); 61 document.registerElement(tag, CustomType);
62 }, throws, reason: 'Cannot register a tag more than once.'); 62 }, throws, reason: 'Cannot register a tag more than once.');
63 63
64 var newTag = nextTag; 64 var newTag = nextTag;
65 document.registerElement(newTag, CustomType); 65 document.registerElement(newTag, CustomType);
66 66
67 var element = new Element.tag(newTag); 67 var element = new Element.tag(newTag) as CustomType;
68 expect(element, isNotNull); 68 expect(element, isNotNull);
69 expect(element is CustomType, isTrue); 69 expect(element is CustomType, isTrue);
70 }); 70 });
71 71
72 test('register null', () { 72 test('register null', () {
73 expect(() { 73 expect(() {
74 document.registerElement(nextTag, null); 74 document.registerElement(nextTag, null);
75 }, throws, reason: 'Cannot register a null type.'); 75 }, throws, reason: 'Cannot register a null type.');
76 }); 76 });
77 77
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 131
132 group('innerHtml', () { 132 group('innerHtml', () {
133 test('query', () { 133 test('query', () {
134 var tag = nextTag; 134 var tag = nextTag;
135 document.registerElement(tag, CustomType); 135 document.registerElement(tag, CustomType);
136 var element = new DivElement(); 136 var element = new DivElement();
137 element.setInnerHtml('<$tag></$tag>', 137 element.setInnerHtml('<$tag></$tag>',
138 treeSanitizer: new NullTreeSanitizer()); 138 treeSanitizer: new NullTreeSanitizer());
139 upgradeCustomElements(element); 139 upgradeCustomElements(element);
140 document.body.nodes.add(element); 140 document.body.nodes.add(element);
141 var queried = query(tag); 141 var queried = query(tag) as CustomType;
142 142
143 expect(queried, isNotNull); 143 expect(queried, isNotNull);
144 expect(queried is CustomType, isTrue); 144 expect(queried is CustomType, isTrue);
145 expect(queried.createdCalled, isTrue); 145 expect(queried.createdCalled, isTrue);
146 }); 146 });
147 147
148 test('query id', () { 148 test('query id', () {
149 var tag = nextTag; 149 var tag = nextTag;
150 document.registerElement(tag, CustomType); 150 document.registerElement(tag, CustomType);
151 var element = new DivElement(); 151 var element = new DivElement();
152 element.setInnerHtml('<$tag id="someid"></$tag>', 152 element.setInnerHtml('<$tag id="someid"></$tag>',
153 treeSanitizer: new NullTreeSanitizer()); 153 treeSanitizer: new NullTreeSanitizer());
154 upgradeCustomElements(element); 154 upgradeCustomElements(element);
155 document.body.nodes.add(element); 155 document.body.nodes.add(element);
156 var queried = query('#someid'); 156 var queried = query('#someid') as CustomType;
157 157
158 expect(queried, isNotNull); 158 expect(queried, isNotNull);
159 expect(queried is CustomType, isTrue); 159 expect(queried is CustomType, isTrue);
160 expect(queried.id, "someid"); 160 expect(queried.id, "someid");
161 }); 161 });
162 }); 162 });
163 163
164 group('lifecycle', () { 164 group('lifecycle', () {
165 test('created', () { 165 test('created', () {
166 int oldCount = customCreatedCount; 166 int oldCount = customCreatedCount;
167 var tag = nextTag; 167 var tag = nextTag;
168 document.registerElement(tag, CustomType); 168 document.registerElement(tag, CustomType);
169 var element = new DivElement(); 169 var element = new DivElement();
170 element.setInnerHtml('<$tag></$tag>', 170 element.setInnerHtml('<$tag></$tag>',
171 treeSanitizer: new NullTreeSanitizer()); 171 treeSanitizer: new NullTreeSanitizer());
172 upgradeCustomElements(element); 172 upgradeCustomElements(element);
173 document.body.nodes.add(element); 173 document.body.nodes.add(element);
174 expect(customCreatedCount, oldCount + 1); 174 expect(customCreatedCount, oldCount + 1);
175 }); 175 });
176 }); 176 });
177 177
178 group('mixins', () { 178 group('mixins', () {
179 test('can invoke mixin methods', () { 179 test('can invoke mixin methods', () {
180 var tag = nextTag; 180 var tag = nextTag;
181 document.registerElement(tag, CustomType); 181 document.registerElement(tag, CustomType);
182 182
183 var element = new Element.tag(tag); 183 var element = new Element.tag(tag) as CustomType;
184 element.invokeMixinMethod(); 184 element.invokeMixinMethod();
185 expect(element.mixinMethodCalled, isTrue); 185 expect(element.mixinMethodCalled, isTrue);
186 }); 186 });
187 }); 187 });
188 } 188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698