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

Side by Side Diff: ash/wm/ash_native_cursor_manager_unittest.cc

Issue 2932563002: Implement cursor changing on Mushrome (Closed)
Patch Set: oshima patch take 2 Created 3 years, 6 months 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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "ash/wm/ash_native_cursor_manager.h"
6
7 #include "ash/display/display_util.h"
8 #include "ash/shell.h"
9 #include "ash/test/ash_test_base.h"
10 #include "ash/test/cursor_manager_test_api.h"
11 #include "ui/aura/test/aura_test_utils.h"
12 #include "ui/aura/test/test_window_delegate.h"
13 #include "ui/aura/test/test_windows.h"
14 #include "ui/aura/window.h"
15 #include "ui/aura/window_event_dispatcher.h"
16 #include "ui/base/cursor/image_cursors.h"
17 #include "ui/display/manager/display_manager.h"
18 #include "ui/display/screen.h"
19 #include "ui/display/test/display_manager_test_api.h"
20
21 #if defined(USE_X11)
22 #include "ui/base/cursor/cursor_loader_x11.h"
23 #include "ui/resources/grit/ui_resources.h"
24 #endif
25
26 namespace ash {
27 namespace test {
28
29 namespace {
30
31 // A delegate for recording a mouse event location.
32 class MouseEventLocationDelegate : public aura::test::TestWindowDelegate {
33 public:
34 MouseEventLocationDelegate() {}
35 ~MouseEventLocationDelegate() override {}
36
37 gfx::Point GetMouseEventLocationAndReset() {
38 gfx::Point p = mouse_event_location_;
39 mouse_event_location_.SetPoint(-100, -100);
40 return p;
41 }
42
43 void OnMouseEvent(ui::MouseEvent* event) override {
44 mouse_event_location_ = event->location();
45 event->SetHandled();
46 }
47
48 private:
49 gfx::Point mouse_event_location_;
50
51 DISALLOW_COPY_AND_ASSIGN(MouseEventLocationDelegate);
52 };
53
54 } // namespace
55
56 typedef test::AshTestBase AshNativeCursorManagerTest;
57
58 TEST_F(AshNativeCursorManagerTest, LockCursor) {
59 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager();
60 CursorManagerTestApi test_api(cursor_manager);
61
62 cursor_manager->SetCursor(ui::CursorType::kCopy);
63 EXPECT_EQ(ui::CursorType::kCopy, test_api.GetCurrentCursor().native_type());
64 UpdateDisplay("800x800*2/r");
65 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
66 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
67 EXPECT_EQ(display::Display::ROTATE_90, test_api.GetCurrentCursorRotation());
68 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
69
70 cursor_manager->LockCursor();
71 EXPECT_TRUE(cursor_manager->IsCursorLocked());
72
73 // Cursor type does not change while cursor is locked.
74 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
75 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL);
76 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
77 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE);
78 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet());
79 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL);
80 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
81
82 // Cursor type does not change while cursor is locked.
83 cursor_manager->SetCursor(ui::CursorType::kPointer);
84 EXPECT_EQ(ui::CursorType::kCopy, test_api.GetCurrentCursor().native_type());
85
86 // Device scale factor and rotation do change even while cursor is locked.
87 UpdateDisplay("800x800/u");
88 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
89 EXPECT_EQ(display::Display::ROTATE_180, test_api.GetCurrentCursorRotation());
90
91 cursor_manager->UnlockCursor();
92 EXPECT_FALSE(cursor_manager->IsCursorLocked());
93
94 // Cursor type changes to the one specified while cursor is locked.
95 EXPECT_EQ(ui::CursorType::kPointer,
96 test_api.GetCurrentCursor().native_type());
97 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
98 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
99 }
100
101 TEST_F(AshNativeCursorManagerTest, SetCursor) {
102 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager();
103 CursorManagerTestApi test_api(cursor_manager);
104 cursor_manager->SetCursor(ui::CursorType::kCopy);
105 EXPECT_EQ(ui::CursorType::kCopy, test_api.GetCurrentCursor().native_type());
106 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
107 cursor_manager->SetCursor(ui::CursorType::kPointer);
108 EXPECT_EQ(ui::CursorType::kPointer,
109 test_api.GetCurrentCursor().native_type());
110 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
111 }
112
113 TEST_F(AshNativeCursorManagerTest, SetCursorSet) {
114 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager();
115 CursorManagerTestApi test_api(cursor_manager);
116
117 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
118
119 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL);
120 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
121
122 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE);
123 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet());
124
125 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL);
126 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
127 }
128
129 TEST_F(AshNativeCursorManagerTest, SetDeviceScaleFactorAndRotation) {
130 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager();
131 CursorManagerTestApi test_api(cursor_manager);
132 UpdateDisplay("800x100*2");
133 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
134 EXPECT_EQ(display::Display::ROTATE_0, test_api.GetCurrentCursorRotation());
135
136 UpdateDisplay("800x100/l");
137 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
138 EXPECT_EQ(display::Display::ROTATE_270, test_api.GetCurrentCursorRotation());
139 }
140
141 TEST_F(AshNativeCursorManagerTest, FractionalScale) {
142 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager();
143 CursorManagerTestApi test_api(cursor_manager);
144 // Cursor should use the resource scale factor.
145 UpdateDisplay("800x100*1.25");
146 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
147 }
148
149 TEST_F(AshNativeCursorManagerTest, UIScaleShouldNotChangeCursor) {
150 int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
151 display::Display::SetInternalDisplayId(display_id);
152
153 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager();
154 CursorManagerTestApi test_api(cursor_manager);
155
156 display::test::DisplayManagerTestApi(Shell::Get()->display_manager())
157 .SetDisplayUIScale(display_id, 0.5f);
158 EXPECT_EQ(
159 1.0f,
160 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
161 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
162
163 display::test::DisplayManagerTestApi(Shell::Get()->display_manager())
164 .SetDisplayUIScale(display_id, 1.0f);
165
166 // 2x display should keep using 2x cursor regardless of the UI scale.
167 UpdateDisplay("800x800*2");
168 EXPECT_EQ(
169 2.0f,
170 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
171 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
172 display::test::DisplayManagerTestApi(Shell::Get()->display_manager())
173 .SetDisplayUIScale(display_id, 2.0f);
174 EXPECT_EQ(
175 1.0f,
176 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
177 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
178 }
179
180 #if defined(USE_X11)
181 // This test is in ash_unittests because ui_base_unittests does not include
182 // 2x assets. crbug.com/372541.
183 TEST_F(AshNativeCursorManagerTest, CursorLoaderX11Test) {
184 const ui::CursorType kCursorId = ui::CursorType::kPointer;
185 ui::CursorLoaderX11 loader;
186 loader.set_scale(1.0f);
187
188 loader.LoadImageCursor(kCursorId, IDR_AURA_CURSOR_MOVE, gfx::Point());
189 const XcursorImage* image = loader.GetXcursorImageForTest(kCursorId);
190 int height = image->height;
191 int width = image->width;
192 loader.UnloadAll();
193
194 // Load 2x cursor and make sure its size is 2x of the 1x cusor.
195 loader.set_scale(2.0f);
196 loader.LoadImageCursor(kCursorId, IDR_AURA_CURSOR_MOVE, gfx::Point());
197 image = loader.GetXcursorImageForTest(kCursorId);
198 EXPECT_EQ(height * 2, static_cast<int>(image->height));
199 EXPECT_EQ(width * 2, static_cast<int>(image->width));
200 }
201 #endif
202
203 } // namespace test
204 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/ash_native_cursor_manager_interactive_uitest.cc ('k') | ash/wm/native_cursor_manager_ash.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698