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,200x200");
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()));
36 ui::MouseEvent
e(ui::ET_MOUSE_DRAGGED
,
40 aura::Window
* target
= tracker
->GetTarget(e
);
44 static ui::LocatedEvent
* ConvertEvent(aura::Window
* target
,
45 const ui::MouseEvent
& event
) {
46 scoped_ptr
<internal::DragDropTracker
> tracker(
47 new internal::DragDropTracker(Shell::GetPrimaryRootWindow()));
48 ui::LocatedEvent
* converted
= tracker
->ConvertEvent(target
, event
);
53 // TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports
56 #define MAYBE_GetTarget GetTarget
58 #define MAYBE_GetTarget DISABLED_GetTarget
61 TEST_F(DragDropTrackerTest
, MAYBE_GetTarget
) {
62 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
63 EXPECT_EQ(2U, root_windows
.size());
65 Shell::GetInstance()->set_active_root_window(root_windows
[0]);
67 scoped_ptr
<aura::Window
> window0(
68 CreateTestWindow(gfx::Rect(0, 0, 100, 100)));
71 Shell::GetInstance()->set_active_root_window(root_windows
[1]);
73 scoped_ptr
<aura::Window
> window1(
74 CreateTestWindow(gfx::Rect(100, 100, 100, 100)));
77 // Make RootWindow0 active so that capture window is parented to it.
78 Shell::GetInstance()->set_active_root_window(root_windows
[0]);
80 // Start tracking from the RootWindow1 and check the point on RootWindow0 that
82 EXPECT_EQ(window0
.get(), GetTarget(gfx::Point(50, 50)));
84 // Start tracking from the RootWindow0 and check the point on RootWindow0 that
85 // neither |window0| nor |window1| covers.
86 EXPECT_NE(window0
.get(), GetTarget(gfx::Point(150, 150)));
87 EXPECT_NE(window1
.get(), GetTarget(gfx::Point(150, 150)));
89 // Start tracking from the RootWindow0 and check the point on RootWindow1 that
91 EXPECT_EQ(window1
.get(), GetTarget(gfx::Point(350, 150)));
93 // Start tracking from the RootWindow0 and check the point on RootWindow1 that
94 // neither |window0| nor |window1| covers.
95 EXPECT_NE(window0
.get(), GetTarget(gfx::Point(50, 250)));
96 EXPECT_NE(window1
.get(), GetTarget(gfx::Point(50, 250)));
98 // Make RootWindow1 active so that capture window is parented to it.
99 Shell::GetInstance()->set_active_root_window(root_windows
[1]);
101 // Start tracking from the RootWindow1 and check the point on RootWindow0 that
103 EXPECT_EQ(window0
.get(), GetTarget(gfx::Point(-150, 50)));
105 // Start tracking from the RootWindow1 and check the point on RootWindow0 that
106 // neither |window0| nor |window1| covers.
107 EXPECT_NE(window0
.get(), GetTarget(gfx::Point(150, -50)));
108 EXPECT_NE(window1
.get(), GetTarget(gfx::Point(150, -50)));
110 // Start tracking from the RootWindow1 and check the point on RootWindow1 that
112 EXPECT_EQ(window1
.get(), GetTarget(gfx::Point(150, 150)));
114 // Start tracking from the RootWindow1 and check the point on RootWindow1 that
115 // neither |window0| nor |window1| covers.
116 EXPECT_NE(window0
.get(), GetTarget(gfx::Point(50, 50)));
117 EXPECT_NE(window1
.get(), GetTarget(gfx::Point(50, 50)));
120 // TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports
121 // non-X11 platforms.
123 #define MAYBE_ConvertEvent ConvertEvent
125 #define MAYBE_ConvertEvent DISABLED_ConvertEvent
128 TEST_F(DragDropTrackerTest
, MAYBE_ConvertEvent
) {
129 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
130 EXPECT_EQ(2U, root_windows
.size());
132 Shell::GetInstance()->set_active_root_window(root_windows
[0]);
133 scoped_ptr
<aura::Window
> window0(
134 CreateTestWindow(gfx::Rect(0, 0, 100, 100)));
137 Shell::GetInstance()->set_active_root_window(root_windows
[1]);
138 scoped_ptr
<aura::Window
> window1(
139 CreateTestWindow(gfx::Rect(100, 100, 100, 100)));
142 // Make RootWindow0 active so that capture window is parented to it.
143 Shell::GetInstance()->set_active_root_window(root_windows
[0]);
145 // Start tracking from the RootWindow0 and converts the mouse event into
146 // |window0|'s coodinates.
147 ui::MouseEvent
original00(ui::ET_MOUSE_DRAGGED
,
151 scoped_ptr
<ui::LocatedEvent
> converted00(ConvertEvent(window0
.get(),
153 EXPECT_EQ(original00
.type(), converted00
->type());
154 EXPECT_EQ("50,50", converted00
->location().ToString());
155 EXPECT_EQ("50,50", converted00
->root_location().ToString());
156 EXPECT_EQ(original00
.flags(), converted00
->flags());
158 // Start tracking from the RootWindow0 and converts the mouse event into
159 // |window1|'s coodinates.
160 ui::MouseEvent
original01(ui::ET_MOUSE_DRAGGED
,
161 gfx::Point(350, 150),
162 gfx::Point(350, 150),
164 scoped_ptr
<ui::LocatedEvent
> converted01(ConvertEvent(window1
.get(),
166 EXPECT_EQ(original01
.type(), converted01
->type());
167 EXPECT_EQ("50,50", converted01
->location().ToString());
168 EXPECT_EQ("150,150", converted01
->root_location().ToString());
169 EXPECT_EQ(original01
.flags(), converted01
->flags());
171 // Make RootWindow1 active so that capture window is parented to it.
172 Shell::GetInstance()->set_active_root_window(root_windows
[1]);
174 // Start tracking from the RootWindow1 and converts the mouse event into
175 // |window0|'s coodinates.
176 ui::MouseEvent
original10(ui::ET_MOUSE_DRAGGED
,
177 gfx::Point(-150, 50),
178 gfx::Point(-150, 50),
180 scoped_ptr
<ui::LocatedEvent
> converted10(ConvertEvent(window0
.get(),
182 EXPECT_EQ(original10
.type(), converted10
->type());
183 EXPECT_EQ("50,50", converted10
->location().ToString());
184 EXPECT_EQ("50,50", converted10
->root_location().ToString());
185 EXPECT_EQ(original10
.flags(), converted10
->flags());
187 // Start tracking from the RootWindow1 and converts the mouse event into
188 // |window1|'s coodinates.
189 ui::MouseEvent
original11(ui::ET_MOUSE_DRAGGED
,
190 gfx::Point(150, 150),
191 gfx::Point(150, 150),
193 scoped_ptr
<ui::LocatedEvent
> converted11(ConvertEvent(window1
.get(),
195 EXPECT_EQ(original11
.type(), converted11
->type());
196 EXPECT_EQ("50,50", converted11
->location().ToString());
197 EXPECT_EQ("150,150", converted11
->root_location().ToString());
198 EXPECT_EQ(original11
.flags(), converted11
->flags());