| 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 140 |
| 141 expect(ErrorConstructorElement.callCount, 1); | 141 expect(ErrorConstructorElement.callCount, 1); |
| 142 | 142 |
| 143 var e = dummy.firstChild; | 143 var e = dummy.firstChild; |
| 144 // Accessing should not re-run the constructor. | 144 // Accessing should not re-run the constructor. |
| 145 expect(ErrorConstructorElement.callCount, 1); | 145 expect(ErrorConstructorElement.callCount, 1); |
| 146 expect(e is HtmlElement, isTrue); | 146 expect(e is HtmlElement, isTrue); |
| 147 expect(e is ErrorConstructorElement, isFalse); | 147 expect(e is ErrorConstructorElement, isFalse); |
| 148 }); | 148 }); |
| 149 | 149 |
| 150 test('cannot register created with params', () { |
| 151 expect(() { |
| 152 document.register('x-created-with-params', CreatedWithParametersElement); |
| 153 }, throws); |
| 154 }); |
| 155 |
| 150 test('created cannot be called from nested constructor', | 156 test('created cannot be called from nested constructor', |
| 151 NestedCreatedConstructorElement.test); | 157 NestedCreatedConstructorElement.test); |
| 152 | 158 |
| 153 | 159 |
| 154 // TODO(vsm): Port additional test from upstream here: | 160 // TODO(vsm): Port additional test from upstream here: |
| 155 // http://src.chromium.org/viewvc/blink/trunk/LayoutTests/fast/dom/custom/crea
ted-callback.html?r1=156141&r2=156185 | 161 // http://src.chromium.org/viewvc/blink/trunk/LayoutTests/fast/dom/custom/crea
ted-callback.html?r1=156141&r2=156185 |
| 156 } | 162 } |
| 157 | 163 |
| 158 | 164 |
| 159 class NestedElement extends HtmlElement { | 165 class NestedElement extends HtmlElement { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 expectGlobalError(() { | 272 expectGlobalError(() { |
| 267 e = new Element.tag(tag); | 273 e = new Element.tag(tag); |
| 268 }); | 274 }); |
| 269 expect(e is NestedCreatedConstructorElement, isFalse); | 275 expect(e is NestedCreatedConstructorElement, isFalse); |
| 270 expect(e is HtmlElement, isTrue); | 276 expect(e is HtmlElement, isTrue); |
| 271 // Should not have been set. | 277 // Should not have been set. |
| 272 expect(constructedB, isNull); | 278 expect(constructedB, isNull); |
| 273 } | 279 } |
| 274 } | 280 } |
| 275 | 281 |
| 282 class CreatedWithParametersElement extends HtmlElement { |
| 283 CreatedWithParametersElement.created(ignoredParam) : super.created(); |
| 284 } |
| 285 |
| 276 void expectGlobalError(Function test) { | 286 void expectGlobalError(Function test) { |
| 277 js.context['testExpectsGlobalError'] = true; | 287 js.context['testExpectsGlobalError'] = true; |
| 278 try { | 288 try { |
| 279 test(); | 289 test(); |
| 280 } catch(e) { | 290 } catch(e) { |
| 281 rethrow; | 291 rethrow; |
| 282 } finally { | 292 } finally { |
| 283 js.context['testExpectsGlobalError'] = false; | 293 js.context['testExpectsGlobalError'] = false; |
| 284 } | 294 } |
| 285 var errors = js.context['testSuppressedGlobalErrors']; | 295 var errors = js.context['testSuppressedGlobalErrors']; |
| 286 expect(errors['length'], 1); | 296 expect(errors['length'], 1); |
| 287 // Clear out the errors; | 297 // Clear out the errors; |
| 288 js.context['testSuppressedGlobalErrors']['length'] = 0; | 298 js.context['testSuppressedGlobalErrors']['length'] = 0; |
| 289 } | 299 } |
| OLD | NEW |