1 // Copyright (c) 2012 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_tracker.h"
8 #include "ash/shell_window_ids.h"
9 #include "ash/test/ash_test_base.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "ui/aura/root_window.h"
12 #include "ui/aura/test/test_windows.h"
13 #include "ui/aura/window.h"
18 class DragDropTrackerTest
: public test::AshTestBase
{
20 virtual void SetUp() OVERRIDE
{
22 UpdateDisplay("200x200,300x300");
25 aura::Window
* CreateTestWindow(const gfx::Rect
& bounds
) {
26 static int window_id
= 0;
27 return CreateTestWindowInShellWithDelegate(
28 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(),
33 static aura::Window
* GetTarget(const gfx::Point
& location
) {
34 scoped_ptr
<internal::DragDropTracker
> tracker(
35 new internal::DragDropTracker(Shell::GetPrimaryRootWindow(),
37 ui::MouseEvent
e(ui::ET_MOUSE_DRAGGED
,
42 aura::Window
* target
= tracker
->GetTarget(e
);
46 static ui::LocatedEvent
* ConvertEvent(aura::Window
* target
,
47 const ui::MouseEvent
& event
) {
48 scoped_ptr
<internal::DragDropTracker
> tracker(
49 new internal::DragDropTracker(Shell::GetPrimaryRootWindow(),
51 ui::LocatedEvent
* converted
= tracker
->ConvertEvent(target
, event
);
56 // TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports
59 #define MAYBE_GetTarget GetTarget
61 #define MAYBE_GetTarget DISABLED_GetTarget
64 TEST_F(DragDropTrackerTest
, MAYBE_GetTarget
) {
65 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
66 EXPECT_EQ(2U, root_windows
.size());
68 scoped_ptr
<aura::Window
> window0(
69 CreateTestWindow(gfx::Rect(0, 0, 100, 100)));
72 scoped_ptr
<aura::Window
> window1(
73 CreateTestWindow(gfx::Rect(300, 100, 100, 100)));
75 EXPECT_EQ(root_windows
[0], window0
->GetRootWindow());
76 EXPECT_EQ(root_windows
[1], window1
->GetRootWindow());
77 EXPECT_EQ("0,0 100x100", window0
->GetBoundsInScreen().ToString());
78 EXPECT_EQ("300,100 100x100", window1
->GetBoundsInScreen().ToString());
80 // Make RootWindow0 active so that capture window is parented to it.
81 Shell::GetInstance()->set_target_root_window(root_windows
[0]);
83 // Start tracking from the RootWindow1 and check the point on RootWindow0 that
85 EXPECT_EQ(window0
.get(), GetTarget(gfx::Point(50, 50)));
87 // Start tracking from the RootWindow0 and check the point on RootWindow0 that
88 // neither |window0| nor |window1| covers.
89 EXPECT_NE(window0
.get(), GetTarget(gfx::Point(150, 150)));
90 EXPECT_NE(window1
.get(), GetTarget(gfx::Point(150, 150)));
92 // Start tracking from the RootWindow0 and check the point on RootWindow1 that
94 EXPECT_EQ(window1
.get(), GetTarget(gfx::Point(350, 150)));
96 // Start tracking from the RootWindow0 and check the point on RootWindow1 that
97 // neither |window0| nor |window1| covers.
98 EXPECT_NE(window0
.get(), GetTarget(gfx::Point(50, 250)));
99 EXPECT_NE(window1
.get(), GetTarget(gfx::Point(50, 250)));
101 // Make RootWindow1 active so that capture window is parented to it.
102 Shell::GetInstance()->set_target_root_window(root_windows
[1]);
104 // Start tracking from the RootWindow1 and check the point on RootWindow0 that
106 EXPECT_EQ(window0
.get(), GetTarget(gfx::Point(-150, 50)));
108 // Start tracking from the RootWindow1 and check the point on RootWindow0 that
109 // neither |window0| nor |window1| covers.
110 EXPECT_NE(window0
.get(), GetTarget(gfx::Point(150, -50)));
111 EXPECT_NE(window1
.get(), GetTarget(gfx::Point(150, -50)));
113 // Start tracking from the RootWindow1 and check the point on RootWindow1 that
115 EXPECT_EQ(window1
.get(), GetTarget(gfx::Point(150, 150)));
117 // Start tracking from the RootWindow1 and check the point on RootWindow1 that
118 // neither |window0| nor |window1| covers.
119 EXPECT_NE(window0
.get(), GetTarget(gfx::Point(50, 50)));
120 EXPECT_NE(window1
.get(), GetTarget(gfx::Point(50, 50)));
123 // TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports
124 // non-X11 platforms.
126 #define MAYBE_ConvertEvent ConvertEvent
128 #define MAYBE_ConvertEvent DISABLED_ConvertEvent
131 TEST_F(DragDropTrackerTest
, MAYBE_ConvertEvent
) {
132 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
133 EXPECT_EQ(2U, root_windows
.size());
135 scoped_ptr
<aura::Window
> window0(
136 CreateTestWindow(gfx::Rect(0, 0, 100, 100)));
139 scoped_ptr
<aura::Window
> window1(
140 CreateTestWindow(gfx::Rect(300, 100, 100, 100)));
143 // Make RootWindow0 active so that capture window is parented to it.
144 Shell::GetInstance()->set_target_root_window(root_windows
[0]);
146 // Start tracking from the RootWindow0 and converts the mouse event into
147 // |window0|'s coodinates.
148 ui::MouseEvent
original00(ui::ET_MOUSE_DRAGGED
,
153 scoped_ptr
<ui::LocatedEvent
> converted00(ConvertEvent(window0
.get(),
155 EXPECT_EQ(original00
.type(), converted00
->type());
156 EXPECT_EQ("50,50", converted00
->location().ToString());
157 EXPECT_EQ("50,50", converted00
->root_location().ToString());
158 EXPECT_EQ(original00
.flags(), converted00
->flags());
160 // Start tracking from the RootWindow0 and converts the mouse event into
161 // |window1|'s coodinates.
162 ui::MouseEvent
original01(ui::ET_MOUSE_DRAGGED
,
163 gfx::Point(350, 150),
164 gfx::Point(350, 150),
167 scoped_ptr
<ui::LocatedEvent
> converted01(ConvertEvent(window1
.get(),
169 EXPECT_EQ(original01
.type(), converted01
->type());
170 EXPECT_EQ("50,50", converted01
->location().ToString());
171 EXPECT_EQ("150,150", converted01
->root_location().ToString());
172 EXPECT_EQ(original01
.flags(), converted01
->flags());
174 // Make RootWindow1 active so that capture window is parented to it.
175 Shell::GetInstance()->set_target_root_window(root_windows
[1]);
177 // Start tracking from the RootWindow1 and converts the mouse event into
178 // |window0|'s coodinates.
179 ui::MouseEvent
original10(ui::ET_MOUSE_DRAGGED
,
180 gfx::Point(-150, 50),
181 gfx::Point(-150, 50),
184 scoped_ptr
<ui::LocatedEvent
> converted10(ConvertEvent(window0
.get(),
186 EXPECT_EQ(original10
.type(), converted10
->type());
187 EXPECT_EQ("50,50", converted10
->location().ToString());
188 EXPECT_EQ("50,50", converted10
->root_location().ToString());
189 EXPECT_EQ(original10
.flags(), converted10
->flags());
191 // Start tracking from the RootWindow1 and converts the mouse event into
192 // |window1|'s coodinates.
193 ui::MouseEvent
original11(ui::ET_MOUSE_DRAGGED
,
194 gfx::Point(150, 150),
195 gfx::Point(150, 150),
198 scoped_ptr
<ui::LocatedEvent
> converted11(ConvertEvent(window1
.get(),
200 EXPECT_EQ(original11
.type(), converted11
->type());
201 EXPECT_EQ("50,50", converted11
->location().ToString());
202 EXPECT_EQ("150,150", converted11
->root_location().ToString());
203 EXPECT_EQ(original11
.flags(), converted11
->flags());