| Index: tests/html/custom/created_callback_test.dart
|
| diff --git a/tests/html/custom/created_callback_test.dart b/tests/html/custom/created_callback_test.dart
|
| index ebd3fba3c8c133acd7f1e307ef37cdc01d01cf49..ea017406627b3fa667db0cd1b9e6e0ee184031d5 100644
|
| --- a/tests/html/custom/created_callback_test.dart
|
| +++ b/tests/html/custom/created_callback_test.dart
|
| @@ -11,10 +11,11 @@ import '../utils.dart';
|
| class A extends HtmlElement {
|
| static final tag = 'x-a';
|
| factory A() => new Element.tag(tag);
|
| + A.created(): super.created();
|
|
|
| static int createdInvocations = 0;
|
|
|
| - void created() {
|
| + void createdCallback() {
|
| createdInvocations++;
|
| }
|
| }
|
| @@ -22,16 +23,18 @@ class A extends HtmlElement {
|
| class B extends HtmlElement {
|
| static final tag = 'x-b';
|
| factory B() => new Element.tag(tag);
|
| + B.created(): super.created();
|
| }
|
|
|
| class C extends HtmlElement {
|
| static final tag = 'x-c';
|
| factory C() => new Element.tag(tag);
|
| + C.created(): super.created();
|
|
|
| static int createdInvocations = 0;
|
| static var div;
|
|
|
| - void created() {
|
| + void createdCallback() {
|
| createdInvocations++;
|
|
|
| if (this.id != 'u') {
|
| @@ -60,7 +63,17 @@ main() {
|
| // Adapted from Blink's
|
| // fast/dom/custom/created-callback test.
|
|
|
| - setUp(loadPolyfills);
|
| + var registered = false;
|
| + setUp(() {
|
| + return loadPolyfills().then((_) {
|
| + if (!registered) {
|
| + registered = true;
|
| + document.register(B.tag, B);
|
| + document.register(C.tag, C);
|
| + ErrorConstructorElement.register();
|
| + }
|
| + });
|
| + });
|
|
|
| test('transfer created callback', () {
|
| document.register(A.tag, A);
|
| @@ -68,10 +81,7 @@ main() {
|
| expect(A.createdInvocations, 1);
|
| });
|
|
|
| - test(':unresolved and created callback timing', () {
|
| - document.register(B.tag, B);
|
| - document.register(C.tag, C);
|
| -
|
| + test('unresolved and created callback timing', () {
|
| var div = new DivElement();
|
| C.div = div;
|
| div.setInnerHtml("""
|
| @@ -87,6 +97,138 @@ main() {
|
| expect(div.query('#w') is B, isTrue);
|
| });
|
|
|
| + test('nesting of constructors', NestedElement.test);
|
| +
|
| + test('access while upgrading gets unupgraded element',
|
| + AccessWhileUpgradingElement.test);
|
| +
|
| + test('cannot call created constructor', () {
|
| + expect(() {
|
| + new B.created();
|
| + }, throws);
|
| + });
|
| +
|
| + test('cannot register without created', () {
|
| + expect(() {
|
| + document.register(MissingCreatedElement.tag, MissingCreatedElement);
|
| + }, throws);
|
| + });
|
| +
|
| + test('throw on createElement does not upgrade', () {
|
| + ErrorConstructorElement.callCount = 0;
|
| +
|
| + var e = new Element.tag(ErrorConstructorElement.tag);
|
| + expect(ErrorConstructorElement.callCount, 1);
|
| + expect(e is HtmlElement, isTrue);
|
| + expect(e is ErrorConstructorElement, isFalse);
|
| +
|
| + var dummy = new DivElement();
|
| + dummy.append(e);
|
| + e = dummy.firstChild;
|
| + expect(ErrorConstructorElement.callCount, 1);
|
| + });
|
| +
|
| + test('throw on innerHtml does not upgrade', () {
|
| + ErrorConstructorElement.callCount = 0;
|
| +
|
| + var dummy = new DivElement();
|
| + var tag = ErrorConstructorElement.tag;
|
| + dummy.setInnerHtml('<$tag></$tag>',
|
| + treeSanitizer: new NullTreeSanitizer());
|
| +
|
| + expect(ErrorConstructorElement.callCount, 1);
|
| +
|
| + var e = dummy.firstChild;
|
| + // Accessing should not re-run the constructor.
|
| + expect(ErrorConstructorElement.callCount, 1);
|
| + expect(e is HtmlElement, isTrue);
|
| + expect(e is ErrorConstructorElement, isFalse);
|
| + });
|
| +
|
| +
|
| // TODO(vsm): Port additional test from upstream here:
|
| // http://src.chromium.org/viewvc/blink/trunk/LayoutTests/fast/dom/custom/created-callback.html?r1=156141&r2=156185
|
| }
|
| +
|
| +
|
| +class NestedElement extends HtmlElement {
|
| + static final tag = 'x-nested';
|
| +
|
| + final Element b = new B();
|
| +
|
| + factory NestedElement() => new Element.tag(tag);
|
| + NestedElement.created(): super.created();
|
| +
|
| + static void register() {
|
| + document.register(tag, NestedElement);
|
| + }
|
| +
|
| + static void test() {
|
| + register();
|
| +
|
| + var e = new NestedElement();
|
| + expect(e.b, isNotNull);
|
| + expect(e.b is B, isTrue);
|
| + expect(e is NestedElement, isTrue);
|
| + }
|
| +}
|
| +
|
| +
|
| +class AccessWhileUpgradingElement extends HtmlElement {
|
| + static final tag = 'x-access-while-upgrading';
|
| +
|
| + static Element upgradingContext;
|
| + static Element upgradingContextChild;
|
| +
|
| + final foo = runInitializerCode();
|
| +
|
| + factory AccessWhileUpgradingElement() => new Element.tag(tag);
|
| + AccessWhileUpgradingElement.created(): super.created();
|
| +
|
| + static runInitializerCode() {
|
| + upgradingContextChild = upgradingContext.firstChild;
|
| +
|
| + return 666;
|
| + }
|
| +
|
| + static void register() {
|
| + document.register(tag, AccessWhileUpgradingElement);
|
| + }
|
| +
|
| + static void test() {
|
| + register();
|
| +
|
| + upgradingContext = new DivElement();
|
| + upgradingContext.setInnerHtml('<$tag></$tag>',
|
| + treeSanitizer: new NullTreeSanitizer());
|
| + var child = upgradingContext.firstChild;
|
| +
|
| + expect(child.foo, 666);
|
| + expect(upgradingContextChild is HTMLElement, isTrue);
|
| + expect(upgradingContextChild is AccessWhileUpgradingElement, isFalse,
|
| + reason: 'Elements accessed while upgrading should not be upgraded.');
|
| + }
|
| +}
|
| +
|
| +class MissingCreatedElement extends HtmlElement {
|
| + static final tag = 'x-missing-created';
|
| +
|
| + factory MissingCreatedElement() => new Element.tag(tag);
|
| +}
|
| +
|
| +class ErrorConstructorElement extends HtmlElement {
|
| + static final tag = 'x-throws-in-constructor';
|
| + static int callCount = 0;
|
| +
|
| + factory ErrorConstructorElement() => new Element.tag(tag);
|
| +
|
| + ErrorConstructorElement.created(): super.created() {
|
| + print('here!!');
|
| + ++callCount;
|
| + throw new Exception('Just messin with ya');
|
| + }
|
| +
|
| + static void register() {
|
| + document.register(tag, ErrorConstructorElement);
|
| + }
|
| +}
|
|
|