OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/views/corewm/cursor_controller.h" |
| 6 |
| 7 #include "ui/views/test/views_test_base.h" |
| 8 |
| 9 class TestingCursorController : public views::corewm::CursorController { |
| 10 public: |
| 11 // Overridden from aura::client::CursorClient |
| 12 virtual void SetDeviceScaleFactor(float device_scale_factor) OVERRIDE { |
| 13 // No implementation, as there are no correct semantics during tests. |
| 14 } |
| 15 |
| 16 gfx::NativeCursor current_cursor() { return GetCurrentCursor(); } |
| 17 }; |
| 18 |
| 19 class CursorControllerTest : public views::ViewsTestBase { |
| 20 protected: |
| 21 TestingCursorController cursor_controller_; |
| 22 }; |
| 23 |
| 24 TEST_F(CursorControllerTest, ShowHideCursor) { |
| 25 cursor_controller_.SetCursor(ui::kCursorCopy); |
| 26 EXPECT_EQ(ui::kCursorCopy, cursor_controller_.current_cursor().native_type()); |
| 27 |
| 28 cursor_controller_.ShowCursor(); |
| 29 EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
| 30 cursor_controller_.HideCursor(); |
| 31 EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
| 32 // The current cursor does not change even when the cursor is not shown. |
| 33 EXPECT_EQ(ui::kCursorCopy, cursor_controller_.current_cursor().native_type()); |
| 34 |
| 35 // Check if cursor visibility is locked. |
| 36 cursor_controller_.LockCursor(); |
| 37 EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
| 38 cursor_controller_.ShowCursor(); |
| 39 EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
| 40 cursor_controller_.UnlockCursor(); |
| 41 EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
| 42 |
| 43 cursor_controller_.LockCursor(); |
| 44 EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
| 45 cursor_controller_.HideCursor(); |
| 46 EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
| 47 cursor_controller_.UnlockCursor(); |
| 48 EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
| 49 |
| 50 // Checks setting visiblity while cursor is locked does not affect the |
| 51 // subsequent uses of UnlockCursor. |
| 52 cursor_controller_.LockCursor(); |
| 53 cursor_controller_.HideCursor(); |
| 54 cursor_controller_.UnlockCursor(); |
| 55 EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
| 56 |
| 57 cursor_controller_.ShowCursor(); |
| 58 cursor_controller_.LockCursor(); |
| 59 cursor_controller_.UnlockCursor(); |
| 60 EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
| 61 |
| 62 cursor_controller_.LockCursor(); |
| 63 cursor_controller_.ShowCursor(); |
| 64 cursor_controller_.UnlockCursor(); |
| 65 EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
| 66 |
| 67 cursor_controller_.HideCursor(); |
| 68 cursor_controller_.LockCursor(); |
| 69 cursor_controller_.UnlockCursor(); |
| 70 EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
| 71 } |
| 72 |
| 73 // Verifies that LockCursor/UnlockCursor work correctly with |
| 74 // EnableMouseEvents and DisableMouseEvents |
| 75 TEST_F(CursorControllerTest, EnableDisableMouseEvents) { |
| 76 cursor_controller_.SetCursor(ui::kCursorCopy); |
| 77 EXPECT_EQ(ui::kCursorCopy, cursor_controller_.current_cursor().native_type()); |
| 78 |
| 79 cursor_controller_.EnableMouseEvents(); |
| 80 EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
| 81 cursor_controller_.DisableMouseEvents(); |
| 82 EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
| 83 // The current cursor does not change even when the cursor is not shown. |
| 84 EXPECT_EQ(ui::kCursorCopy, cursor_controller_.current_cursor().native_type()); |
| 85 |
| 86 // Check if cursor enable state is locked. |
| 87 cursor_controller_.LockCursor(); |
| 88 EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
| 89 cursor_controller_.EnableMouseEvents(); |
| 90 EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
| 91 cursor_controller_.UnlockCursor(); |
| 92 EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
| 93 |
| 94 cursor_controller_.LockCursor(); |
| 95 EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
| 96 cursor_controller_.DisableMouseEvents(); |
| 97 EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
| 98 cursor_controller_.UnlockCursor(); |
| 99 EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
| 100 |
| 101 // Checks enabling cursor while cursor is locked does not affect the |
| 102 // subsequent uses of UnlockCursor. |
| 103 cursor_controller_.LockCursor(); |
| 104 cursor_controller_.DisableMouseEvents(); |
| 105 cursor_controller_.UnlockCursor(); |
| 106 EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
| 107 |
| 108 cursor_controller_.EnableMouseEvents(); |
| 109 cursor_controller_.LockCursor(); |
| 110 cursor_controller_.UnlockCursor(); |
| 111 EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
| 112 |
| 113 cursor_controller_.LockCursor(); |
| 114 cursor_controller_.EnableMouseEvents(); |
| 115 cursor_controller_.UnlockCursor(); |
| 116 EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
| 117 |
| 118 cursor_controller_.DisableMouseEvents(); |
| 119 cursor_controller_.LockCursor(); |
| 120 cursor_controller_.UnlockCursor(); |
| 121 EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
| 122 } |
| 123 |
| 124 TEST_F(CursorControllerTest, IsMouseEventsEnabled) { |
| 125 cursor_controller_.EnableMouseEvents(); |
| 126 EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
| 127 cursor_controller_.DisableMouseEvents(); |
| 128 EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
| 129 } |
| 130 |
| 131 // Verifies that the mouse events enable state changes correctly when |
| 132 // ShowCursor/HideCursor and EnableMouseEvents/DisableMouseEvents are used |
| 133 // together. |
| 134 TEST_F(CursorControllerTest, ShowAndEnable) { |
| 135 // Changing the visibility of the cursor does not affect the enable state. |
| 136 cursor_controller_.EnableMouseEvents(); |
| 137 cursor_controller_.ShowCursor(); |
| 138 EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
| 139 EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
| 140 cursor_controller_.HideCursor(); |
| 141 EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
| 142 EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
| 143 cursor_controller_.ShowCursor(); |
| 144 EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
| 145 EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
| 146 |
| 147 // When mouse events are disabled, it also gets invisible. |
| 148 EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
| 149 cursor_controller_.DisableMouseEvents(); |
| 150 EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
| 151 EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
| 152 |
| 153 // When mouse events are enabled, it restores the visibility state. |
| 154 cursor_controller_.EnableMouseEvents(); |
| 155 EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
| 156 EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
| 157 |
| 158 cursor_controller_.ShowCursor(); |
| 159 cursor_controller_.DisableMouseEvents(); |
| 160 EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
| 161 EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
| 162 cursor_controller_.EnableMouseEvents(); |
| 163 EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
| 164 EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
| 165 |
| 166 cursor_controller_.HideCursor(); |
| 167 cursor_controller_.DisableMouseEvents(); |
| 168 EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
| 169 EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
| 170 cursor_controller_.EnableMouseEvents(); |
| 171 EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
| 172 EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
| 173 |
| 174 // When mouse events are disabled, ShowCursor is ignored. |
| 175 cursor_controller_.DisableMouseEvents(); |
| 176 EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
| 177 EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
| 178 cursor_controller_.ShowCursor(); |
| 179 EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
| 180 EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
| 181 cursor_controller_.DisableMouseEvents(); |
| 182 EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
| 183 EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
| 184 } |
| 185 |
| 186 // Verifies that calling DisableMouseEvents multiple times in a row makes no |
| 187 // difference compared with calling it once. |
| 188 // This is a regression test for http://crbug.com/169404. |
| 189 TEST_F(CursorControllerTest, MultipleDisableMouseEvents) { |
| 190 cursor_controller_.DisableMouseEvents(); |
| 191 cursor_controller_.DisableMouseEvents(); |
| 192 cursor_controller_.EnableMouseEvents(); |
| 193 cursor_controller_.LockCursor(); |
| 194 cursor_controller_.UnlockCursor(); |
| 195 EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
| 196 } |
| 197 |
| 198 // Verifies that calling EnableMouseEvents multiple times in a row makes no |
| 199 // difference compared with calling it once. |
| 200 TEST_F(CursorControllerTest, MultipleEnableMouseEvents) { |
| 201 cursor_controller_.DisableMouseEvents(); |
| 202 cursor_controller_.EnableMouseEvents(); |
| 203 cursor_controller_.EnableMouseEvents(); |
| 204 cursor_controller_.LockCursor(); |
| 205 cursor_controller_.UnlockCursor(); |
| 206 EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
| 207 } |
OLD | NEW |