| OLD | NEW |
| 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/frame/LocalFrame.h" | 5 #include "core/frame/LocalFrame.h" |
| 6 | 6 |
| 7 #include "core/editing/FrameSelection.h" | 7 #include "core/editing/FrameSelection.h" |
| 8 #include "core/frame/FrameHost.h" | 8 #include "core/frame/FrameHost.h" |
| 9 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
| 10 #include "core/frame/VisualViewport.h" | 10 #include "core/frame/VisualViewport.h" |
| 11 #include "core/html/HTMLElement.h" | 11 #include "core/html/HTMLElement.h" |
| 12 #include "core/inspector/InspectorWebPerfAgent.h" |
| 12 #include "core/layout/LayoutObject.h" | 13 #include "core/layout/LayoutObject.h" |
| 13 #include "core/testing/DummyPageHolder.h" | 14 #include "core/testing/DummyPageHolder.h" |
| 15 #include "core/timing/Performance.h" |
| 14 #include "platform/DragImage.h" | 16 #include "platform/DragImage.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 18 |
| 17 namespace blink { | 19 namespace blink { |
| 18 | 20 |
| 19 class LocalFrameTest : public ::testing::Test { | 21 class LocalFrameTest : public ::testing::Test { |
| 20 protected: | 22 protected: |
| 21 LocalFrameTest() = default; | 23 LocalFrameTest() = default; |
| 22 ~LocalFrameTest() override = default; | 24 ~LocalFrameTest() override = default; |
| 23 | 25 |
| 24 Document& document() const { return m_dummyPageHolder->document(); } | 26 Document& document() const { return m_dummyPageHolder->document(); } |
| 25 LocalFrame& frame() const { return *document().frame(); } | 27 LocalFrame& frame() const { return *document().frame(); } |
| 28 Performance* performance() const { return m_performance; } |
| 26 | 29 |
| 27 void setBodyContent(const std::string& bodyContent) { | 30 void setBodyContent(const std::string& bodyContent) { |
| 28 document().body()->setInnerHTML(String::fromUTF8(bodyContent.c_str()), | 31 document().body()->setInnerHTML(String::fromUTF8(bodyContent.c_str()), |
| 29 ASSERT_NO_EXCEPTION); | 32 ASSERT_NO_EXCEPTION); |
| 30 updateAllLifecyclePhases(); | 33 updateAllLifecyclePhases(); |
| 31 } | 34 } |
| 32 | 35 |
| 33 void updateAllLifecyclePhases() { | 36 void updateAllLifecyclePhases() { |
| 34 document().view()->updateAllLifecyclePhases(); | 37 document().view()->updateAllLifecyclePhases(); |
| 35 } | 38 } |
| 36 | 39 |
| 40 bool hasWebPerformanceAgent() { return frame().m_inspectorWebPerfAgent; } |
| 41 bool hasWebPerformanceAgentObservers() { |
| 42 return frame().m_inspectorWebPerfAgent->hasWebPerformanceObservers(); |
| 43 } |
| 44 |
| 37 private: | 45 private: |
| 38 void SetUp() override { | 46 void SetUp() override { |
| 39 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); | 47 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); |
| 48 m_performance = Performance::create(&frame()); |
| 40 } | 49 } |
| 41 | 50 |
| 42 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | 51 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 52 Persistent<Performance> m_performance; |
| 43 }; | 53 }; |
| 44 | 54 |
| 45 TEST_F(LocalFrameTest, nodeImage) { | 55 TEST_F(LocalFrameTest, nodeImage) { |
| 46 setBodyContent( | 56 setBodyContent( |
| 47 "<style>" | 57 "<style>" |
| 48 "#sample { width: 100px; height: 100px; }" | 58 "#sample { width: 100px; height: 100px; }" |
| 49 "</style>" | 59 "</style>" |
| 50 "<div id=sample></div>"); | 60 "<div id=sample></div>"); |
| 51 Element* sample = document().getElementById("sample"); | 61 Element* sample = document().getElementById("sample"); |
| 52 const std::unique_ptr<DragImage> image = frame().nodeImage(*sample); | 62 const std::unique_ptr<DragImage> image = frame().nodeImage(*sample); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 frame().selection().selectAll(); | 141 frame().selection().selectAll(); |
| 132 updateAllLifecyclePhases(); | 142 updateAllLifecyclePhases(); |
| 133 const std::unique_ptr<DragImage> image2(frame().dragImageForSelection(0.75f)); | 143 const std::unique_ptr<DragImage> image2(frame().dragImageForSelection(0.75f)); |
| 134 | 144 |
| 135 EXPECT_GT(image1->size().width(), 0); | 145 EXPECT_GT(image1->size().width(), 0); |
| 136 EXPECT_GT(image1->size().height(), 0); | 146 EXPECT_GT(image1->size().height(), 0); |
| 137 EXPECT_EQ(image1->size().width() * 2, image2->size().width()); | 147 EXPECT_EQ(image1->size().width() * 2, image2->size().width()); |
| 138 EXPECT_EQ(image1->size().height() * 2, image2->size().height()); | 148 EXPECT_EQ(image1->size().height() * 2, image2->size().height()); |
| 139 } | 149 } |
| 140 | 150 |
| 151 TEST_F(LocalFrameTest, LongTaskObserverInstrumentation) { |
| 152 EXPECT_FALSE(hasWebPerformanceAgent()); |
| 153 frame().enableInspectorWebPerfAgent(performance()); |
| 154 EXPECT_TRUE(hasWebPerformanceAgent()); |
| 155 EXPECT_TRUE(hasWebPerformanceAgentObservers()); |
| 156 |
| 157 frame().disableInspectorWebPerfAgent(performance()); |
| 158 EXPECT_FALSE(hasWebPerformanceAgent()); |
| 159 } |
| 160 |
| 141 } // namespace blink | 161 } // namespace blink |
| OLD | NEW |