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 'dart:async'; | 6 import 'dart:async'; |
7 import 'dart:html'; | 7 import 'dart:html'; |
8 import 'package:unittest/html_individual_config.dart'; | 8 import 'package:unittest/html_individual_config.dart'; |
9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
10 import 'utils.dart'; | 10 import 'utils.dart'; |
(...skipping 28 matching lines...) Expand all Loading... |
39 class NotAnElement {} | 39 class NotAnElement {} |
40 | 40 |
41 main() { | 41 main() { |
42 useHtmlIndividualConfiguration(); | 42 useHtmlIndividualConfiguration(); |
43 | 43 |
44 setUp(() => customElementsReady); | 44 setUp(() => customElementsReady); |
45 | 45 |
46 group('register', () { | 46 group('register', () { |
47 test('register', () { | 47 test('register', () { |
48 var tag = nextTag; | 48 var tag = nextTag; |
49 document.register(tag, CustomType); | 49 document.registerElement(tag, CustomType); |
50 | 50 |
51 var element = new Element.tag(tag); | 51 var element = new Element.tag(tag); |
52 expect(element, isNotNull); | 52 expect(element, isNotNull); |
53 expect(element is CustomType, isTrue); | 53 expect(element is CustomType, isTrue); |
54 expect(element.createdCalled, isTrue); | 54 expect(element.createdCalled, isTrue); |
55 }); | 55 }); |
56 | 56 |
57 test('register twice', () { | 57 test('register twice', () { |
58 var tag = nextTag; | 58 var tag = nextTag; |
59 document.register(tag, CustomType); | 59 document.registerElement(tag, CustomType); |
60 expect(() { | 60 expect(() { |
61 document.register(tag, CustomType); | 61 document.registerElement(tag, CustomType); |
62 }, throws, reason: 'Cannot register a tag more than once.'); | 62 }, throws, reason: 'Cannot register a tag more than once.'); |
63 | 63 |
64 var newTag = nextTag; | 64 var newTag = nextTag; |
65 document.register(newTag, CustomType); | 65 document.registerElement(newTag, CustomType); |
66 | 66 |
67 var element = new Element.tag(newTag); | 67 var element = new Element.tag(newTag); |
68 expect(element, isNotNull); | 68 expect(element, isNotNull); |
69 expect(element is CustomType, isTrue); | 69 expect(element is CustomType, isTrue); |
70 }); | 70 }); |
71 | 71 |
72 test('register null', () { | 72 test('register null', () { |
73 expect(() { | 73 expect(() { |
74 document.register(nextTag, null); | 74 document.registerElement(nextTag, null); |
75 }, throws, reason: 'Cannot register a null type.'); | 75 }, throws, reason: 'Cannot register a null type.'); |
76 }); | 76 }); |
77 | 77 |
78 test('register native', () { | 78 test('register native', () { |
79 expect(() { | 79 expect(() { |
80 document.register(nextTag, BodyElement); | 80 document.registerElement(nextTag, BodyElement); |
81 }, throws, reason: 'Cannot register a native element.'); | 81 }, throws, reason: 'Cannot register a native element.'); |
82 }); | 82 }); |
83 | 83 |
84 test('register non-element', () { | 84 test('register non-element', () { |
85 expect(() { | 85 expect(() { |
86 document.register(nextTag, NotAnElement); | 86 document.registerElement(nextTag, NotAnElement); |
87 }, throws, reason: 'Cannot register a non-element.'); | 87 }, throws, reason: 'Cannot register a non-element.'); |
88 }); | 88 }); |
89 }); | 89 }); |
90 | 90 |
91 // TODO(vsm): Modify this test once we agree on the proper semantics. | 91 // TODO(vsm): Modify this test once we agree on the proper semantics. |
92 /* | 92 /* |
93 group('preregister', () { | 93 group('preregister', () { |
94 | 94 |
95 test('pre-registration construction', () { | 95 test('pre-registration construction', () { |
96 var tag = nextTag; | 96 var tag = nextTag; |
97 var dom = new Element.html('<div><$tag></$tag></div>'); | 97 var dom = new Element.html('<div><$tag></$tag></div>'); |
98 | 98 |
99 var preElement = dom.children[0]; | 99 var preElement = dom.children[0]; |
100 expect(preElement, isNotNull); | 100 expect(preElement, isNotNull); |
101 expect(preElement is HtmlElement, isTrue); | 101 expect(preElement is HtmlElement, isTrue); |
102 expect(preElement is CustomType, isFalse); | 102 expect(preElement is CustomType, isFalse); |
103 var firedOnPre = false; | 103 var firedOnPre = false; |
104 preElement.onFocus.listen((_) { | 104 preElement.onFocus.listen((_) { |
105 firedOnPre = true; | 105 firedOnPre = true; |
106 }); | 106 }); |
107 | 107 |
108 document.register(tag, CustomType); | 108 document.registerElement(tag, CustomType); |
109 upgradeCustomElements(dom); | 109 upgradeCustomElements(dom); |
110 | 110 |
111 var postElement = dom.children[0]; | 111 var postElement = dom.children[0]; |
112 expect(postElement, isNotNull); | 112 expect(postElement, isNotNull); |
113 expect(postElement is CustomType, isTrue); | 113 expect(postElement is CustomType, isTrue); |
114 expect(postElement.createdCalled, isTrue); | 114 expect(postElement.createdCalled, isTrue); |
115 | 115 |
116 // Element from first query remains an UnknownElement. | 116 // Element from first query remains an UnknownElement. |
117 expect(preElement is HtmlElement, isTrue); | 117 expect(preElement is HtmlElement, isTrue); |
118 expect(preElement.parent, dom); | 118 expect(preElement.parent, dom); |
119 expect(dom.children.length, 1); | 119 expect(dom.children.length, 1); |
120 | 120 |
121 var firedOnPost = false; | 121 var firedOnPost = false; |
122 postElement.onFocus.listen((_) { | 122 postElement.onFocus.listen((_) { |
123 firedOnPost = true; | 123 firedOnPost = true; |
124 }); | 124 }); |
125 // Event handlers persist on old and new element. | 125 // Event handlers persist on old and new element. |
126 postElement.dispatchEvent(new Event('focus')); | 126 postElement.dispatchEvent(new Event('focus')); |
127 expect(firedOnPre, isTrue); | 127 expect(firedOnPre, isTrue); |
128 expect(firedOnPost, isTrue); | 128 expect(firedOnPost, isTrue); |
129 }); | 129 }); |
130 });*/ | 130 });*/ |
131 | 131 |
132 group('innerHtml', () { | 132 group('innerHtml', () { |
133 test('query', () { | 133 test('query', () { |
134 var tag = nextTag; | 134 var tag = nextTag; |
135 document.register(tag, CustomType); | 135 document.registerElement(tag, CustomType); |
136 var element = new DivElement(); | 136 var element = new DivElement(); |
137 element.setInnerHtml('<$tag></$tag>', | 137 element.setInnerHtml('<$tag></$tag>', |
138 treeSanitizer: new NullTreeSanitizer()); | 138 treeSanitizer: new NullTreeSanitizer()); |
139 upgradeCustomElements(element); | 139 upgradeCustomElements(element); |
140 document.body.nodes.add(element); | 140 document.body.nodes.add(element); |
141 var queried = query(tag); | 141 var queried = query(tag); |
142 | 142 |
143 expect(queried, isNotNull); | 143 expect(queried, isNotNull); |
144 expect(queried is CustomType, isTrue); | 144 expect(queried is CustomType, isTrue); |
145 expect(queried.createdCalled, isTrue); | 145 expect(queried.createdCalled, isTrue); |
146 }); | 146 }); |
147 | 147 |
148 test('query id', () { | 148 test('query id', () { |
149 var tag = nextTag; | 149 var tag = nextTag; |
150 document.register(tag, CustomType); | 150 document.registerElement(tag, CustomType); |
151 var element = new DivElement(); | 151 var element = new DivElement(); |
152 element.setInnerHtml('<$tag id="someid"></$tag>', | 152 element.setInnerHtml('<$tag id="someid"></$tag>', |
153 treeSanitizer: new NullTreeSanitizer()); | 153 treeSanitizer: new NullTreeSanitizer()); |
154 upgradeCustomElements(element); | 154 upgradeCustomElements(element); |
155 document.body.nodes.add(element); | 155 document.body.nodes.add(element); |
156 var queried = query('#someid'); | 156 var queried = query('#someid'); |
157 | 157 |
158 expect(queried, isNotNull); | 158 expect(queried, isNotNull); |
159 expect(queried is CustomType, isTrue); | 159 expect(queried is CustomType, isTrue); |
160 expect(queried.id, "someid"); | 160 expect(queried.id, "someid"); |
161 }); | 161 }); |
162 }); | 162 }); |
163 | 163 |
164 group('lifecycle', () { | 164 group('lifecycle', () { |
165 test('created', () { | 165 test('created', () { |
166 int oldCount = customCreatedCount; | 166 int oldCount = customCreatedCount; |
167 var tag = nextTag; | 167 var tag = nextTag; |
168 document.register(tag, CustomType); | 168 document.registerElement(tag, CustomType); |
169 var element = new DivElement(); | 169 var element = new DivElement(); |
170 element.setInnerHtml('<$tag></$tag>', | 170 element.setInnerHtml('<$tag></$tag>', |
171 treeSanitizer: new NullTreeSanitizer()); | 171 treeSanitizer: new NullTreeSanitizer()); |
172 upgradeCustomElements(element); | 172 upgradeCustomElements(element); |
173 document.body.nodes.add(element); | 173 document.body.nodes.add(element); |
174 expect(customCreatedCount, oldCount + 1); | 174 expect(customCreatedCount, oldCount + 1); |
175 }); | 175 }); |
176 }); | 176 }); |
177 | 177 |
178 group('mixins', () { | 178 group('mixins', () { |
179 test('can invoke mixin methods', () { | 179 test('can invoke mixin methods', () { |
180 var tag = nextTag; | 180 var tag = nextTag; |
181 document.register(tag, CustomType); | 181 document.registerElement(tag, CustomType); |
182 | 182 |
183 var element = new Element.tag(tag); | 183 var element = new Element.tag(tag); |
184 element.invokeMixinMethod(); | 184 element.invokeMixinMethod(); |
185 expect(element.mixinMethodCalled, isTrue); | 185 expect(element.mixinMethodCalled, isTrue); |
186 }); | 186 }); |
187 }); | 187 }); |
188 } | 188 } |
OLD | NEW |