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

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: 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* CreateWindow(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);
39 tracker->StartTracking(root_window);
40 ui::MouseEvent e(ui::ET_MOUSE_DRAGGED,
41 location,
42 location,
43 ui::EF_NONE);
44 aura::Window* target = tracker->GetTarget(e);
45 tracker->StopTracking();
46 return target;
47 }
48
49 static ui::MouseEvent* ConvertMouseEvent(aura::RootWindow* root_window,
50 aura::Window* target,
51 const ui::MouseEvent& event) {
52 scoped_ptr<internal::DragDropTracker> tracker(
53 new internal::DragDropTracker);
54 tracker->StartTracking(root_window);
55 ui::MouseEvent* converted = tracker->ConvertMouseEvent(target, event);
56 tracker->StopTracking();
57 return converted;
58 }
59 };
60
61 TEST_F(DragDropTrackerTest, GetTarget) {
62 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
63 EXPECT_EQ(2U, root_windows.size());
64
65 aura::Window* default_container0 =
66 ash::Shell::GetContainer(root_windows[0],
67 ash::internal::kShellWindowId_DefaultContainer);
68 EXPECT_TRUE(NULL != default_container0);
69
70 scoped_ptr<aura::Window> window0(
71 CreateWindow(gfx::Rect(0, 0, 100, 100), default_container0));
72 window0->Show();
73
74 aura::Window* default_container1 =
75 ash::Shell::GetContainer(root_windows[1],
76 ash::internal::kShellWindowId_DefaultContainer);
77 EXPECT_TRUE(NULL != default_container1);
78
79 scoped_ptr<aura::Window> window1(
80 CreateWindow(gfx::Rect(100, 100, 100, 100), default_container1));
81 window1->Show();
82
83 // Start tracking from the RootWindow0 and check the point on RootWindow0 that
84 // |window0| convers.
85 EXPECT_EQ(window0.get(), GetTarget(root_windows[0], gfx::Point(50, 50)));
86
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(root_windows[0], gfx::Point(150, 150)));
90 EXPECT_NE(window1.get(), GetTarget(root_windows[0], gfx::Point(150, 150)));
91
92 // Start tracking from the RootWindow0 and check the point on RootWindow1 that
93 // |window1| convers.
94 EXPECT_EQ(window1.get(), GetTarget(root_windows[0], gfx::Point(150, 350)));
95
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(root_windows[0], gfx::Point(50, 250)));
99 EXPECT_NE(window1.get(), GetTarget(root_windows[0], gfx::Point(50, 250)));
100
101 // Start tracking from the RootWindow1 and check the point on RootWindow0 that
102 // |window0| convers.
103 EXPECT_EQ(window0.get(), GetTarget(root_windows[1], gfx::Point(50, -150)));
104
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(root_windows[1], gfx::Point(150, -50)));
108 EXPECT_NE(window1.get(), GetTarget(root_windows[1], gfx::Point(150, -50)));
109
110 // Start tracking from the RootWindow1 and check the point on RootWindow1 that
111 // |window1| convers.
112 EXPECT_EQ(window1.get(), GetTarget(root_windows[1], gfx::Point(150, 150)));
113
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(root_windows[1], gfx::Point(50, 50)));
117 EXPECT_NE(window1.get(), GetTarget(root_windows[1], gfx::Point(50, 50)));
118 }
119
120 TEST_F(DragDropTrackerTest, ConvertMouseEvent) {
121 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
122 EXPECT_EQ(2U, root_windows.size());
123
124 aura::Window* default_container0 =
125 ash::Shell::GetContainer(root_windows[0],
126 ash::internal::kShellWindowId_DefaultContainer);
127 EXPECT_TRUE(NULL != default_container0);
128
129 scoped_ptr<aura::Window> window0(
130 CreateWindow(gfx::Rect(0, 0, 100, 100), default_container0));
131 window0->Show();
132
133 aura::Window* default_container1 =
134 ash::Shell::GetContainer(root_windows[1],
135 ash::internal::kShellWindowId_DefaultContainer);
136 EXPECT_TRUE(NULL != default_container1);
137
138 scoped_ptr<aura::Window> window1(
139 CreateWindow(gfx::Rect(100, 100, 100, 100), default_container1));
140 window1->Show();
141
142 // Start tracking from the RootWindow0 and converts the mouse event into
143 // |window0|'s coodinates.
144 ui::MouseEvent original00(ui::ET_MOUSE_DRAGGED,
145 gfx::Point(50, 50),
146 gfx::Point(50, 50),
147 ui::EF_NONE);
148 scoped_ptr<ui::MouseEvent> converted00(ConvertMouseEvent(root_windows[0],
149 window0.get(),
150 original00));
151 EXPECT_EQ(original00.type(), converted00->type());
152 EXPECT_EQ(gfx::Point(50, 50), converted00->location());
153 EXPECT_EQ(gfx::Point(50, 50), converted00->root_location());
154 EXPECT_EQ(original00.flags(), converted00->flags());
155
156 // Start tracking from the RootWindow0 and converts the mouse event into
157 // |window1|'s coodinates.
158 ui::MouseEvent original01(ui::ET_MOUSE_DRAGGED,
159 gfx::Point(150, 350),
160 gfx::Point(150, 350),
161 ui::EF_NONE);
162 scoped_ptr<ui::MouseEvent> converted01(ConvertMouseEvent(root_windows[0],
163 window1.get(),
164 original01));
165 EXPECT_EQ(original01.type(), converted01->type());
166 EXPECT_EQ(gfx::Point(50, 50), converted01->location());
167 EXPECT_EQ(gfx::Point(150, 150), converted01->root_location());
168 EXPECT_EQ(original01.flags(), converted01->flags());
169
170 // Start tracking from the RootWindow1 and converts the mouse event into
171 // |window0|'s coodinates.
172 ui::MouseEvent original10(ui::ET_MOUSE_DRAGGED,
173 gfx::Point(50, -150),
174 gfx::Point(50, -150),
175 ui::EF_NONE);
176 scoped_ptr<ui::MouseEvent> converted10(ConvertMouseEvent(root_windows[1],
177 window0.get(),
178 original10));
179 EXPECT_EQ(original10.type(), converted10->type());
180 EXPECT_EQ(gfx::Point(50, 50), converted10->location());
181 EXPECT_EQ(gfx::Point(50, 50), converted10->root_location());
182 EXPECT_EQ(original10.flags(), converted10->flags());
183
184 // Start tracking from the RootWindow1 and converts the mouse event into
185 // |window1|'s coodinates.
186 ui::MouseEvent original11(ui::ET_MOUSE_DRAGGED,
187 gfx::Point(150, 150),
188 gfx::Point(150, 150),
189 ui::EF_NONE);
190 scoped_ptr<ui::MouseEvent> converted11(ConvertMouseEvent(root_windows[1],
191 window1.get(),
192 original11));
193 EXPECT_EQ(original11.type(), converted11->type());
194 EXPECT_EQ(gfx::Point(50, 50), converted11->location());
195 EXPECT_EQ(gfx::Point(150, 150), converted11->root_location());
196 EXPECT_EQ(original11.flags(), converted11->flags());
197 }
198
199 } // namespace test
200 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698