| 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/views/corewm/cursor_manager.h" | 5 #include "ui/views/corewm/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/views/corewm/native_cursor_manager.h" | 8 #include "ui/views/corewm/native_cursor_manager.h" |
| 9 #include "ui/views/test/views_test_base.h" | 9 #include "ui/views/test/views_test_base.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 class TestingCursorManager : public views::corewm::NativeCursorManager { | 13 class TestingCursorManager : public views::corewm::NativeCursorManager { |
| 14 public: | 14 public: |
| 15 gfx::NativeCursor current_cursor() { return cursor_; } | |
| 16 | |
| 17 // Overridden from views::corewm::NativeCursorManager: | 15 // Overridden from views::corewm::NativeCursorManager: |
| 18 virtual void SetDisplay( | 16 virtual void SetDisplay( |
| 19 const gfx::Display& display, | 17 const gfx::Display& display, |
| 20 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE {} | 18 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE {} |
| 21 | 19 |
| 22 virtual void SetCursor( | 20 virtual void SetCursor( |
| 23 gfx::NativeCursor cursor, | 21 gfx::NativeCursor cursor, |
| 24 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { | 22 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { |
| 25 cursor_ = cursor; | |
| 26 delegate->CommitCursor(cursor); | 23 delegate->CommitCursor(cursor); |
| 27 } | 24 } |
| 28 | 25 |
| 29 virtual void SetVisibility( | 26 virtual void SetVisibility( |
| 30 bool visible, | 27 bool visible, |
| 31 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { | 28 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { |
| 32 delegate->CommitVisibility(visible); | 29 delegate->CommitVisibility(visible); |
| 33 } | 30 } |
| 34 | 31 |
| 35 virtual void SetMouseEventsEnabled( | 32 virtual void SetMouseEventsEnabled( |
| 36 bool enabled, | 33 bool enabled, |
| 37 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { | 34 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { |
| 38 delegate->CommitMouseEventsEnabled(enabled); | 35 delegate->CommitMouseEventsEnabled(enabled); |
| 39 } | 36 } |
| 40 | 37 |
| 41 virtual void SetCursorSet( | 38 virtual void SetCursorSet( |
| 42 ui::CursorSetType cursor_set, | 39 ui::CursorSetType cursor_set, |
| 43 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { | 40 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { |
| 44 delegate->CommitCursorSet(cursor_set); | 41 delegate->CommitCursorSet(cursor_set); |
| 45 } | 42 } |
| 46 | 43 |
| 47 virtual void SetScale( | 44 virtual void SetScale( |
| 48 float scale, | 45 float scale, |
| 49 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { | 46 views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE { |
| 50 delegate->CommitScale(scale); | 47 delegate->CommitScale(scale); |
| 51 } | 48 } |
| 52 | |
| 53 private: | |
| 54 gfx::NativeCursor cursor_; | |
| 55 }; | 49 }; |
| 56 | 50 |
| 57 } // namespace | 51 } // namespace |
| 58 | 52 |
| 59 class CursorManagerTest : public views::ViewsTestBase { | 53 class CursorManagerTest : public views::ViewsTestBase { |
| 60 protected: | 54 protected: |
| 61 CursorManagerTest() | 55 CursorManagerTest() |
| 62 : delegate_(new TestingCursorManager), | 56 : delegate_(new TestingCursorManager), |
| 57 delegate_second_(new TestingCursorManager), |
| 63 cursor_manager_(scoped_ptr<views::corewm::NativeCursorManager>( | 58 cursor_manager_(scoped_ptr<views::corewm::NativeCursorManager>( |
| 64 delegate_)) { | 59 delegate_)), |
| 60 cursor_manager_second_(scoped_ptr<views::corewm::NativeCursorManager>( |
| 61 delegate_second_)) { |
| 65 } | 62 } |
| 66 | 63 |
| 67 gfx::NativeCursor current_cursor() { return delegate_->current_cursor(); } | |
| 68 | |
| 69 TestingCursorManager* delegate_; | 64 TestingCursorManager* delegate_; |
| 65 TestingCursorManager* delegate_second_; |
| 70 views::corewm::CursorManager cursor_manager_; | 66 views::corewm::CursorManager cursor_manager_; |
| 67 views::corewm::CursorManager cursor_manager_second_; |
| 71 }; | 68 }; |
| 72 | 69 |
| 73 class TestingCursorClientObserver : public aura::client::CursorClientObserver { | 70 class TestingCursorClientObserver : public aura::client::CursorClientObserver { |
| 74 public: | 71 public: |
| 75 TestingCursorClientObserver() | 72 TestingCursorClientObserver() |
| 76 : cursor_visibility_(false), | 73 : cursor_visibility_(false), |
| 77 did_visibility_change_(false) {} | 74 did_visibility_change_(false) {} |
| 78 void reset() { cursor_visibility_ = did_visibility_change_ = false; } | 75 void reset() { cursor_visibility_ = did_visibility_change_ = false; } |
| 79 bool is_cursor_visible() const { return cursor_visibility_; } | 76 bool is_cursor_visible() const { return cursor_visibility_; } |
| 80 bool did_visibility_change() const { return did_visibility_change_; } | 77 bool did_visibility_change() const { return did_visibility_change_; } |
| 81 | 78 |
| 82 // Overridden from aura::client::CursorClientObserver: | 79 // Overridden from aura::client::CursorClientObserver: |
| 83 virtual void OnCursorVisibilityChanged(bool is_visible) OVERRIDE { | 80 virtual void OnCursorVisibilityChanged(bool is_visible) OVERRIDE { |
| 84 cursor_visibility_ = is_visible; | 81 cursor_visibility_ = is_visible; |
| 85 did_visibility_change_ = true; | 82 did_visibility_change_ = true; |
| 86 } | 83 } |
| 87 | 84 |
| 88 private: | 85 private: |
| 89 bool cursor_visibility_; | 86 bool cursor_visibility_; |
| 90 bool did_visibility_change_; | 87 bool did_visibility_change_; |
| 91 | 88 |
| 92 DISALLOW_COPY_AND_ASSIGN(TestingCursorClientObserver); | 89 DISALLOW_COPY_AND_ASSIGN(TestingCursorClientObserver); |
| 93 }; | 90 }; |
| 94 | 91 |
| 95 TEST_F(CursorManagerTest, ShowHideCursor) { | 92 TEST_F(CursorManagerTest, ShowHideCursor) { |
| 93 cursor_manager_.ResetState(); |
| 94 |
| 96 cursor_manager_.SetCursor(ui::kCursorCopy); | 95 cursor_manager_.SetCursor(ui::kCursorCopy); |
| 97 EXPECT_EQ(ui::kCursorCopy, current_cursor().native_type()); | 96 EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type()); |
| 98 | 97 |
| 99 cursor_manager_.ShowCursor(); | 98 cursor_manager_.ShowCursor(); |
| 100 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); | 99 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); |
| 101 cursor_manager_.HideCursor(); | 100 cursor_manager_.HideCursor(); |
| 102 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); | 101 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); |
| 103 // The current cursor does not change even when the cursor is not shown. | 102 // The current cursor does not change even when the cursor is not shown. |
| 104 EXPECT_EQ(ui::kCursorCopy, current_cursor().native_type()); | 103 EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type()); |
| 105 | 104 |
| 106 // Check if cursor visibility is locked. | 105 // Check if cursor visibility is locked. |
| 107 cursor_manager_.LockCursor(); | 106 cursor_manager_.LockCursor(); |
| 108 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); | 107 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); |
| 109 cursor_manager_.ShowCursor(); | 108 cursor_manager_.ShowCursor(); |
| 110 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); | 109 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); |
| 111 cursor_manager_.UnlockCursor(); | 110 cursor_manager_.UnlockCursor(); |
| 112 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); | 111 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); |
| 113 | 112 |
| 114 cursor_manager_.LockCursor(); | 113 cursor_manager_.LockCursor(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 137 | 136 |
| 138 cursor_manager_.HideCursor(); | 137 cursor_manager_.HideCursor(); |
| 139 cursor_manager_.LockCursor(); | 138 cursor_manager_.LockCursor(); |
| 140 cursor_manager_.UnlockCursor(); | 139 cursor_manager_.UnlockCursor(); |
| 141 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); | 140 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); |
| 142 } | 141 } |
| 143 | 142 |
| 144 // Verifies that LockCursor/UnlockCursor work correctly with | 143 // Verifies that LockCursor/UnlockCursor work correctly with |
| 145 // EnableMouseEvents and DisableMouseEvents | 144 // EnableMouseEvents and DisableMouseEvents |
| 146 TEST_F(CursorManagerTest, EnableDisableMouseEvents) { | 145 TEST_F(CursorManagerTest, EnableDisableMouseEvents) { |
| 146 cursor_manager_.ResetState(); |
| 147 |
| 147 cursor_manager_.SetCursor(ui::kCursorCopy); | 148 cursor_manager_.SetCursor(ui::kCursorCopy); |
| 148 EXPECT_EQ(ui::kCursorCopy, current_cursor().native_type()); | 149 EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type()); |
| 149 | 150 |
| 150 cursor_manager_.EnableMouseEvents(); | 151 cursor_manager_.EnableMouseEvents(); |
| 151 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); | 152 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); |
| 152 cursor_manager_.DisableMouseEvents(); | 153 cursor_manager_.DisableMouseEvents(); |
| 153 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); | 154 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); |
| 154 // The current cursor does not change even when the cursor is not shown. | 155 // The current cursor does not change even when the cursor is not shown. |
| 155 EXPECT_EQ(ui::kCursorCopy, current_cursor().native_type()); | 156 EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type()); |
| 156 | 157 |
| 157 // Check if cursor enable state is locked. | 158 // Check if cursor enable state is locked. |
| 158 cursor_manager_.LockCursor(); | 159 cursor_manager_.LockCursor(); |
| 159 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); | 160 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); |
| 160 cursor_manager_.EnableMouseEvents(); | 161 cursor_manager_.EnableMouseEvents(); |
| 161 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); | 162 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); |
| 162 cursor_manager_.UnlockCursor(); | 163 cursor_manager_.UnlockCursor(); |
| 163 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); | 164 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); |
| 164 | 165 |
| 165 cursor_manager_.LockCursor(); | 166 cursor_manager_.LockCursor(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 186 cursor_manager_.UnlockCursor(); | 187 cursor_manager_.UnlockCursor(); |
| 187 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); | 188 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); |
| 188 | 189 |
| 189 cursor_manager_.DisableMouseEvents(); | 190 cursor_manager_.DisableMouseEvents(); |
| 190 cursor_manager_.LockCursor(); | 191 cursor_manager_.LockCursor(); |
| 191 cursor_manager_.UnlockCursor(); | 192 cursor_manager_.UnlockCursor(); |
| 192 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); | 193 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); |
| 193 } | 194 } |
| 194 | 195 |
| 195 TEST_F(CursorManagerTest, SetCursorSet) { | 196 TEST_F(CursorManagerTest, SetCursorSet) { |
| 196 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCurrentCursorSet()); | 197 cursor_manager_.ResetState(); |
| 198 |
| 199 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet()); |
| 197 | 200 |
| 198 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL); | 201 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL); |
| 199 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCurrentCursorSet()); | 202 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet()); |
| 200 | 203 |
| 201 cursor_manager_.SetCursorSet(ui::CURSOR_SET_LARGE); | 204 cursor_manager_.SetCursorSet(ui::CURSOR_SET_LARGE); |
| 202 EXPECT_EQ(ui::CURSOR_SET_LARGE, cursor_manager_.GetCurrentCursorSet()); | 205 EXPECT_EQ(ui::CURSOR_SET_LARGE, cursor_manager_.GetCursorSet()); |
| 203 | 206 |
| 204 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL); | 207 cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL); |
| 205 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCurrentCursorSet()); | 208 EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet()); |
| 206 } | 209 } |
| 207 | 210 |
| 208 TEST_F(CursorManagerTest, SetScale) { | 211 TEST_F(CursorManagerTest, SetScale) { |
| 209 EXPECT_EQ(1.f, cursor_manager_.GetCurrentScale()); | 212 cursor_manager_.ResetState(); |
| 213 |
| 214 EXPECT_EQ(1.f, cursor_manager_.GetScale()); |
| 210 cursor_manager_.SetScale(2.f); | 215 cursor_manager_.SetScale(2.f); |
| 211 EXPECT_EQ(2.f, cursor_manager_.GetCurrentScale()); | 216 EXPECT_EQ(2.f, cursor_manager_.GetScale()); |
| 212 | 217 |
| 213 // Cusror scale does change even while cursor is locked. | 218 // Cusror scale does change even while cursor is locked. |
| 214 cursor_manager_.LockCursor(); | 219 cursor_manager_.LockCursor(); |
| 215 EXPECT_EQ(2.f, cursor_manager_.GetCurrentScale()); | 220 EXPECT_EQ(2.f, cursor_manager_.GetScale()); |
| 216 cursor_manager_.SetScale(2.5f); | 221 cursor_manager_.SetScale(2.5f); |
| 217 EXPECT_EQ(2.5f, cursor_manager_.GetCurrentScale()); | 222 EXPECT_EQ(2.5f, cursor_manager_.GetScale()); |
| 218 cursor_manager_.UnlockCursor(); | 223 cursor_manager_.UnlockCursor(); |
| 219 | 224 |
| 220 EXPECT_EQ(2.5f, cursor_manager_.GetCurrentScale()); | 225 EXPECT_EQ(2.5f, cursor_manager_.GetScale()); |
| 221 cursor_manager_.SetScale(1.f); | 226 cursor_manager_.SetScale(1.f); |
| 222 EXPECT_EQ(1.f, cursor_manager_.GetCurrentScale()); | 227 EXPECT_EQ(1.f, cursor_manager_.GetScale()); |
| 223 } | 228 } |
| 224 | 229 |
| 225 TEST_F(CursorManagerTest, IsMouseEventsEnabled) { | 230 TEST_F(CursorManagerTest, IsMouseEventsEnabled) { |
| 231 cursor_manager_.ResetState(); |
| 232 |
| 226 cursor_manager_.EnableMouseEvents(); | 233 cursor_manager_.EnableMouseEvents(); |
| 227 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); | 234 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); |
| 228 cursor_manager_.DisableMouseEvents(); | 235 cursor_manager_.DisableMouseEvents(); |
| 229 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); | 236 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); |
| 230 } | 237 } |
| 231 | 238 |
| 232 // Verifies that the mouse events enable state changes correctly when | 239 // Verifies that the mouse events enable state changes correctly when |
| 233 // ShowCursor/HideCursor and EnableMouseEvents/DisableMouseEvents are used | 240 // ShowCursor/HideCursor and EnableMouseEvents/DisableMouseEvents are used |
| 234 // together. | 241 // together. |
| 235 TEST_F(CursorManagerTest, ShowAndEnable) { | 242 TEST_F(CursorManagerTest, ShowAndEnable) { |
| 243 cursor_manager_.ResetState(); |
| 244 |
| 236 // Changing the visibility of the cursor does not affect the enable state. | 245 // Changing the visibility of the cursor does not affect the enable state. |
| 237 cursor_manager_.EnableMouseEvents(); | 246 cursor_manager_.EnableMouseEvents(); |
| 238 cursor_manager_.ShowCursor(); | 247 cursor_manager_.ShowCursor(); |
| 239 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); | 248 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); |
| 240 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); | 249 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); |
| 241 cursor_manager_.HideCursor(); | 250 cursor_manager_.HideCursor(); |
| 242 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); | 251 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); |
| 243 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); | 252 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); |
| 244 cursor_manager_.ShowCursor(); | 253 cursor_manager_.ShowCursor(); |
| 245 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); | 254 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); | 290 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); |
| 282 cursor_manager_.DisableMouseEvents(); | 291 cursor_manager_.DisableMouseEvents(); |
| 283 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); | 292 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); |
| 284 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); | 293 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); |
| 285 } | 294 } |
| 286 | 295 |
| 287 // Verifies that calling DisableMouseEvents multiple times in a row makes no | 296 // Verifies that calling DisableMouseEvents multiple times in a row makes no |
| 288 // difference compared with calling it once. | 297 // difference compared with calling it once. |
| 289 // This is a regression test for http://crbug.com/169404. | 298 // This is a regression test for http://crbug.com/169404. |
| 290 TEST_F(CursorManagerTest, MultipleDisableMouseEvents) { | 299 TEST_F(CursorManagerTest, MultipleDisableMouseEvents) { |
| 300 cursor_manager_.ResetState(); |
| 301 |
| 291 cursor_manager_.DisableMouseEvents(); | 302 cursor_manager_.DisableMouseEvents(); |
| 292 cursor_manager_.DisableMouseEvents(); | 303 cursor_manager_.DisableMouseEvents(); |
| 293 cursor_manager_.EnableMouseEvents(); | 304 cursor_manager_.EnableMouseEvents(); |
| 294 cursor_manager_.LockCursor(); | 305 cursor_manager_.LockCursor(); |
| 295 cursor_manager_.UnlockCursor(); | 306 cursor_manager_.UnlockCursor(); |
| 296 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); | 307 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); |
| 297 } | 308 } |
| 298 | 309 |
| 299 // Verifies that calling EnableMouseEvents multiple times in a row makes no | 310 // Verifies that calling EnableMouseEvents multiple times in a row makes no |
| 300 // difference compared with calling it once. | 311 // difference compared with calling it once. |
| 301 TEST_F(CursorManagerTest, MultipleEnableMouseEvents) { | 312 TEST_F(CursorManagerTest, MultipleEnableMouseEvents) { |
| 313 cursor_manager_.ResetState(); |
| 314 |
| 302 cursor_manager_.DisableMouseEvents(); | 315 cursor_manager_.DisableMouseEvents(); |
| 303 cursor_manager_.EnableMouseEvents(); | 316 cursor_manager_.EnableMouseEvents(); |
| 304 cursor_manager_.EnableMouseEvents(); | 317 cursor_manager_.EnableMouseEvents(); |
| 305 cursor_manager_.LockCursor(); | 318 cursor_manager_.LockCursor(); |
| 306 cursor_manager_.UnlockCursor(); | 319 cursor_manager_.UnlockCursor(); |
| 307 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); | 320 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); |
| 308 } | 321 } |
| 309 | 322 |
| 310 TEST_F(CursorManagerTest, TestCursorClientObserver) { | 323 TEST_F(CursorManagerTest, TestCursorClientObserver) { |
| 324 cursor_manager_.ResetState(); |
| 325 |
| 311 // Add two observers. Both should have OnCursorVisibilityChanged() | 326 // Add two observers. Both should have OnCursorVisibilityChanged() |
| 312 // invoked when the visibility of the cursor changes. | 327 // invoked when the visibility of the cursor changes. |
| 313 TestingCursorClientObserver observer_a; | 328 TestingCursorClientObserver observer_a; |
| 314 TestingCursorClientObserver observer_b; | 329 TestingCursorClientObserver observer_b; |
| 315 cursor_manager_.AddObserver(&observer_a); | 330 cursor_manager_.AddObserver(&observer_a); |
| 316 cursor_manager_.AddObserver(&observer_b); | 331 cursor_manager_.AddObserver(&observer_b); |
| 317 | 332 |
| 318 // Initial state before any events have been sent. | 333 // Initial state before any events have been sent. |
| 319 observer_a.reset(); | 334 observer_a.reset(); |
| 320 observer_b.reset(); | 335 observer_b.reset(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 EXPECT_FALSE(observer_a.is_cursor_visible()); | 367 EXPECT_FALSE(observer_a.is_cursor_visible()); |
| 353 | 368 |
| 354 // Show the cursor using ShowCursor(). | 369 // Show the cursor using ShowCursor(). |
| 355 observer_a.reset(); | 370 observer_a.reset(); |
| 356 observer_b.reset(); | 371 observer_b.reset(); |
| 357 cursor_manager_.ShowCursor(); | 372 cursor_manager_.ShowCursor(); |
| 358 EXPECT_TRUE(observer_a.did_visibility_change()); | 373 EXPECT_TRUE(observer_a.did_visibility_change()); |
| 359 EXPECT_FALSE(observer_b.did_visibility_change()); | 374 EXPECT_FALSE(observer_b.did_visibility_change()); |
| 360 EXPECT_TRUE(observer_a.is_cursor_visible()); | 375 EXPECT_TRUE(observer_a.is_cursor_visible()); |
| 361 } | 376 } |
| 377 |
| 378 // Verifies that the cursor state is global among all CursorManager instances. |
| 379 TEST_F(CursorManagerTest, CursorManagerGlobalState) { |
| 380 cursor_manager_.ResetState(); |
| 381 cursor_manager_second_.ResetState(); |
| 382 |
| 383 // Verify the cursor can be locked using one cursor manager and |
| 384 // unlocked using another. |
| 385 EXPECT_FALSE(cursor_manager_.IsCursorLocked()); |
| 386 EXPECT_FALSE(cursor_manager_second_.IsCursorLocked()); |
| 387 |
| 388 cursor_manager_.LockCursor(); |
| 389 EXPECT_TRUE(cursor_manager_.IsCursorLocked()); |
| 390 EXPECT_TRUE(cursor_manager_second_.IsCursorLocked()); |
| 391 |
| 392 cursor_manager_second_.UnlockCursor(); |
| 393 EXPECT_FALSE(cursor_manager_.IsCursorLocked()); |
| 394 EXPECT_FALSE(cursor_manager_second_.IsCursorLocked()); |
| 395 |
| 396 // Verify that mouse events can be disabled using one cursor manager |
| 397 // and re-enabled using another. |
| 398 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); |
| 399 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); |
| 400 EXPECT_TRUE(cursor_manager_second_.IsCursorVisible()); |
| 401 EXPECT_TRUE(cursor_manager_second_.IsMouseEventsEnabled()); |
| 402 |
| 403 cursor_manager_second_.DisableMouseEvents(); |
| 404 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); |
| 405 EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled()); |
| 406 EXPECT_FALSE(cursor_manager_second_.IsCursorVisible()); |
| 407 EXPECT_FALSE(cursor_manager_second_.IsMouseEventsEnabled()); |
| 408 |
| 409 cursor_manager_.EnableMouseEvents(); |
| 410 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); |
| 411 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); |
| 412 EXPECT_TRUE(cursor_manager_second_.IsCursorVisible()); |
| 413 EXPECT_TRUE(cursor_manager_second_.IsMouseEventsEnabled()); |
| 414 |
| 415 // Verify that setting the cursor on one cursor manager will set |
| 416 // it on another. |
| 417 EXPECT_EQ(ui::kCursorNone, cursor_manager_.GetCursor().native_type()); |
| 418 EXPECT_EQ(ui::kCursorNone, cursor_manager_second_.GetCursor().native_type()); |
| 419 |
| 420 cursor_manager_.SetCursor(ui::kCursorPointer); |
| 421 EXPECT_EQ(ui::kCursorPointer, cursor_manager_.GetCursor().native_type()); |
| 422 EXPECT_EQ(ui::kCursorPointer, |
| 423 cursor_manager_second_.GetCursor().native_type()); |
| 424 |
| 425 // Verify that hiding the cursor using one cursor manager will |
| 426 // also hide it on the other. |
| 427 cursor_manager_second_.HideCursor(); |
| 428 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); |
| 429 EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled()); |
| 430 EXPECT_FALSE(cursor_manager_second_.IsCursorVisible()); |
| 431 EXPECT_TRUE(cursor_manager_second_.IsMouseEventsEnabled()); |
| 432 |
| 433 // Verify that the visibility cannot be changed by one cursor |
| 434 // manager if the cursor has been locked by another. |
| 435 cursor_manager_second_.LockCursor(); |
| 436 cursor_manager_.ShowCursor(); |
| 437 EXPECT_FALSE(cursor_manager_.IsCursorVisible()); |
| 438 EXPECT_FALSE(cursor_manager_second_.IsCursorVisible()); |
| 439 |
| 440 // Verify the cursor is visible on unlock. |
| 441 cursor_manager_.UnlockCursor(); |
| 442 EXPECT_TRUE(cursor_manager_.IsCursorVisible()); |
| 443 EXPECT_TRUE(cursor_manager_second_.IsCursorVisible()); |
| 444 } |
| OLD | NEW |