Index: ui/views/corewm/cursor_controller_unittest.cc |
diff --git a/ui/views/corewm/cursor_controller_unittest.cc b/ui/views/corewm/cursor_controller_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..08d3ea7dcab27df22bb049ba57e188ad7095b4ed |
--- /dev/null |
+++ b/ui/views/corewm/cursor_controller_unittest.cc |
@@ -0,0 +1,207 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ui/views/corewm/cursor_controller.h" |
+ |
+#include "ui/views/test/views_test_base.h" |
+ |
+class TestingCursorController : public views::corewm::CursorController { |
+ public: |
+ // Overridden from aura::client::CursorClient |
+ virtual void SetDeviceScaleFactor(float device_scale_factor) OVERRIDE { |
+ // No implementation, as there are no correct semantics during tests. |
+ } |
+ |
+ gfx::NativeCursor current_cursor() { return GetCurrentCursor(); } |
+}; |
+ |
+class CursorControllerTest : public views::ViewsTestBase { |
+ protected: |
+ TestingCursorController cursor_controller_; |
+}; |
+ |
+TEST_F(CursorControllerTest, ShowHideCursor) { |
+ cursor_controller_.SetCursor(ui::kCursorCopy); |
+ EXPECT_EQ(ui::kCursorCopy, cursor_controller_.current_cursor().native_type()); |
+ |
+ cursor_controller_.ShowCursor(); |
+ EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
+ cursor_controller_.HideCursor(); |
+ EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
+ // The current cursor does not change even when the cursor is not shown. |
+ EXPECT_EQ(ui::kCursorCopy, cursor_controller_.current_cursor().native_type()); |
+ |
+ // Check if cursor visibility is locked. |
+ cursor_controller_.LockCursor(); |
+ EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
+ cursor_controller_.ShowCursor(); |
+ EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
+ cursor_controller_.UnlockCursor(); |
+ EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
+ |
+ cursor_controller_.LockCursor(); |
+ EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
+ cursor_controller_.HideCursor(); |
+ EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
+ cursor_controller_.UnlockCursor(); |
+ EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
+ |
+ // Checks setting visiblity while cursor is locked does not affect the |
+ // subsequent uses of UnlockCursor. |
+ cursor_controller_.LockCursor(); |
+ cursor_controller_.HideCursor(); |
+ cursor_controller_.UnlockCursor(); |
+ EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
+ |
+ cursor_controller_.ShowCursor(); |
+ cursor_controller_.LockCursor(); |
+ cursor_controller_.UnlockCursor(); |
+ EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
+ |
+ cursor_controller_.LockCursor(); |
+ cursor_controller_.ShowCursor(); |
+ cursor_controller_.UnlockCursor(); |
+ EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
+ |
+ cursor_controller_.HideCursor(); |
+ cursor_controller_.LockCursor(); |
+ cursor_controller_.UnlockCursor(); |
+ EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
+} |
+ |
+// Verifies that LockCursor/UnlockCursor work correctly with |
+// EnableMouseEvents and DisableMouseEvents |
+TEST_F(CursorControllerTest, EnableDisableMouseEvents) { |
+ cursor_controller_.SetCursor(ui::kCursorCopy); |
+ EXPECT_EQ(ui::kCursorCopy, cursor_controller_.current_cursor().native_type()); |
+ |
+ cursor_controller_.EnableMouseEvents(); |
+ EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
+ cursor_controller_.DisableMouseEvents(); |
+ EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
+ // The current cursor does not change even when the cursor is not shown. |
+ EXPECT_EQ(ui::kCursorCopy, cursor_controller_.current_cursor().native_type()); |
+ |
+ // Check if cursor enable state is locked. |
+ cursor_controller_.LockCursor(); |
+ EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
+ cursor_controller_.EnableMouseEvents(); |
+ EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
+ cursor_controller_.UnlockCursor(); |
+ EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
+ |
+ cursor_controller_.LockCursor(); |
+ EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
+ cursor_controller_.DisableMouseEvents(); |
+ EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
+ cursor_controller_.UnlockCursor(); |
+ EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
+ |
+ // Checks enabling cursor while cursor is locked does not affect the |
+ // subsequent uses of UnlockCursor. |
+ cursor_controller_.LockCursor(); |
+ cursor_controller_.DisableMouseEvents(); |
+ cursor_controller_.UnlockCursor(); |
+ EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
+ |
+ cursor_controller_.EnableMouseEvents(); |
+ cursor_controller_.LockCursor(); |
+ cursor_controller_.UnlockCursor(); |
+ EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
+ |
+ cursor_controller_.LockCursor(); |
+ cursor_controller_.EnableMouseEvents(); |
+ cursor_controller_.UnlockCursor(); |
+ EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
+ |
+ cursor_controller_.DisableMouseEvents(); |
+ cursor_controller_.LockCursor(); |
+ cursor_controller_.UnlockCursor(); |
+ EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
+} |
+ |
+TEST_F(CursorControllerTest, IsMouseEventsEnabled) { |
+ cursor_controller_.EnableMouseEvents(); |
+ EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
+ cursor_controller_.DisableMouseEvents(); |
+ EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
+} |
+ |
+// Verifies that the mouse events enable state changes correctly when |
+// ShowCursor/HideCursor and EnableMouseEvents/DisableMouseEvents are used |
+// together. |
+TEST_F(CursorControllerTest, ShowAndEnable) { |
+ // Changing the visibility of the cursor does not affect the enable state. |
+ cursor_controller_.EnableMouseEvents(); |
+ cursor_controller_.ShowCursor(); |
+ EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
+ EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
+ cursor_controller_.HideCursor(); |
+ EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
+ EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
+ cursor_controller_.ShowCursor(); |
+ EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
+ EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
+ |
+ // When mouse events are disabled, it also gets invisible. |
+ EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
+ cursor_controller_.DisableMouseEvents(); |
+ EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
+ EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
+ |
+ // When mouse events are enabled, it restores the visibility state. |
+ cursor_controller_.EnableMouseEvents(); |
+ EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
+ EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
+ |
+ cursor_controller_.ShowCursor(); |
+ cursor_controller_.DisableMouseEvents(); |
+ EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
+ EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
+ cursor_controller_.EnableMouseEvents(); |
+ EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
+ EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
+ |
+ cursor_controller_.HideCursor(); |
+ cursor_controller_.DisableMouseEvents(); |
+ EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
+ EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
+ cursor_controller_.EnableMouseEvents(); |
+ EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
+ EXPECT_TRUE(cursor_controller_.IsMouseEventsEnabled()); |
+ |
+ // When mouse events are disabled, ShowCursor is ignored. |
+ cursor_controller_.DisableMouseEvents(); |
+ EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
+ EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
+ cursor_controller_.ShowCursor(); |
+ EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
+ EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
+ cursor_controller_.DisableMouseEvents(); |
+ EXPECT_FALSE(cursor_controller_.IsCursorVisible()); |
+ EXPECT_FALSE(cursor_controller_.IsMouseEventsEnabled()); |
+} |
+ |
+// Verifies that calling DisableMouseEvents multiple times in a row makes no |
+// difference compared with calling it once. |
+// This is a regression test for http://crbug.com/169404. |
+TEST_F(CursorControllerTest, MultipleDisableMouseEvents) { |
+ cursor_controller_.DisableMouseEvents(); |
+ cursor_controller_.DisableMouseEvents(); |
+ cursor_controller_.EnableMouseEvents(); |
+ cursor_controller_.LockCursor(); |
+ cursor_controller_.UnlockCursor(); |
+ EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
+} |
+ |
+// Verifies that calling EnableMouseEvents multiple times in a row makes no |
+// difference compared with calling it once. |
+TEST_F(CursorControllerTest, MultipleEnableMouseEvents) { |
+ cursor_controller_.DisableMouseEvents(); |
+ cursor_controller_.EnableMouseEvents(); |
+ cursor_controller_.EnableMouseEvents(); |
+ cursor_controller_.LockCursor(); |
+ cursor_controller_.UnlockCursor(); |
+ EXPECT_TRUE(cursor_controller_.IsCursorVisible()); |
+} |