Chromium Code Reviews| 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..a27470cced73fa4b87a11e2254c5e1b5c66296cd 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_; } |
| + |
| + 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); |
| +}; |
| + |
| +} |
|
oshima
2012/12/05 23:46:45
// namespace
mazda
2012/12/06 01:36:50
Done.
|
| + |
| typedef test::AshTestBase CursorManagerTest; |
| TEST_F(CursorManagerTest, LockCursor) { |
| @@ -118,5 +145,152 @@ 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())); |
| + aura::Window* window_ptr = &*window; |
|
oshima
2012/12/05 23:46:45
window.get() is more common, or you can just use i
mazda
2012/12/06 01:36:50
Replaced window_ptr with window.get().
|
| + |
| + 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_ptr, 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_ptr, 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_ptr, root_window, &local_point); |
| + EXPECT_TRUE(window->bounds().Contains(local_point)); |
| +} |
| + |
| } // namespace test |
| } // namespace ash |