| 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" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 CursorManagerTestApi test_api(cursor_manager); | 78 CursorManagerTestApi test_api(cursor_manager); |
| 79 | 79 |
| 80 cursor_manager->SetCursor(ui::kCursorCopy); | 80 cursor_manager->SetCursor(ui::kCursorCopy); |
| 81 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); | 81 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); |
| 82 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); | 82 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); |
| 83 cursor_manager->SetCursor(ui::kCursorPointer); | 83 cursor_manager->SetCursor(ui::kCursorPointer); |
| 84 EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type()); | 84 EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type()); |
| 85 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); | 85 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 TEST_F(CursorManagerTest, ShowHideCursor) { | |
| 89 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | |
| 90 CursorManagerTestApi test_api(cursor_manager); | |
| 91 | |
| 92 cursor_manager->SetCursor(ui::kCursorCopy); | |
| 93 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); | |
| 94 | |
| 95 cursor_manager->ShowCursor(); | |
| 96 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
| 97 cursor_manager->HideCursor(); | |
| 98 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 99 // The current cursor does not change even when the cursor is not shown. | |
| 100 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); | |
| 101 | |
| 102 // Check if cursor visibility is locked. | |
| 103 cursor_manager->LockCursor(); | |
| 104 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 105 cursor_manager->ShowCursor(); | |
| 106 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 107 cursor_manager->UnlockCursor(); | |
| 108 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
| 109 | |
| 110 cursor_manager->LockCursor(); | |
| 111 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
| 112 cursor_manager->HideCursor(); | |
| 113 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
| 114 cursor_manager->UnlockCursor(); | |
| 115 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 116 | |
| 117 // Checks setting visiblity while cursor is locked does not affect the | |
| 118 // subsequent uses of UnlockCursor. | |
| 119 cursor_manager->LockCursor(); | |
| 120 cursor_manager->HideCursor(); | |
| 121 cursor_manager->UnlockCursor(); | |
| 122 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 123 | |
| 124 cursor_manager->ShowCursor(); | |
| 125 cursor_manager->LockCursor(); | |
| 126 cursor_manager->UnlockCursor(); | |
| 127 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
| 128 | |
| 129 cursor_manager->LockCursor(); | |
| 130 cursor_manager->ShowCursor(); | |
| 131 cursor_manager->UnlockCursor(); | |
| 132 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
| 133 | |
| 134 cursor_manager->HideCursor(); | |
| 135 cursor_manager->LockCursor(); | |
| 136 cursor_manager->UnlockCursor(); | |
| 137 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 138 } | |
| 139 | |
| 140 TEST_F(CursorManagerTest, SetDeviceScaleFactor) { | 88 TEST_F(CursorManagerTest, SetDeviceScaleFactor) { |
| 141 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | 89 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); |
| 142 CursorManagerTestApi test_api(cursor_manager); | 90 CursorManagerTestApi test_api(cursor_manager); |
| 143 | 91 |
| 144 cursor_manager->SetDeviceScaleFactor(2.0f); | 92 cursor_manager->SetDeviceScaleFactor(2.0f); |
| 145 EXPECT_EQ(2.0f, test_api.GetDeviceScaleFactor()); | 93 EXPECT_EQ(2.0f, test_api.GetDeviceScaleFactor()); |
| 146 cursor_manager->SetDeviceScaleFactor(1.0f); | 94 cursor_manager->SetDeviceScaleFactor(1.0f); |
| 147 EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor()); | 95 EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor()); |
| 148 } | 96 } |
| 149 | 97 |
| 150 // Verifies that LockCursor/UnlockCursor work correctly with | |
| 151 // EnableMouseEvents and DisableMouseEvents | |
| 152 TEST_F(CursorManagerTest, EnableDisableMouseEvents) { | |
| 153 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | |
| 154 CursorManagerTestApi test_api(cursor_manager); | |
| 155 | |
| 156 cursor_manager->SetCursor(ui::kCursorCopy); | |
| 157 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); | |
| 158 | |
| 159 cursor_manager->EnableMouseEvents(); | |
| 160 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 161 cursor_manager->DisableMouseEvents(); | |
| 162 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); | |
| 163 // The current cursor does not change even when the cursor is not shown. | |
| 164 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); | |
| 165 | |
| 166 // Check if cursor enable state is locked. | |
| 167 cursor_manager->LockCursor(); | |
| 168 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); | |
| 169 cursor_manager->EnableMouseEvents(); | |
| 170 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); | |
| 171 cursor_manager->UnlockCursor(); | |
| 172 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 173 | |
| 174 cursor_manager->LockCursor(); | |
| 175 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 176 cursor_manager->DisableMouseEvents(); | |
| 177 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 178 cursor_manager->UnlockCursor(); | |
| 179 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); | |
| 180 | |
| 181 // Checks enabling cursor while cursor is locked does not affect the | |
| 182 // subsequent uses of UnlockCursor. | |
| 183 cursor_manager->LockCursor(); | |
| 184 cursor_manager->DisableMouseEvents(); | |
| 185 cursor_manager->UnlockCursor(); | |
| 186 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); | |
| 187 | |
| 188 cursor_manager->EnableMouseEvents(); | |
| 189 cursor_manager->LockCursor(); | |
| 190 cursor_manager->UnlockCursor(); | |
| 191 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 192 | |
| 193 cursor_manager->LockCursor(); | |
| 194 cursor_manager->EnableMouseEvents(); | |
| 195 cursor_manager->UnlockCursor(); | |
| 196 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 197 | |
| 198 cursor_manager->DisableMouseEvents(); | |
| 199 cursor_manager->LockCursor(); | |
| 200 cursor_manager->UnlockCursor(); | |
| 201 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); | |
| 202 } | |
| 203 | |
| 204 TEST_F(CursorManagerTest, IsMouseEventsEnabled) { | |
| 205 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | |
| 206 cursor_manager->EnableMouseEvents(); | |
| 207 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 208 cursor_manager->DisableMouseEvents(); | |
| 209 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); | |
| 210 } | |
| 211 | |
| 212 // Verifies that the mouse events enable state changes correctly when | |
| 213 // ShowCursor/HideCursor and EnableMouseEvents/DisableMouseEvents are used | |
| 214 // together. | |
| 215 TEST_F(CursorManagerTest, ShowAndEnable) { | |
| 216 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | |
| 217 | |
| 218 // Changing the visibility of the cursor does not affect the enable state. | |
| 219 cursor_manager->EnableMouseEvents(); | |
| 220 cursor_manager->ShowCursor(); | |
| 221 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
| 222 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 223 cursor_manager->HideCursor(); | |
| 224 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 225 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 226 cursor_manager->ShowCursor(); | |
| 227 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
| 228 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 229 | |
| 230 // When mouse events are disabled, it also gets invisible. | |
| 231 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
| 232 cursor_manager->DisableMouseEvents(); | |
| 233 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 234 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); | |
| 235 | |
| 236 // When mouse events are enabled, it restores the visibility state. | |
| 237 cursor_manager->EnableMouseEvents(); | |
| 238 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
| 239 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 240 | |
| 241 cursor_manager->ShowCursor(); | |
| 242 cursor_manager->DisableMouseEvents(); | |
| 243 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 244 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); | |
| 245 cursor_manager->EnableMouseEvents(); | |
| 246 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
| 247 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 248 | |
| 249 cursor_manager->HideCursor(); | |
| 250 cursor_manager->DisableMouseEvents(); | |
| 251 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 252 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); | |
| 253 cursor_manager->EnableMouseEvents(); | |
| 254 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 255 EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled()); | |
| 256 | |
| 257 // When mouse events are disabled, ShowCursor is ignored. | |
| 258 cursor_manager->DisableMouseEvents(); | |
| 259 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 260 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); | |
| 261 cursor_manager->ShowCursor(); | |
| 262 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 263 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); | |
| 264 cursor_manager->DisableMouseEvents(); | |
| 265 EXPECT_FALSE(cursor_manager->IsCursorVisible()); | |
| 266 EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled()); | |
| 267 } | |
| 268 | |
| 269 // Verifies that calling DisableMouseEvents multiple times in a row makes no | |
| 270 // difference compared with calling it once. | |
| 271 // This is a regression test for http://crbug.com/169404. | |
| 272 TEST_F(CursorManagerTest, MultipleDisableMouseEvents) { | |
| 273 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | |
| 274 cursor_manager->DisableMouseEvents(); | |
| 275 cursor_manager->DisableMouseEvents(); | |
| 276 cursor_manager->EnableMouseEvents(); | |
| 277 cursor_manager->LockCursor(); | |
| 278 cursor_manager->UnlockCursor(); | |
| 279 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
| 280 } | |
| 281 | |
| 282 // Verifies that calling EnableMouseEvents multiple times in a row makes no | |
| 283 // difference compared with calling it once. | |
| 284 TEST_F(CursorManagerTest, MultipleEnableMouseEvents) { | |
| 285 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | |
| 286 cursor_manager->DisableMouseEvents(); | |
| 287 cursor_manager->EnableMouseEvents(); | |
| 288 cursor_manager->EnableMouseEvents(); | |
| 289 cursor_manager->LockCursor(); | |
| 290 cursor_manager->UnlockCursor(); | |
| 291 EXPECT_TRUE(cursor_manager->IsCursorVisible()); | |
| 292 } | |
| 293 | |
| 294 #if defined(OS_WIN) | 98 #if defined(OS_WIN) |
| 295 // Temporarily disabled for windows. See crbug.com/112222. | 99 // Temporarily disabled for windows. See crbug.com/112222. |
| 296 #define MAYBE_DisabledMouseEventsLocation DISABLED_DisabledMouseEventsLocation | 100 #define MAYBE_DisabledMouseEventsLocation DISABLED_DisabledMouseEventsLocation |
| 297 #else | 101 #else |
| 298 #define MAYBE_DisabledMouseEventsLocation DisabledMouseEventsLocation | 102 #define MAYBE_DisabledMouseEventsLocation DisabledMouseEventsLocation |
| 299 #endif // defined(OS_WIN) | 103 #endif // defined(OS_WIN) |
| 300 | 104 |
| 301 // Verifies that RootWindow generates a mouse event located outside of a window | 105 // Verifies that RootWindow generates a mouse event located outside of a window |
| 302 // when mouse events are disabled. | 106 // when mouse events are disabled. |
| 303 TEST_F(CursorManagerTest, MAYBE_DisabledMouseEventsLocation) { | 107 TEST_F(CursorManagerTest, MAYBE_DisabledMouseEventsLocation) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 gfx::Point mouse_location; | 155 gfx::Point mouse_location; |
| 352 EXPECT_TRUE(root_window->QueryMouseLocationForTest(&mouse_location)); | 156 EXPECT_TRUE(root_window->QueryMouseLocationForTest(&mouse_location)); |
| 353 EXPECT_EQ("10,10", mouse_location.ToString()); | 157 EXPECT_EQ("10,10", mouse_location.ToString()); |
| 354 Shell::GetInstance()->cursor_manager()->DisableMouseEvents(); | 158 Shell::GetInstance()->cursor_manager()->DisableMouseEvents(); |
| 355 EXPECT_FALSE(root_window->QueryMouseLocationForTest(&mouse_location)); | 159 EXPECT_FALSE(root_window->QueryMouseLocationForTest(&mouse_location)); |
| 356 EXPECT_EQ("0,0", mouse_location.ToString()); | 160 EXPECT_EQ("0,0", mouse_location.ToString()); |
| 357 } | 161 } |
| 358 | 162 |
| 359 } // namespace test | 163 } // namespace test |
| 360 } // namespace ash | 164 } // namespace ash |
| OLD | NEW |