OLD | NEW |
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 created_callback_test; | 5 library created_callback_test; |
6 import 'package:unittest/unittest.dart'; | 6 import 'package:unittest/unittest.dart'; |
7 import 'package:unittest/html_config.dart'; | 7 import 'package:unittest/html_config.dart'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 import 'dart:js' as js; | 9 import 'dart:js' as js; |
10 import '../utils.dart'; | 10 import '../utils.dart'; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 useHtmlConfiguration(); | 58 useHtmlConfiguration(); |
59 | 59 |
60 // Adapted from Blink's | 60 // Adapted from Blink's |
61 // fast/dom/custom/created-callback test. | 61 // fast/dom/custom/created-callback test. |
62 | 62 |
63 var registered = false; | 63 var registered = false; |
64 setUp(() { | 64 setUp(() { |
65 return customElementsReady.then((_) { | 65 return customElementsReady.then((_) { |
66 if (!registered) { | 66 if (!registered) { |
67 registered = true; | 67 registered = true; |
68 document.register(B.tag, B); | 68 document.registerElement(B.tag, B); |
69 document.register(C.tag, C); | 69 document.registerElement(C.tag, C); |
70 ErrorConstructorElement.register(); | 70 ErrorConstructorElement.registerElement(); |
71 } | 71 } |
72 }); | 72 }); |
73 }); | 73 }); |
74 | 74 |
75 test('transfer created callback', () { | 75 test('transfer created callback', () { |
76 document.register(A.tag, A); | 76 document.registerElement(A.tag, A); |
77 var x = new A(); | 77 var x = new A(); |
78 expect(A.createdInvocations, 1); | 78 expect(A.createdInvocations, 1); |
79 }); | 79 }); |
80 | 80 |
81 test('unresolved and created callback timing', () { | 81 test('unresolved and created callback timing', () { |
82 var div = new DivElement(); | 82 var div = new DivElement(); |
83 C.div = div; | 83 C.div = div; |
84 div.setInnerHtml(""" | 84 div.setInnerHtml(""" |
85 <x-c id="t"></x-c> | 85 <x-c id="t"></x-c> |
86 <x-b id="u"></x-b> | 86 <x-b id="u"></x-b> |
(...skipping 13 matching lines...) Expand all Loading... |
100 AccessWhileUpgradingElement.test); | 100 AccessWhileUpgradingElement.test); |
101 | 101 |
102 test('cannot call created constructor', () { | 102 test('cannot call created constructor', () { |
103 expect(() { | 103 expect(() { |
104 new B.created(); | 104 new B.created(); |
105 }, throws); | 105 }, throws); |
106 }); | 106 }); |
107 | 107 |
108 test('cannot register without created', () { | 108 test('cannot register without created', () { |
109 expect(() { | 109 expect(() { |
110 document.register(MissingCreatedElement.tag, MissingCreatedElement); | 110 document.registerElement(MissingCreatedElement.tag, |
| 111 MissingCreatedElement); |
111 }, throws); | 112 }, throws); |
112 }); | 113 }); |
113 | 114 |
114 test('throw on createElement does not upgrade', () { | 115 test('throw on createElement does not upgrade', () { |
115 ErrorConstructorElement.callCount = 0; | 116 ErrorConstructorElement.callCount = 0; |
116 | 117 |
117 var e; | 118 var e; |
118 expectGlobalError(() { | 119 expectGlobalError(() { |
119 e = new Element.tag(ErrorConstructorElement.tag); | 120 e = new Element.tag(ErrorConstructorElement.tag); |
120 }); | 121 }); |
(...skipping 21 matching lines...) Expand all Loading... |
142 | 143 |
143 var e = dummy.firstChild; | 144 var e = dummy.firstChild; |
144 // Accessing should not re-run the constructor. | 145 // Accessing should not re-run the constructor. |
145 expect(ErrorConstructorElement.callCount, 1); | 146 expect(ErrorConstructorElement.callCount, 1); |
146 expect(e is HtmlElement, isTrue); | 147 expect(e is HtmlElement, isTrue); |
147 expect(e is ErrorConstructorElement, isFalse); | 148 expect(e is ErrorConstructorElement, isFalse); |
148 }); | 149 }); |
149 | 150 |
150 test('cannot register created with params', () { | 151 test('cannot register created with params', () { |
151 expect(() { | 152 expect(() { |
152 document.register('x-created-with-params', CreatedWithParametersElement); | 153 document.registerElement('x-created-with-params', |
| 154 CreatedWithParametersElement); |
153 }, throws); | 155 }, throws); |
154 }); | 156 }); |
155 | 157 |
156 test('created cannot be called from nested constructor', | 158 test('created cannot be called from nested constructor', |
157 NestedCreatedConstructorElement.test); | 159 NestedCreatedConstructorElement.test); |
158 | 160 |
159 | 161 |
160 // TODO(vsm): Port additional test from upstream here: | 162 // TODO(vsm): Port additional test from upstream here: |
161 // http://src.chromium.org/viewvc/blink/trunk/LayoutTests/fast/dom/custom/crea
ted-callback.html?r1=156141&r2=156185 | 163 // http://src.chromium.org/viewvc/blink/trunk/LayoutTests/fast/dom/custom/crea
ted-callback.html?r1=156141&r2=156185 |
162 } | 164 } |
163 | 165 |
164 | 166 |
165 class NestedElement extends HtmlElement { | 167 class NestedElement extends HtmlElement { |
166 static final tag = 'x-nested'; | 168 static final tag = 'x-nested'; |
167 | 169 |
168 final Element b = new B(); | 170 final Element b = new B(); |
169 | 171 |
170 factory NestedElement() => new Element.tag(tag); | 172 factory NestedElement() => new Element.tag(tag); |
171 NestedElement.created() : super.created(); | 173 NestedElement.created() : super.created(); |
172 | 174 |
173 static void register() { | 175 static void register() { |
174 document.register(tag, NestedElement); | 176 document.registerElement(tag, NestedElement); |
175 } | 177 } |
176 | 178 |
177 static void test() { | 179 static void test() { |
178 register(); | 180 register(); |
179 | 181 |
180 var e = new NestedElement(); | 182 var e = new NestedElement(); |
181 expect(e.b, isNotNull); | 183 expect(e.b, isNotNull); |
182 expect(e.b is B, isTrue); | 184 expect(e.b is B, isTrue); |
183 expect(e is NestedElement, isTrue); | 185 expect(e is NestedElement, isTrue); |
184 } | 186 } |
(...skipping 11 matching lines...) Expand all Loading... |
196 factory AccessWhileUpgradingElement() => new Element.tag(tag); | 198 factory AccessWhileUpgradingElement() => new Element.tag(tag); |
197 AccessWhileUpgradingElement.created() : super.created(); | 199 AccessWhileUpgradingElement.created() : super.created(); |
198 | 200 |
199 static runInitializerCode() { | 201 static runInitializerCode() { |
200 upgradingContextChild = upgradingContext.firstChild; | 202 upgradingContextChild = upgradingContext.firstChild; |
201 | 203 |
202 return 666; | 204 return 666; |
203 } | 205 } |
204 | 206 |
205 static void register() { | 207 static void register() { |
206 document.register(tag, AccessWhileUpgradingElement); | 208 document.registerElement(tag, AccessWhileUpgradingElement); |
207 } | 209 } |
208 | 210 |
209 static void test() { | 211 static void test() { |
210 register(); | 212 register(); |
211 | 213 |
212 upgradingContext = new DivElement(); | 214 upgradingContext = new DivElement(); |
213 upgradingContext.setInnerHtml('<$tag></$tag>', | 215 upgradingContext.setInnerHtml('<$tag></$tag>', |
214 treeSanitizer: new NullTreeSanitizer()); | 216 treeSanitizer: new NullTreeSanitizer()); |
215 var child = upgradingContext.firstChild; | 217 var child = upgradingContext.firstChild; |
216 | 218 |
(...skipping 15 matching lines...) Expand all Loading... |
232 static int callCount = 0; | 234 static int callCount = 0; |
233 | 235 |
234 factory ErrorConstructorElement() => new Element.tag(tag); | 236 factory ErrorConstructorElement() => new Element.tag(tag); |
235 | 237 |
236 ErrorConstructorElement.created() : super.created() { | 238 ErrorConstructorElement.created() : super.created() { |
237 ++callCount; | 239 ++callCount; |
238 throw new Exception('Just messin with ya'); | 240 throw new Exception('Just messin with ya'); |
239 } | 241 } |
240 | 242 |
241 static void register() { | 243 static void register() { |
242 document.register(tag, ErrorConstructorElement); | 244 document.registerElement(tag, ErrorConstructorElement); |
243 } | 245 } |
244 } | 246 } |
245 | 247 |
246 class NestedCreatedConstructorElement extends HtmlElement { | 248 class NestedCreatedConstructorElement extends HtmlElement { |
247 static final tag = 'x-nested-created-constructor'; | 249 static final tag = 'x-nested-created-constructor'; |
248 | 250 |
249 // Should not be able to call this here. | 251 // Should not be able to call this here. |
250 final B b = constructB(); | 252 final B b = constructB(); |
251 static B constructedB; | 253 static B constructedB; |
252 | 254 |
253 factory NestedCreatedConstructorElement() => new Element.tag(tag); | 255 factory NestedCreatedConstructorElement() => new Element.tag(tag); |
254 NestedCreatedConstructorElement.created() : super.created(); | 256 NestedCreatedConstructorElement.created() : super.created(); |
255 | 257 |
256 static void register() { | 258 static void register() { |
257 document.register(tag, NestedCreatedConstructorElement); | 259 document.registerElement(tag, NestedCreatedConstructorElement); |
258 } | 260 } |
259 | 261 |
260 // Try to run the created constructor, and record the results. | 262 // Try to run the created constructor, and record the results. |
261 static constructB() { | 263 static constructB() { |
262 // This should throw an exception. | 264 // This should throw an exception. |
263 constructedB = new B.created(); | 265 constructedB = new B.created(); |
264 return constructedB; | 266 return constructedB; |
265 } | 267 } |
266 | 268 |
267 static void test() { | 269 static void test() { |
(...skipping 22 matching lines...) Expand all Loading... |
290 } catch(e) { | 292 } catch(e) { |
291 rethrow; | 293 rethrow; |
292 } finally { | 294 } finally { |
293 js.context['testExpectsGlobalError'] = false; | 295 js.context['testExpectsGlobalError'] = false; |
294 } | 296 } |
295 var errors = js.context['testSuppressedGlobalErrors']; | 297 var errors = js.context['testSuppressedGlobalErrors']; |
296 expect(errors['length'], 1); | 298 expect(errors['length'], 1); |
297 // Clear out the errors; | 299 // Clear out the errors; |
298 js.context['testSuppressedGlobalErrors']['length'] = 0; | 300 js.context['testSuppressedGlobalErrors']['length'] = 0; |
299 } | 301 } |
OLD | NEW |