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 '../utils.dart'; | 9 import '../utils.dart'; |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 factory BadE() => new Element.tag(tag); | 40 factory BadE() => new Element.tag(tag); |
41 } | 41 } |
42 | 42 |
43 main() { | 43 main() { |
44 useHtmlConfiguration(); | 44 useHtmlConfiguration(); |
45 | 45 |
46 // Adapted from Blink's fast/dom/custom/document-register-basic test. | 46 // Adapted from Blink's fast/dom/custom/document-register-basic test. |
47 | 47 |
48 setUp(() => customElementsReady); | 48 setUp(() => customElementsReady); |
49 | 49 |
50 test('Testing document.register() basic behaviors', () { | 50 test('Testing document.registerElement() basic behaviors', () { |
51 document.register(Foo.tag, Foo); | 51 document.registerElement(Foo.tag, Foo); |
52 | 52 |
53 // Cannot register an existing dart:html type. | 53 // Cannot register an existing dart:html type. |
54 expect(() => document.register('x-bad-a', HtmlElement), throws); | 54 expect(() => document.registerElement('x-bad-a', HtmlElement), throws); |
55 | 55 |
56 // Invalid user type. Doesn't inherit from HtmlElement. | 56 // Invalid user type. Doesn't inherit from HtmlElement. |
57 expect(() => document.register('x-bad-b', BadB), throws); | 57 expect(() => document.registerElement('x-bad-b', BadB), throws); |
58 | 58 |
59 // Not a type. | 59 // Not a type. |
60 expect(() => document.register('x-bad-c', null), throws); | 60 expect(() => document.registerElement('x-bad-c', null), throws); |
61 | 61 |
62 // Cannot register system type. | 62 // Cannot register system type. |
63 expect(() => document.register('x-bad-d', Object), throws); | 63 expect(() => document.registerElement('x-bad-d', Object), throws); |
64 | 64 |
65 // Must extend HtmlElement, not just implement it. | 65 // Must extend HtmlElement, not just implement it. |
66 expect(() => document.register(BadE.tag, BadE), throws); | 66 expect(() => document.registerElement(BadE.tag, BadE), throws); |
67 | 67 |
68 // Constructor initiated instantiation | 68 // Constructor initiated instantiation |
69 var createdFoo = new Foo(); | 69 var createdFoo = new Foo(); |
70 expect(createdFoo.thisIsACustomClass, isTrue); | 70 expect(createdFoo.thisIsACustomClass, isTrue); |
71 | 71 |
72 // Dart type correctness | 72 // Dart type correctness |
73 expect(createdFoo is HtmlElement, isTrue); | 73 expect(createdFoo is HtmlElement, isTrue); |
74 expect(createdFoo is Foo, isTrue); | 74 expect(createdFoo is Foo, isTrue); |
75 expect(createdFoo.runtimeType, Foo); | 75 expect(createdFoo.runtimeType, Foo); |
76 | 76 |
(...skipping 20 matching lines...) Expand all Loading... |
97 expect(parsedFoo is Foo, isTrue); | 97 expect(parsedFoo is Foo, isTrue); |
98 expect(parsedFoo.tagName, "X-FOO"); | 98 expect(parsedFoo.tagName, "X-FOO"); |
99 | 99 |
100 // Ensuring the wrapper is retained | 100 // Ensuring the wrapper is retained |
101 var someProperty = new Expando(); | 101 var someProperty = new Expando(); |
102 someProperty[parsedFoo] = "hello"; | 102 someProperty[parsedFoo] = "hello"; |
103 expect(container.firstChild, parsedFoo); | 103 expect(container.firstChild, parsedFoo); |
104 expect(someProperty[container.firstChild], someProperty[parsedFoo]); | 104 expect(someProperty[container.firstChild], someProperty[parsedFoo]); |
105 | 105 |
106 // Having another constructor | 106 // Having another constructor |
107 document.register(Bar.tag, Bar); | 107 document.registerElement(Bar.tag, Bar); |
108 var createdBar = new Bar(); | 108 var createdBar = new Bar(); |
109 expect(createdBar is Bar, isTrue); | 109 expect(createdBar is Bar, isTrue); |
110 expect(createdBar is Foo, isFalse); | 110 expect(createdBar is Foo, isFalse); |
111 expect(createdBar.tagName, "X-BAR"); | 111 expect(createdBar.tagName, "X-BAR"); |
112 | 112 |
113 // Having a subclass | 113 // Having a subclass |
114 document.register(Baz.tag, Baz); | 114 document.registerElement(Baz.tag, Baz); |
115 var createdBaz = new Baz(); | 115 var createdBaz = new Baz(); |
116 expect(createdBaz.tagName, "X-BAZ"); | 116 expect(createdBaz.tagName, "X-BAZ"); |
117 expect(createdBaz.thisIsACustomClass, isTrue); | 117 expect(createdBaz.thisIsACustomClass, isTrue); |
118 expect(createdBaz.thisIsAlsoACustomClass, isTrue); | 118 expect(createdBaz.thisIsAlsoACustomClass, isTrue); |
119 | 119 |
120 // With irregular cases | 120 // With irregular cases |
121 var createdUpperBar = new Element.tag("X-BAR"); | 121 var createdUpperBar = new Element.tag("X-BAR"); |
122 var createdMixedBar = new Element.tag("X-Bar"); | 122 var createdMixedBar = new Element.tag("X-Bar"); |
123 expect(createdUpperBar is Bar, isTrue); | 123 expect(createdUpperBar is Bar, isTrue); |
124 expect(createdUpperBar.tagName, "X-BAR"); | 124 expect(createdUpperBar.tagName, "X-BAR"); |
125 expect(createdMixedBar is Bar, isTrue); | 125 expect(createdMixedBar is Bar, isTrue); |
126 expect(createdMixedBar.tagName, "X-BAR"); | 126 expect(createdMixedBar.tagName, "X-BAR"); |
127 | 127 |
128 container.setInnerHtml("<X-BAR></X-BAR><X-Bar></X-Bar>", | 128 container.setInnerHtml("<X-BAR></X-BAR><X-Bar></X-Bar>", |
129 treeSanitizer: new NullTreeSanitizer()); | 129 treeSanitizer: new NullTreeSanitizer()); |
130 upgradeCustomElements(container); | 130 upgradeCustomElements(container); |
131 expect(container.firstChild is Bar, isTrue); | 131 expect(container.firstChild is Bar, isTrue); |
132 expect(container.firstChild.tagName, "X-BAR"); | 132 expect(container.firstChild.tagName, "X-BAR"); |
133 expect(container.lastChild is Bar, isTrue); | 133 expect(container.lastChild is Bar, isTrue); |
134 expect(container.lastChild.tagName, "X-BAR"); | 134 expect(container.lastChild.tagName, "X-BAR"); |
135 | 135 |
136 // Constructors shouldn't interfere with each other | 136 // Constructors shouldn't interfere with each other |
137 expect((new Foo()).tagName, "X-FOO"); | 137 expect((new Foo()).tagName, "X-FOO"); |
138 expect((new Bar()).tagName, "X-BAR"); | 138 expect((new Bar()).tagName, "X-BAR"); |
139 expect((new Baz()).tagName, "X-BAZ"); | 139 expect((new Baz()).tagName, "X-BAZ"); |
140 }); | 140 }); |
141 } | 141 } |
OLD | NEW |