| 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/LocalFrameView.h" | 8 #include "core/frame/LocalFrameView.h" |
| 9 #include "core/frame/PerformanceMonitor.h" | 9 #include "core/frame/PerformanceMonitor.h" |
| 10 #include "core/frame/VisualViewport.h" | 10 #include "core/frame/VisualViewport.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 Persistent<Performance> performance_; | 45 Persistent<Performance> performance_; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 TEST_F(LocalFrameTest, nodeImage) { | 48 TEST_F(LocalFrameTest, nodeImage) { |
| 49 SetBodyContent( | 49 SetBodyContent( |
| 50 "<style>" | 50 "<style>" |
| 51 "#sample { width: 100px; height: 100px; }" | 51 "#sample { width: 100px; height: 100px; }" |
| 52 "</style>" | 52 "</style>" |
| 53 "<div id=sample></div>"); | 53 "<div id=sample></div>"); |
| 54 Element* sample = GetDocument().getElementById("sample"); | 54 Element* sample = GetDocument().getElementById("sample"); |
| 55 const std::unique_ptr<DragImage> image = GetFrame().NodeImage(*sample); | 55 const std::unique_ptr<DragImage> image = |
| 56 GetFrame().NodeImage(GetFrame(), *sample); |
| 56 EXPECT_EQ(IntSize(100, 100), image->Size()); | 57 EXPECT_EQ(IntSize(100, 100), image->Size()); |
| 57 } | 58 } |
| 58 | 59 |
| 59 TEST_F(LocalFrameTest, nodeImageWithNestedElement) { | 60 TEST_F(LocalFrameTest, nodeImageWithNestedElement) { |
| 60 SetBodyContent( | 61 SetBodyContent( |
| 61 "<style>" | 62 "<style>" |
| 62 "div { -webkit-user-drag: element }" | 63 "div { -webkit-user-drag: element }" |
| 63 "span:-webkit-drag { color: #0F0 }" | 64 "span:-webkit-drag { color: #0F0 }" |
| 64 "</style>" | 65 "</style>" |
| 65 "<div id=sample><span>Green when dragged</span></div>"); | 66 "<div id=sample><span>Green when dragged</span></div>"); |
| 66 Element* sample = GetDocument().getElementById("sample"); | 67 Element* sample = GetDocument().getElementById("sample"); |
| 67 const std::unique_ptr<DragImage> image = GetFrame().NodeImage(*sample); | 68 const std::unique_ptr<DragImage> image = |
| 69 GetFrame().NodeImage(GetFrame(), *sample); |
| 68 EXPECT_EQ( | 70 EXPECT_EQ( |
| 69 Color(0, 255, 0), | 71 Color(0, 255, 0), |
| 70 sample->firstChild()->GetLayoutObject()->ResolveColor(CSSPropertyColor)) | 72 sample->firstChild()->GetLayoutObject()->ResolveColor(CSSPropertyColor)) |
| 71 << "Descendants node should have :-webkit-drag."; | 73 << "Descendants node should have :-webkit-drag."; |
| 72 } | 74 } |
| 73 | 75 |
| 74 TEST_F(LocalFrameTest, nodeImageWithPsuedoClassWebKitDrag) { | 76 TEST_F(LocalFrameTest, nodeImageWithPsuedoClassWebKitDrag) { |
| 75 SetBodyContent( | 77 SetBodyContent( |
| 76 "<style>" | 78 "<style>" |
| 77 "#sample { width: 100px; height: 100px; }" | 79 "#sample { width: 100px; height: 100px; }" |
| 78 "#sample:-webkit-drag { width: 200px; height: 200px; }" | 80 "#sample:-webkit-drag { width: 200px; height: 200px; }" |
| 79 "</style>" | 81 "</style>" |
| 80 "<div id=sample></div>"); | 82 "<div id=sample></div>"); |
| 81 Element* sample = GetDocument().getElementById("sample"); | 83 Element* sample = GetDocument().getElementById("sample"); |
| 82 const std::unique_ptr<DragImage> image = GetFrame().NodeImage(*sample); | 84 const std::unique_ptr<DragImage> image = |
| 85 GetFrame().NodeImage(GetFrame(), *sample); |
| 83 EXPECT_EQ(IntSize(200, 200), image->Size()) | 86 EXPECT_EQ(IntSize(200, 200), image->Size()) |
| 84 << ":-webkit-drag should affect dragged image."; | 87 << ":-webkit-drag should affect dragged image."; |
| 85 } | 88 } |
| 86 | 89 |
| 87 TEST_F(LocalFrameTest, nodeImageWithoutDraggedLayoutObject) { | 90 TEST_F(LocalFrameTest, nodeImageWithoutDraggedLayoutObject) { |
| 88 SetBodyContent( | 91 SetBodyContent( |
| 89 "<style>" | 92 "<style>" |
| 90 "#sample { width: 100px; height: 100px; }" | 93 "#sample { width: 100px; height: 100px; }" |
| 91 "#sample:-webkit-drag { display:none }" | 94 "#sample:-webkit-drag { display:none }" |
| 92 "</style>" | 95 "</style>" |
| 93 "<div id=sample></div>"); | 96 "<div id=sample></div>"); |
| 94 Element* sample = GetDocument().getElementById("sample"); | 97 Element* sample = GetDocument().getElementById("sample"); |
| 95 const std::unique_ptr<DragImage> image = GetFrame().NodeImage(*sample); | 98 const std::unique_ptr<DragImage> image = |
| 99 GetFrame().NodeImage(GetFrame(), *sample); |
| 96 EXPECT_EQ(nullptr, image.get()) << ":-webkit-drag blows away layout object"; | 100 EXPECT_EQ(nullptr, image.get()) << ":-webkit-drag blows away layout object"; |
| 97 } | 101 } |
| 98 | 102 |
| 99 TEST_F(LocalFrameTest, nodeImageWithChangingLayoutObject) { | 103 TEST_F(LocalFrameTest, nodeImageWithChangingLayoutObject) { |
| 100 SetBodyContent( | 104 SetBodyContent( |
| 101 "<style>" | 105 "<style>" |
| 102 "#sample { color: blue; }" | 106 "#sample { color: blue; }" |
| 103 "#sample:-webkit-drag { display: inline-block; color: red; }" | 107 "#sample:-webkit-drag { display: inline-block; color: red; }" |
| 104 "</style>" | 108 "</style>" |
| 105 "<span id=sample>foo</span>"); | 109 "<span id=sample>foo</span>"); |
| 106 Element* sample = GetDocument().getElementById("sample"); | 110 Element* sample = GetDocument().getElementById("sample"); |
| 107 UpdateAllLifecyclePhases(); | 111 UpdateAllLifecyclePhases(); |
| 108 LayoutObject* before_layout_object = sample->GetLayoutObject(); | 112 LayoutObject* before_layout_object = sample->GetLayoutObject(); |
| 109 const std::unique_ptr<DragImage> image = GetFrame().NodeImage(*sample); | 113 const std::unique_ptr<DragImage> image = |
| 114 GetFrame().NodeImage(GetFrame(), *sample); |
| 110 | 115 |
| 111 EXPECT_TRUE(sample->GetLayoutObject() != before_layout_object) | 116 EXPECT_TRUE(sample->GetLayoutObject() != before_layout_object) |
| 112 << ":-webkit-drag causes sample to have different layout object."; | 117 << ":-webkit-drag causes sample to have different layout object."; |
| 113 EXPECT_EQ(Color(255, 0, 0), | 118 EXPECT_EQ(Color(255, 0, 0), |
| 114 sample->GetLayoutObject()->ResolveColor(CSSPropertyColor)) | 119 sample->GetLayoutObject()->ResolveColor(CSSPropertyColor)) |
| 115 << "#sample has :-webkit-drag."; | 120 << "#sample has :-webkit-drag."; |
| 116 | 121 |
| 117 // Layout w/o :-webkit-drag | 122 // Layout w/o :-webkit-drag |
| 118 UpdateAllLifecyclePhases(); | 123 UpdateAllLifecyclePhases(); |
| 119 | 124 |
| 120 EXPECT_EQ(Color(0, 0, 255), | 125 EXPECT_EQ(Color(0, 0, 255), |
| 121 sample->GetLayoutObject()->ResolveColor(CSSPropertyColor)) | 126 sample->GetLayoutObject()->ResolveColor(CSSPropertyColor)) |
| 122 << "#sample doesn't have :-webkit-drag."; | 127 << "#sample doesn't have :-webkit-drag."; |
| 123 } | 128 } |
| 124 | 129 |
| 125 TEST_F(LocalFrameTest, dragImageForSelectionUsesPageScaleFactor) { | 130 TEST_F(LocalFrameTest, dragImageForSelectionUsesPageScaleFactor) { |
| 126 SetBodyContent( | 131 SetBodyContent( |
| 127 "<div>Hello world! This tests that the bitmap for drag image is scaled " | 132 "<div>Hello world! This tests that the bitmap for drag image is scaled " |
| 128 "by page scale factor</div>"); | 133 "by page scale factor</div>"); |
| 129 GetFrame().GetPage()->GetVisualViewport().SetScale(1); | 134 GetFrame().GetPage()->GetVisualViewport().SetScale(1); |
| 130 GetFrame().Selection().SelectAll(); | 135 GetFrame().Selection().SelectAll(); |
| 131 UpdateAllLifecyclePhases(); | 136 UpdateAllLifecyclePhases(); |
| 132 const std::unique_ptr<DragImage> image1( | 137 const std::unique_ptr<DragImage> image1( |
| 133 GetFrame().DragImageForSelection(0.75f)); | 138 GetFrame().DragImageForSelection(GetFrame(), 0.75f)); |
| 134 GetFrame().GetPage()->GetVisualViewport().SetScale(2); | 139 GetFrame().GetPage()->GetVisualViewport().SetScale(2); |
| 135 GetFrame().Selection().SelectAll(); | 140 GetFrame().Selection().SelectAll(); |
| 136 UpdateAllLifecyclePhases(); | 141 UpdateAllLifecyclePhases(); |
| 137 const std::unique_ptr<DragImage> image2( | 142 const std::unique_ptr<DragImage> image2( |
| 138 GetFrame().DragImageForSelection(0.75f)); | 143 GetFrame().DragImageForSelection(GetFrame(), 0.75f)); |
| 139 | 144 |
| 140 EXPECT_GT(image1->Size().Width(), 0); | 145 EXPECT_GT(image1->Size().Width(), 0); |
| 141 EXPECT_GT(image1->Size().Height(), 0); | 146 EXPECT_GT(image1->Size().Height(), 0); |
| 142 EXPECT_EQ(image1->Size().Width() * 2, image2->Size().Width()); | 147 EXPECT_EQ(image1->Size().Width() * 2, image2->Size().Width()); |
| 143 EXPECT_EQ(image1->Size().Height() * 2, image2->Size().Height()); | 148 EXPECT_EQ(image1->Size().Height() * 2, image2->Size().Height()); |
| 144 } | 149 } |
| 145 | 150 |
| 146 } // namespace blink | 151 } // namespace blink |
| OLD | NEW |