Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Unified Diff: ash/wm/cursor_manager_unittest.cc

Issue 11412315: Make the cursor have separate mode for disabled mouse events and invisible. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/wm/cursor_manager_unittest.cc
diff --git a/ash/wm/cursor_manager_unittest.cc b/ash/wm/cursor_manager_unittest.cc
index 7d8286446a184a722d75383113fc801c465b751d..0e2a5ca4a9f45b688d6310345c9b2a9b04a0cefc 100644
--- a/ash/wm/cursor_manager_unittest.cc
+++ b/ash/wm/cursor_manager_unittest.cc
@@ -8,10 +8,37 @@
#include "ash/test/ash_test_base.h"
#include "ash/test/cursor_manager_test_api.h"
#include "ash/wm/image_cursors.h"
+#include "ui/aura/root_window.h"
+#include "ui/aura/test/test_window_delegate.h"
+#include "ui/aura/test/test_windows.h"
+#include "ui/aura/window.h"
namespace ash {
namespace test {
+namespace {
+
+// A delegate for recording a mouse event location.
+class MouseEventLocationDelegate : public aura::test::TestWindowDelegate {
+ public:
+ MouseEventLocationDelegate() {}
+ virtual ~MouseEventLocationDelegate() {}
+
+ gfx::Point mouse_event_location() const { return mouse_event_location_; }
oshima 2012/12/06 18:55:46 const gfx::Point&
mazda 2012/12/07 20:50:51 Done.
+
+ virtual ui::EventResult OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
+ mouse_event_location_ = event->location();
+ return ui::ER_HANDLED;
+ }
+
+ private:
+ gfx::Point mouse_event_location_;
+
+ DISALLOW_COPY_AND_ASSIGN(MouseEventLocationDelegate);
+};
+
+} // namespace
+
typedef test::AshTestBase CursorManagerTest;
TEST_F(CursorManagerTest, LockCursor) {
@@ -118,5 +145,151 @@ TEST_F(CursorManagerTest, SetDeviceScaleFactor) {
EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor());
}
+// Verifies that LockCursor/UnlockCursor work correctly with EnableCursor.
+TEST_F(CursorManagerTest, EnableCursor) {
+ CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
+ CursorManagerTestApi test_api(cursor_manager);
+
+ cursor_manager->SetCursor(ui::kCursorCopy);
+ EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
+
+ cursor_manager->EnableCursor(true);
+ EXPECT_TRUE(test_api.GetEnabled());
+ cursor_manager->EnableCursor(false);
+ EXPECT_FALSE(test_api.GetEnabled());
+ // The current cursor does not change even when the cursor is not shown.
+ EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
+
+ // Check if cursor enable state is locked.
+ cursor_manager->LockCursor();
+ EXPECT_FALSE(test_api.GetEnabled());
+ cursor_manager->EnableCursor(true);
+ EXPECT_FALSE(test_api.GetEnabled());
+ cursor_manager->UnlockCursor();
+ EXPECT_TRUE(test_api.GetEnabled());
+
+ cursor_manager->LockCursor();
+ EXPECT_TRUE(test_api.GetEnabled());
+ cursor_manager->EnableCursor(false);
+ EXPECT_TRUE(test_api.GetEnabled());
+ cursor_manager->UnlockCursor();
+ EXPECT_FALSE(test_api.GetEnabled());
+
+ // Checks enabling cursor while cursor is locked does not affect the
+ // subsequent uses of UnlockCursor.
+ cursor_manager->LockCursor();
+ cursor_manager->EnableCursor(false);
+ cursor_manager->UnlockCursor();
+ EXPECT_FALSE(test_api.GetEnabled());
+
+ cursor_manager->EnableCursor(true);
+ cursor_manager->LockCursor();
+ cursor_manager->UnlockCursor();
+ EXPECT_TRUE(test_api.GetEnabled());
+
+ cursor_manager->LockCursor();
+ cursor_manager->EnableCursor(true);
+ cursor_manager->UnlockCursor();
+ EXPECT_TRUE(test_api.GetEnabled());
+
+ cursor_manager->EnableCursor(false);
+ cursor_manager->LockCursor();
+ cursor_manager->UnlockCursor();
+ EXPECT_FALSE(test_api.GetEnabled());
+}
+
+// Verifies that the cursor state changes correctly when ShowCursor and
+// EnableCursor are used together.
+TEST_F(CursorManagerTest, ShowAndEnable) {
+ CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
+ CursorManagerTestApi test_api(cursor_manager);
+
+ // Changing the visibility of the cursor does not affect the enable state.
+ cursor_manager->EnableCursor(true);
+ cursor_manager->ShowCursor(true);
+ EXPECT_TRUE(cursor_manager->IsCursorVisible());
+ EXPECT_TRUE(test_api.GetEnabled());
+ cursor_manager->ShowCursor(false);
+ EXPECT_FALSE(cursor_manager->IsCursorVisible());
+ EXPECT_TRUE(test_api.GetEnabled());
+ cursor_manager->ShowCursor(true);
+ EXPECT_TRUE(cursor_manager->IsCursorVisible());
+ EXPECT_TRUE(test_api.GetEnabled());
+
+ // When the cursor is disabled, it also gets invisible.
+ EXPECT_TRUE(cursor_manager->IsCursorVisible());
+ cursor_manager->EnableCursor(false);
+ EXPECT_FALSE(cursor_manager->IsCursorVisible());
+ EXPECT_FALSE(test_api.GetEnabled());
+
+ // When the cursor is enabled, it restores the visibility state.
+ cursor_manager->EnableCursor(true);
+ EXPECT_TRUE(cursor_manager->IsCursorVisible());
+ EXPECT_TRUE(test_api.GetEnabled());
+ cursor_manager->ShowCursor(false);
+ cursor_manager->EnableCursor(false);
+ EXPECT_FALSE(cursor_manager->IsCursorVisible());
+ EXPECT_FALSE(test_api.GetEnabled());
+ cursor_manager->EnableCursor(true);
+ EXPECT_FALSE(cursor_manager->IsCursorVisible());
+ EXPECT_TRUE(test_api.GetEnabled());
+
+ // When the cursor is disabled, ShowCursor is ignored.
+ cursor_manager->EnableCursor(false);
+ EXPECT_FALSE(cursor_manager->IsCursorVisible());
+ EXPECT_FALSE(test_api.GetEnabled());
+ cursor_manager->ShowCursor(true);
+ EXPECT_FALSE(cursor_manager->IsCursorVisible());
+ EXPECT_FALSE(test_api.GetEnabled());
+ cursor_manager->EnableCursor(false);
+ EXPECT_FALSE(cursor_manager->IsCursorVisible());
+ EXPECT_FALSE(test_api.GetEnabled());
+}
+
+// Verifies that RootWindow generates a mouse event located outside of a window
+// when the cursor is disabled.
+#if defined(OS_WIN)
+// Temporarily disabled for windows. See crbug.com/112222.
+TEST_F(CursorManagerTest, DISABLED_DisabledCursorLocation) {
+#else
+TEST_F(CursorManagerTest, DisabledCursorLocation) {
+#endif // defined(OS_WIN)
+ scoped_ptr<MouseEventLocationDelegate> delegate(
+ new MouseEventLocationDelegate());
+ const int kWindowWidth = 123;
+ const int kWindowHeight = 45;
+ gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
+ scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
+ delegate.get(), 1, bounds, Shell::GetInstance()->GetPrimaryRootWindow()));
+
+ CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
+ cursor_manager->EnableCursor(true);
+ // Send a mouse event to window.
+ gfx::Point point(101, 201);
+ gfx::Point local_point;
+ ui::MouseEvent event(ui::ET_MOUSE_MOVED, point, point, 0);
+ aura::RootWindow* root_window = window->GetRootWindow();
+ root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&event);
+
+ // Location was in window.
+ local_point = delegate->mouse_event_location();
+ aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point);
+ EXPECT_TRUE(window->bounds().Contains(local_point));
+
+ // Location is now out of window.
+ cursor_manager->EnableCursor(false);
+ RunAllPendingInMessageLoop();
+ local_point = delegate->mouse_event_location();
+ aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point);
+ EXPECT_FALSE(window->bounds().Contains(local_point));
+
+ // Location is back in window.
+ cursor_manager->EnableCursor(true);
+ RunAllPendingInMessageLoop();
+ local_point = delegate->mouse_event_location();
+ aura::Window::ConvertPointToTarget(window.get(), root_window, &local_point);
+ EXPECT_TRUE(window->bounds().Contains(local_point));
+}
+
} // namespace test
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698