OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/wm/ash_native_cursor_manager.h" | 5 #include "ash/wm/ash_native_cursor_manager.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
9 #include "ash/test/cursor_manager_test_api.h" | 9 #include "ash/test/cursor_manager_test_api.h" |
10 #include "ash/wm/image_cursors.h" | 10 #include "ash/wm/image_cursors.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | 55 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); |
56 CursorManagerTestApi test_api(cursor_manager); | 56 CursorManagerTestApi test_api(cursor_manager); |
57 gfx::Display display(0); | 57 gfx::Display display(0); |
58 #if defined(OS_WIN) | 58 #if defined(OS_WIN) |
59 ui::CursorLoaderWin::SetCursorResourceModule(L"ash_unittests.exe"); | 59 ui::CursorLoaderWin::SetCursorResourceModule(L"ash_unittests.exe"); |
60 #endif | 60 #endif |
61 cursor_manager->SetCursor(ui::kCursorCopy); | 61 cursor_manager->SetCursor(ui::kCursorCopy); |
62 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); | 62 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); |
63 display.set_device_scale_factor(2.0f); | 63 display.set_device_scale_factor(2.0f); |
64 display.set_rotation(gfx::Display::ROTATE_90); | 64 display.set_rotation(gfx::Display::ROTATE_90); |
65 cursor_manager->SetScale(2.5f); | |
66 cursor_manager->SetDisplay(display); | 65 cursor_manager->SetDisplay(display); |
67 EXPECT_EQ(2.5f, test_api.GetCurrentScale()); | |
68 EXPECT_EQ(2.0f, test_api.GetDisplay().device_scale_factor()); | 66 EXPECT_EQ(2.0f, test_api.GetDisplay().device_scale_factor()); |
69 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); | 67 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); |
70 EXPECT_EQ(gfx::Display::ROTATE_90, test_api.GetDisplay().rotation()); | 68 EXPECT_EQ(gfx::Display::ROTATE_90, test_api.GetDisplay().rotation()); |
71 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); | 69 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); |
72 | 70 |
73 cursor_manager->LockCursor(); | 71 cursor_manager->LockCursor(); |
74 EXPECT_TRUE(cursor_manager->IsCursorLocked()); | 72 EXPECT_TRUE(cursor_manager->IsCursorLocked()); |
75 | 73 |
76 // Cursor type does not change while cursor is locked. | 74 // Cursor type does not change while cursor is locked. |
77 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); | 75 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); |
78 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); | 76 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); |
79 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); | 77 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); |
80 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE); | 78 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE); |
81 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet()); | 79 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet()); |
82 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); | 80 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); |
83 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); | 81 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); |
84 | 82 |
85 // Cusror scale does change even while cursor is locked. | |
86 EXPECT_EQ(2.5f, test_api.GetCurrentScale()); | |
87 cursor_manager->SetScale(1.f); | |
88 EXPECT_EQ(1.f, test_api.GetCurrentScale()); | |
89 cursor_manager->SetScale(1.5f); | |
90 EXPECT_EQ(1.5f, test_api.GetCurrentScale()); | |
91 | |
92 // Cursor type does not change while cursor is locked. | 83 // Cursor type does not change while cursor is locked. |
93 cursor_manager->SetCursor(ui::kCursorPointer); | 84 cursor_manager->SetCursor(ui::kCursorPointer); |
94 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); | 85 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); |
95 | 86 |
96 // Device scale factor and rotation do change even while cursor is locked. | 87 // Device scale factor and rotation do change even while cursor is locked. |
97 display.set_device_scale_factor(1.0f); | 88 display.set_device_scale_factor(1.0f); |
98 display.set_rotation(gfx::Display::ROTATE_180); | 89 display.set_rotation(gfx::Display::ROTATE_180); |
99 cursor_manager->SetDisplay(display); | 90 cursor_manager->SetDisplay(display); |
100 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); | 91 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); |
101 EXPECT_EQ(gfx::Display::ROTATE_180, test_api.GetDisplay().rotation()); | 92 EXPECT_EQ(gfx::Display::ROTATE_180, test_api.GetDisplay().rotation()); |
102 | 93 |
103 cursor_manager->UnlockCursor(); | 94 cursor_manager->UnlockCursor(); |
104 EXPECT_FALSE(cursor_manager->IsCursorLocked()); | 95 EXPECT_FALSE(cursor_manager->IsCursorLocked()); |
105 | 96 |
106 // Cursor type changes to the one specified while cursor is locked. | 97 // Cursor type changes to the one specified while cursor is locked. |
107 EXPECT_EQ(1.5f, test_api.GetCurrentScale()); | |
108 EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type()); | 98 EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type()); |
109 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); | 99 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); |
110 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); | 100 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); |
111 } | 101 } |
112 | 102 |
113 TEST_F(AshNativeCursorManagerTest, SetCursor) { | 103 TEST_F(AshNativeCursorManagerTest, SetCursor) { |
114 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | 104 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); |
115 CursorManagerTestApi test_api(cursor_manager); | 105 CursorManagerTestApi test_api(cursor_manager); |
116 #if defined(OS_WIN) | 106 #if defined(OS_WIN) |
117 ui::CursorLoaderWin::SetCursorResourceModule(L"ash_unittests.exe"); | 107 ui::CursorLoaderWin::SetCursorResourceModule(L"ash_unittests.exe"); |
(...skipping 15 matching lines...) Expand all Loading... |
133 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); | 123 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); |
134 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); | 124 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); |
135 | 125 |
136 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE); | 126 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE); |
137 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet()); | 127 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet()); |
138 | 128 |
139 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); | 129 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); |
140 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); | 130 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); |
141 } | 131 } |
142 | 132 |
143 TEST_F(AshNativeCursorManagerTest, SetScale) { | |
144 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | |
145 CursorManagerTestApi test_api(cursor_manager); | |
146 | |
147 EXPECT_EQ(1.f, test_api.GetCurrentScale()); | |
148 | |
149 cursor_manager->SetScale(2.5f); | |
150 EXPECT_EQ(2.5f, test_api.GetCurrentScale()); | |
151 | |
152 cursor_manager->SetScale(1.f); | |
153 EXPECT_EQ(1.f, test_api.GetCurrentScale()); | |
154 } | |
155 | |
156 TEST_F(AshNativeCursorManagerTest, SetDeviceScaleFactorAndRotation) { | 133 TEST_F(AshNativeCursorManagerTest, SetDeviceScaleFactorAndRotation) { |
157 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); | 134 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); |
158 CursorManagerTestApi test_api(cursor_manager); | 135 CursorManagerTestApi test_api(cursor_manager); |
159 | 136 |
160 gfx::Display display(0); | 137 gfx::Display display(0); |
161 display.set_device_scale_factor(2.0f); | 138 display.set_device_scale_factor(2.0f); |
162 cursor_manager->SetDisplay(display); | 139 cursor_manager->SetDisplay(display); |
163 EXPECT_EQ(2.0f, test_api.GetDisplay().device_scale_factor()); | 140 EXPECT_EQ(2.0f, test_api.GetDisplay().device_scale_factor()); |
164 EXPECT_EQ(gfx::Display::ROTATE_0, test_api.GetDisplay().rotation()); | 141 EXPECT_EQ(gfx::Display::ROTATE_0, test_api.GetDisplay().rotation()); |
165 | 142 |
(...skipping 29 matching lines...) Expand all Loading... |
195 gfx::Point mouse_location; | 172 gfx::Point mouse_location; |
196 EXPECT_TRUE(host->QueryMouseLocation(&mouse_location)); | 173 EXPECT_TRUE(host->QueryMouseLocation(&mouse_location)); |
197 EXPECT_EQ("10,10", mouse_location.ToString()); | 174 EXPECT_EQ("10,10", mouse_location.ToString()); |
198 Shell::GetInstance()->cursor_manager()->DisableMouseEvents(); | 175 Shell::GetInstance()->cursor_manager()->DisableMouseEvents(); |
199 EXPECT_FALSE(host->QueryMouseLocation(&mouse_location)); | 176 EXPECT_FALSE(host->QueryMouseLocation(&mouse_location)); |
200 EXPECT_EQ("0,0", mouse_location.ToString()); | 177 EXPECT_EQ("0,0", mouse_location.ToString()); |
201 } | 178 } |
202 | 179 |
203 } // namespace test | 180 } // namespace test |
204 } // namespace ash | 181 } // namespace ash |
OLD | NEW |