| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "core/frame/LocalFrame.h" | |
| 6 | |
| 7 #include "core/editing/FrameSelection.h" | |
| 8 #include "core/frame/LocalFrameView.h" | |
| 9 #include "core/frame/PerformanceMonitor.h" | |
| 10 #include "core/frame/VisualViewport.h" | |
| 11 #include "core/html/HTMLElement.h" | |
| 12 #include "core/layout/LayoutObject.h" | |
| 13 #include "core/testing/DummyPageHolder.h" | |
| 14 #include "core/timing/Performance.h" | |
| 15 #include "platform/DragImage.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | |
| 17 | |
| 18 namespace blink { | |
| 19 | |
| 20 class LocalFrameTest : public ::testing::Test { | |
| 21 protected: | |
| 22 LocalFrameTest() = default; | |
| 23 ~LocalFrameTest() override = default; | |
| 24 | |
| 25 Document& GetDocument() const { return dummy_page_holder_->GetDocument(); } | |
| 26 LocalFrame& GetFrame() const { return *GetDocument().GetFrame(); } | |
| 27 Performance* GetPerformance() const { return performance_; } | |
| 28 | |
| 29 void SetBodyContent(const std::string& body_content) { | |
| 30 GetDocument().body()->setInnerHTML(String::FromUTF8(body_content.c_str())); | |
| 31 UpdateAllLifecyclePhases(); | |
| 32 } | |
| 33 | |
| 34 void UpdateAllLifecyclePhases() { | |
| 35 GetDocument().View()->UpdateAllLifecyclePhases(); | |
| 36 } | |
| 37 | |
| 38 private: | |
| 39 void SetUp() override { | |
| 40 dummy_page_holder_ = DummyPageHolder::Create(IntSize(800, 600)); | |
| 41 performance_ = Performance::Create(&GetFrame()); | |
| 42 } | |
| 43 | |
| 44 std::unique_ptr<DummyPageHolder> dummy_page_holder_; | |
| 45 Persistent<Performance> performance_; | |
| 46 }; | |
| 47 | |
| 48 TEST_F(LocalFrameTest, nodeImage) { | |
| 49 SetBodyContent( | |
| 50 "<style>" | |
| 51 "#sample { width: 100px; height: 100px; }" | |
| 52 "</style>" | |
| 53 "<div id=sample></div>"); | |
| 54 Element* sample = GetDocument().getElementById("sample"); | |
| 55 const std::unique_ptr<DragImage> image = GetFrame().NodeImage(*sample); | |
| 56 EXPECT_EQ(IntSize(100, 100), image->Size()); | |
| 57 } | |
| 58 | |
| 59 TEST_F(LocalFrameTest, nodeImageWithNestedElement) { | |
| 60 SetBodyContent( | |
| 61 "<style>" | |
| 62 "div { -webkit-user-drag: element }" | |
| 63 "span:-webkit-drag { color: #0F0 }" | |
| 64 "</style>" | |
| 65 "<div id=sample><span>Green when dragged</span></div>"); | |
| 66 Element* sample = GetDocument().getElementById("sample"); | |
| 67 const std::unique_ptr<DragImage> image = GetFrame().NodeImage(*sample); | |
| 68 EXPECT_EQ( | |
| 69 Color(0, 255, 0), | |
| 70 sample->firstChild()->GetLayoutObject()->ResolveColor(CSSPropertyColor)) | |
| 71 << "Descendants node should have :-webkit-drag."; | |
| 72 } | |
| 73 | |
| 74 TEST_F(LocalFrameTest, nodeImageWithPsuedoClassWebKitDrag) { | |
| 75 SetBodyContent( | |
| 76 "<style>" | |
| 77 "#sample { width: 100px; height: 100px; }" | |
| 78 "#sample:-webkit-drag { width: 200px; height: 200px; }" | |
| 79 "</style>" | |
| 80 "<div id=sample></div>"); | |
| 81 Element* sample = GetDocument().getElementById("sample"); | |
| 82 const std::unique_ptr<DragImage> image = GetFrame().NodeImage(*sample); | |
| 83 EXPECT_EQ(IntSize(200, 200), image->Size()) | |
| 84 << ":-webkit-drag should affect dragged image."; | |
| 85 } | |
| 86 | |
| 87 TEST_F(LocalFrameTest, nodeImageWithoutDraggedLayoutObject) { | |
| 88 SetBodyContent( | |
| 89 "<style>" | |
| 90 "#sample { width: 100px; height: 100px; }" | |
| 91 "#sample:-webkit-drag { display:none }" | |
| 92 "</style>" | |
| 93 "<div id=sample></div>"); | |
| 94 Element* sample = GetDocument().getElementById("sample"); | |
| 95 const std::unique_ptr<DragImage> image = GetFrame().NodeImage(*sample); | |
| 96 EXPECT_EQ(nullptr, image.get()) << ":-webkit-drag blows away layout object"; | |
| 97 } | |
| 98 | |
| 99 TEST_F(LocalFrameTest, nodeImageWithChangingLayoutObject) { | |
| 100 SetBodyContent( | |
| 101 "<style>" | |
| 102 "#sample { color: blue; }" | |
| 103 "#sample:-webkit-drag { display: inline-block; color: red; }" | |
| 104 "</style>" | |
| 105 "<span id=sample>foo</span>"); | |
| 106 Element* sample = GetDocument().getElementById("sample"); | |
| 107 UpdateAllLifecyclePhases(); | |
| 108 LayoutObject* before_layout_object = sample->GetLayoutObject(); | |
| 109 const std::unique_ptr<DragImage> image = GetFrame().NodeImage(*sample); | |
| 110 | |
| 111 EXPECT_TRUE(sample->GetLayoutObject() != before_layout_object) | |
| 112 << ":-webkit-drag causes sample to have different layout object."; | |
| 113 EXPECT_EQ(Color(255, 0, 0), | |
| 114 sample->GetLayoutObject()->ResolveColor(CSSPropertyColor)) | |
| 115 << "#sample has :-webkit-drag."; | |
| 116 | |
| 117 // Layout w/o :-webkit-drag | |
| 118 UpdateAllLifecyclePhases(); | |
| 119 | |
| 120 EXPECT_EQ(Color(0, 0, 255), | |
| 121 sample->GetLayoutObject()->ResolveColor(CSSPropertyColor)) | |
| 122 << "#sample doesn't have :-webkit-drag."; | |
| 123 } | |
| 124 | |
| 125 TEST_F(LocalFrameTest, dragImageForSelectionUsesPageScaleFactor) { | |
| 126 SetBodyContent( | |
| 127 "<div>Hello world! This tests that the bitmap for drag image is scaled " | |
| 128 "by page scale factor</div>"); | |
| 129 GetFrame().GetPage()->GetVisualViewport().SetScale(1); | |
| 130 GetFrame().Selection().SelectAll(); | |
| 131 UpdateAllLifecyclePhases(); | |
| 132 const std::unique_ptr<DragImage> image1( | |
| 133 GetFrame().DragImageForSelection(0.75f)); | |
| 134 GetFrame().GetPage()->GetVisualViewport().SetScale(2); | |
| 135 GetFrame().Selection().SelectAll(); | |
| 136 UpdateAllLifecyclePhases(); | |
| 137 const std::unique_ptr<DragImage> image2( | |
| 138 GetFrame().DragImageForSelection(0.75f)); | |
| 139 | |
| 140 EXPECT_GT(image1->Size().Width(), 0); | |
| 141 EXPECT_GT(image1->Size().Height(), 0); | |
| 142 EXPECT_EQ(image1->Size().Width() * 2, image2->Size().Width()); | |
| 143 EXPECT_EQ(image1->Size().Height() * 2, image2->Size().Height()); | |
| 144 } | |
| 145 | |
| 146 } // namespace blink | |
| OLD | NEW |