Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: ash/drag_drop/drag_drop_tracker_unittest.cc

Issue 10855159: Support Drag and Drop across displays. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable DragDropTrackerTest on Win Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "ash/drag_drop/drag_drop_tracker.h"
6
7 #include "ash/shell.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"
14
15 namespace ash {
16 namespace test {
17
18 class DragDropTrackerTest : public test::AshTestBase {
19 public:
20 virtual void SetUp() OVERRIDE {
21 AshTestBase::SetUp();
22 UpdateDisplay("0+0-200x200,0+201-200x200");
23 }
24
25 static aura::Window* CreateTestWindow(const gfx::Rect& bounds,
26 aura::Window* parent) {
27 static int window_id = 0;
28 return aura::test::CreateTestWindowWithDelegate(
29 new aura::test::TestWindowDelegate,
30 window_id++,
31 bounds,
32 parent);
33 }
34
35 static aura::Window* GetTarget(aura::RootWindow* root_window,
36 const gfx::Point& location) {
37 scoped_ptr<internal::DragDropTracker> tracker(
38 new internal::DragDropTracker(root_window));
39 ui::MouseEvent e(ui::ET_MOUSE_DRAGGED,
40 location,
41 location,
42 ui::EF_NONE);
43 aura::Window* target = tracker->GetTarget(e);
44 return target;
45 }
46
47 static ui::MouseEvent* ConvertMouseEvent(aura::RootWindow* root_window,
48 aura::Window* target,
49 const ui::MouseEvent& event) {
50 scoped_ptr<internal::DragDropTracker> tracker(
51 new internal::DragDropTracker(root_window));
52 ui::MouseEvent* converted = tracker->ConvertMouseEvent(target, event);
53 return converted;
54 }
55 };
56
57 // TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports
58 // non-X11 platforms.
59 #if defined(USE_X11)
60 #define MAYBE_GetTarget GetTarget
61 #else
62 #define MAYBE_GetTarget DISABLED_GetTarget
63 #endif
64
65 TEST_F(DragDropTrackerTest, MAYBE_GetTarget) {
66 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
67 EXPECT_EQ(2U, root_windows.size());
68
69 aura::Window* default_container0 =
70 ash::Shell::GetContainer(root_windows[0],
71 ash::internal::kShellWindowId_DefaultContainer);
72 EXPECT_TRUE(NULL != default_container0);
73
74 scoped_ptr<aura::Window> window0(
75 CreateTestWindow(gfx::Rect(0, 0, 100, 100), default_container0));
76 window0->Show();
77
78 aura::Window* default_container1 =
79 ash::Shell::GetContainer(root_windows[1],
80 ash::internal::kShellWindowId_DefaultContainer);
81 EXPECT_TRUE(NULL != default_container1);
82
83 scoped_ptr<aura::Window> window1(
84 CreateTestWindow(gfx::Rect(100, 100, 100, 100), default_container1));
85 window1->Show();
86
87 // Start tracking from the RootWindow0 and check the point on RootWindow0 that
88 // |window0| covers.
89 EXPECT_EQ(window0.get(), GetTarget(root_windows[0], gfx::Point(50, 50)));
90
91 // Start tracking from the RootWindow0 and check the point on RootWindow0 that
92 // neither |window0| nor |window1| covers.
93 EXPECT_NE(window0.get(), GetTarget(root_windows[0], gfx::Point(150, 150)));
94 EXPECT_NE(window1.get(), GetTarget(root_windows[0], gfx::Point(150, 150)));
95
96 // Start tracking from the RootWindow0 and check the point on RootWindow1 that
97 // |window1| covers.
98 EXPECT_EQ(window1.get(), GetTarget(root_windows[0], gfx::Point(150, 350)));
99
100 // Start tracking from the RootWindow0 and check the point on RootWindow1 that
101 // neither |window0| nor |window1| covers.
102 EXPECT_NE(window0.get(), GetTarget(root_windows[0], gfx::Point(50, 250)));
103 EXPECT_NE(window1.get(), GetTarget(root_windows[0], gfx::Point(50, 250)));
104
105 // Start tracking from the RootWindow1 and check the point on RootWindow0 that
106 // |window0| covers.
107 EXPECT_EQ(window0.get(), GetTarget(root_windows[1], gfx::Point(50, -150)));
108
109 // Start tracking from the RootWindow1 and check the point on RootWindow0 that
110 // neither |window0| nor |window1| covers.
111 EXPECT_NE(window0.get(), GetTarget(root_windows[1], gfx::Point(150, -50)));
112 EXPECT_NE(window1.get(), GetTarget(root_windows[1], gfx::Point(150, -50)));
113
114 // Start tracking from the RootWindow1 and check the point on RootWindow1 that
115 // |window1| covers.
116 EXPECT_EQ(window1.get(), GetTarget(root_windows[1], gfx::Point(150, 150)));
117
118 // Start tracking from the RootWindow1 and check the point on RootWindow1 that
119 // neither |window0| nor |window1| covers.
120 EXPECT_NE(window0.get(), GetTarget(root_windows[1], gfx::Point(50, 50)));
121 EXPECT_NE(window1.get(), GetTarget(root_windows[1], gfx::Point(50, 50)));
122 }
123
124 // TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports
125 // non-X11 platforms.
126 #if defined(USE_X11)
127 #define MAYBE_ConvertMouseEvent ConvertMouseEvent
128 #else
129 #define MAYBE_ConvertMouseEvent DISABLED_ConvertMouseEvent
130 #endif
131
132 TEST_F(DragDropTrackerTest, MAYBE_ConvertMouseEvent) {
133 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
134 EXPECT_EQ(2U, root_windows.size());
135
136 aura::Window* default_container0 =
137 ash::Shell::GetContainer(root_windows[0],
138 ash::internal::kShellWindowId_DefaultContainer);
139 EXPECT_TRUE(NULL != default_container0);
140
141 scoped_ptr<aura::Window> window0(
142 CreateTestWindow(gfx::Rect(0, 0, 100, 100), default_container0));
143 window0->Show();
144
145 aura::Window* default_container1 =
146 ash::Shell::GetContainer(root_windows[1],
147 ash::internal::kShellWindowId_DefaultContainer);
148 EXPECT_TRUE(NULL != default_container1);
149
150 scoped_ptr<aura::Window> window1(
151 CreateTestWindow(gfx::Rect(100, 100, 100, 100), default_container1));
152 window1->Show();
153
154 // Start tracking from the RootWindow0 and converts the mouse event into
155 // |window0|'s coodinates.
156 ui::MouseEvent original00(ui::ET_MOUSE_DRAGGED,
157 gfx::Point(50, 50),
158 gfx::Point(50, 50),
159 ui::EF_NONE);
160 scoped_ptr<ui::MouseEvent> converted00(ConvertMouseEvent(root_windows[0],
161 window0.get(),
162 original00));
163 EXPECT_EQ(original00.type(), converted00->type());
164 EXPECT_EQ(gfx::Point(50, 50), converted00->location());
165 EXPECT_EQ(gfx::Point(50, 50), converted00->root_location());
166 EXPECT_EQ(original00.flags(), converted00->flags());
167
168 // Start tracking from the RootWindow0 and converts the mouse event into
169 // |window1|'s coodinates.
170 ui::MouseEvent original01(ui::ET_MOUSE_DRAGGED,
171 gfx::Point(150, 350),
172 gfx::Point(150, 350),
173 ui::EF_NONE);
174 scoped_ptr<ui::MouseEvent> converted01(ConvertMouseEvent(root_windows[0],
175 window1.get(),
176 original01));
177 EXPECT_EQ(original01.type(), converted01->type());
178 EXPECT_EQ(gfx::Point(50, 50), converted01->location());
179 EXPECT_EQ(gfx::Point(150, 150), converted01->root_location());
180 EXPECT_EQ(original01.flags(), converted01->flags());
181
182 // Start tracking from the RootWindow1 and converts the mouse event into
183 // |window0|'s coodinates.
184 ui::MouseEvent original10(ui::ET_MOUSE_DRAGGED,
185 gfx::Point(50, -150),
186 gfx::Point(50, -150),
187 ui::EF_NONE);
188 scoped_ptr<ui::MouseEvent> converted10(ConvertMouseEvent(root_windows[1],
189 window0.get(),
190 original10));
191 EXPECT_EQ(original10.type(), converted10->type());
192 EXPECT_EQ(gfx::Point(50, 50), converted10->location());
193 EXPECT_EQ(gfx::Point(50, 50), converted10->root_location());
194 EXPECT_EQ(original10.flags(), converted10->flags());
195
196 // Start tracking from the RootWindow1 and converts the mouse event into
197 // |window1|'s coodinates.
198 ui::MouseEvent original11(ui::ET_MOUSE_DRAGGED,
199 gfx::Point(150, 150),
200 gfx::Point(150, 150),
201 ui::EF_NONE);
202 scoped_ptr<ui::MouseEvent> converted11(ConvertMouseEvent(root_windows[1],
203 window1.get(),
204 original11));
205 EXPECT_EQ(original11.type(), converted11->type());
206 EXPECT_EQ(gfx::Point(50, 50), converted11->location());
207 EXPECT_EQ(gfx::Point(150, 150), converted11->root_location());
208 EXPECT_EQ(original11.flags(), converted11->flags());
209 }
210
211 } // namespace test
212 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698