Don't preload rarely seen large images
[chromium-blink-merge.git] / ash / drag_drop / drag_drop_interactive_uitest.cc
blob739847bcf498112ca9e4f4add984e9d2d6b23263
1 // Copyright (c) 2013 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.
5 #include "ash/drag_drop/drag_drop_controller.h"
7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h"
9 #include "base/bind.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/path_service.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "ui/aura/window_event_dispatcher.h"
14 #include "ui/base/dragdrop/drag_drop_types.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/base/test/ui_controls.h"
17 #include "ui/base/ui_base_paths.h"
18 #include "ui/gl/gl_surface.h"
19 #include "ui/views/view.h"
20 #include "ui/views/widget/widget.h"
22 namespace ash {
23 namespace {
25 class DraggableView : public views::View {
26 public:
27 DraggableView() {}
28 ~DraggableView() override {}
30 // views::View overrides:
31 int GetDragOperations(const gfx::Point& press_pt) override {
32 return ui::DragDropTypes::DRAG_MOVE;
34 void WriteDragData(const gfx::Point& press_pt,
35 OSExchangeData* data) override {
36 data->SetString(base::UTF8ToUTF16("test"));
39 private:
40 DISALLOW_COPY_AND_ASSIGN(DraggableView);
43 class TargetView : public views::View {
44 public:
45 TargetView() : dropped_(false) {}
46 ~TargetView() override {}
48 // views::View overrides:
49 bool GetDropFormats(
50 int* formats,
51 std::set<OSExchangeData::CustomFormat>* custom_formats) override {
52 *formats = ui::OSExchangeData::STRING;
53 return true;
55 bool AreDropTypesRequired() override { return false; }
56 bool CanDrop(const OSExchangeData& data) override { return true; }
57 int OnDragUpdated(const ui::DropTargetEvent& event) override {
58 return ui::DragDropTypes::DRAG_MOVE;
60 int OnPerformDrop(const ui::DropTargetEvent& event) override {
61 dropped_ = true;
62 return ui::DragDropTypes::DRAG_MOVE;
65 bool dropped() const { return dropped_; }
67 private:
68 bool dropped_;
70 DISALLOW_COPY_AND_ASSIGN(TargetView);
73 views::Widget* CreateWidget(views::View* contents_view,
74 const gfx::Rect& bounds) {
75 views::Widget* widget = new views::Widget;
76 views::Widget::InitParams params;
77 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS;
78 params.accept_events = true;
79 params.context = Shell::GetPrimaryRootWindow();
80 params.bounds = bounds;
81 widget->Init(params);
83 widget->SetContentsView(contents_view);
84 widget->Show();
85 return widget;
88 void QuitLoop() {
89 base::MessageLoop::current()->Quit();
92 void DragDropAcrossMultiDisplay_Step4() {
93 ui_controls::SendMouseEventsNotifyWhenDone(
94 ui_controls::LEFT, ui_controls::UP,
95 base::Bind(&QuitLoop));
98 void DragDropAcrossMultiDisplay_Step3() {
99 // Move to the edge of the 1st display so that the mouse
100 // is moved to 2nd display by ash.
101 ui_controls::SendMouseMoveNotifyWhenDone(
102 399, 10,
103 base::Bind(&DragDropAcrossMultiDisplay_Step4));
106 void DragDropAcrossMultiDisplay_Step2() {
107 ui_controls::SendMouseMoveNotifyWhenDone(
108 20, 10,
109 base::Bind(&DragDropAcrossMultiDisplay_Step3));
112 void DragDropAcrossMultiDisplay_Step1() {
113 ui_controls::SendMouseEventsNotifyWhenDone(
114 ui_controls::LEFT, ui_controls::DOWN,
115 base::Bind(&DragDropAcrossMultiDisplay_Step2));
118 } // namespace
120 class DragDropTest : public test::AshTestBase {
121 public:
122 DragDropTest() {}
123 ~DragDropTest() override {}
125 void SetUp() override {
126 gfx::GLSurface::InitializeOneOffForTests();
128 ui::RegisterPathProvider();
129 ui::ResourceBundle::InitSharedInstanceWithLocale(
130 "en-US", NULL, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
131 base::FilePath resources_pack_path;
132 PathService::Get(base::DIR_MODULE, &resources_pack_path);
133 resources_pack_path =
134 resources_pack_path.Append(FILE_PATH_LITERAL("resources.pak"));
135 ResourceBundle::GetSharedInstance().AddDataPackFromPath(
136 resources_pack_path, ui::SCALE_FACTOR_NONE);
138 test::AshTestBase::SetUp();
142 #if !defined(OS_CHROMEOS)
143 #define MAYBE_DragDropAcrossMultiDisplay DISABLED_DragDropAcrossMultiDisplay
144 #else
145 #define MAYBE_DragDropAcrossMultiDisplay DragDropAcrossMultiDisplay
146 #endif
148 // Test if the mouse gets moved properly to another display
149 // during drag & drop operation.
150 TEST_F(DragDropTest, MAYBE_DragDropAcrossMultiDisplay) {
151 if (!SupportsMultipleDisplays())
152 return;
154 UpdateDisplay("400x400,400x400");
155 aura::Window::Windows root_windows =
156 Shell::GetInstance()->GetAllRootWindows();
157 views::View* draggable_view = new DraggableView();
158 draggable_view->set_drag_controller(NULL);
159 draggable_view->SetBounds(0, 0, 100, 100);
160 views::Widget* source =
161 CreateWidget(draggable_view, gfx::Rect(0, 0, 100, 100));
163 TargetView* target_view = new TargetView();
164 target_view->SetBounds(0, 0, 100, 100);
165 views::Widget* target =
166 CreateWidget(target_view, gfx::Rect(400, 0, 100, 100));
168 // Make sure they're on the different root windows.
169 EXPECT_EQ(root_windows[0], source->GetNativeView()->GetRootWindow());
170 EXPECT_EQ(root_windows[1], target->GetNativeView()->GetRootWindow());
172 ui_controls::SendMouseMoveNotifyWhenDone(
173 10, 10, base::Bind(&DragDropAcrossMultiDisplay_Step1));
175 base::MessageLoop::current()->Run();
177 EXPECT_TRUE(target_view->dropped());
179 source->Close();
180 target->Close();
183 } // namespace ash