OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ui/wm/core/cursor_manager.h" | 5 #include "ui/wm/core/cursor_manager.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "ui/aura/client/cursor_client_observer.h" | 9 #include "ui/aura/client/cursor_client_observer.h" |
10 #include "ui/aura/test/aura_test_base.h" | 10 #include "ui/aura/test/aura_test_base.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 wm::NativeCursorManagerDelegate* delegate) override { | 28 wm::NativeCursorManagerDelegate* delegate) override { |
29 delegate->CommitVisibility(visible); | 29 delegate->CommitVisibility(visible); |
30 } | 30 } |
31 | 31 |
32 void SetMouseEventsEnabled( | 32 void SetMouseEventsEnabled( |
33 bool enabled, | 33 bool enabled, |
34 wm::NativeCursorManagerDelegate* delegate) override { | 34 wm::NativeCursorManagerDelegate* delegate) override { |
35 delegate->CommitMouseEventsEnabled(enabled); | 35 delegate->CommitMouseEventsEnabled(enabled); |
36 } | 36 } |
37 | 37 |
38 void SetCursorSet(ui::CursorSetType cursor_set, | 38 void SetCursorSize(ui::CursorSize cursor_size, |
39 wm::NativeCursorManagerDelegate* delegate) override { | 39 wm::NativeCursorManagerDelegate* delegate) override { |
40 delegate->CommitCursorSet(cursor_set); | 40 delegate->CommitCursorSize(cursor_size); |
41 } | 41 } |
42 }; | 42 }; |
43 | 43 |
44 } // namespace | 44 } // namespace |
45 | 45 |
46 class CursorManagerTest : public aura::test::AuraTestBase { | 46 class CursorManagerTest : public aura::test::AuraTestBase { |
47 protected: | 47 protected: |
48 CursorManagerTest() | 48 CursorManagerTest() |
49 : delegate_(new TestingCursorManager), | 49 : delegate_(new TestingCursorManager), |
50 cursor_manager_(base::WrapUnique(delegate_)) {} | 50 cursor_manager_(base::WrapUnique(delegate_)) {} |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 cursor_manager_.EnableMouseEvents(); | 146 cursor_manager_.EnableMouseEvents(); |
147 cursor_manager_.UnlockCursor(); | 147 cursor_manager_.UnlockCursor(); |
148 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); | 148 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); |
149 | 149 |
150 cursor_manager_.DisableMouseEvents(); | 150 cursor_manager_.DisableMouseEvents(); |
151 cursor_manager_.LockCursor(); | 151 cursor_manager_.LockCursor(); |
152 cursor_manager_.UnlockCursor(); | 152 cursor_manager_.UnlockCursor(); |
153 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); | 153 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); |
154 } | 154 } |
155 | 155 |
156 TEST_F(CursorManagerTest, SetCursorSet) { | 156 TEST_F(CursorManagerTest, SetCursorSize) { |
157 wm::TestingCursorClientObserver observer; | 157 wm::TestingCursorClientObserver observer; |
158 cursor_manager_.AddObserver(&observer); | 158 cursor_manager_.AddObserver(&observer); |
159 | 159 |
160 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet()); | 160 EXPECT_EQ(ui::CursorSize::kNormal, cursor_manager_.GetCursorSize()); |
161 EXPECT_EQ(ui::CURSOR_SET_NORMAL, observer.cursor_set()); | 161 EXPECT_EQ(ui::CursorSize::kNormal, observer.cursor_size()); |
162 | 162 |
163 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL); | 163 cursor_manager_.SetCursorSize(ui::CursorSize::kNormal); |
164 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet()); | 164 EXPECT_EQ(ui::CursorSize::kNormal, cursor_manager_.GetCursorSize()); |
165 EXPECT_EQ(ui::CURSOR_SET_NORMAL, observer.cursor_set()); | 165 EXPECT_EQ(ui::CursorSize::kNormal, observer.cursor_size()); |
166 | 166 |
167 cursor_manager_.SetCursorSet(ui::CURSOR_SET_LARGE); | 167 cursor_manager_.SetCursorSize(ui::CursorSize::kLarge); |
168 EXPECT_EQ(ui::CURSOR_SET_LARGE, cursor_manager_.GetCursorSet()); | 168 EXPECT_EQ(ui::CursorSize::kLarge, cursor_manager_.GetCursorSize()); |
169 EXPECT_EQ(ui::CURSOR_SET_LARGE, observer.cursor_set()); | 169 EXPECT_EQ(ui::CursorSize::kLarge, observer.cursor_size()); |
170 | 170 |
171 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL); | 171 cursor_manager_.SetCursorSize(ui::CursorSize::kNormal); |
172 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet()); | 172 EXPECT_EQ(ui::CursorSize::kNormal, cursor_manager_.GetCursorSize()); |
173 EXPECT_EQ(ui::CURSOR_SET_NORMAL, observer.cursor_set()); | 173 EXPECT_EQ(ui::CursorSize::kNormal, observer.cursor_size()); |
174 } | 174 } |
175 | 175 |
176 TEST_F(CursorManagerTest, IsMouseEventsEnabled) { | 176 TEST_F(CursorManagerTest, IsMouseEventsEnabled) { |
177 cursor_manager_.EnableMouseEvents(); | 177 cursor_manager_.EnableMouseEvents(); |
178 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); | 178 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); |
179 cursor_manager_.DisableMouseEvents(); | 179 cursor_manager_.DisableMouseEvents(); |
180 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); | 180 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); |
181 } | 181 } |
182 | 182 |
183 // Verifies that the mouse events enable state changes correctly when | 183 // Verifies that the mouse events enable state changes correctly when |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 cursor_manager_.AddObserver(&observer_a); | 266 cursor_manager_.AddObserver(&observer_a); |
267 cursor_manager_.AddObserver(&observer_b); | 267 cursor_manager_.AddObserver(&observer_b); |
268 | 268 |
269 // Initial state before any events have been sent. | 269 // Initial state before any events have been sent. |
270 observer_a.reset(); | 270 observer_a.reset(); |
271 observer_b.reset(); | 271 observer_b.reset(); |
272 EXPECT_FALSE(observer_a.did_visibility_change()); | 272 EXPECT_FALSE(observer_a.did_visibility_change()); |
273 EXPECT_FALSE(observer_b.did_visibility_change()); | 273 EXPECT_FALSE(observer_b.did_visibility_change()); |
274 EXPECT_FALSE(observer_a.is_cursor_visible()); | 274 EXPECT_FALSE(observer_a.is_cursor_visible()); |
275 EXPECT_FALSE(observer_b.is_cursor_visible()); | 275 EXPECT_FALSE(observer_b.is_cursor_visible()); |
276 EXPECT_FALSE(observer_a.did_cursor_set_change()); | 276 EXPECT_FALSE(observer_a.did_cursor_size_change()); |
277 EXPECT_FALSE(observer_b.did_cursor_set_change()); | 277 EXPECT_FALSE(observer_b.did_cursor_size_change()); |
278 | 278 |
279 // Hide the cursor using HideCursor(). | 279 // Hide the cursor using HideCursor(). |
280 cursor_manager_.HideCursor(); | 280 cursor_manager_.HideCursor(); |
281 EXPECT_TRUE(observer_a.did_visibility_change()); | 281 EXPECT_TRUE(observer_a.did_visibility_change()); |
282 EXPECT_TRUE(observer_b.did_visibility_change()); | 282 EXPECT_TRUE(observer_b.did_visibility_change()); |
283 EXPECT_FALSE(observer_a.is_cursor_visible()); | 283 EXPECT_FALSE(observer_a.is_cursor_visible()); |
284 EXPECT_FALSE(observer_b.is_cursor_visible()); | 284 EXPECT_FALSE(observer_b.is_cursor_visible()); |
285 | 285 |
286 // Set the cursor set. | 286 // Set the cursor set. |
287 cursor_manager_.SetCursorSet(ui::CURSOR_SET_LARGE); | 287 cursor_manager_.SetCursorSize(ui::CursorSize::kLarge); |
288 EXPECT_TRUE(observer_a.did_cursor_set_change()); | 288 EXPECT_TRUE(observer_a.did_cursor_size_change()); |
289 EXPECT_EQ(ui::CURSOR_SET_LARGE, observer_a.cursor_set()); | 289 EXPECT_EQ(ui::CursorSize::kLarge, observer_a.cursor_size()); |
290 EXPECT_TRUE(observer_b.did_cursor_set_change()); | 290 EXPECT_TRUE(observer_b.did_cursor_size_change()); |
291 EXPECT_EQ(ui::CURSOR_SET_LARGE, observer_b.cursor_set()); | 291 EXPECT_EQ(ui::CursorSize::kLarge, observer_b.cursor_size()); |
292 | 292 |
293 // Show the cursor using ShowCursor(). | 293 // Show the cursor using ShowCursor(). |
294 observer_a.reset(); | 294 observer_a.reset(); |
295 observer_b.reset(); | 295 observer_b.reset(); |
296 cursor_manager_.ShowCursor(); | 296 cursor_manager_.ShowCursor(); |
297 EXPECT_TRUE(observer_a.did_visibility_change()); | 297 EXPECT_TRUE(observer_a.did_visibility_change()); |
298 EXPECT_TRUE(observer_b.did_visibility_change()); | 298 EXPECT_TRUE(observer_b.did_visibility_change()); |
299 EXPECT_TRUE(observer_a.is_cursor_visible()); | 299 EXPECT_TRUE(observer_a.is_cursor_visible()); |
300 EXPECT_TRUE(observer_b.is_cursor_visible()); | 300 EXPECT_TRUE(observer_b.is_cursor_visible()); |
301 | 301 |
302 // Remove observer_b. Its OnCursorVisibilityChanged() should | 302 // Remove observer_b. Its OnCursorVisibilityChanged() should |
303 // not be invoked past this point. | 303 // not be invoked past this point. |
304 cursor_manager_.RemoveObserver(&observer_b); | 304 cursor_manager_.RemoveObserver(&observer_b); |
305 | 305 |
306 // Hide the cursor using HideCursor(). | 306 // Hide the cursor using HideCursor(). |
307 observer_a.reset(); | 307 observer_a.reset(); |
308 observer_b.reset(); | 308 observer_b.reset(); |
309 cursor_manager_.HideCursor(); | 309 cursor_manager_.HideCursor(); |
310 EXPECT_TRUE(observer_a.did_visibility_change()); | 310 EXPECT_TRUE(observer_a.did_visibility_change()); |
311 EXPECT_FALSE(observer_b.did_visibility_change()); | 311 EXPECT_FALSE(observer_b.did_visibility_change()); |
312 EXPECT_FALSE(observer_a.is_cursor_visible()); | 312 EXPECT_FALSE(observer_a.is_cursor_visible()); |
313 | 313 |
314 // Set back the cursor set to normal. | 314 // Set back the cursor set to normal. |
315 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL); | 315 cursor_manager_.SetCursorSize(ui::CursorSize::kNormal); |
316 EXPECT_TRUE(observer_a.did_cursor_set_change()); | 316 EXPECT_TRUE(observer_a.did_cursor_size_change()); |
317 EXPECT_EQ(ui::CURSOR_SET_NORMAL, observer_a.cursor_set()); | 317 EXPECT_EQ(ui::CursorSize::kNormal, observer_a.cursor_size()); |
318 EXPECT_FALSE(observer_b.did_cursor_set_change()); | 318 EXPECT_FALSE(observer_b.did_cursor_size_change()); |
319 | 319 |
320 // Show the cursor using ShowCursor(). | 320 // Show the cursor using ShowCursor(). |
321 observer_a.reset(); | 321 observer_a.reset(); |
322 observer_b.reset(); | 322 observer_b.reset(); |
323 cursor_manager_.ShowCursor(); | 323 cursor_manager_.ShowCursor(); |
324 EXPECT_TRUE(observer_a.did_visibility_change()); | 324 EXPECT_TRUE(observer_a.did_visibility_change()); |
325 EXPECT_FALSE(observer_b.did_visibility_change()); | 325 EXPECT_FALSE(observer_b.did_visibility_change()); |
326 EXPECT_TRUE(observer_a.is_cursor_visible()); | 326 EXPECT_TRUE(observer_a.is_cursor_visible()); |
327 } | 327 } |
328 | 328 |
(...skipping 24 matching lines...) Expand all Loading... |
353 // This block validates that the cursor is visible initially. It then | 353 // This block validates that the cursor is visible initially. It then |
354 // performs normal cursor visibility operations. | 354 // performs normal cursor visibility operations. |
355 { | 355 { |
356 wm::CursorManager cursor_manager3( | 356 wm::CursorManager cursor_manager3( |
357 base::WrapUnique(new TestingCursorManager)); | 357 base::WrapUnique(new TestingCursorManager)); |
358 EXPECT_TRUE(cursor_manager3.IsCursorVisible()); | 358 EXPECT_TRUE(cursor_manager3.IsCursorVisible()); |
359 cursor_manager3.HideCursor(); | 359 cursor_manager3.HideCursor(); |
360 EXPECT_FALSE(cursor_manager3.IsCursorVisible()); | 360 EXPECT_FALSE(cursor_manager3.IsCursorVisible()); |
361 } | 361 } |
362 } | 362 } |
OLD | NEW |