[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / ash / wm / cursor_manager_unittest.cc
blob7d8286446a184a722d75383113fc801c465b751d
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/wm/cursor_manager.h"
7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h"
9 #include "ash/test/cursor_manager_test_api.h"
10 #include "ash/wm/image_cursors.h"
12 namespace ash {
13 namespace test {
15 typedef test::AshTestBase CursorManagerTest;
17 TEST_F(CursorManagerTest, LockCursor) {
18 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
19 CursorManagerTestApi test_api(cursor_manager);
21 cursor_manager->SetCursor(ui::kCursorCopy);
22 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
23 cursor_manager->SetDeviceScaleFactor(2.0f);
24 EXPECT_EQ(2.0f, test_api.GetDeviceScaleFactor());
25 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
27 cursor_manager->LockCursor();
28 EXPECT_TRUE(cursor_manager->is_cursor_locked());
30 // Cursor type does not change while cursor is locked.
31 cursor_manager->SetCursor(ui::kCursorPointer);
32 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
34 // Device scale factor does change even while cursor is locked.
35 cursor_manager->SetDeviceScaleFactor(1.0f);
36 EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor());
38 cursor_manager->UnlockCursor();
39 EXPECT_FALSE(cursor_manager->is_cursor_locked());
41 // Cursor type changes to the one specified while cursor is locked.
42 EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type());
43 EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor());
44 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
47 TEST_F(CursorManagerTest, SetCursor) {
48 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
49 CursorManagerTestApi test_api(cursor_manager);
51 cursor_manager->SetCursor(ui::kCursorCopy);
52 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
53 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
54 cursor_manager->SetCursor(ui::kCursorPointer);
55 EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type());
56 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
59 TEST_F(CursorManagerTest, ShowCursor) {
60 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
61 CursorManagerTestApi test_api(cursor_manager);
63 cursor_manager->SetCursor(ui::kCursorCopy);
64 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
66 cursor_manager->ShowCursor(true);
67 EXPECT_TRUE(cursor_manager->IsCursorVisible());
68 cursor_manager->ShowCursor(false);
69 EXPECT_FALSE(cursor_manager->IsCursorVisible());
70 // The current cursor does not change even when the cursor is not shown.
71 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
73 // Check if cursor visibility is locked.
74 cursor_manager->LockCursor();
75 EXPECT_FALSE(cursor_manager->IsCursorVisible());
76 cursor_manager->ShowCursor(true);
77 EXPECT_FALSE(cursor_manager->IsCursorVisible());
78 cursor_manager->UnlockCursor();
79 EXPECT_TRUE(cursor_manager->IsCursorVisible());
81 cursor_manager->LockCursor();
82 EXPECT_TRUE(cursor_manager->IsCursorVisible());
83 cursor_manager->ShowCursor(false);
84 EXPECT_TRUE(cursor_manager->IsCursorVisible());
85 cursor_manager->UnlockCursor();
86 EXPECT_FALSE(cursor_manager->IsCursorVisible());
88 // Checks setting visiblity while cursor is locked does not affect the
89 // subsequent uses of UnlockCursor.
90 cursor_manager->LockCursor();
91 cursor_manager->ShowCursor(false);
92 cursor_manager->UnlockCursor();
93 EXPECT_FALSE(cursor_manager->IsCursorVisible());
95 cursor_manager->ShowCursor(true);
96 cursor_manager->LockCursor();
97 cursor_manager->UnlockCursor();
98 EXPECT_TRUE(cursor_manager->IsCursorVisible());
100 cursor_manager->LockCursor();
101 cursor_manager->ShowCursor(true);
102 cursor_manager->UnlockCursor();
103 EXPECT_TRUE(cursor_manager->IsCursorVisible());
105 cursor_manager->ShowCursor(false);
106 cursor_manager->LockCursor();
107 cursor_manager->UnlockCursor();
108 EXPECT_FALSE(cursor_manager->IsCursorVisible());
111 TEST_F(CursorManagerTest, SetDeviceScaleFactor) {
112 CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
113 CursorManagerTestApi test_api(cursor_manager);
115 cursor_manager->SetDeviceScaleFactor(2.0f);
116 EXPECT_EQ(2.0f, test_api.GetDeviceScaleFactor());
117 cursor_manager->SetDeviceScaleFactor(1.0f);
118 EXPECT_EQ(1.0f, test_api.GetDeviceScaleFactor());
121 } // namespace test
122 } // namespace ash