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

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

Issue 2932563002: Implement cursor changing on Mushrome (Closed)
Patch Set: why would you put that there 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
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/native_cursor_manager_ash.h"
6 6
7 #include "ash/display/display_util.h" 7 #include "ash/display/display_util.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/test/ash_test_base.h" 9 #include "ash/test/ash_test_base.h"
10 #include "ash/test/cursor_manager_test_api.h" 10 #include "ash/test/cursor_manager_test_api.h"
11 #include "ui/aura/test/aura_test_utils.h" 11 #include "ui/aura/test/aura_test_utils.h"
12 #include "ui/aura/test/test_window_delegate.h" 12 #include "ui/aura/test/test_window_delegate.h"
13 #include "ui/aura/test/test_windows.h" 13 #include "ui/aura/test/test_windows.h"
14 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
15 #include "ui/aura/window_event_dispatcher.h" 15 #include "ui/aura/window_event_dispatcher.h"
(...skipping 30 matching lines...) Expand all
46 } 46 }
47 47
48 private: 48 private:
49 gfx::Point mouse_event_location_; 49 gfx::Point mouse_event_location_;
50 50
51 DISALLOW_COPY_AND_ASSIGN(MouseEventLocationDelegate); 51 DISALLOW_COPY_AND_ASSIGN(MouseEventLocationDelegate);
52 }; 52 };
53 53
54 } // namespace 54 } // namespace
55 55
56 typedef test::AshTestBase AshNativeCursorManagerTest; 56 typedef test::AshTestBase NativeCursorManagerAshTest;
James Cook 2017/06/13 00:49:27 nit: use using
Elliot Glaysher 2017/06/13 18:05:45 Done.
57 57
58 TEST_F(AshNativeCursorManagerTest, LockCursor) { 58 TEST_F(NativeCursorManagerAshTest, LockCursor) {
59 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager(); 59 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager();
60 CursorManagerTestApi test_api(cursor_manager); 60 CursorManagerTestApi test_api(cursor_manager);
61 61
62 cursor_manager->SetCursor(ui::CursorType::kCopy); 62 cursor_manager->SetCursor(ui::CursorType::kCopy);
63 EXPECT_EQ(ui::CursorType::kCopy, test_api.GetCurrentCursor().native_type()); 63 EXPECT_EQ(ui::CursorType::kCopy, test_api.GetCurrentCursor().native_type());
64 UpdateDisplay("800x800*2/r"); 64 UpdateDisplay("800x800*2/r");
65 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor()); 65 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
66 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); 66 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
67 EXPECT_EQ(display::Display::ROTATE_90, test_api.GetCurrentCursorRotation()); 67 EXPECT_EQ(display::Display::ROTATE_90, test_api.GetCurrentCursorRotation());
68 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); 68 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
(...skipping 22 matching lines...) Expand all
91 cursor_manager->UnlockCursor(); 91 cursor_manager->UnlockCursor();
92 EXPECT_FALSE(cursor_manager->IsCursorLocked()); 92 EXPECT_FALSE(cursor_manager->IsCursorLocked());
93 93
94 // Cursor type changes to the one specified while cursor is locked. 94 // Cursor type changes to the one specified while cursor is locked.
95 EXPECT_EQ(ui::CursorType::kPointer, 95 EXPECT_EQ(ui::CursorType::kPointer,
96 test_api.GetCurrentCursor().native_type()); 96 test_api.GetCurrentCursor().native_type());
97 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor()); 97 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
98 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); 98 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
99 } 99 }
100 100
101 TEST_F(AshNativeCursorManagerTest, SetCursor) { 101 TEST_F(NativeCursorManagerAshTest, SetCursor) {
102 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager(); 102 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager();
103 CursorManagerTestApi test_api(cursor_manager); 103 CursorManagerTestApi test_api(cursor_manager);
104 cursor_manager->SetCursor(ui::CursorType::kCopy); 104 cursor_manager->SetCursor(ui::CursorType::kCopy);
105 EXPECT_EQ(ui::CursorType::kCopy, test_api.GetCurrentCursor().native_type()); 105 EXPECT_EQ(ui::CursorType::kCopy, test_api.GetCurrentCursor().native_type());
106 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); 106 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
107 cursor_manager->SetCursor(ui::CursorType::kPointer); 107 cursor_manager->SetCursor(ui::CursorType::kPointer);
108 EXPECT_EQ(ui::CursorType::kPointer, 108 EXPECT_EQ(ui::CursorType::kPointer,
109 test_api.GetCurrentCursor().native_type()); 109 test_api.GetCurrentCursor().native_type());
110 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); 110 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
111 } 111 }
112 112
113 TEST_F(AshNativeCursorManagerTest, SetCursorSet) { 113 TEST_F(NativeCursorManagerAshTest, SetCursorSet) {
114 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager(); 114 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager();
115 CursorManagerTestApi test_api(cursor_manager); 115 CursorManagerTestApi test_api(cursor_manager);
116 116
117 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); 117 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
118 118
119 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); 119 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL);
120 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); 120 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
121 121
122 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE); 122 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE);
123 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet()); 123 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet());
124 124
125 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); 125 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL);
126 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); 126 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
127 } 127 }
128 128
129 TEST_F(AshNativeCursorManagerTest, SetDeviceScaleFactorAndRotation) { 129 TEST_F(NativeCursorManagerAshTest, SetDeviceScaleFactorAndRotation) {
130 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager(); 130 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager();
131 CursorManagerTestApi test_api(cursor_manager); 131 CursorManagerTestApi test_api(cursor_manager);
132 UpdateDisplay("800x100*2"); 132 UpdateDisplay("800x100*2");
133 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor()); 133 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
134 EXPECT_EQ(display::Display::ROTATE_0, test_api.GetCurrentCursorRotation()); 134 EXPECT_EQ(display::Display::ROTATE_0, test_api.GetCurrentCursorRotation());
135 135
136 UpdateDisplay("800x100/l"); 136 UpdateDisplay("800x100/l");
137 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor()); 137 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
138 EXPECT_EQ(display::Display::ROTATE_270, test_api.GetCurrentCursorRotation()); 138 EXPECT_EQ(display::Display::ROTATE_270, test_api.GetCurrentCursorRotation());
139 } 139 }
140 140
141 TEST_F(AshNativeCursorManagerTest, FractionalScale) { 141 TEST_F(NativeCursorManagerAshTest, FractionalScale) {
142 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager(); 142 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager();
143 CursorManagerTestApi test_api(cursor_manager); 143 CursorManagerTestApi test_api(cursor_manager);
144 // Cursor should use the resource scale factor. 144 // Cursor should use the resource scale factor.
145 UpdateDisplay("800x100*1.25"); 145 UpdateDisplay("800x100*1.25");
146 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor()); 146 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
147 } 147 }
148 148
149 TEST_F(AshNativeCursorManagerTest, UIScaleShouldNotChangeCursor) { 149 TEST_F(NativeCursorManagerAshTest, UIScaleShouldNotChangeCursor) {
150 int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); 150 int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
151 display::Display::SetInternalDisplayId(display_id); 151 display::Display::SetInternalDisplayId(display_id);
152 152
153 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager(); 153 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager();
154 CursorManagerTestApi test_api(cursor_manager); 154 CursorManagerTestApi test_api(cursor_manager);
155 155
156 display::test::DisplayManagerTestApi(Shell::Get()->display_manager()) 156 display::test::DisplayManagerTestApi(Shell::Get()->display_manager())
157 .SetDisplayUIScale(display_id, 0.5f); 157 .SetDisplayUIScale(display_id, 0.5f);
158 EXPECT_EQ( 158 EXPECT_EQ(
159 1.0f, 159 1.0f,
(...skipping 13 matching lines...) Expand all
173 .SetDisplayUIScale(display_id, 2.0f); 173 .SetDisplayUIScale(display_id, 2.0f);
174 EXPECT_EQ( 174 EXPECT_EQ(
175 1.0f, 175 1.0f,
176 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor()); 176 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor());
177 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor()); 177 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
178 } 178 }
179 179
180 #if defined(USE_X11) 180 #if defined(USE_X11)
181 // This test is in ash_unittests because ui_base_unittests does not include 181 // This test is in ash_unittests because ui_base_unittests does not include
182 // 2x assets. crbug.com/372541. 182 // 2x assets. crbug.com/372541.
183 TEST_F(AshNativeCursorManagerTest, CursorLoaderX11Test) { 183 TEST_F(NativeCursorManagerAshTest, CursorLoaderX11Test) {
184 const ui::CursorType kCursorId = ui::CursorType::kPointer; 184 const ui::CursorType kCursorId = ui::CursorType::kPointer;
185 ui::CursorLoaderX11 loader; 185 ui::CursorLoaderX11 loader;
186 loader.set_scale(1.0f); 186 loader.set_scale(1.0f);
187 187
188 loader.LoadImageCursor(kCursorId, IDR_AURA_CURSOR_MOVE, gfx::Point()); 188 loader.LoadImageCursor(kCursorId, IDR_AURA_CURSOR_MOVE, gfx::Point());
189 const XcursorImage* image = loader.GetXcursorImageForTest(kCursorId); 189 const XcursorImage* image = loader.GetXcursorImageForTest(kCursorId);
190 int height = image->height; 190 int height = image->height;
191 int width = image->width; 191 int width = image->width;
192 loader.UnloadAll(); 192 loader.UnloadAll();
193 193
194 // Load 2x cursor and make sure its size is 2x of the 1x cusor. 194 // Load 2x cursor and make sure its size is 2x of the 1x cusor.
195 loader.set_scale(2.0f); 195 loader.set_scale(2.0f);
196 loader.LoadImageCursor(kCursorId, IDR_AURA_CURSOR_MOVE, gfx::Point()); 196 loader.LoadImageCursor(kCursorId, IDR_AURA_CURSOR_MOVE, gfx::Point());
197 image = loader.GetXcursorImageForTest(kCursorId); 197 image = loader.GetXcursorImageForTest(kCursorId);
198 EXPECT_EQ(height * 2, static_cast<int>(image->height)); 198 EXPECT_EQ(height * 2, static_cast<int>(image->height));
199 EXPECT_EQ(width * 2, static_cast<int>(image->width)); 199 EXPECT_EQ(width * 2, static_cast<int>(image->width));
200 } 200 }
201 #endif 201 #endif
202 202
203 } // namespace test 203 } // namespace test
204 } // namespace ash 204 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698