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"
8 #include "ash/test/ash_interactive_ui_test_base.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "ui/aura/window_event_dispatcher.h"
13 #include "ui/base/dragdrop/drag_drop_types.h"
14 #include "ui/base/test/ui_controls.h"
15 #include "ui/views/view.h"
16 #include "ui/views/widget/widget.h"
21 class DraggableView
: public views::View
{
24 ~DraggableView() override
{}
26 // views::View overrides:
27 int GetDragOperations(const gfx::Point
& press_pt
) override
{
28 return ui::DragDropTypes::DRAG_MOVE
;
30 void WriteDragData(const gfx::Point
& press_pt
,
31 OSExchangeData
* data
) override
{
32 data
->SetString(base::UTF8ToUTF16("test"));
36 DISALLOW_COPY_AND_ASSIGN(DraggableView
);
39 class TargetView
: public views::View
{
41 TargetView() : dropped_(false) {}
42 ~TargetView() override
{}
44 // views::View overrides:
47 std::set
<OSExchangeData::CustomFormat
>* custom_formats
) override
{
48 *formats
= ui::OSExchangeData::STRING
;
51 bool AreDropTypesRequired() override
{ return false; }
52 bool CanDrop(const OSExchangeData
& data
) override
{ return true; }
53 int OnDragUpdated(const ui::DropTargetEvent
& event
) override
{
54 return ui::DragDropTypes::DRAG_MOVE
;
56 int OnPerformDrop(const ui::DropTargetEvent
& event
) override
{
58 return ui::DragDropTypes::DRAG_MOVE
;
61 bool dropped() const { return dropped_
; }
66 DISALLOW_COPY_AND_ASSIGN(TargetView
);
69 views::Widget
* CreateWidget(views::View
* contents_view
,
70 const gfx::Rect
& bounds
) {
71 views::Widget
* widget
= new views::Widget
;
72 views::Widget::InitParams params
;
73 params
.type
= views::Widget::InitParams::TYPE_WINDOW_FRAMELESS
;
74 params
.accept_events
= true;
75 params
.context
= Shell::GetPrimaryRootWindow();
76 params
.bounds
= bounds
;
79 widget
->SetContentsView(contents_view
);
85 base::MessageLoop::current()->Quit();
88 void DragDropAcrossMultiDisplay_Step4() {
89 ui_controls::SendMouseEventsNotifyWhenDone(
90 ui_controls::LEFT
, ui_controls::UP
,
91 base::Bind(&QuitLoop
));
94 void DragDropAcrossMultiDisplay_Step3() {
95 // Move to the edge of the 1st display so that the mouse
96 // is moved to 2nd display by ash.
97 ui_controls::SendMouseMoveNotifyWhenDone(
99 base::Bind(&DragDropAcrossMultiDisplay_Step4
));
102 void DragDropAcrossMultiDisplay_Step2() {
103 ui_controls::SendMouseMoveNotifyWhenDone(
105 base::Bind(&DragDropAcrossMultiDisplay_Step3
));
108 void DragDropAcrossMultiDisplay_Step1() {
109 ui_controls::SendMouseEventsNotifyWhenDone(
110 ui_controls::LEFT
, ui_controls::DOWN
,
111 base::Bind(&DragDropAcrossMultiDisplay_Step2
));
116 using DragDropTest
= test::AshInteractiveUITestBase
;
118 #if !defined(OS_CHROMEOS)
119 #define MAYBE_DragDropAcrossMultiDisplay DISABLED_DragDropAcrossMultiDisplay
121 #define MAYBE_DragDropAcrossMultiDisplay DragDropAcrossMultiDisplay
124 // Test if the mouse gets moved properly to another display
125 // during drag & drop operation.
126 TEST_F(DragDropTest
, MAYBE_DragDropAcrossMultiDisplay
) {
127 if (!SupportsMultipleDisplays())
130 UpdateDisplay("400x400,400x400");
131 aura::Window::Windows root_windows
=
132 Shell::GetInstance()->GetAllRootWindows();
133 views::View
* draggable_view
= new DraggableView();
134 draggable_view
->set_drag_controller(NULL
);
135 draggable_view
->SetBounds(0, 0, 100, 100);
136 views::Widget
* source
=
137 CreateWidget(draggable_view
, gfx::Rect(0, 0, 100, 100));
139 TargetView
* target_view
= new TargetView();
140 target_view
->SetBounds(0, 0, 100, 100);
141 views::Widget
* target
=
142 CreateWidget(target_view
, gfx::Rect(400, 0, 100, 100));
144 // Make sure they're on the different root windows.
145 EXPECT_EQ(root_windows
[0], source
->GetNativeView()->GetRootWindow());
146 EXPECT_EQ(root_windows
[1], target
->GetNativeView()->GetRootWindow());
148 ui_controls::SendMouseMoveNotifyWhenDone(
149 10, 10, base::Bind(&DragDropAcrossMultiDisplay_Step1
));
151 base::MessageLoop::current()->Run();
153 EXPECT_TRUE(target_view
->dropped());