OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library custom_element_proxy_test; | 4 library custom_element_proxy_test; |
5 | 5 |
6 import 'dart:async'; | 6 import 'dart:async'; |
7 import 'dart:html'; | 7 import 'dart:html'; |
8 import 'dart:js'; | 8 import 'dart:js'; |
9 import 'package:initialize/initialize.dart' as init; | |
10 import 'package:unittest/html_config.dart'; | 9 import 'package:unittest/html_config.dart'; |
11 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
12 import 'package:web_components/custom_element_proxy.dart'; | 11 import 'package:web_components/web_components.dart'; |
13 | 12 |
14 @CustomElementProxy('basic-element') | 13 @CustomElementProxy('basic-element') |
15 class BasicElement extends HtmlElement { | 14 class BasicElement extends HtmlElement { |
16 BasicElement.created() : super.created(); | 15 BasicElement.created() : super.created(); |
17 | 16 |
18 factory BasicElement() => document.createElement('basic-element'); | 17 factory BasicElement() => document.createElement('basic-element'); |
19 | 18 |
20 bool get isBasicElement => | 19 bool get isBasicElement => |
21 new JsObject.fromBrowserObject(this)['isBasicElement']; | 20 new JsObject.fromBrowserObject(this)['isBasicElement']; |
22 } | 21 } |
23 | 22 |
24 @CustomElementProxy('extended-element', extendsTag: 'input') | 23 @CustomElementProxy('extended-element', extendsTag: 'input') |
25 class ExtendedElement extends InputElement { | 24 class ExtendedElement extends InputElement { |
26 ExtendedElement.created() : super.created(); | 25 ExtendedElement.created() : super.created(); |
27 | 26 |
28 factory ExtendedElement() => | 27 factory ExtendedElement() => |
29 document.createElement('input', 'extended-element'); | 28 document.createElement('input', 'extended-element'); |
30 | 29 |
31 bool get isExtendedElement => | 30 bool get isExtendedElement => |
32 new JsObject.fromBrowserObject(this)['isExtendedElement']; | 31 new JsObject.fromBrowserObject(this)['isExtendedElement']; |
33 } | 32 } |
34 | 33 |
35 main() { | 34 main() { |
36 useHtmlConfiguration(); | 35 useHtmlConfiguration(); |
37 init.run().then((_) { | 36 initWebComponents().then((_) { |
38 var container = querySelector('#container') as DivElement; | 37 var container = querySelector('#container') as DivElement; |
39 | 38 |
40 tearDown(() { | 39 tearDown(() { |
41 container.children.clear(); | 40 container.children.clear(); |
42 }); | 41 }); |
43 | 42 |
44 test('basic custom element', () { | 43 test('basic custom element', () { |
45 container.append(new BasicElement()); | 44 container.append(new BasicElement()); |
46 container.appendHtml('<basic-element></basic_element>'); | 45 container.appendHtml('<basic-element></basic_element>'); |
47 // TODO(jakemac): after appendHtml elements are upgraded asynchronously, | 46 // TODO(jakemac): after appendHtml elements are upgraded asynchronously, |
(...skipping 17 matching lines...) Expand all Loading... |
65 return new Future(() {}).then((_) { | 64 return new Future(() {}).then((_) { |
66 var elements = container.querySelectorAll('input'); | 65 var elements = container.querySelectorAll('input'); |
67 expect(elements.length, 2); | 66 expect(elements.length, 2); |
68 for (ExtendedElement element in elements) { | 67 for (ExtendedElement element in elements) { |
69 expect(element.isExtendedElement, isTrue); | 68 expect(element.isExtendedElement, isTrue); |
70 } | 69 } |
71 }); | 70 }); |
72 }); | 71 }); |
73 }); | 72 }); |
74 } | 73 } |
OLD | NEW |