| 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 custom_elements_test; | 5 library custom_elements_test; |
| 6 import '../../pkg/unittest/lib/unittest.dart'; | 6 import '../../pkg/unittest/lib/unittest.dart'; |
| 7 import '../../pkg/unittest/lib/html_individual_config.dart'; | 7 import '../../pkg/unittest/lib/html_individual_config.dart'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 | 9 |
| 10 class CustomType extends Element { | 10 class CustomType extends HtmlElement { |
| 11 factory CustomType() => null; | 11 factory CustomType() => null; |
| 12 bool onCreatedCalled; // = false; | 12 bool onCreatedCalled; // = false; |
| 13 void onCreated() { | 13 void onCreated() { |
| 14 onCreatedCalled = true; | 14 onCreatedCalled = true; |
| 15 customCreatedCount++; | 15 customCreatedCount++; |
| 16 } | 16 } |
| 17 } | 17 } |
| 18 | 18 |
| 19 int customCreatedCount = 0; | 19 int customCreatedCount = 0; |
| 20 | 20 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 document.register('x-type8', CustomType); | 105 document.register('x-type8', CustomType); |
| 106 var element = new DivElement(); | 106 var element = new DivElement(); |
| 107 element.innerHtml = '<x-type8></x-type8>'; | 107 element.innerHtml = '<x-type8></x-type8>'; |
| 108 document.body.nodes.add(element); | 108 document.body.nodes.add(element); |
| 109 var queried = query('x-type8'); | 109 var queried = query('x-type8'); |
| 110 | 110 |
| 111 expect(queried, isNotNull); | 111 expect(queried, isNotNull); |
| 112 expect(queried is CustomType, isTrue); | 112 expect(queried is CustomType, isTrue); |
| 113 expect(queried.onCreatedCalled, isTrue); | 113 expect(queried.onCreatedCalled, isTrue); |
| 114 }); | 114 }); |
| 115 |
| 116 test('query id', () { |
| 117 document.register('x-type9', CustomType); |
| 118 var element = new DivElement(); |
| 119 element.innerHtml = '<x-type9 id="someid"></x-type9>'; |
| 120 document.body.nodes.add(element); |
| 121 var queried = query('#someid'); |
| 122 |
| 123 expect(queried, isNotNull); |
| 124 expect(queried is CustomType, isTrue); |
| 125 expect(queried.id, "someid"); |
| 126 }); |
| 115 }); | 127 }); |
| 116 | 128 |
| 117 group('lifecycle', () { | 129 group('lifecycle', () { |
| 118 test('onCreated', () { | 130 test('onCreated', () { |
| 119 int oldCount = customCreatedCount; | 131 int oldCount = customCreatedCount; |
| 120 | 132 |
| 121 document.register('x-type9', CustomType); | 133 document.register('x-type10', CustomType); |
| 122 var element = new DivElement(); | 134 var element = new DivElement(); |
| 123 element.innerHtml = '<x-type9></x-type9>'; | 135 element.innerHtml = '<x-type10></x-type10>'; |
| 124 document.body.nodes.add(element); | 136 document.body.nodes.add(element); |
| 125 expect(customCreatedCount, oldCount + 1); | 137 expect(customCreatedCount, oldCount + 1); |
| 126 }); | 138 }); |
| 127 }); | 139 }); |
| 128 } | 140 } |
| OLD | NEW |