Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: third_party/WebKit/Source/core/dom/custom/CustomElementRegistryTest.cpp

Issue 2442223003: Make createElement tag name case handling consistent for custom elements (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/dom/custom/CustomElementRegistry.h" 5 #include "core/dom/custom/CustomElementRegistry.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/ScriptValue.h"
9 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
10 #include "core/dom/Element.h" 9 #include "core/dom/Element.h"
11 #include "core/dom/ElementDefinitionOptions.h" 10 #include "core/dom/ElementDefinitionOptions.h"
12 #include "core/dom/custom/CEReactionsScope.h" 11 #include "core/dom/custom/CEReactionsScope.h"
13 #include "core/dom/custom/CustomElementDefinition.h" 12 #include "core/dom/custom/CustomElementDefinition.h"
14 #include "core/dom/custom/CustomElementDefinitionBuilder.h" 13 #include "core/dom/custom/CustomElementDefinitionBuilder.h"
15 #include "core/dom/custom/CustomElementDescriptor.h" 14 #include "core/dom/custom/CustomElementDescriptor.h"
16 #include "core/dom/custom/CustomElementTestHelpers.h" 15 #include "core/dom/custom/CustomElementTestHelpers.h"
17 #include "core/dom/shadow/ShadowRoot.h" 16 #include "core/dom/shadow/ShadowRoot.h"
18 #include "core/dom/shadow/ShadowRootInit.h" 17 #include "core/dom/shadow/ShadowRootInit.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 document().documentElement()->appendChild(elementC); 153 document().documentElement()->appendChild(elementC);
155 154
156 HeapVector<Member<Element>> elements; 155 HeapVector<Member<Element>> elements;
157 collectCandidates(CustomElementDescriptor("a-a", "a-a"), &elements); 156 collectCandidates(CustomElementDescriptor("a-a", "a-a"), &elements);
158 157
159 EXPECT_EQ(elementA, elements[0].get()); 158 EXPECT_EQ(elementA, elements[0].get());
160 EXPECT_EQ(elementB, elements[1].get()); 159 EXPECT_EQ(elementB, elements[1].get());
161 EXPECT_EQ(elementC, elements[2].get()); 160 EXPECT_EQ(elementC, elements[2].get());
162 } 161 }
163 162
164 class TestCustomElementDefinition : public CustomElementDefinition {
165 WTF_MAKE_NONCOPYABLE(TestCustomElementDefinition);
166
167 public:
168 TestCustomElementDefinition(const CustomElementDescriptor& descriptor)
169 : CustomElementDefinition(descriptor) {}
170
171 TestCustomElementDefinition(const CustomElementDescriptor& descriptor,
172 const HashSet<AtomicString>& observedAttributes)
173 : CustomElementDefinition(descriptor, observedAttributes) {}
174
175 ~TestCustomElementDefinition() override = default;
176
177 ScriptValue getConstructorForScript() override { return ScriptValue(); }
178
179 bool runConstructor(Element* element) override {
180 if (constructionStack().isEmpty() || constructionStack().last() != element)
181 return false;
182 constructionStack().last().clear();
183 return true;
184 }
185
186 HTMLElement* createElementSync(Document&, const QualifiedName&) override {
187 return nullptr;
188 }
189
190 HTMLElement* createElementSync(Document&,
191 const QualifiedName&,
192 ExceptionState&) override {
193 return nullptr;
194 }
195 };
196
197 // Classes which use trace macros cannot be local because of the 163 // Classes which use trace macros cannot be local because of the
198 // traceImpl template. 164 // traceImpl template.
199 class LogUpgradeDefinition : public TestCustomElementDefinition { 165 class LogUpgradeDefinition : public TestCustomElementDefinition {
200 WTF_MAKE_NONCOPYABLE(LogUpgradeDefinition); 166 WTF_MAKE_NONCOPYABLE(LogUpgradeDefinition);
201 167
202 public: 168 public:
203 LogUpgradeDefinition(const CustomElementDescriptor& descriptor) 169 LogUpgradeDefinition(const CustomElementDescriptor& descriptor)
204 : TestCustomElementDefinition( 170 : TestCustomElementDefinition(
205 descriptor, 171 descriptor,
206 { 172 {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 void runAttributeChangedCallback(Element* element, 248 void runAttributeChangedCallback(Element* element,
283 const QualifiedName& name, 249 const QualifiedName& name,
284 const AtomicString& oldValue, 250 const AtomicString& oldValue,
285 const AtomicString& newValue) override { 251 const AtomicString& newValue) override {
286 m_logs.append(AttributeChangedCallback); 252 m_logs.append(AttributeChangedCallback);
287 EXPECT_EQ(element, m_element); 253 EXPECT_EQ(element, m_element);
288 m_attributeChanged.append(AttributeChanged{name, oldValue, newValue}); 254 m_attributeChanged.append(AttributeChanged{name, oldValue, newValue});
289 } 255 }
290 }; 256 };
291 257
292 class LogUpgradeBuilder final : public CustomElementDefinitionBuilder { 258 class LogUpgradeBuilder final : public TestCustomElementDefinitionBuilder {
293 STACK_ALLOCATED(); 259 STACK_ALLOCATED();
294 WTF_MAKE_NONCOPYABLE(LogUpgradeBuilder); 260 WTF_MAKE_NONCOPYABLE(LogUpgradeBuilder);
295 261
296 public: 262 public:
297 LogUpgradeBuilder() {} 263 LogUpgradeBuilder() {}
298 264
299 bool checkConstructorIntrinsics() override { return true; } 265 CustomElementDefinition* build(
300 bool checkConstructorNotRegistered() override { return true; } 266 const CustomElementDescriptor& descriptor) override {
301 bool checkPrototype() override { return true; }
302 bool rememberOriginalProperties() override { return true; }
303 CustomElementDefinition* build(const CustomElementDescriptor& descriptor) {
304 return new LogUpgradeDefinition(descriptor); 267 return new LogUpgradeDefinition(descriptor);
305 } 268 }
306 }; 269 };
307 270
308 TEST_F(CustomElementRegistryTest, define_upgradesInDocumentElements) { 271 TEST_F(CustomElementRegistryTest, define_upgradesInDocumentElements) {
309 ScriptForbiddenScope doNotRelyOnScript; 272 ScriptForbiddenScope doNotRelyOnScript;
310 273
311 Element* element = CreateElement("a-a").inDocument(&document()); 274 Element* element = CreateElement("a-a").inDocument(&document());
312 element->setAttribute( 275 element->setAttribute(
313 QualifiedName(nullAtom, "attr1", HTMLNames::xhtmlNamespaceURI), "v1"); 276 QualifiedName(nullAtom, "attr1", HTMLNames::xhtmlNamespaceURI), "v1");
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 << "adoptedCallback should have been passed the new owner document"; 411 << "adoptedCallback should have been passed the new owner document";
449 412
450 EXPECT_EQ(2u, definition->m_logs.size()) 413 EXPECT_EQ(2u, definition->m_logs.size())
451 << "adoptNode() should not invoke other callbacks"; 414 << "adoptNode() should not invoke other callbacks";
452 } 415 }
453 416
454 // TODO(dominicc): Add tests which adjust the "is" attribute when type 417 // TODO(dominicc): Add tests which adjust the "is" attribute when type
455 // extensions are implemented. 418 // extensions are implemented.
456 419
457 } // namespace blink 420 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Document.cpp ('k') | third_party/WebKit/Source/core/dom/custom/CustomElementTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698