From 44e64a65a53a38b439b8abd61ec934fa0e8cf694 Mon Sep 17 00:00:00 2001 From: "mazda@chromium.org" Date: Fri, 21 Sep 2012 04:21:11 +0000 Subject: [PATCH] Fix cursor getting invisible after moving a window. The platform cursor value was not correctly set when cursor was unlocked. This CL fixes it and adds unittests. BUG=150904 Review URL: https://chromiumcodereview.appspot.com/10965020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157924 0039d316-1c4b-4281-b951-d872f2087c98 --- ash/ash.gyp | 3 ++ ash/test/cursor_manager_test_api.cc | 29 +++++++++++++++ ash/test/cursor_manager_test_api.h | 35 +++++++++++++++++++ ash/wm/cursor_manager.cc | 2 +- ash/wm/cursor_manager.h | 13 +++++-- ash/wm/cursor_manager_unittest.cc | 70 +++++++++++++++++++++++++++++++++++++ 6 files changed, 148 insertions(+), 4 deletions(-) create mode 100644 ash/test/cursor_manager_test_api.cc create mode 100644 ash/test/cursor_manager_test_api.h create mode 100644 ash/wm/cursor_manager_unittest.cc diff --git a/ash/ash.gyp b/ash/ash.gyp index c138b3cef882..44de29ce23ed 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -490,6 +490,8 @@ 'test/ash_unittests.cc', 'test/capture_tracking_view.cc', 'test/capture_tracking_view.h', + 'test/cursor_manager_test_api.cc', + 'test/cursor_manager_test_api.h', 'test/launcher_view_test_api.cc', 'test/launcher_view_test_api.h', 'test/test_activation_delegate.cc', @@ -505,6 +507,7 @@ 'tooltips/tooltip_controller_unittest.cc', 'wm/activation_controller_unittest.cc', 'wm/base_layout_manager_unittest.cc', + 'wm/cursor_manager_unittest.cc', 'wm/custom_frame_view_ash_unittest.cc', 'wm/frame_painter_unittest.cc', 'wm/image_grid_unittest.cc', diff --git a/ash/test/cursor_manager_test_api.cc b/ash/test/cursor_manager_test_api.cc new file mode 100644 index 000000000000..e992f9ca0162 --- /dev/null +++ b/ash/test/cursor_manager_test_api.cc @@ -0,0 +1,29 @@ +// Copyright (c) 2012 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 "ash/test/cursor_manager_test_api.h" + +#include "ash/wm/cursor_manager.h" +#include "ash/wm/image_cursors.h" + +namespace ash { +namespace test { + +CursorManagerTestApi::CursorManagerTestApi(CursorManager* cursor_manager) + : cursor_manager_(cursor_manager) { +} + +CursorManagerTestApi::~CursorManagerTestApi() { +} + +gfx::NativeCursor CursorManagerTestApi::GetCurrentCursor() { + return cursor_manager_->current_cursor_; +} + +float CursorManagerTestApi::GetDeviceScaleFactor() { + return cursor_manager_->image_cursors_->GetDeviceScaleFactor(); +} + +} // namespace test +} // namespace ash diff --git a/ash/test/cursor_manager_test_api.h b/ash/test/cursor_manager_test_api.h new file mode 100644 index 000000000000..5cb25add8d82 --- /dev/null +++ b/ash/test/cursor_manager_test_api.h @@ -0,0 +1,35 @@ +// Copyright (c) 2012 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. + +#ifndef ASH_TEST_CURSOR_MANAGER_TEST_API_H_ +#define ASH_TEST_CURSOR_MANAGER_TEST_API_H_ + +#include "base/basictypes.h" +#include "ui/gfx/native_widget_types.h" + +namespace ash { + +class CursorManager; + +namespace test { + +// Use the api in this class to test CursorManager. +class CursorManagerTestApi { + public: + explicit CursorManagerTestApi(CursorManager* cursor_manager); + ~CursorManagerTestApi(); + + gfx::NativeCursor GetCurrentCursor(); + float GetDeviceScaleFactor(); + + private: + CursorManager* cursor_manager_; + + DISALLOW_COPY_AND_ASSIGN(CursorManagerTestApi); +}; + +} // namespace test +} // namespace ash + +#endif // ASH_TEST_CURSOR_MANAGER_TEST_API_H_ diff --git a/ash/wm/cursor_manager.cc b/ash/wm/cursor_manager.cc index 3afee4b20d84..da2248e111c9 100644 --- a/ash/wm/cursor_manager.cc +++ b/ash/wm/cursor_manager.cc @@ -36,7 +36,7 @@ void CursorManager::UnlockCursor() { if (did_cursor_change_) { did_cursor_change_ = false; if (delegate_) - delegate_->SetCursor(cursor_to_set_on_unlock_); + SetCursorInternal(cursor_to_set_on_unlock_); } did_cursor_change_ = false; cursor_to_set_on_unlock_ = gfx::kNullCursor; diff --git a/ash/wm/cursor_manager.h b/ash/wm/cursor_manager.h index f5b5548b8684..f2b857e8c711 100644 --- a/ash/wm/cursor_manager.h +++ b/ash/wm/cursor_manager.h @@ -5,21 +5,26 @@ #ifndef ASH_WM_CURSOR_MANAGER_H_ #define ASH_WM_CURSOR_MANAGER_H_ +#include "ash/ash_export.h" #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" -#include "ui/aura/aura_export.h" #include "ui/aura/client/cursor_client.h" #include "ui/gfx/native_widget_types.h" namespace ash { + +namespace test { +class CursorManagerTestApi; +} + class CursorDelegate; class ImageCursors; // This class controls the visibility and the type of the cursor. // The cursor type can be locked so that the type stays the same // until it's unlocked. -class CursorManager : public aura::client::CursorClient { +class ASH_EXPORT CursorManager : public aura::client::CursorClient { public: CursorManager(); virtual ~CursorManager(); @@ -42,6 +47,8 @@ class CursorManager : public aura::client::CursorClient { virtual void SetDeviceScaleFactor(float device_scale_factor) OVERRIDE; private: + friend class test::CursorManagerTestApi; + void SetCursorInternal(gfx::NativeCursor cursor); CursorDelegate* delegate_; @@ -68,6 +75,6 @@ class CursorManager : public aura::client::CursorClient { DISALLOW_COPY_AND_ASSIGN(CursorManager); }; -} // namespace aura +} // namespace ash #endif // UI_AURA_CURSOR_MANAGER_H_ diff --git a/ash/wm/cursor_manager_unittest.cc b/ash/wm/cursor_manager_unittest.cc new file mode 100644 index 000000000000..79b2aea83bdc --- /dev/null +++ b/ash/wm/cursor_manager_unittest.cc @@ -0,0 +1,70 @@ +// Copyright (c) 2012 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 "ash/wm/cursor_manager.h" + +#include "ash/shell.h" +#include "ash/test/ash_test_base.h" +#include "ash/test/cursor_manager_test_api.h" +#include "ash/wm/image_cursors.h" + +namespace ash { +namespace test { + +typedef test::AshTestBase CursorManagerTest; + +TEST_F(CursorManagerTest, LockCursor) { + 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->SetDeviceScaleFactor(2.0f); + EXPECT_EQ(2.0f, test_api.GetDeviceScaleFactor()); + EXPECT_TRUE(test_api.GetCurrentCursor().platform()); + + cursor_manager->LockCursor(); + EXPECT_TRUE(cursor_manager->is_cursor_locked()); + + // Cursor type does not change while cursor is locked. + cursor_manager->SetCursor(ui::kCursorPointer); + EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); + + // Device scale factor does change even while cursor is locked. + cursor_manager->SetDeviceScaleFactor(1.0f); + EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor()); + + cursor_manager->UnlockCursor(); + EXPECT_FALSE(cursor_manager->is_cursor_locked()); + + // Cursor type changes to the one specified while cursor is locked. + EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type()); + EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor()); + EXPECT_TRUE(test_api.GetCurrentCursor().platform()); +} + +TEST_F(CursorManagerTest, SetCursor) { + 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()); + EXPECT_TRUE(test_api.GetCurrentCursor().platform()); + cursor_manager->SetCursor(ui::kCursorPointer); + EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type()); + EXPECT_TRUE(test_api.GetCurrentCursor().platform()); +} + +TEST_F(CursorManagerTest, SetDeviceScaleFactor) { + CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); + CursorManagerTestApi test_api(cursor_manager); + + cursor_manager->SetDeviceScaleFactor(2.0f); + EXPECT_EQ(2.0f, test_api.GetDeviceScaleFactor()); + cursor_manager->SetDeviceScaleFactor(1.0f); + EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor()); +} + +} // namespace test +} // namespace ash -- 2.11.4.GIT