| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef LayoutTestHelper_h | 5 #ifndef LayoutTestHelper_h |
| 6 #define LayoutTestHelper_h | 6 #define LayoutTestHelper_h |
| 7 | 7 |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/frame/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
| 10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| 11 #include "core/frame/Settings.h" | 11 #include "core/frame/Settings.h" |
| 12 #include "core/html/HTMLElement.h" | 12 #include "core/html/HTMLElement.h" |
| 13 #include "core/layout/api/LayoutAPIShim.h" | 13 #include "core/layout/api/LayoutAPIShim.h" |
| 14 #include "core/layout/api/LayoutViewItem.h" | 14 #include "core/layout/api/LayoutViewItem.h" |
| 15 #include "core/loader/EmptyClients.h" | 15 #include "core/loader/EmptyClients.h" |
| 16 #include "core/testing/DummyPageHolder.h" | 16 #include "core/testing/DummyPageHolder.h" |
| 17 #include "wtf/Allocator.h" | 17 #include "wtf/Allocator.h" |
| 18 #include <gtest/gtest.h> | 18 #include <gtest/gtest.h> |
| 19 #include <memory> | 19 #include <memory> |
| 20 | 20 |
| 21 namespace blink { | 21 namespace blink { |
| 22 | 22 |
| 23 class SingleChildFrameLoaderClient final : public EmptyFrameLoaderClient { |
| 24 public: |
| 25 static SingleChildFrameLoaderClient* create() { |
| 26 return new SingleChildFrameLoaderClient(); |
| 27 } |
| 28 |
| 29 void setChildHTML(const String& childHTML) { m_childHTML = childHTML; } |
| 30 |
| 31 DEFINE_INLINE_VIRTUAL_TRACE() { |
| 32 visitor->trace(m_child); |
| 33 EmptyFrameLoaderClient::trace(visitor); |
| 34 } |
| 35 |
| 36 // FrameLoaderClient overrides: |
| 37 LocalFrame* firstChild() const override { return m_child.get(); } |
| 38 LocalFrame* createFrame(const FrameLoadRequest&, |
| 39 const AtomicString& name, |
| 40 HTMLFrameOwnerElement*) override; |
| 41 |
| 42 void didDetachChild() { m_child = nullptr; } |
| 43 |
| 44 private: |
| 45 explicit SingleChildFrameLoaderClient() {} |
| 46 |
| 47 String m_childHTML; |
| 48 Member<LocalFrame> m_child; |
| 49 }; |
| 50 |
| 51 class FrameLoaderClientWithParent final : public EmptyFrameLoaderClient { |
| 52 public: |
| 53 static FrameLoaderClientWithParent* create(LocalFrame* parent) { |
| 54 return new FrameLoaderClientWithParent(parent); |
| 55 } |
| 56 |
| 57 DEFINE_INLINE_VIRTUAL_TRACE() { |
| 58 visitor->trace(m_parent); |
| 59 EmptyFrameLoaderClient::trace(visitor); |
| 60 } |
| 61 |
| 62 // FrameClient overrides: |
| 63 void detached(FrameDetachType) override; |
| 64 LocalFrame* parent() const override { return m_parent.get(); } |
| 65 |
| 66 private: |
| 67 explicit FrameLoaderClientWithParent(LocalFrame* parent) : m_parent(parent) {} |
| 68 |
| 69 Member<LocalFrame> m_parent; |
| 70 }; |
| 71 |
| 23 class RenderingTest : public testing::Test { | 72 class RenderingTest : public testing::Test { |
| 24 USING_FAST_MALLOC(RenderingTest); | 73 USING_FAST_MALLOC(RenderingTest); |
| 25 | 74 |
| 26 public: | 75 public: |
| 27 virtual FrameSettingOverrideFunction settingOverrider() const { | 76 virtual FrameSettingOverrideFunction settingOverrider() const { |
| 28 return nullptr; | 77 return nullptr; |
| 29 } | 78 } |
| 30 | 79 |
| 31 RenderingTest(FrameLoaderClient* = nullptr); | 80 RenderingTest(FrameLoaderClient* = nullptr); |
| 32 | 81 |
| 33 protected: | 82 protected: |
| 34 void SetUp() override; | 83 void SetUp() override; |
| 35 void TearDown() override; | 84 void TearDown() override; |
| 36 | 85 |
| 37 Document& document() const { return m_pageHolder->document(); } | 86 Document& document() const { return m_pageHolder->document(); } |
| 38 LayoutView& layoutView() const { | 87 LayoutView& layoutView() const { |
| 39 return *toLayoutView( | 88 return *toLayoutView( |
| 40 LayoutAPIShim::layoutObjectFrom(document().view()->layoutViewItem())); | 89 LayoutAPIShim::layoutObjectFrom(document().view()->layoutViewItem())); |
| 41 } | 90 } |
| 42 | 91 |
| 43 // Both sets the inner html and runs the document lifecycle. | 92 // Both sets the inner html and runs the document lifecycle. |
| 44 void setBodyInnerHTML(const String& htmlContent) { | 93 void setBodyInnerHTML(const String& htmlContent) { |
| 45 document().body()->setInnerHTML(htmlContent, ASSERT_NO_EXCEPTION); | 94 document().body()->setInnerHTML(htmlContent, ASSERT_NO_EXCEPTION); |
| 46 document().view()->updateAllLifecyclePhases(); | 95 document().view()->updateAllLifecyclePhases(); |
| 47 } | 96 } |
| 48 | 97 |
| 49 // Returns the Document for the iframe. | 98 // Sets the content that will be loaded into the child iframe. |
| 50 Document& setupChildIframe(const AtomicString& iframeElementId, | 99 void setChildFrameHTML(const String htmlContent) { |
| 51 const String& htmlContentOfIframe); | 100 static_cast<SingleChildFrameLoaderClient*>(m_frameLoaderClient.get()) |
| 101 ->setChildHTML(htmlContent); |
| 102 } |
| 103 |
| 104 Document& childDocument() { |
| 105 return *static_cast<SingleChildFrameLoaderClient*>( |
| 106 m_frameLoaderClient.get()) |
| 107 ->firstChild() |
| 108 ->document(); |
| 109 } |
| 52 | 110 |
| 53 // Both enables compositing and runs the document lifecycle. | 111 // Both enables compositing and runs the document lifecycle. |
| 54 void enableCompositing() { | 112 void enableCompositing() { |
| 55 m_pageHolder->page().settings().setAcceleratedCompositingEnabled(true); | 113 m_pageHolder->page().settings().setAcceleratedCompositingEnabled(true); |
| 56 document().view()->setParentVisible(true); | 114 document().view()->setParentVisible(true); |
| 57 document().view()->setSelfVisible(true); | 115 document().view()->setSelfVisible(true); |
| 58 document().view()->updateAllLifecyclePhases(); | 116 document().view()->updateAllLifecyclePhases(); |
| 59 } | 117 } |
| 60 | 118 |
| 61 LayoutObject* getLayoutObjectByElementId(const char* id) const { | 119 LayoutObject* getLayoutObjectByElementId(const char* id) const { |
| 62 Node* node = document().getElementById(id); | 120 Node* node = document().getElementById(id); |
| 63 return node ? node->layoutObject() : nullptr; | 121 return node ? node->layoutObject() : nullptr; |
| 64 } | 122 } |
| 65 | 123 |
| 66 private: | 124 private: |
| 67 Persistent<LocalFrame> m_subframe; | |
| 68 Persistent<FrameLoaderClient> m_frameLoaderClient; | 125 Persistent<FrameLoaderClient> m_frameLoaderClient; |
| 69 Persistent<FrameLoaderClient> m_childFrameLoaderClient; | |
| 70 std::unique_ptr<DummyPageHolder> m_pageHolder; | 126 std::unique_ptr<DummyPageHolder> m_pageHolder; |
| 71 }; | 127 }; |
| 72 | 128 |
| 73 class SingleChildFrameLoaderClient final : public EmptyFrameLoaderClient { | |
| 74 public: | |
| 75 static SingleChildFrameLoaderClient* create() { | |
| 76 return new SingleChildFrameLoaderClient; | |
| 77 } | |
| 78 | |
| 79 DEFINE_INLINE_VIRTUAL_TRACE() { | |
| 80 visitor->trace(m_child); | |
| 81 EmptyFrameLoaderClient::trace(visitor); | |
| 82 } | |
| 83 | |
| 84 Frame* firstChild() const override { return m_child.get(); } | |
| 85 | |
| 86 void setChild(Frame* child) { m_child = child; } | |
| 87 | |
| 88 private: | |
| 89 SingleChildFrameLoaderClient() : m_child(nullptr) {} | |
| 90 | |
| 91 Member<Frame> m_child; | |
| 92 }; | |
| 93 | |
| 94 class FrameLoaderClientWithParent final : public EmptyFrameLoaderClient { | |
| 95 public: | |
| 96 static FrameLoaderClientWithParent* create(Frame* parent) { | |
| 97 return new FrameLoaderClientWithParent(parent); | |
| 98 } | |
| 99 | |
| 100 DEFINE_INLINE_VIRTUAL_TRACE() { | |
| 101 visitor->trace(m_parent); | |
| 102 EmptyFrameLoaderClient::trace(visitor); | |
| 103 } | |
| 104 | |
| 105 Frame* parent() const override { return m_parent.get(); } | |
| 106 | |
| 107 private: | |
| 108 explicit FrameLoaderClientWithParent(Frame* parent) : m_parent(parent) {} | |
| 109 | |
| 110 Member<Frame> m_parent; | |
| 111 }; | |
| 112 | |
| 113 } // namespace blink | 129 } // namespace blink |
| 114 | 130 |
| 115 #endif // LayoutTestHelper_h | 131 #endif // LayoutTestHelper_h |
| OLD | NEW |