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/wm/cursor_manager.h" | 5 #include "ash/wm/cursor_manager.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
9 #include "ash/test/cursor_manager_test_api.h" | 9 #include "ash/test/cursor_manager_test_api.h" |
10 #include "ash/wm/image_cursors.h" | 10 #include "ash/wm/image_cursors.h" |
11 #include "ui/aura/root_window.h" | |
12 #include "ui/aura/test/test_window_delegate.h" | |
13 #include "ui/aura/test/test_windows.h" | |
14 #include "ui/aura/window.h" | |
11 | 15 |
12 namespace ash { | 16 namespace ash { |
13 namespace test { | 17 namespace test { |
14 | 18 |
19 namespace { | |
20 | |
21 // A delegate for recording a mouse event location. | |
22 class MouseEventLocationDelegate : public aura::test::TestWindowDelegate { | |
23 public: | |
24 MouseEventLocationDelegate() {} | |
25 virtual ~MouseEventLocationDelegate() {} | |
26 | |
27 gfx::Point mouse_event_location() const { return mouse_event_location_; } | |
oshima
2012/12/06 18:55:46
const gfx::Point&
mazda
2012/12/07 20:50:51
Done.
| |
28 | |
29 virtual ui::EventResult OnMouseEvent(ui::MouseEvent* event) OVERRIDE { | |
30 mouse_event_location_ = event->location(); | |
31 return ui::ER_HANDLED; | |
32 } | |
33 | |
34 private: | |
35 gfx::Point mouse_event_location_; | |
36 | |
37 DISALLOW_COPY_AND_ASSIGN(MouseEventLocationDelegate); | |
38 }; | |
39 | |
40 } // namespace | |
41 | |
15 typedef test::AshTestBase CursorManagerTest; | 42 typedef test::AshTestBase CursorManagerTest; |
16 | 43 |
17 TEST_F(CursorManagerTest, LockCursor) { | 44 TEST_F(CursorManagerTest, LockCursor) { |
18 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | 45 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); |
19 CursorManagerTestApi test_api(cursor_manager); | 46 CursorManagerTestApi test_api(cursor_manager); |
20 | 47 |
21 cursor_manager->SetCursor(ui::kCursorCopy); | 48 cursor_manager->SetCursor(ui::kCursorCopy); |
22 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); | 49 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); |
23 cursor_manager->SetDeviceScaleFactor(2.0f); | 50 cursor_manager->SetDeviceScaleFactor(2.0f); |
24 EXPECT_EQ(2.0f, test_api.GetDeviceScaleFactor()); | 51 EXPECT_EQ(2.0f, test_api.GetDeviceScaleFactor()); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 TEST_F(CursorManagerTest, SetDeviceScaleFactor) { | 138 TEST_F(CursorManagerTest, SetDeviceScaleFactor) { |
112 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | 139 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); |
113 CursorManagerTestApi test_api(cursor_manager); | 140 CursorManagerTestApi test_api(cursor_manager); |
114 | 141 |
115 cursor_manager->SetDeviceScaleFactor(2.0f); | 142 cursor_manager->SetDeviceScaleFactor(2.0f); |
116 EXPECT_EQ(2.0f, test_api.GetDeviceScaleFactor()); | 143 EXPECT_EQ(2.0f, test_api.GetDeviceScaleFactor()); |
117 cursor_manager->SetDeviceScaleFactor(1.0f); | 144 cursor_manager->SetDeviceScaleFactor(1.0f); |
118 EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor()); | 145 EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor()); |
119 } | 146 } |
120 | 147 |
148 // Verifies that LockCursor/UnlockCursor work correctly with EnableCursor. | |
149 TEST_F(CursorManagerTest, EnableCursor) { | |
150 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | |
151 CursorManagerTestApi test_api(cursor_manager); | |
152 | |
153 cursor_manager->SetCursor(ui::kCursorCopy); | |
154 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); | |
155 | |
156 cursor_manager->EnableCursor(true); | |
157 EXPECT_TRUE(test_api.GetEnabled()); | |
158 cursor_manager->EnableCursor(false); | |
159 EXPECT_FALSE(test_api.GetEnabled()); | |
160 // The current cursor does not change even when the cursor is not shown. | |
161 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); | |
162 | |
163 // Check if cursor enable state is locked. | |
164 cursor_manager->LockCursor(); | |
165 EXPECT_FALSE(test_api.GetEnabled()); | |
166 cursor_manager->EnableCursor(true); | |
167 EXPECT_FALSE(test_api.GetEnabled()); | |
168 cursor_manager->UnlockCursor(); | |
169 EXPECT_TRUE(test_api.GetEnabled()); | |
170 | |
171 cursor_manager->LockCursor(); | |
172 EXPECT_TRUE(test_api.GetEnabled()); | |
173 cursor_manager->EnableCursor(false); | |
174 EXPECT_TRUE(test_api.GetEnabled()); | |
175 cursor_manager->UnlockCursor(); | |
176 EXPECT_FALSE(test_api.GetEnabled()); | |
177 | |
178 // Checks enabling cursor while cursor is locked does not affect the | |
179 // subsequent uses of UnlockCursor. | |
180 cursor_manager->LockCursor(); | |
181 cursor_manager->EnableCursor(false); | |
182 cursor_manager->UnlockCursor(); | |
183 EXPECT_FALSE(test_api.GetEnabled()); | |
184 | |
185 cursor_manager->EnableCursor(true); | |
186 cursor_manager->LockCursor(); | |
187 cursor_manager->UnlockCursor(); | |
188 EXPECT_TRUE(test_api.GetEnabled()); | |
189 | |
190 cursor_manager->LockCursor(); | |
191 cursor_manager->EnableCursor(true); | |
192 cursor_manager->UnlockCursor(); | |
193 EXPECT_TRUE(test_api.GetEnabled()); | |
194 | |
195 cursor_manager->EnableCursor(false); | |
196 cursor_manager->LockCursor(); | |
197 cursor_manager->UnlockCursor(); | |
198 EXPECT_FALSE(test_api.GetEnabled()); | |
199 } | |
200 | |
201 // Verifies that the cursor state changes correctly when ShowCursor and | |
202 // EnableCursor are used together. | |
203 TEST_F(CursorManagerTest, ShowAndEnable) { | |
204 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | |
205 CursorManagerTestApi test_api(cursor_manager); | |
206 | |
207 // Changing the visibility of the cursor does not affect the enable state. | |
208 cursor_manager->EnableCursor(true); | |
209 cursor_manager->ShowCursor(true); | |
210 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
211 EXPECT_TRUE(test_api.GetEnabled()); | |
212 cursor_manager->ShowCursor(false); | |
213 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
214 EXPECT_TRUE(test_api.GetEnabled()); | |
215 cursor_manager->ShowCursor(true); | |
216 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
217 EXPECT_TRUE(test_api.GetEnabled()); | |
218 | |
219 // When the cursor is disabled, it also gets invisible. | |
220 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
221 cursor_manager->EnableCursor(false); | |
222 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
223 EXPECT_FALSE(test_api.GetEnabled()); | |
224 | |
225 // When the cursor is enabled, it restores the visibility state. | |
226 cursor_manager->EnableCursor(true); | |
227 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
228 EXPECT_TRUE(test_api.GetEnabled()); | |
229 cursor_manager->ShowCursor(false); | |
230 cursor_manager->EnableCursor(false); | |
231 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
232 EXPECT_FALSE(test_api.GetEnabled()); | |
233 cursor_manager->EnableCursor(true); | |
234 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
235 EXPECT_TRUE(test_api.GetEnabled()); | |
236 | |
237 // When the cursor is disabled, ShowCursor is ignored. | |
238 cursor_manager->EnableCursor(false); | |
239 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
240 EXPECT_FALSE(test_api.GetEnabled()); | |
241 cursor_manager->ShowCursor(true); | |
242 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
243 EXPECT_FALSE(test_api.GetEnabled()); | |
244 cursor_manager->EnableCursor(false); | |
245 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
246 EXPECT_FALSE(test_api.GetEnabled()); | |
247 } | |
248 | |
249 // Verifies that RootWindow generates a mouse event located outside of a window | |
250 // when the cursor is disabled. | |
251 #if defined(OS_WIN) | |
252 // Temporarily disabled for windows. See crbug.com/112222. | |
253 TEST_F(CursorManagerTest, DISABLED_DisabledCursorLocation) { | |
254 #else | |
255 TEST_F(CursorManagerTest, DisabledCursorLocation) { | |
256 #endif // defined(OS_WIN) | |
257 scoped_ptr<MouseEventLocationDelegate> delegate( | |
258 new MouseEventLocationDelegate()); | |
259 const int kWindowWidth = 123; | |
260 const int kWindowHeight = 45; | |
261 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | |
262 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( | |
263 delegate.get(), 1, bounds, Shell::GetInstance()->GetPrimaryRootWindow())); | |
264 | |
265 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | |
266 cursor_manager->EnableCursor(true); | |
267 // Send a mouse event to window. | |
268 gfx::Point point(101, 201); | |
269 gfx::Point local_point; | |
270 ui::MouseEvent event(ui::ET_MOUSE_MOVED, point, point, 0); | |
271 aura::RootWindow* root_window = window->GetRootWindow(); | |
272 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&event); | |
273 | |
274 // Location was in window. | |
275 local_point = delegate->mouse_event_location(); | |
276 aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point); | |
277 EXPECT_TRUE(window->bounds().Contains(local_point)); | |
278 | |
279 // Location is now out of window. | |
280 cursor_manager->EnableCursor(false); | |
281 RunAllPendingInMessageLoop(); | |
282 local_point = delegate->mouse_event_location(); | |
283 aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point); | |
284 EXPECT_FALSE(window->bounds().Contains(local_point)); | |
285 | |
286 // Location is back in window. | |
287 cursor_manager->EnableCursor(true); | |
288 RunAllPendingInMessageLoop(); | |
289 local_point = delegate->mouse_event_location(); | |
290 aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point); | |
291 EXPECT_TRUE(window->bounds().Contains(local_point)); | |
292 } | |
293 | |
121 } // namespace test | 294 } // namespace test |
122 } // namespace ash | 295 } // namespace ash |
OLD | NEW |