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

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

Issue 226293005: Use platform's device scale factor for cursor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new tests Created 6 years, 8 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 | Annotate | Revision Log
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/ash_native_cursor_manager.h"
6 6
7 #include "ash/display/display_info.h"
8 #include "ash/display/display_manager.h"
7 #include "ash/shell.h" 9 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
9 #include "ash/test/cursor_manager_test_api.h" 11 #include "ash/test/cursor_manager_test_api.h"
10 #include "ash/wm/image_cursors.h" 12 #include "ash/wm/image_cursors.h"
11 #include "ui/aura/test/test_window_delegate.h" 13 #include "ui/aura/test/test_window_delegate.h"
12 #include "ui/aura/test/test_windows.h" 14 #include "ui/aura/test/test_windows.h"
13 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
14 #include "ui/aura/window_event_dispatcher.h" 16 #include "ui/aura/window_event_dispatcher.h"
15 #include "ui/gfx/screen.h" 17 #include "ui/gfx/screen.h"
16 18
(...skipping 30 matching lines...) Expand all
47 DISALLOW_COPY_AND_ASSIGN(MouseEventLocationDelegate); 49 DISALLOW_COPY_AND_ASSIGN(MouseEventLocationDelegate);
48 }; 50 };
49 51
50 } // namespace 52 } // namespace
51 53
52 typedef test::AshTestBase AshNativeCursorManagerTest; 54 typedef test::AshTestBase AshNativeCursorManagerTest;
53 55
54 TEST_F(AshNativeCursorManagerTest, LockCursor) { 56 TEST_F(AshNativeCursorManagerTest, LockCursor) {
55 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); 57 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
56 CursorManagerTestApi test_api(cursor_manager); 58 CursorManagerTestApi test_api(cursor_manager);
57 gfx::Display display(0); 59
58 #if defined(OS_WIN) 60 #if defined(OS_WIN)
59 ui::CursorLoaderWin::SetCursorResourceModule(L"ash_unittests.exe"); 61 ui::CursorLoaderWin::SetCursorResourceModule(L"ash_unittests.exe");
60 #endif 62 #endif
61 cursor_manager->SetCursor(ui::kCursorCopy); 63 cursor_manager->SetCursor(ui::kCursorCopy);
62 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); 64 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
63 display.set_device_scale_factor(2.0f); 65 UpdateDisplay("800x800*2/r");
64 display.set_rotation(gfx::Display::ROTATE_90); 66 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
65 cursor_manager->SetDisplay(display);
66 EXPECT_EQ(2.0f, test_api.GetDisplay().device_scale_factor());
67 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); 67 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
68 EXPECT_EQ(gfx::Display::ROTATE_90, test_api.GetDisplay().rotation()); 68 EXPECT_EQ(gfx::Display::ROTATE_90, test_api.GetCurrentCursorRotation());
69 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); 69 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
70 70
71 cursor_manager->LockCursor(); 71 cursor_manager->LockCursor();
72 EXPECT_TRUE(cursor_manager->IsCursorLocked()); 72 EXPECT_TRUE(cursor_manager->IsCursorLocked());
73 73
74 // Cursor type does not change while cursor is locked. 74 // Cursor type does not change while cursor is locked.
75 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); 75 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
76 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); 76 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL);
77 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); 77 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
78 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE); 78 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE);
79 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet()); 79 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet());
80 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); 80 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL);
81 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); 81 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
82 82
83 // Cursor type does not change while cursor is locked. 83 // Cursor type does not change while cursor is locked.
84 cursor_manager->SetCursor(ui::kCursorPointer); 84 cursor_manager->SetCursor(ui::kCursorPointer);
85 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type()); 85 EXPECT_EQ(ui::kCursorCopy, test_api.GetCurrentCursor().native_type());
86 86
87 // 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.
88 display.set_device_scale_factor(1.0f); 88 UpdateDisplay("800x800/u");
89 display.set_rotation(gfx::Display::ROTATE_180); 89 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
90 cursor_manager->SetDisplay(display); 90 EXPECT_EQ(gfx::Display::ROTATE_180, test_api.GetCurrentCursorRotation());
91 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor());
92 EXPECT_EQ(gfx::Display::ROTATE_180, test_api.GetDisplay().rotation());
93 91
94 cursor_manager->UnlockCursor(); 92 cursor_manager->UnlockCursor();
95 EXPECT_FALSE(cursor_manager->IsCursorLocked()); 93 EXPECT_FALSE(cursor_manager->IsCursorLocked());
96 94
97 // Cursor type changes to the one specified while cursor is locked. 95 // Cursor type changes to the one specified while cursor is locked.
98 EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type()); 96 EXPECT_EQ(ui::kCursorPointer, test_api.GetCurrentCursor().native_type());
99 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); 97 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
100 EXPECT_TRUE(test_api.GetCurrentCursor().platform()); 98 EXPECT_TRUE(test_api.GetCurrentCursor().platform());
101 } 99 }
102 100
103 TEST_F(AshNativeCursorManagerTest, SetCursor) { 101 TEST_F(AshNativeCursorManagerTest, SetCursor) {
104 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); 102 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
105 CursorManagerTestApi test_api(cursor_manager); 103 CursorManagerTestApi test_api(cursor_manager);
106 #if defined(OS_WIN) 104 #if defined(OS_WIN)
107 ui::CursorLoaderWin::SetCursorResourceModule(L"ash_unittests.exe"); 105 ui::CursorLoaderWin::SetCursorResourceModule(L"ash_unittests.exe");
108 #endif 106 #endif
109 cursor_manager->SetCursor(ui::kCursorCopy); 107 cursor_manager->SetCursor(ui::kCursorCopy);
(...skipping 16 matching lines...) Expand all
126 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE); 124 cursor_manager->SetCursorSet(ui::CURSOR_SET_LARGE);
127 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet()); 125 EXPECT_EQ(ui::CURSOR_SET_LARGE, test_api.GetCurrentCursorSet());
128 126
129 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL); 127 cursor_manager->SetCursorSet(ui::CURSOR_SET_NORMAL);
130 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet()); 128 EXPECT_EQ(ui::CURSOR_SET_NORMAL, test_api.GetCurrentCursorSet());
131 } 129 }
132 130
133 TEST_F(AshNativeCursorManagerTest, SetDeviceScaleFactorAndRotation) { 131 TEST_F(AshNativeCursorManagerTest, SetDeviceScaleFactorAndRotation) {
134 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); 132 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
135 CursorManagerTestApi test_api(cursor_manager); 133 CursorManagerTestApi test_api(cursor_manager);
134 UpdateDisplay("800x100*2");
135 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
136 EXPECT_EQ(gfx::Display::ROTATE_0, test_api.GetCurrentCursorRotation());
136 137
137 gfx::Display display(0); 138 UpdateDisplay("800x100/l");
138 display.set_device_scale_factor(2.0f); 139 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
139 cursor_manager->SetDisplay(display); 140 EXPECT_EQ(gfx::Display::ROTATE_270, test_api.GetCurrentCursorRotation());
140 EXPECT_EQ(2.0f, test_api.GetDisplay().device_scale_factor()); 141 }
141 EXPECT_EQ(gfx::Display::ROTATE_0, test_api.GetDisplay().rotation());
142 142
143 display.set_device_scale_factor(1.0f); 143 TEST_F(AshNativeCursorManagerTest, UIScaleShouldNotChangeCursor) {
144 display.set_rotation(gfx::Display::ROTATE_270); 144 int64 display_id = Shell::GetScreen()->GetPrimaryDisplay().id();
145 cursor_manager->SetDisplay(display); 145 gfx::Display::SetInternalDisplayId(display_id);
146 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); 146
147 EXPECT_EQ(gfx::Display::ROTATE_270, test_api.GetDisplay().rotation()); 147 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager();
148 CursorManagerTestApi test_api(cursor_manager);
149 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
150
151 DisplayInfo::SetAllowUpgradeToHighDPI(false);
152 display_manager->SetDisplayUIScale(display_id, 0.5f);
153 EXPECT_EQ(1.0f,
154 Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
155 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
156
157 display_manager->SetDisplayUIScale(display_id, 1.0f);
158
159 DisplayInfo::SetAllowUpgradeToHighDPI(true);
160 // 1x display should keep using 1x cursor even if the DSF is upgraded to 2x.
161 display_manager->SetDisplayUIScale(display_id, 0.5f);
162 EXPECT_EQ(2.0f,
163 Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
164 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
165
166 // 2x display should keep using 2x cursor regardless of the UI scale.
167 UpdateDisplay("800x800*2");
168 EXPECT_EQ(2.0f,
169 Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
170 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
171 display_manager->SetDisplayUIScale(display_id, 2.0f);
172 EXPECT_EQ(1.0f,
173 Shell::GetScreen()->GetPrimaryDisplay().device_scale_factor());
174 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
148 } 175 }
149 176
150 TEST_F(AshNativeCursorManagerTest, DisabledQueryMouseLocation) { 177 TEST_F(AshNativeCursorManagerTest, DisabledQueryMouseLocation) {
151 aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow(); 178 aura::Window* root_window = Shell::GetInstance()->GetPrimaryRootWindow();
152 #if defined(OS_WIN) 179 #if defined(OS_WIN)
153 if (base::win::GetVersion() < base::win::VERSION_WIN8) 180 if (base::win::GetVersion() < base::win::VERSION_WIN8)
154 return; 181 return;
155 // On Windows 8 the ASH environment has two processes, the viewer process 182 // On Windows 8 the ASH environment has two processes, the viewer process
156 // which runs in Windows 8 mode and the browser process. The initialization 183 // which runs in Windows 8 mode and the browser process. The initialization
157 // happens when the viewer process connects to the browser channel and sends 184 // happens when the viewer process connects to the browser channel and sends
(...skipping 14 matching lines...) Expand all
172 gfx::Point mouse_location; 199 gfx::Point mouse_location;
173 EXPECT_TRUE(host->QueryMouseLocation(&mouse_location)); 200 EXPECT_TRUE(host->QueryMouseLocation(&mouse_location));
174 EXPECT_EQ("10,10", mouse_location.ToString()); 201 EXPECT_EQ("10,10", mouse_location.ToString());
175 Shell::GetInstance()->cursor_manager()->DisableMouseEvents(); 202 Shell::GetInstance()->cursor_manager()->DisableMouseEvents();
176 EXPECT_FALSE(host->QueryMouseLocation(&mouse_location)); 203 EXPECT_FALSE(host->QueryMouseLocation(&mouse_location));
177 EXPECT_EQ("0,0", mouse_location.ToString()); 204 EXPECT_EQ("0,0", mouse_location.ToString());
178 } 205 }
179 206
180 } // namespace test 207 } // namespace test
181 } // namespace ash 208 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698