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

Unified Diff: ui/views/corewm/cursor_manager_unittest.cc

Issue 92413002: Cursor state should be global for all CursorManagers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch for review Created 7 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: ui/views/corewm/cursor_manager_unittest.cc
diff --git a/ui/views/corewm/cursor_manager_unittest.cc b/ui/views/corewm/cursor_manager_unittest.cc
index 1e6a16509076a6d81125b57e51f3bfa4d56e132b..fb0cbbfaf2950aee9d02cafe5e767837787e0408 100644
--- a/ui/views/corewm/cursor_manager_unittest.cc
+++ b/ui/views/corewm/cursor_manager_unittest.cc
@@ -12,8 +12,6 @@ namespace {
class TestingCursorManager : public views::corewm::NativeCursorManager {
public:
- gfx::NativeCursor current_cursor() { return cursor_; }
-
// Overridden from views::corewm::NativeCursorManager:
virtual void SetDisplay(
const gfx::Display& display,
@@ -22,7 +20,6 @@ class TestingCursorManager : public views::corewm::NativeCursorManager {
virtual void SetCursor(
gfx::NativeCursor cursor,
views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE {
- cursor_ = cursor;
delegate->CommitCursor(cursor);
}
@@ -49,9 +46,6 @@ class TestingCursorManager : public views::corewm::NativeCursorManager {
views::corewm::NativeCursorManagerDelegate* delegate) OVERRIDE {
delegate->CommitScale(scale);
}
-
- private:
- gfx::NativeCursor cursor_;
};
} // namespace
@@ -60,14 +54,17 @@ class CursorManagerTest : public views::ViewsTestBase {
protected:
CursorManagerTest()
: delegate_(new TestingCursorManager),
+ delegate_second_(new TestingCursorManager),
cursor_manager_(scoped_ptr<views::corewm::NativeCursorManager>(
- delegate_)) {
+ delegate_)),
+ cursor_manager_second_(scoped_ptr<views::corewm::NativeCursorManager>(
+ delegate_second_)) {
}
- gfx::NativeCursor current_cursor() { return delegate_->current_cursor(); }
-
TestingCursorManager* delegate_;
+ TestingCursorManager* delegate_second_;
views::corewm::CursorManager cursor_manager_;
+ views::corewm::CursorManager cursor_manager_second_;
};
class TestingCursorClientObserver : public aura::client::CursorClientObserver {
@@ -93,15 +90,17 @@ class TestingCursorClientObserver : public aura::client::CursorClientObserver {
};
TEST_F(CursorManagerTest, ShowHideCursor) {
+ cursor_manager_.ResetState();
+
cursor_manager_.SetCursor(ui::kCursorCopy);
- EXPECT_EQ(ui::kCursorCopy, current_cursor().native_type());
+ EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type());
cursor_manager_.ShowCursor();
EXPECT_TRUE(cursor_manager_.IsCursorVisible());
cursor_manager_.HideCursor();
EXPECT_FALSE(cursor_manager_.IsCursorVisible());
// The current cursor does not change even when the cursor is not shown.
- EXPECT_EQ(ui::kCursorCopy, current_cursor().native_type());
+ EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type());
// Check if cursor visibility is locked.
cursor_manager_.LockCursor();
@@ -144,15 +143,17 @@ TEST_F(CursorManagerTest, ShowHideCursor) {
// Verifies that LockCursor/UnlockCursor work correctly with
// EnableMouseEvents and DisableMouseEvents
TEST_F(CursorManagerTest, EnableDisableMouseEvents) {
+ cursor_manager_.ResetState();
+
cursor_manager_.SetCursor(ui::kCursorCopy);
- EXPECT_EQ(ui::kCursorCopy, current_cursor().native_type());
+ EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type());
cursor_manager_.EnableMouseEvents();
EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.DisableMouseEvents();
EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
// The current cursor does not change even when the cursor is not shown.
- EXPECT_EQ(ui::kCursorCopy, current_cursor().native_type());
+ EXPECT_EQ(ui::kCursorCopy, cursor_manager_.GetCursor().native_type());
// Check if cursor enable state is locked.
cursor_manager_.LockCursor();
@@ -193,36 +194,42 @@ TEST_F(CursorManagerTest, EnableDisableMouseEvents) {
}
TEST_F(CursorManagerTest, SetCursorSet) {
- EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCurrentCursorSet());
+ cursor_manager_.ResetState();
+
+ EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet());
cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL);
- EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCurrentCursorSet());
+ EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet());
cursor_manager_.SetCursorSet(ui::CURSOR_SET_LARGE);
- EXPECT_EQ(ui::CURSOR_SET_LARGE, cursor_manager_.GetCurrentCursorSet());
+ EXPECT_EQ(ui::CURSOR_SET_LARGE, cursor_manager_.GetCursorSet());
cursor_manager_.SetCursorSet(ui::CURSOR_SET_NORMAL);
- EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCurrentCursorSet());
+ EXPECT_EQ(ui::CURSOR_SET_NORMAL, cursor_manager_.GetCursorSet());
}
TEST_F(CursorManagerTest, SetScale) {
- EXPECT_EQ(1.f, cursor_manager_.GetCurrentScale());
+ cursor_manager_.ResetState();
+
+ EXPECT_EQ(1.f, cursor_manager_.GetScale());
cursor_manager_.SetScale(2.f);
- EXPECT_EQ(2.f, cursor_manager_.GetCurrentScale());
+ EXPECT_EQ(2.f, cursor_manager_.GetScale());
// Cusror scale does change even while cursor is locked.
cursor_manager_.LockCursor();
- EXPECT_EQ(2.f, cursor_manager_.GetCurrentScale());
+ EXPECT_EQ(2.f, cursor_manager_.GetScale());
cursor_manager_.SetScale(2.5f);
- EXPECT_EQ(2.5f, cursor_manager_.GetCurrentScale());
+ EXPECT_EQ(2.5f, cursor_manager_.GetScale());
cursor_manager_.UnlockCursor();
- EXPECT_EQ(2.5f, cursor_manager_.GetCurrentScale());
+ EXPECT_EQ(2.5f, cursor_manager_.GetScale());
cursor_manager_.SetScale(1.f);
- EXPECT_EQ(1.f, cursor_manager_.GetCurrentScale());
+ EXPECT_EQ(1.f, cursor_manager_.GetScale());
}
TEST_F(CursorManagerTest, IsMouseEventsEnabled) {
+ cursor_manager_.ResetState();
+
cursor_manager_.EnableMouseEvents();
EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
cursor_manager_.DisableMouseEvents();
@@ -233,6 +240,8 @@ TEST_F(CursorManagerTest, IsMouseEventsEnabled) {
// ShowCursor/HideCursor and EnableMouseEvents/DisableMouseEvents are used
// together.
TEST_F(CursorManagerTest, ShowAndEnable) {
+ cursor_manager_.ResetState();
+
// Changing the visibility of the cursor does not affect the enable state.
cursor_manager_.EnableMouseEvents();
cursor_manager_.ShowCursor();
@@ -288,6 +297,8 @@ TEST_F(CursorManagerTest, ShowAndEnable) {
// difference compared with calling it once.
// This is a regression test for http://crbug.com/169404.
TEST_F(CursorManagerTest, MultipleDisableMouseEvents) {
+ cursor_manager_.ResetState();
+
cursor_manager_.DisableMouseEvents();
cursor_manager_.DisableMouseEvents();
cursor_manager_.EnableMouseEvents();
@@ -299,6 +310,8 @@ TEST_F(CursorManagerTest, MultipleDisableMouseEvents) {
// Verifies that calling EnableMouseEvents multiple times in a row makes no
// difference compared with calling it once.
TEST_F(CursorManagerTest, MultipleEnableMouseEvents) {
+ cursor_manager_.ResetState();
+
cursor_manager_.DisableMouseEvents();
cursor_manager_.EnableMouseEvents();
cursor_manager_.EnableMouseEvents();
@@ -308,6 +321,8 @@ TEST_F(CursorManagerTest, MultipleEnableMouseEvents) {
}
TEST_F(CursorManagerTest, TestCursorClientObserver) {
+ cursor_manager_.ResetState();
+
// Add two observers. Both should have OnCursorVisibilityChanged()
// invoked when the visibility of the cursor changes.
TestingCursorClientObserver observer_a;
@@ -359,3 +374,71 @@ TEST_F(CursorManagerTest, TestCursorClientObserver) {
EXPECT_FALSE(observer_b.did_visibility_change());
EXPECT_TRUE(observer_a.is_cursor_visible());
}
+
+// Verifies that the cursor state is global among all CursorManager instances.
+TEST_F(CursorManagerTest, CursorManagerGlobalState) {
+ cursor_manager_.ResetState();
+ cursor_manager_second_.ResetState();
+
+ // Verify the cursor can be locked using one cursor manager and
+ // unlocked using another.
+ EXPECT_FALSE(cursor_manager_.IsCursorLocked());
+ EXPECT_FALSE(cursor_manager_second_.IsCursorLocked());
+
+ cursor_manager_.LockCursor();
+ EXPECT_TRUE(cursor_manager_.IsCursorLocked());
+ EXPECT_TRUE(cursor_manager_second_.IsCursorLocked());
+
+ cursor_manager_second_.UnlockCursor();
+ EXPECT_FALSE(cursor_manager_.IsCursorLocked());
+ EXPECT_FALSE(cursor_manager_second_.IsCursorLocked());
+
+ // Verify that mouse events can be disabled using one cursor manager
+ // and re-enabled using another.
+ EXPECT_TRUE(cursor_manager_.IsCursorVisible());
+ EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
+ EXPECT_TRUE(cursor_manager_second_.IsCursorVisible());
+ EXPECT_TRUE(cursor_manager_second_.IsMouseEventsEnabled());
+
+ cursor_manager_second_.DisableMouseEvents();
+ EXPECT_FALSE(cursor_manager_.IsCursorVisible());
+ EXPECT_FALSE(cursor_manager_.IsMouseEventsEnabled());
+ EXPECT_FALSE(cursor_manager_second_.IsCursorVisible());
+ EXPECT_FALSE(cursor_manager_second_.IsMouseEventsEnabled());
+
+ cursor_manager_.EnableMouseEvents();
+ EXPECT_TRUE(cursor_manager_.IsCursorVisible());
+ EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
+ EXPECT_TRUE(cursor_manager_second_.IsCursorVisible());
+ EXPECT_TRUE(cursor_manager_second_.IsMouseEventsEnabled());
+
+ // Verify that setting the cursor on one cursor manager will set
+ // it on another.
+ EXPECT_EQ(ui::kCursorNone, cursor_manager_.GetCursor().native_type());
+ EXPECT_EQ(ui::kCursorNone, cursor_manager_second_.GetCursor().native_type());
+
+ cursor_manager_.SetCursor(ui::kCursorPointer);
+ EXPECT_EQ(ui::kCursorPointer, cursor_manager_.GetCursor().native_type());
+ EXPECT_EQ(ui::kCursorPointer,
+ cursor_manager_second_.GetCursor().native_type());
+
+ // Verify that hiding the cursor using one cursor manager will
+ // also hide it on the other.
+ cursor_manager_second_.HideCursor();
+ EXPECT_FALSE(cursor_manager_.IsCursorVisible());
+ EXPECT_TRUE(cursor_manager_.IsMouseEventsEnabled());
+ EXPECT_FALSE(cursor_manager_second_.IsCursorVisible());
+ EXPECT_TRUE(cursor_manager_second_.IsMouseEventsEnabled());
+
+ // Verify that the visibility cannot be changed by one cursor
+ // manager if the cursor has been locked by another.
+ cursor_manager_second_.LockCursor();
+ cursor_manager_.ShowCursor();
+ EXPECT_FALSE(cursor_manager_.IsCursorVisible());
+ EXPECT_FALSE(cursor_manager_second_.IsCursorVisible());
+
+ // Verify the cursor is visible on unlock.
+ cursor_manager_.UnlockCursor();
+ EXPECT_TRUE(cursor_manager_.IsCursorVisible());
+ EXPECT_TRUE(cursor_manager_second_.IsCursorVisible());
+}

Powered by Google App Engine
This is Rietveld 408576698