Chromium Code Reviews| Index: third_party/WebKit/Source/core/page/DragControllerTest.cpp |
| diff --git a/third_party/WebKit/Source/core/page/DragControllerTest.cpp b/third_party/WebKit/Source/core/page/DragControllerTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4b4204b9c988eb4bb6da1ff143e96d29c9379181 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/page/DragControllerTest.cpp |
| @@ -0,0 +1,69 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
|
tkent
2017/06/19 00:12:45
Though git failed to detect file copy, this file i
tanvir
2017/06/19 07:01:33
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "core/page/DragController.h" |
| + |
| +#include "core/editing/FrameSelection.h" |
| +#include "core/frame/LocalFrame.h" |
| +#include "core/frame/LocalFrameView.h" |
| +#include "core/frame/PerformanceMonitor.h" |
| +#include "core/frame/VisualViewport.h" |
| +#include "core/html/HTMLElement.h" |
| +#include "core/layout/LayoutObject.h" |
| +#include "core/testing/DummyPageHolder.h" |
| +#include "core/timing/Performance.h" |
| +#include "platform/DragImage.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace blink { |
| + |
| +class DragControllerTest : public ::testing::Test { |
| + protected: |
| + DragControllerTest() = default; |
| + ~DragControllerTest() override = default; |
| + |
| + Document& GetDocument() const { return dummy_page_holder_->GetDocument(); } |
| + LocalFrame& GetFrame() const { return *GetDocument().GetFrame(); } |
| + Performance* GetPerformance() const { return performance_; } |
| + |
| + void SetBodyContent(const std::string& body_content) { |
| + GetDocument().body()->setInnerHTML(String::FromUTF8(body_content.c_str())); |
| + UpdateAllLifecyclePhases(); |
| + } |
| + |
| + void UpdateAllLifecyclePhases() { |
| + GetDocument().View()->UpdateAllLifecyclePhases(); |
| + } |
| + |
| + private: |
| + void SetUp() override { |
| + dummy_page_holder_ = DummyPageHolder::Create(IntSize(800, 600)); |
| + performance_ = Performance::Create(&GetFrame()); |
| + } |
| + |
| + std::unique_ptr<DummyPageHolder> dummy_page_holder_; |
| + Persistent<Performance> performance_; |
| +}; |
| + |
| +TEST_F(DragControllerTest, dragImageForSelectionUsesPageScaleFactor) { |
| + SetBodyContent( |
| + "<div>Hello world! This tests that the bitmap for drag image is scaled " |
| + "by page scale factor</div>"); |
| + GetFrame().GetPage()->GetVisualViewport().SetScale(1); |
| + GetFrame().Selection().SelectAll(); |
| + UpdateAllLifecyclePhases(); |
| + const std::unique_ptr<DragImage> image1( |
| + DragController::DragImageForSelection(GetFrame(), 0.75f)); |
| + GetFrame().GetPage()->GetVisualViewport().SetScale(2); |
| + GetFrame().Selection().SelectAll(); |
| + UpdateAllLifecyclePhases(); |
| + const std::unique_ptr<DragImage> image2( |
| + DragController::DragImageForSelection(GetFrame(), 0.75f)); |
| + |
| + EXPECT_GT(image1->Size().Width(), 0); |
| + EXPECT_GT(image1->Size().Height(), 0); |
| + EXPECT_EQ(image1->Size().Width() * 2, image2->Size().Width()); |
| + EXPECT_EQ(image1->Size().Height() * 2, image2->Size().Height()); |
| +} |
| +} // namespace blink |