| 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 document_register_basic_test; | 5 library document_register_basic_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 '../utils.dart'; | 10 import '../utils.dart'; |
| 10 | 11 |
| 11 class Foo extends HtmlElement { | 12 class Foo extends HtmlElement { |
| 12 static final tag = 'x-foo'; | 13 static final tag = 'x-foo'; |
| 13 factory Foo() => new Element.tag(tag); | 14 factory Foo() => new Element.tag(tag); |
| 14 Foo.created() : super.created(); | 15 Foo.created() : super.created(); |
| 15 | 16 |
| 16 get thisIsACustomClass => true; | 17 get thisIsACustomClass => true; |
| 17 } | 18 } |
| 18 | 19 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // Native method | 85 // Native method |
| 85 var childDiv = new DivElement(); | 86 var childDiv = new DivElement(); |
| 86 createdFoo.append(childDiv); | 87 createdFoo.append(childDiv); |
| 87 expect(createdFoo.lastChild, childDiv); | 88 expect(createdFoo.lastChild, childDiv); |
| 88 | 89 |
| 89 // Parser initiated instantiation | 90 // Parser initiated instantiation |
| 90 var container = new DivElement()..id = "container"; | 91 var container = new DivElement()..id = "container"; |
| 91 document.body.append(container); | 92 document.body.append(container); |
| 92 container.setInnerHtml("<x-foo></x-foo>", | 93 container.setInnerHtml("<x-foo></x-foo>", |
| 93 treeSanitizer: new NullTreeSanitizer()); | 94 treeSanitizer: new NullTreeSanitizer()); |
| 94 Platform.upgradeCustomElements(container); | 95 customElementsTakeRecords(); |
| 95 var parsedFoo = container.firstChild; | 96 var parsedFoo = container.firstChild; |
| 96 | 97 |
| 97 expect(parsedFoo is Foo, isTrue); | 98 expect(parsedFoo is Foo, isTrue); |
| 98 expect(parsedFoo.tagName, "X-FOO"); | 99 expect(parsedFoo.tagName, "X-FOO"); |
| 99 | 100 |
| 100 // Ensuring the wrapper is retained | 101 // Ensuring the wrapper is retained |
| 101 var someProperty = new Expando(); | 102 var someProperty = new Expando(); |
| 102 someProperty[parsedFoo] = "hello"; | 103 someProperty[parsedFoo] = "hello"; |
| 103 expect(container.firstChild, parsedFoo); | 104 expect(container.firstChild, parsedFoo); |
| 104 expect(someProperty[container.firstChild], someProperty[parsedFoo]); | 105 expect(someProperty[container.firstChild], someProperty[parsedFoo]); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 120 // With irregular cases | 121 // With irregular cases |
| 121 var createdUpperBar = new Element.tag("X-BAR"); | 122 var createdUpperBar = new Element.tag("X-BAR"); |
| 122 var createdMixedBar = new Element.tag("X-Bar"); | 123 var createdMixedBar = new Element.tag("X-Bar"); |
| 123 expect(createdUpperBar is Bar, isTrue); | 124 expect(createdUpperBar is Bar, isTrue); |
| 124 expect(createdUpperBar.tagName, "X-BAR"); | 125 expect(createdUpperBar.tagName, "X-BAR"); |
| 125 expect(createdMixedBar is Bar, isTrue); | 126 expect(createdMixedBar is Bar, isTrue); |
| 126 expect(createdMixedBar.tagName, "X-BAR"); | 127 expect(createdMixedBar.tagName, "X-BAR"); |
| 127 | 128 |
| 128 container.setInnerHtml("<X-BAR></X-BAR><X-Bar></X-Bar>", | 129 container.setInnerHtml("<X-BAR></X-BAR><X-Bar></X-Bar>", |
| 129 treeSanitizer: new NullTreeSanitizer()); | 130 treeSanitizer: new NullTreeSanitizer()); |
| 130 Platform.upgradeCustomElements(container); | 131 customElementsTakeRecords(); |
| 131 expect(container.firstChild is Bar, isTrue); | 132 expect(container.firstChild is Bar, isTrue); |
| 132 expect(container.firstChild.tagName, "X-BAR"); | 133 expect(container.firstChild.tagName, "X-BAR"); |
| 133 expect(container.lastChild is Bar, isTrue); | 134 expect(container.lastChild is Bar, isTrue); |
| 134 expect(container.lastChild.tagName, "X-BAR"); | 135 expect(container.lastChild.tagName, "X-BAR"); |
| 135 | 136 |
| 136 // Constructors shouldn't interfere with each other | 137 // Constructors shouldn't interfere with each other |
| 137 expect((new Foo()).tagName, "X-FOO"); | 138 expect((new Foo()).tagName, "X-FOO"); |
| 138 expect((new Bar()).tagName, "X-BAR"); | 139 expect((new Bar()).tagName, "X-BAR"); |
| 139 expect((new Baz()).tagName, "X-BAZ"); | 140 expect((new Baz()).tagName, "X-BAZ"); |
| 140 }); | 141 }); |
| 141 } | 142 } |
| OLD | NEW |