OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/drag_drop/drag_drop_tracker.h" | 5 #include "ash/drag_drop/drag_drop_tracker.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 static aura::Window* CreateTestWindow(const gfx::Rect& bounds, | 25 static aura::Window* CreateTestWindow(const gfx::Rect& bounds, |
26 aura::Window* parent) { | 26 aura::Window* parent) { |
27 static int window_id = 0; | 27 static int window_id = 0; |
28 return aura::test::CreateTestWindowWithDelegate( | 28 return aura::test::CreateTestWindowWithDelegate( |
29 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), | 29 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate(), |
30 window_id++, | 30 window_id++, |
31 bounds, | 31 bounds, |
32 parent); | 32 parent); |
33 } | 33 } |
34 | 34 |
35 static aura::Window* GetTarget(aura::RootWindow* root_window, | 35 static aura::Window* GetTarget(const gfx::Point& location) { |
36 const gfx::Point& location) { | |
37 scoped_ptr<internal::DragDropTracker> tracker( | 36 scoped_ptr<internal::DragDropTracker> tracker( |
38 new internal::DragDropTracker(root_window)); | 37 new internal::DragDropTracker); |
39 ui::MouseEvent e(ui::ET_MOUSE_DRAGGED, | 38 ui::MouseEvent e(ui::ET_MOUSE_DRAGGED, |
40 location, | 39 location, |
41 location, | 40 location, |
42 ui::EF_NONE); | 41 ui::EF_NONE); |
43 aura::Window* target = tracker->GetTarget(e); | 42 aura::Window* target = tracker->GetTarget(e); |
44 return target; | 43 return target; |
45 } | 44 } |
46 | 45 |
47 static ui::MouseEvent* ConvertMouseEvent(aura::RootWindow* root_window, | 46 static ui::MouseEvent* ConvertMouseEvent(aura::Window* target, |
48 aura::Window* target, | |
49 const ui::MouseEvent& event) { | 47 const ui::MouseEvent& event) { |
50 scoped_ptr<internal::DragDropTracker> tracker( | 48 scoped_ptr<internal::DragDropTracker> tracker( |
51 new internal::DragDropTracker(root_window)); | 49 new internal::DragDropTracker); |
52 ui::MouseEvent* converted = tracker->ConvertMouseEvent(target, event); | 50 ui::MouseEvent* converted = tracker->ConvertMouseEvent(target, event); |
53 return converted; | 51 return converted; |
54 } | 52 } |
55 }; | 53 }; |
56 | 54 |
57 // TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports | 55 // TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports |
58 // non-X11 platforms. | 56 // non-X11 platforms. |
59 #if defined(USE_X11) | 57 #if defined(USE_X11) |
60 #define MAYBE_GetTarget GetTarget | 58 #define MAYBE_GetTarget GetTarget |
61 #else | 59 #else |
62 #define MAYBE_GetTarget DISABLED_GetTarget | 60 #define MAYBE_GetTarget DISABLED_GetTarget |
63 #endif | 61 #endif |
64 | 62 |
65 TEST_F(DragDropTrackerTest, MAYBE_GetTarget) { | 63 TEST_F(DragDropTrackerTest, MAYBE_GetTarget) { |
66 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 64 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
67 EXPECT_EQ(2U, root_windows.size()); | 65 EXPECT_EQ(2U, root_windows.size()); |
68 | 66 |
69 Shell::GetInstance()->set_active_root_window(root_windows[0]); | 67 Shell::GetInstance()->set_active_root_window(root_windows[0]); |
70 | 68 |
71 scoped_ptr<aura::Window> window0( | 69 scoped_ptr<aura::Window> window0( |
72 CreateTestWindow(gfx::Rect(0, 0, 100, 100), NULL)); | 70 CreateTestWindow(gfx::Rect(0, 0, 100, 100), NULL)); |
73 window0->Show(); | 71 window0->Show(); |
74 | 72 |
75 Shell::GetInstance()->set_active_root_window(root_windows[1]); | 73 Shell::GetInstance()->set_active_root_window(root_windows[1]); |
76 | 74 |
77 scoped_ptr<aura::Window> window1( | 75 scoped_ptr<aura::Window> window1( |
78 CreateTestWindow(gfx::Rect(100, 100, 100, 100), NULL)); | 76 CreateTestWindow(gfx::Rect(100, 100, 100, 100), NULL)); |
79 window1->Show(); | 77 window1->Show(); |
80 | 78 |
81 // Start tracking from the RootWindow0 and check the point on RootWindow0 that | 79 // Make RootWindow0 active so that capture window is parented to it. |
| 80 Shell::GetInstance()->set_active_root_window(root_windows[0]); |
| 81 |
| 82 // Start tracking from the RootWindow1 and check the point on RootWindow0 that |
82 // |window0| covers. | 83 // |window0| covers. |
83 EXPECT_EQ(window0.get(), GetTarget(root_windows[0], gfx::Point(50, 50))); | 84 EXPECT_EQ(window0.get(), GetTarget(gfx::Point(50, 50))); |
84 | 85 |
85 // Start tracking from the RootWindow0 and check the point on RootWindow0 that | 86 // Start tracking from the RootWindow0 and check the point on RootWindow0 that |
86 // neither |window0| nor |window1| covers. | 87 // neither |window0| nor |window1| covers. |
87 EXPECT_NE(window0.get(), GetTarget(root_windows[0], gfx::Point(150, 150))); | 88 EXPECT_NE(window0.get(), GetTarget(gfx::Point(150, 150))); |
88 EXPECT_NE(window1.get(), GetTarget(root_windows[0], gfx::Point(150, 150))); | 89 EXPECT_NE(window1.get(), GetTarget(gfx::Point(150, 150))); |
89 | 90 |
90 // Start tracking from the RootWindow0 and check the point on RootWindow1 that | 91 // Start tracking from the RootWindow0 and check the point on RootWindow1 that |
91 // |window1| covers. | 92 // |window1| covers. |
92 EXPECT_EQ(window1.get(), GetTarget(root_windows[0], gfx::Point(350, 150))); | 93 EXPECT_EQ(window1.get(), GetTarget(gfx::Point(350, 150))); |
93 | 94 |
94 // Start tracking from the RootWindow0 and check the point on RootWindow1 that | 95 // Start tracking from the RootWindow0 and check the point on RootWindow1 that |
95 // neither |window0| nor |window1| covers. | 96 // neither |window0| nor |window1| covers. |
96 EXPECT_NE(window0.get(), GetTarget(root_windows[0], gfx::Point(50, 250))); | 97 EXPECT_NE(window0.get(), GetTarget(gfx::Point(50, 250))); |
97 EXPECT_NE(window1.get(), GetTarget(root_windows[0], gfx::Point(50, 250))); | 98 EXPECT_NE(window1.get(), GetTarget(gfx::Point(50, 250))); |
| 99 |
| 100 // Make RootWindow1 active so that capture window is parented to it. |
| 101 Shell::GetInstance()->set_active_root_window(root_windows[1]); |
98 | 102 |
99 // Start tracking from the RootWindow1 and check the point on RootWindow0 that | 103 // Start tracking from the RootWindow1 and check the point on RootWindow0 that |
100 // |window0| covers. | 104 // |window0| covers. |
101 EXPECT_EQ(window0.get(), GetTarget(root_windows[1], gfx::Point(-150, 50))); | 105 EXPECT_EQ(window0.get(), GetTarget(gfx::Point(-150, 50))); |
102 | 106 |
103 // Start tracking from the RootWindow1 and check the point on RootWindow0 that | 107 // Start tracking from the RootWindow1 and check the point on RootWindow0 that |
104 // neither |window0| nor |window1| covers. | 108 // neither |window0| nor |window1| covers. |
105 EXPECT_NE(window0.get(), GetTarget(root_windows[1], gfx::Point(150, -50))); | 109 EXPECT_NE(window0.get(), GetTarget(gfx::Point(150, -50))); |
106 EXPECT_NE(window1.get(), GetTarget(root_windows[1], gfx::Point(150, -50))); | 110 EXPECT_NE(window1.get(), GetTarget(gfx::Point(150, -50))); |
107 | 111 |
108 // Start tracking from the RootWindow1 and check the point on RootWindow1 that | 112 // Start tracking from the RootWindow1 and check the point on RootWindow1 that |
109 // |window1| covers. | 113 // |window1| covers. |
110 EXPECT_EQ(window1.get(), GetTarget(root_windows[1], gfx::Point(150, 150))); | 114 EXPECT_EQ(window1.get(), GetTarget(gfx::Point(150, 150))); |
111 | 115 |
112 // Start tracking from the RootWindow1 and check the point on RootWindow1 that | 116 // Start tracking from the RootWindow1 and check the point on RootWindow1 that |
113 // neither |window0| nor |window1| covers. | 117 // neither |window0| nor |window1| covers. |
114 EXPECT_NE(window0.get(), GetTarget(root_windows[1], gfx::Point(50, 50))); | 118 EXPECT_NE(window0.get(), GetTarget(gfx::Point(50, 50))); |
115 EXPECT_NE(window1.get(), GetTarget(root_windows[1], gfx::Point(50, 50))); | 119 EXPECT_NE(window1.get(), GetTarget(gfx::Point(50, 50))); |
116 } | 120 } |
117 | 121 |
118 // TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports | 122 // TODO(mazda): Remove this once ash/wm/coordinate_conversion.h supports |
119 // non-X11 platforms. | 123 // non-X11 platforms. |
120 #if defined(USE_X11) | 124 #if defined(USE_X11) |
121 #define MAYBE_ConvertMouseEvent ConvertMouseEvent | 125 #define MAYBE_ConvertMouseEvent ConvertMouseEvent |
122 #else | 126 #else |
123 #define MAYBE_ConvertMouseEvent DISABLED_ConvertMouseEvent | 127 #define MAYBE_ConvertMouseEvent DISABLED_ConvertMouseEvent |
124 #endif | 128 #endif |
125 | 129 |
126 TEST_F(DragDropTrackerTest, MAYBE_ConvertMouseEvent) { | 130 TEST_F(DragDropTrackerTest, MAYBE_ConvertMouseEvent) { |
127 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 131 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
128 EXPECT_EQ(2U, root_windows.size()); | 132 EXPECT_EQ(2U, root_windows.size()); |
129 | 133 |
130 Shell::GetInstance()->set_active_root_window(root_windows[0]); | 134 Shell::GetInstance()->set_active_root_window(root_windows[0]); |
131 scoped_ptr<aura::Window> window0( | 135 scoped_ptr<aura::Window> window0( |
132 CreateTestWindow(gfx::Rect(0, 0, 100, 100), NULL)); | 136 CreateTestWindow(gfx::Rect(0, 0, 100, 100), NULL)); |
133 window0->Show(); | 137 window0->Show(); |
134 | 138 |
135 Shell::GetInstance()->set_active_root_window(root_windows[1]); | 139 Shell::GetInstance()->set_active_root_window(root_windows[1]); |
136 scoped_ptr<aura::Window> window1( | 140 scoped_ptr<aura::Window> window1( |
137 CreateTestWindow(gfx::Rect(100, 100, 100, 100), NULL)); | 141 CreateTestWindow(gfx::Rect(100, 100, 100, 100), NULL)); |
138 window1->Show(); | 142 window1->Show(); |
139 | 143 |
| 144 // Make RootWindow0 active so that capture window is parented to it. |
| 145 Shell::GetInstance()->set_active_root_window(root_windows[0]); |
| 146 |
140 // Start tracking from the RootWindow0 and converts the mouse event into | 147 // Start tracking from the RootWindow0 and converts the mouse event into |
141 // |window0|'s coodinates. | 148 // |window0|'s coodinates. |
142 ui::MouseEvent original00(ui::ET_MOUSE_DRAGGED, | 149 ui::MouseEvent original00(ui::ET_MOUSE_DRAGGED, |
143 gfx::Point(50, 50), | 150 gfx::Point(50, 50), |
144 gfx::Point(50, 50), | 151 gfx::Point(50, 50), |
145 ui::EF_NONE); | 152 ui::EF_NONE); |
146 scoped_ptr<ui::MouseEvent> converted00(ConvertMouseEvent(root_windows[0], | 153 scoped_ptr<ui::MouseEvent> converted00(ConvertMouseEvent(window0.get(), |
147 window0.get(), | |
148 original00)); | 154 original00)); |
149 EXPECT_EQ(original00.type(), converted00->type()); | 155 EXPECT_EQ(original00.type(), converted00->type()); |
150 EXPECT_EQ("50,50", converted00->location().ToString()); | 156 EXPECT_EQ("50,50", converted00->location().ToString()); |
151 EXPECT_EQ("50,50", converted00->root_location().ToString()); | 157 EXPECT_EQ("50,50", converted00->root_location().ToString()); |
152 EXPECT_EQ(original00.flags(), converted00->flags()); | 158 EXPECT_EQ(original00.flags(), converted00->flags()); |
153 | 159 |
154 // Start tracking from the RootWindow0 and converts the mouse event into | 160 // Start tracking from the RootWindow0 and converts the mouse event into |
155 // |window1|'s coodinates. | 161 // |window1|'s coodinates. |
156 ui::MouseEvent original01(ui::ET_MOUSE_DRAGGED, | 162 ui::MouseEvent original01(ui::ET_MOUSE_DRAGGED, |
157 gfx::Point(350, 150), | 163 gfx::Point(350, 150), |
158 gfx::Point(350, 150), | 164 gfx::Point(350, 150), |
159 ui::EF_NONE); | 165 ui::EF_NONE); |
160 scoped_ptr<ui::MouseEvent> converted01(ConvertMouseEvent(root_windows[0], | 166 scoped_ptr<ui::MouseEvent> converted01(ConvertMouseEvent(window1.get(), |
161 window1.get(), | |
162 original01)); | 167 original01)); |
163 EXPECT_EQ(original01.type(), converted01->type()); | 168 EXPECT_EQ(original01.type(), converted01->type()); |
164 EXPECT_EQ("50,50", converted01->location().ToString()); | 169 EXPECT_EQ("50,50", converted01->location().ToString()); |
165 EXPECT_EQ("150,150", converted01->root_location().ToString()); | 170 EXPECT_EQ("150,150", converted01->root_location().ToString()); |
166 EXPECT_EQ(original01.flags(), converted01->flags()); | 171 EXPECT_EQ(original01.flags(), converted01->flags()); |
167 | 172 |
| 173 // Make RootWindow1 active so that capture window is parented to it. |
| 174 Shell::GetInstance()->set_active_root_window(root_windows[1]); |
| 175 |
168 // Start tracking from the RootWindow1 and converts the mouse event into | 176 // Start tracking from the RootWindow1 and converts the mouse event into |
169 // |window0|'s coodinates. | 177 // |window0|'s coodinates. |
170 ui::MouseEvent original10(ui::ET_MOUSE_DRAGGED, | 178 ui::MouseEvent original10(ui::ET_MOUSE_DRAGGED, |
171 gfx::Point(-150, 50), | 179 gfx::Point(-150, 50), |
172 gfx::Point(-150, 50), | 180 gfx::Point(-150, 50), |
173 ui::EF_NONE); | 181 ui::EF_NONE); |
174 scoped_ptr<ui::MouseEvent> converted10(ConvertMouseEvent(root_windows[1], | 182 scoped_ptr<ui::MouseEvent> converted10(ConvertMouseEvent(window0.get(), |
175 window0.get(), | |
176 original10)); | 183 original10)); |
177 EXPECT_EQ(original10.type(), converted10->type()); | 184 EXPECT_EQ(original10.type(), converted10->type()); |
178 EXPECT_EQ("50,50", converted10->location().ToString()); | 185 EXPECT_EQ("50,50", converted10->location().ToString()); |
179 EXPECT_EQ("50,50", converted10->root_location().ToString()); | 186 EXPECT_EQ("50,50", converted10->root_location().ToString()); |
180 EXPECT_EQ(original10.flags(), converted10->flags()); | 187 EXPECT_EQ(original10.flags(), converted10->flags()); |
181 | 188 |
182 // Start tracking from the RootWindow1 and converts the mouse event into | 189 // Start tracking from the RootWindow1 and converts the mouse event into |
183 // |window1|'s coodinates. | 190 // |window1|'s coodinates. |
184 ui::MouseEvent original11(ui::ET_MOUSE_DRAGGED, | 191 ui::MouseEvent original11(ui::ET_MOUSE_DRAGGED, |
185 gfx::Point(150, 150), | 192 gfx::Point(150, 150), |
186 gfx::Point(150, 150), | 193 gfx::Point(150, 150), |
187 ui::EF_NONE); | 194 ui::EF_NONE); |
188 scoped_ptr<ui::MouseEvent> converted11(ConvertMouseEvent(root_windows[1], | 195 scoped_ptr<ui::MouseEvent> converted11(ConvertMouseEvent(window1.get(), |
189 window1.get(), | |
190 original11)); | 196 original11)); |
191 EXPECT_EQ(original11.type(), converted11->type()); | 197 EXPECT_EQ(original11.type(), converted11->type()); |
192 EXPECT_EQ("50,50", converted11->location().ToString()); | 198 EXPECT_EQ("50,50", converted11->location().ToString()); |
193 EXPECT_EQ("150,150", converted11->root_location().ToString()); | 199 EXPECT_EQ("150,150", converted11->root_location().ToString()); |
194 EXPECT_EQ(original11.flags(), converted11->flags()); | 200 EXPECT_EQ(original11.flags(), converted11->flags()); |
195 } | 201 } |
196 | 202 |
197 } // namespace test | 203 } // namespace test |
198 } // namespace aura | 204 } // namespace aura |
OLD | NEW |