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

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

Issue 2200613002: The HTML parser synchronously creates custom elements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Eliminate redundant TODOs. Created 4 years, 4 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/CustomElementsRegistry.h" 5 #include "core/dom/custom/CustomElementsRegistry.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/ScriptValue.h" 8 #include "bindings/core/v8/ScriptValue.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/dom/Element.h" 10 #include "core/dom/Element.h"
11 #include "core/dom/ElementRegistrationOptions.h" 11 #include "core/dom/ElementRegistrationOptions.h"
12 #include "core/dom/custom/CEReactionsScope.h" 12 #include "core/dom/custom/CEReactionsScope.h"
13 #include "core/dom/custom/CustomElementDefinition.h" 13 #include "core/dom/custom/CustomElementDefinition.h"
14 #include "core/dom/custom/CustomElementDefinitionBuilder.h" 14 #include "core/dom/custom/CustomElementDefinitionBuilder.h"
15 #include "core/dom/custom/CustomElementDescriptor.h" 15 #include "core/dom/custom/CustomElementDescriptor.h"
16 #include "core/dom/custom/CustomElementTestHelpers.h" 16 #include "core/dom/custom/CustomElementTestHelpers.h"
17 #include "core/dom/shadow/ShadowRoot.h" 17 #include "core/dom/shadow/ShadowRoot.h"
18 #include "core/dom/shadow/ShadowRootInit.h" 18 #include "core/dom/shadow/ShadowRootInit.h"
19 #include "core/testing/DummyPageHolder.h" 19 #include "core/testing/DummyPageHolder.h"
20 #include "platform/ScriptForbiddenScope.h" 20 #include "platform/ScriptForbiddenScope.h"
21 #include "platform/heap/Handle.h" 21 #include "platform/heap/Handle.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 #include "wtf/text/AtomicString.h" 23 #include "wtf/text/AtomicString.h"
24 #include <memory> 24 #include <memory>
25 25
26 namespace blink { 26 namespace blink {
27 27
28 class CustomElementsRegistryTestBase : public ::testing::Test { 28 class CustomElementsRegistryTest : public ::testing::Test {
29 protected: 29 protected:
30 virtual Document& document() = 0; 30 void SetUp()
31 virtual CustomElementsRegistry& registry() = 0;
32
33 void collectCandidates(
34 const CustomElementDescriptor& desc,
35 HeapVector<Member<Element>>* elements)
36 { 31 {
37 registry().collectCandidates(desc, elements);
38 }
39 };
40
41 class CustomElementsRegistryTest : public CustomElementsRegistryTestBase {
42 protected:
43 void SetUp() override
44 {
45 CustomElementsRegistryTestBase::SetUp();
46
47 m_document = HTMLDocument::create();
48 m_document->appendChild(CreateElement("html").inDocument(m_document));
49
50 m_registry = CustomElementsRegistry::create(m_document);
51 }
52
53 void TearDown() override
54 {
55 m_document = nullptr;
56 m_registry = nullptr;
57 CustomElementsRegistryTestBase::TearDown();
58 }
59
60 Document& document() override { return *m_document; }
61 CustomElementsRegistry& registry() override { return *m_registry; }
62
63 private:
64 Persistent<Document> m_document;
65 Persistent<CustomElementsRegistry> m_registry;
66 };
67
68 class CustomElementsRegistryFrameTest : public CustomElementsRegistryTestBase {
69 protected:
70 void SetUp() override
71 {
72 CustomElementsRegistryTestBase::SetUp();
73 m_page.reset(DummyPageHolder::create(IntSize(1, 1)).release()); 32 m_page.reset(DummyPageHolder::create(IntSize(1, 1)).release());
74 } 33 }
75 34
76 void TearDown() override 35 void TearDown()
77 { 36 {
78 m_page = nullptr; 37 m_page = nullptr;
79 CustomElementsRegistryTestBase::TearDown();
80 } 38 }
81 39
82 Document& document() override { return m_page->document(); } 40 Document& document() { return m_page->document(); }
83 41
84 CustomElementsRegistry& registry() override 42 CustomElementsRegistry& registry()
85 { 43 {
86 return *m_page->frame().localDOMWindow()->customElements(); 44 return *m_page->frame().localDOMWindow()->customElements();
87 } 45 }
88 46
89 ScriptState* scriptState() 47 ScriptState* scriptState()
90 { 48 {
91 return ScriptState::forMainWorld(&m_page->frame()); 49 return ScriptState::forMainWorld(&m_page->frame());
92 } 50 }
93 51
52 void collectCandidates(
53 const CustomElementDescriptor& desc,
54 HeapVector<Member<Element>>* elements)
55 {
56 registry().collectCandidates(desc, elements);
57 }
58
94 ShadowRoot* attachShadowTo(Element* element) 59 ShadowRoot* attachShadowTo(Element* element)
95 { 60 {
96 NonThrowableExceptionState noExceptions; 61 NonThrowableExceptionState noExceptions;
97 ShadowRootInit shadowRootInit; 62 ShadowRootInit shadowRootInit;
98 return 63 return
99 element->attachShadow(scriptState(), shadowRootInit, noExceptions); 64 element->attachShadow(scriptState(), shadowRootInit, noExceptions);
100 } 65 }
101 66
102 private: 67 private:
103 std::unique_ptr<DummyPageHolder> m_page; 68 std::unique_ptr<DummyPageHolder> m_page;
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 bool checkConstructorIntrinsics() override { return true; } 319 bool checkConstructorIntrinsics() override { return true; }
355 bool checkConstructorNotRegistered() override { return true; } 320 bool checkConstructorNotRegistered() override { return true; }
356 bool checkPrototype() override { return true; } 321 bool checkPrototype() override { return true; }
357 bool rememberOriginalProperties() override { return true; } 322 bool rememberOriginalProperties() override { return true; }
358 CustomElementDefinition* build( 323 CustomElementDefinition* build(
359 const CustomElementDescriptor& descriptor) { 324 const CustomElementDescriptor& descriptor) {
360 return new LogUpgradeDefinition(descriptor); 325 return new LogUpgradeDefinition(descriptor);
361 } 326 }
362 }; 327 };
363 328
364 TEST_F(CustomElementsRegistryFrameTest, define_upgradesInDocumentElements) 329 TEST_F(CustomElementsRegistryTest, define_upgradesInDocumentElements)
365 { 330 {
366 ScriptForbiddenScope doNotRelyOnScript; 331 ScriptForbiddenScope doNotRelyOnScript;
367 332
368 Element* element = CreateElement("a-a").inDocument(&document()); 333 Element* element = CreateElement("a-a").inDocument(&document());
369 element->setAttribute(QualifiedName(nullAtom, "attr1", HTMLNames::xhtmlNames paceURI), "v1"); 334 element->setAttribute(QualifiedName(nullAtom, "attr1", HTMLNames::xhtmlNames paceURI), "v1");
370 element->setBooleanAttribute(HTMLNames::contenteditableAttr, true); 335 element->setBooleanAttribute(HTMLNames::contenteditableAttr, true);
371 document().documentElement()->appendChild(element); 336 document().documentElement()->appendChild(element);
372 337
373 LogUpgradeBuilder builder; 338 LogUpgradeBuilder builder;
374 NonThrowableExceptionState shouldNotThrow; 339 NonThrowableExceptionState shouldNotThrow;
(...skipping 26 matching lines...) Expand all
401 EXPECT_EQ(2u, definition->m_attributeChanged.size()) 366 EXPECT_EQ(2u, definition->m_attributeChanged.size())
402 << "Upgrade should invoke attributeChangedCallback for all attributes"; 367 << "Upgrade should invoke attributeChangedCallback for all attributes";
403 368
404 EXPECT_EQ(LogUpgradeDefinition::ConnectedCallback, definition->m_logs[3]) 369 EXPECT_EQ(LogUpgradeDefinition::ConnectedCallback, definition->m_logs[3])
405 << "upgrade should invoke connectedCallback"; 370 << "upgrade should invoke connectedCallback";
406 371
407 EXPECT_EQ(4u, definition->m_logs.size()) 372 EXPECT_EQ(4u, definition->m_logs.size())
408 << "upgrade should not invoke other callbacks"; 373 << "upgrade should not invoke other callbacks";
409 } 374 }
410 375
411 TEST_F(CustomElementsRegistryFrameTest, attributeChangedCallback) 376 TEST_F(CustomElementsRegistryTest, attributeChangedCallback)
412 { 377 {
413 ScriptForbiddenScope doNotRelyOnScript; 378 ScriptForbiddenScope doNotRelyOnScript;
414 379
415 Element* element = CreateElement("a-a").inDocument(&document()); 380 Element* element = CreateElement("a-a").inDocument(&document());
416 document().documentElement()->appendChild(element); 381 document().documentElement()->appendChild(element);
417 382
418 LogUpgradeBuilder builder; 383 LogUpgradeBuilder builder;
419 NonThrowableExceptionState shouldNotThrow; 384 NonThrowableExceptionState shouldNotThrow;
420 { 385 {
421 CEReactionsScope reactions; 386 CEReactionsScope reactions;
(...skipping 16 matching lines...) Expand all
438 EXPECT_EQ(1u, definition->m_attributeChanged.size()) 403 EXPECT_EQ(1u, definition->m_attributeChanged.size())
439 << "Adding an attribute should invoke attributeChangedCallback"; 404 << "Adding an attribute should invoke attributeChangedCallback";
440 EXPECT_EQ("attr2", definition->m_attributeChanged[0].name); 405 EXPECT_EQ("attr2", definition->m_attributeChanged[0].name);
441 EXPECT_EQ(nullAtom, definition->m_attributeChanged[0].oldValue); 406 EXPECT_EQ(nullAtom, definition->m_attributeChanged[0].oldValue);
442 EXPECT_EQ("v2", definition->m_attributeChanged[0].newValue); 407 EXPECT_EQ("v2", definition->m_attributeChanged[0].newValue);
443 408
444 EXPECT_EQ(1u, definition->m_logs.size()) 409 EXPECT_EQ(1u, definition->m_logs.size())
445 << "upgrade should not invoke other callbacks"; 410 << "upgrade should not invoke other callbacks";
446 } 411 }
447 412
448 TEST_F(CustomElementsRegistryFrameTest, disconnectedCallback) 413 TEST_F(CustomElementsRegistryTest, disconnectedCallback)
449 { 414 {
450 ScriptForbiddenScope doNotRelyOnScript; 415 ScriptForbiddenScope doNotRelyOnScript;
451 416
452 Element* element = CreateElement("a-a").inDocument(&document()); 417 Element* element = CreateElement("a-a").inDocument(&document());
453 document().documentElement()->appendChild(element); 418 document().documentElement()->appendChild(element);
454 419
455 LogUpgradeBuilder builder; 420 LogUpgradeBuilder builder;
456 NonThrowableExceptionState shouldNotThrow; 421 NonThrowableExceptionState shouldNotThrow;
457 { 422 {
458 CEReactionsScope reactions; 423 CEReactionsScope reactions;
(...skipping 15 matching lines...) Expand all
474 << "remove() should invoke disconnectedCallback"; 439 << "remove() should invoke disconnectedCallback";
475 440
476 EXPECT_EQ(1u, definition->m_logs.size()) 441 EXPECT_EQ(1u, definition->m_logs.size())
477 << "remove() should not invoke other callbacks"; 442 << "remove() should not invoke other callbacks";
478 } 443 }
479 444
480 // TODO(dominicc): Add tests which adjust the "is" attribute when type 445 // TODO(dominicc): Add tests which adjust the "is" attribute when type
481 // extensions are implemented. 446 // extensions are implemented.
482 447
483 } // namespace blink 448 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698