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 "ui/aura/client/cursor_client_observer.h" | 7 #include "ui/aura/client/cursor_client_observer.h" |
8 #include "ui/aura/test/aura_test_base.h" | 8 #include "ui/aura/test/aura_test_base.h" |
9 #include "ui/wm/core/native_cursor_manager.h" | 9 #include "ui/wm/core/native_cursor_manager.h" |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 class TestingCursorManager : public wm::NativeCursorManager { | 13 class TestingCursorManager : public wm::NativeCursorManager { |
14 public: | 14 public: |
15 // Overridden from wm::NativeCursorManager: | 15 // Overridden from wm::NativeCursorManager: |
16 virtual void SetDisplay( | 16 void SetDisplay(const gfx::Display& display, |
17 const gfx::Display& display, | 17 wm::NativeCursorManagerDelegate* delegate) override {} |
18 wm::NativeCursorManagerDelegate* delegate) override {} | |
19 | 18 |
20 virtual void SetCursor( | 19 void SetCursor(gfx::NativeCursor cursor, |
21 gfx::NativeCursor cursor, | 20 wm::NativeCursorManagerDelegate* delegate) override { |
22 wm::NativeCursorManagerDelegate* delegate) override { | |
23 delegate->CommitCursor(cursor); | 21 delegate->CommitCursor(cursor); |
24 } | 22 } |
25 | 23 |
26 virtual void SetVisibility( | 24 void SetVisibility(bool visible, |
27 bool visible, | 25 wm::NativeCursorManagerDelegate* delegate) override { |
28 wm::NativeCursorManagerDelegate* delegate) override { | |
29 delegate->CommitVisibility(visible); | 26 delegate->CommitVisibility(visible); |
30 } | 27 } |
31 | 28 |
32 virtual void SetMouseEventsEnabled( | 29 void SetMouseEventsEnabled( |
33 bool enabled, | 30 bool enabled, |
34 wm::NativeCursorManagerDelegate* delegate) override { | 31 wm::NativeCursorManagerDelegate* delegate) override { |
35 delegate->CommitMouseEventsEnabled(enabled); | 32 delegate->CommitMouseEventsEnabled(enabled); |
36 } | 33 } |
37 | 34 |
38 virtual void SetCursorSet( | 35 void SetCursorSet(ui::CursorSetType cursor_set, |
39 ui::CursorSetType cursor_set, | 36 wm::NativeCursorManagerDelegate* delegate) override { |
40 wm::NativeCursorManagerDelegate* delegate) override { | |
41 delegate->CommitCursorSet(cursor_set); | 37 delegate->CommitCursorSet(cursor_set); |
42 } | 38 } |
43 }; | 39 }; |
44 | 40 |
45 } // namespace | 41 } // namespace |
46 | 42 |
47 class CursorManagerTest : public aura::test::AuraTestBase { | 43 class CursorManagerTest : public aura::test::AuraTestBase { |
48 protected: | 44 protected: |
49 CursorManagerTest() | 45 CursorManagerTest() |
50 : delegate_(new TestingCursorManager), | 46 : delegate_(new TestingCursorManager), |
51 cursor_manager_(scoped_ptr<wm::NativeCursorManager>( | 47 cursor_manager_(scoped_ptr<wm::NativeCursorManager>( |
52 delegate_)) { | 48 delegate_)) { |
53 } | 49 } |
54 | 50 |
55 TestingCursorManager* delegate_; | 51 TestingCursorManager* delegate_; |
56 wm::CursorManager cursor_manager_; | 52 wm::CursorManager cursor_manager_; |
57 }; | 53 }; |
58 | 54 |
59 class TestingCursorClientObserver : public aura::client::CursorClientObserver { | 55 class TestingCursorClientObserver : public aura::client::CursorClientObserver { |
60 public: | 56 public: |
61 TestingCursorClientObserver() | 57 TestingCursorClientObserver() |
62 : cursor_visibility_(false), | 58 : cursor_visibility_(false), |
63 did_visibility_change_(false) {} | 59 did_visibility_change_(false) {} |
64 void reset() { cursor_visibility_ = did_visibility_change_ = false; } | 60 void reset() { cursor_visibility_ = did_visibility_change_ = false; } |
65 bool is_cursor_visible() const { return cursor_visibility_; } | 61 bool is_cursor_visible() const { return cursor_visibility_; } |
66 bool did_visibility_change() const { return did_visibility_change_; } | 62 bool did_visibility_change() const { return did_visibility_change_; } |
67 | 63 |
68 // Overridden from aura::client::CursorClientObserver: | 64 // Overridden from aura::client::CursorClientObserver: |
69 virtual void OnCursorVisibilityChanged(bool is_visible) override { | 65 void OnCursorVisibilityChanged(bool is_visible) override { |
70 cursor_visibility_ = is_visible; | 66 cursor_visibility_ = is_visible; |
71 did_visibility_change_ = true; | 67 did_visibility_change_ = true; |
72 } | 68 } |
73 | 69 |
74 private: | 70 private: |
75 bool cursor_visibility_; | 71 bool cursor_visibility_; |
76 bool did_visibility_change_; | 72 bool did_visibility_change_; |
77 | 73 |
78 DISALLOW_COPY_AND_ASSIGN(TestingCursorClientObserver); | 74 DISALLOW_COPY_AND_ASSIGN(TestingCursorClientObserver); |
79 }; | 75 }; |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 EXPECT_FALSE(observer_a.is_cursor_visible()); | 317 EXPECT_FALSE(observer_a.is_cursor_visible()); |
322 | 318 |
323 // Show the cursor using ShowCursor(). | 319 // Show the cursor using ShowCursor(). |
324 observer_a.reset(); | 320 observer_a.reset(); |
325 observer_b.reset(); | 321 observer_b.reset(); |
326 cursor_manager_.ShowCursor(); | 322 cursor_manager_.ShowCursor(); |
327 EXPECT_TRUE(observer_a.did_visibility_change()); | 323 EXPECT_TRUE(observer_a.did_visibility_change()); |
328 EXPECT_FALSE(observer_b.did_visibility_change()); | 324 EXPECT_FALSE(observer_b.did_visibility_change()); |
329 EXPECT_TRUE(observer_a.is_cursor_visible()); | 325 EXPECT_TRUE(observer_a.is_cursor_visible()); |
330 } | 326 } |
OLD | NEW |