OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/shadow/FlatTreeTraversal.h" | 5 #include "core/dom/shadow/FlatTreeTraversal.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 7 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/dom/Element.h" | 9 #include "core/dom/Element.h" |
10 #include "core/dom/Node.h" | 10 #include "core/dom/Node.h" |
11 #include "core/dom/NodeTraversal.h" | 11 #include "core/dom/NodeTraversal.h" |
12 #include "core/dom/shadow/ShadowRoot.h" | 12 #include "core/dom/shadow/ShadowRoot.h" |
13 #include "core/frame/FrameView.h" | 13 #include "core/frame/FrameView.h" |
14 #include "core/html/HTMLDocument.h" | |
15 #include "core/html/HTMLElement.h" | 14 #include "core/html/HTMLElement.h" |
16 #include "core/testing/DummyPageHolder.h" | 15 #include "core/testing/DummyPageHolder.h" |
17 #include "platform/geometry/IntSize.h" | 16 #include "platform/geometry/IntSize.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "wtf/Compiler.h" | 18 #include "wtf/Compiler.h" |
20 #include "wtf/StdLibExtras.h" | 19 #include "wtf/StdLibExtras.h" |
21 #include "wtf/Vector.h" | 20 #include "wtf/Vector.h" |
22 #include <memory> | 21 #include <memory> |
23 | 22 |
24 namespace blink { | 23 namespace blink { |
25 | 24 |
26 class FlatTreeTraversalTest : public ::testing::Test { | 25 class FlatTreeTraversalTest : public ::testing::Test { |
27 protected: | 26 protected: |
28 HTMLDocument& document() const; | 27 Document& document() const; |
29 | 28 |
30 // Sets |mainHTML| to BODY element with |innerHTML| property and attaches | 29 // Sets |mainHTML| to BODY element with |innerHTML| property and attaches |
31 // shadow root to child with |shadowHTML|, then update distribution for | 30 // shadow root to child with |shadowHTML|, then update distribution for |
32 // calling member functions in |FlatTreeTraversal|. | 31 // calling member functions in |FlatTreeTraversal|. |
33 void setupSampleHTML(const char* mainHTML, const char* shadowHTML, unsigned)
; | 32 void setupSampleHTML(const char* mainHTML, const char* shadowHTML, unsigned)
; |
34 | 33 |
35 void setupDocumentTree(const char* mainHTML); | 34 void setupDocumentTree(const char* mainHTML); |
36 | 35 |
37 void attachV0ShadowRoot(Element& shadowHost, const char* shadowInnerHTML); | 36 void attachV0ShadowRoot(Element& shadowHost, const char* shadowInnerHTML); |
38 void attachOpenShadowRoot(Element& shadowHost, const char* shadowInnerHTML); | 37 void attachOpenShadowRoot(Element& shadowHost, const char* shadowInnerHTML); |
39 | 38 |
40 private: | 39 private: |
41 void SetUp() override; | 40 void SetUp() override; |
42 | 41 |
43 Persistent<HTMLDocument> m_document; | 42 Persistent<Document> m_document; |
44 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 43 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
45 }; | 44 }; |
46 | 45 |
47 void FlatTreeTraversalTest::SetUp() | 46 void FlatTreeTraversalTest::SetUp() |
48 { | 47 { |
49 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); | 48 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); |
50 m_document = toHTMLDocument(&m_dummyPageHolder->document()); | 49 m_document = &m_dummyPageHolder->document(); |
51 DCHECK(m_document); | 50 DCHECK(m_document); |
52 } | 51 } |
53 | 52 |
54 HTMLDocument& FlatTreeTraversalTest::document() const | 53 Document& FlatTreeTraversalTest::document() const |
55 { | 54 { |
56 return *m_document; | 55 return *m_document; |
57 } | 56 } |
58 | 57 |
59 void FlatTreeTraversalTest::setupSampleHTML(const char* mainHTML, const char* sh
adowHTML, unsigned index) | 58 void FlatTreeTraversalTest::setupSampleHTML(const char* mainHTML, const char* sh
adowHTML, unsigned index) |
60 { | 59 { |
61 Element* body = document().body(); | 60 Element* body = document().body(); |
62 body->setInnerHTML(String::fromUTF8(mainHTML), ASSERT_NO_EXCEPTION); | 61 body->setInnerHTML(String::fromUTF8(mainHTML), ASSERT_NO_EXCEPTION); |
63 Element* shadowHost = toElement(NodeTraversal::childAt(*body, index)); | 62 Element* shadowHost = toElement(NodeTraversal::childAt(*body, index)); |
64 ShadowRoot* shadowRoot = shadowHost->createShadowRootInternal(ShadowRootType
::V0, ASSERT_NO_EXCEPTION); | 63 ShadowRoot* shadowRoot = shadowHost->createShadowRootInternal(ShadowRootType
::V0, ASSERT_NO_EXCEPTION); |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 | 561 |
563 EXPECT_EQ(d11, FlatTreeTraversal::parent(*d111)); | 562 EXPECT_EQ(d11, FlatTreeTraversal::parent(*d111)); |
564 EXPECT_EQ(d11, FlatTreeTraversal::parent(*d112)); | 563 EXPECT_EQ(d11, FlatTreeTraversal::parent(*d112)); |
565 EXPECT_EQ(d11, FlatTreeTraversal::parent(*d2)); | 564 EXPECT_EQ(d11, FlatTreeTraversal::parent(*d2)); |
566 EXPECT_EQ(d11, FlatTreeTraversal::parent(*d14)); | 565 EXPECT_EQ(d11, FlatTreeTraversal::parent(*d14)); |
567 EXPECT_EQ(nullptr, FlatTreeTraversal::parent(*d3)); | 566 EXPECT_EQ(nullptr, FlatTreeTraversal::parent(*d3)); |
568 EXPECT_EQ(nullptr, FlatTreeTraversal::parent(*d4)); | 567 EXPECT_EQ(nullptr, FlatTreeTraversal::parent(*d4)); |
569 } | 568 } |
570 | 569 |
571 } // namespace blink | 570 } // namespace blink |
OLD | NEW |