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

Side by Side Diff: ash/display/root_window_transformers_unittest.cc

Issue 2355063002: Separate ash::test::DisplayManagerTestApi from ash (Closed)
Patch Set: rebased, cleanup Created 4 years, 2 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/display/root_window_transformers.h" 5 #include "ash/display/root_window_transformers.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ash/common/shelf/shelf_widget.h" 9 #include "ash/common/shelf/shelf_widget.h"
10 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 float touch_radius_x_; 104 float touch_radius_x_;
105 float touch_radius_y_; 105 float touch_radius_y_;
106 float scroll_x_offset_; 106 float scroll_x_offset_;
107 float scroll_y_offset_; 107 float scroll_y_offset_;
108 float scroll_x_offset_ordinal_; 108 float scroll_x_offset_ordinal_;
109 float scroll_y_offset_ordinal_; 109 float scroll_y_offset_ordinal_;
110 110
111 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); 111 DISALLOW_COPY_AND_ASSIGN(TestEventHandler);
112 }; 112 };
113 113
114 float GetStoredUIScale(int64_t id) { 114 class RootWindowTransformersTest : public test::AshTestBase {
115 return Shell::GetInstance() 115 public:
116 ->display_manager() 116 RootWindowTransformersTest(){};
117 ->GetDisplayInfo(id) 117 ~RootWindowTransformersTest() override{};
oshima 2016/10/04 00:47:16 space before {}
rjkroege 2016/10/05 00:21:45 Done.
118 .GetEffectiveUIScale();
119 }
120 118
121 std::unique_ptr<RootWindowTransformer> 119 float GetStoredUIScale(int64_t id) {
122 CreateCurrentRootWindowTransformerForMirroring() { 120 return display_manager()->GetDisplayInfo(id).GetEffectiveUIScale();
123 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 121 };
124 DCHECK(display_manager->IsInMirrorMode()); 122
125 const display::ManagedDisplayInfo& mirror_display_info = 123 std::unique_ptr<RootWindowTransformer>
126 display_manager->GetDisplayInfo(display_manager->mirroring_display_id()); 124 CreateCurrentRootWindowTransformerForMirroring() {
127 const display::ManagedDisplayInfo& source_display_info = 125 DCHECK(display_manager()->IsInMirrorMode());
128 display_manager->GetDisplayInfo( 126 const display::ManagedDisplayInfo& mirror_display_info =
129 display::Screen::GetScreen()->GetPrimaryDisplay().id()); 127 display_manager()->GetDisplayInfo(
130 return std::unique_ptr<RootWindowTransformer>( 128 display_manager()->mirroring_display_id());
131 CreateRootWindowTransformerForMirroredDisplay(source_display_info, 129 const display::ManagedDisplayInfo& source_display_info =
132 mirror_display_info)); 130 display_manager()->GetDisplayInfo(
133 } 131 display::Screen::GetScreen()->GetPrimaryDisplay().id());
132 return std::unique_ptr<RootWindowTransformer>(
133 CreateRootWindowTransformerForMirroredDisplay(source_display_info,
134 mirror_display_info));
135 };
136 };
oshima 2016/10/04 00:47:16 DISALLOW_COPY_AND_ASSIGN
rjkroege 2016/10/05 00:21:45 Done.
134 137
135 } // namespace 138 } // namespace
136 139
137 typedef test::AshTestBase RootWindowTransformersTest; 140 // using RootWindowTransformersTest = test::AshTestBase;
138 141
139 #if defined(OS_WIN) 142 #if defined(OS_WIN)
140 // TODO(scottmg): RootWindow doesn't get resized on Windows 143 // TODO(scottmg): RootWindow doesn't get resized on Windows
141 // Ash. http://crbug.com/247916. 144 // Ash. http://crbug.com/247916.
142 #define MAYBE_RotateAndMagnify DISABLED_RotateAndMagniy 145 #define MAYBE_RotateAndMagnify DISABLED_RotateAndMagniy
143 #define MAYBE_TouchScaleAndMagnify DISABLED_TouchScaleAndMagnify 146 #define MAYBE_TouchScaleAndMagnify DISABLED_TouchScaleAndMagnify
144 #define MAYBE_ConvertHostToRootCoords DISABLED_ConvertHostToRootCoords 147 #define MAYBE_ConvertHostToRootCoords DISABLED_ConvertHostToRootCoords
145 #else 148 #else
146 #define MAYBE_RotateAndMagnify RotateAndMagniy 149 #define MAYBE_RotateAndMagnify RotateAndMagniy
147 #define MAYBE_TouchScaleAndMagnify TouchScaleAndMagnify 150 #define MAYBE_TouchScaleAndMagnify TouchScaleAndMagnify
148 #define MAYBE_ConvertHostToRootCoords ConvertHostToRootCoords 151 #define MAYBE_ConvertHostToRootCoords ConvertHostToRootCoords
149 #endif 152 #endif
150 153
151 TEST_F(RootWindowTransformersTest, MAYBE_RotateAndMagnify) { 154 TEST_F(RootWindowTransformersTest, MAYBE_RotateAndMagnify) {
152 MagnificationController* magnifier = 155 MagnificationController* magnifier =
153 Shell::GetInstance()->magnification_controller(); 156 Shell::GetInstance()->magnification_controller();
154 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
155 157
156 TestEventHandler event_handler; 158 TestEventHandler event_handler;
157 Shell::GetInstance()->AddPreTargetHandler(&event_handler); 159 Shell::GetInstance()->AddPreTargetHandler(&event_handler);
158 160
159 UpdateDisplay("120x200,300x400*2"); 161 UpdateDisplay("120x200,300x400*2");
160 display::Display display1 = display::Screen::GetScreen()->GetPrimaryDisplay(); 162 display::Display display1 = display::Screen::GetScreen()->GetPrimaryDisplay();
161 int64_t display2_id = ScreenUtil::GetSecondaryDisplay().id(); 163 int64_t display2_id = display_manager()->GetSecondaryDisplay().id();
162 164
163 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 165 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
164 ui::test::EventGenerator generator1(root_windows[0]); 166 ui::test::EventGenerator generator1(root_windows[0]);
165 ui::test::EventGenerator generator2(root_windows[1]); 167 ui::test::EventGenerator generator2(root_windows[1]);
166 168
167 magnifier->SetEnabled(true); 169 magnifier->SetEnabled(true);
168 EXPECT_EQ(2.0f, magnifier->GetScale()); 170 EXPECT_EQ(2.0f, magnifier->GetScale());
169 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); 171 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString());
170 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); 172 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString());
171 EXPECT_EQ("120,0 150x200", 173 EXPECT_EQ("120,0 150x200",
172 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 174 display_manager()->GetSecondaryDisplay().bounds().ToString());
173 generator1.MoveMouseToInHost(40, 80); 175 generator1.MoveMouseToInHost(40, 80);
174 EXPECT_EQ("50,90", event_handler.GetLocationAndReset()); 176 EXPECT_EQ("50,90", event_handler.GetLocationAndReset());
175 EXPECT_EQ("50,90", 177 EXPECT_EQ("50,90",
176 aura::Env::GetInstance()->last_mouse_location().ToString()); 178 aura::Env::GetInstance()->last_mouse_location().ToString());
177 EXPECT_EQ(display::Display::ROTATE_0, 179 EXPECT_EQ(display::Display::ROTATE_0,
178 GetActiveDisplayRotation(display1.id())); 180 GetActiveDisplayRotation(display1.id()));
179 EXPECT_EQ(display::Display::ROTATE_0, GetActiveDisplayRotation(display2_id)); 181 EXPECT_EQ(display::Display::ROTATE_0, GetActiveDisplayRotation(display2_id));
180 magnifier->SetEnabled(false); 182 magnifier->SetEnabled(false);
181 183
182 display_manager->SetDisplayRotation(display1.id(), 184 display_manager()->SetDisplayRotation(
183 display::Display::ROTATE_90, 185 display1.id(), display::Display::ROTATE_90,
184 display::Display::ROTATION_SOURCE_ACTIVE); 186 display::Display::ROTATION_SOURCE_ACTIVE);
185 // Move the cursor to the center of the first root window. 187 // Move the cursor to the center of the first root window.
186 generator1.MoveMouseToInHost(59, 100); 188 generator1.MoveMouseToInHost(59, 100);
187 189
188 magnifier->SetEnabled(true); 190 magnifier->SetEnabled(true);
189 EXPECT_EQ(2.0f, magnifier->GetScale()); 191 EXPECT_EQ(2.0f, magnifier->GetScale());
190 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); 192 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString());
191 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); 193 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString());
192 EXPECT_EQ("200,0 150x200", 194 EXPECT_EQ("200,0 150x200",
193 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 195 display_manager()->GetSecondaryDisplay().bounds().ToString());
194 generator1.MoveMouseToInHost(39, 120); 196 generator1.MoveMouseToInHost(39, 120);
195 EXPECT_EQ("110,70", event_handler.GetLocationAndReset()); 197 EXPECT_EQ("110,70", event_handler.GetLocationAndReset());
196 EXPECT_EQ("110,70", 198 EXPECT_EQ("110,70",
197 aura::Env::GetInstance()->last_mouse_location().ToString()); 199 aura::Env::GetInstance()->last_mouse_location().ToString());
198 EXPECT_EQ(display::Display::ROTATE_90, 200 EXPECT_EQ(display::Display::ROTATE_90,
199 GetActiveDisplayRotation(display1.id())); 201 GetActiveDisplayRotation(display1.id()));
200 EXPECT_EQ(display::Display::ROTATE_0, GetActiveDisplayRotation(display2_id)); 202 EXPECT_EQ(display::Display::ROTATE_0, GetActiveDisplayRotation(display2_id));
201 magnifier->SetEnabled(false); 203 magnifier->SetEnabled(false);
202 204
203 display_manager->SetLayoutForCurrentDisplays( 205 display_manager()->SetLayoutForCurrentDisplays(test::CreateDisplayLayout(
204 test::CreateDisplayLayout(display::DisplayPlacement::BOTTOM, 50)); 206 display_manager(), display::DisplayPlacement::BOTTOM, 50));
205 EXPECT_EQ("50,120 150x200", 207 EXPECT_EQ("50,120 150x200",
206 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 208 display_manager()->GetSecondaryDisplay().bounds().ToString());
207 209
208 display_manager->SetDisplayRotation(display2_id, display::Display::ROTATE_270, 210 display_manager()->SetDisplayRotation(
209 display::Display::ROTATION_SOURCE_ACTIVE); 211 display2_id, display::Display::ROTATE_270,
212 display::Display::ROTATION_SOURCE_ACTIVE);
210 // Move the cursor to the center of the second root window. 213 // Move the cursor to the center of the second root window.
211 generator2.MoveMouseToInHost(151, 199); 214 generator2.MoveMouseToInHost(151, 199);
212 215
213 magnifier->SetEnabled(true); 216 magnifier->SetEnabled(true);
214 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); 217 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString());
215 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); 218 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString());
216 EXPECT_EQ("50,120 200x150", 219 EXPECT_EQ("50,120 200x150",
217 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 220 display_manager()->GetSecondaryDisplay().bounds().ToString());
218 generator2.MoveMouseToInHost(172, 219); 221 generator2.MoveMouseToInHost(172, 219);
219 EXPECT_EQ("95,80", event_handler.GetLocationAndReset()); 222 EXPECT_EQ("95,80", event_handler.GetLocationAndReset());
220 EXPECT_EQ("145,200", 223 EXPECT_EQ("145,200",
221 aura::Env::GetInstance()->last_mouse_location().ToString()); 224 aura::Env::GetInstance()->last_mouse_location().ToString());
222 EXPECT_EQ(display::Display::ROTATE_90, 225 EXPECT_EQ(display::Display::ROTATE_90,
223 GetActiveDisplayRotation(display1.id())); 226 GetActiveDisplayRotation(display1.id()));
224 EXPECT_EQ(display::Display::ROTATE_270, 227 EXPECT_EQ(display::Display::ROTATE_270,
225 GetActiveDisplayRotation(display2_id)); 228 GetActiveDisplayRotation(display2_id));
226 magnifier->SetEnabled(false); 229 magnifier->SetEnabled(false);
227 230
228 display_manager->SetDisplayRotation(display1.id(), 231 display_manager()->SetDisplayRotation(
229 display::Display::ROTATE_180, 232 display1.id(), display::Display::ROTATE_180,
230 display::Display::ROTATION_SOURCE_ACTIVE); 233 display::Display::ROTATION_SOURCE_ACTIVE);
231 // Move the cursor to the center of the first root window. 234 // Move the cursor to the center of the first root window.
232 generator1.MoveMouseToInHost(59, 99); 235 generator1.MoveMouseToInHost(59, 99);
233 236
234 magnifier->SetEnabled(true); 237 magnifier->SetEnabled(true);
235 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); 238 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString());
236 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); 239 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString());
237 // Dislay must share at least 100, so the x's offset becomes 20. 240 // Dislay must share at least 100, so the x's offset becomes 20.
238 EXPECT_EQ("20,200 200x150", 241 EXPECT_EQ("20,200 200x150",
239 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); 242 display_manager()->GetSecondaryDisplay().bounds().ToString());
240 generator1.MoveMouseToInHost(39, 59); 243 generator1.MoveMouseToInHost(39, 59);
241 EXPECT_EQ("70,120", event_handler.GetLocationAndReset()); 244 EXPECT_EQ("70,120", event_handler.GetLocationAndReset());
242 EXPECT_EQ(display::Display::ROTATE_180, 245 EXPECT_EQ(display::Display::ROTATE_180,
243 GetActiveDisplayRotation(display1.id())); 246 GetActiveDisplayRotation(display1.id()));
244 EXPECT_EQ(display::Display::ROTATE_270, 247 EXPECT_EQ(display::Display::ROTATE_270,
245 GetActiveDisplayRotation(display2_id)); 248 GetActiveDisplayRotation(display2_id));
246 magnifier->SetEnabled(false); 249 magnifier->SetEnabled(false);
247 250
248 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); 251 Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
249 } 252 }
250 253
251 TEST_F(RootWindowTransformersTest, ScaleAndMagnify) { 254 TEST_F(RootWindowTransformersTest, ScaleAndMagnify) {
252 if (!SupportsMultipleDisplays()) 255 if (!SupportsMultipleDisplays())
253 return; 256 return;
254 257
255 TestEventHandler event_handler; 258 TestEventHandler event_handler;
256 Shell::GetInstance()->AddPreTargetHandler(&event_handler); 259 Shell::GetInstance()->AddPreTargetHandler(&event_handler);
257 260
258 UpdateDisplay("600x400*2@1.5,500x300"); 261 UpdateDisplay("600x400*2@1.5,500x300");
259 262
260 display::Display display1 = display::Screen::GetScreen()->GetPrimaryDisplay(); 263 display::Display display1 = display::Screen::GetScreen()->GetPrimaryDisplay();
261 test::ScopedSetInternalDisplayId set_internal(display1.id()); 264 test::ScopedSetInternalDisplayId set_internal(display_manager(),
262 display::Display display2 = ScreenUtil::GetSecondaryDisplay(); 265 display1.id());
266 display::Display display2 = display_manager()->GetSecondaryDisplay();
263 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 267 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
264 MagnificationController* magnifier = 268 MagnificationController* magnifier =
265 Shell::GetInstance()->magnification_controller(); 269 Shell::GetInstance()->magnification_controller();
266 270
267 magnifier->SetEnabled(true); 271 magnifier->SetEnabled(true);
268 EXPECT_EQ(2.0f, magnifier->GetScale()); 272 EXPECT_EQ(2.0f, magnifier->GetScale());
269 EXPECT_EQ("0,0 450x300", display1.bounds().ToString()); 273 EXPECT_EQ("0,0 450x300", display1.bounds().ToString());
270 EXPECT_EQ("0,0 450x300", root_windows[0]->bounds().ToString()); 274 EXPECT_EQ("0,0 450x300", root_windows[0]->bounds().ToString());
271 EXPECT_EQ("450,0 500x300", display2.bounds().ToString()); 275 EXPECT_EQ("450,0 500x300", display2.bounds().ToString());
272 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id())); 276 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id()));
273 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); 277 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id()));
274 278
275 ui::test::EventGenerator generator(root_windows[0]); 279 ui::test::EventGenerator generator(root_windows[0]);
276 generator.MoveMouseToInHost(500, 200); 280 generator.MoveMouseToInHost(500, 200);
277 EXPECT_EQ("299,150", event_handler.GetLocationAndReset()); 281 EXPECT_EQ("299,150", event_handler.GetLocationAndReset());
278 magnifier->SetEnabled(false); 282 magnifier->SetEnabled(false);
279 283
280 Shell::GetInstance()->display_manager()->SetDisplayUIScale(display1.id(), 284 display_manager()->SetDisplayUIScale(display1.id(), 1.25f);
281 1.25f);
282 display1 = display::Screen::GetScreen()->GetPrimaryDisplay(); 285 display1 = display::Screen::GetScreen()->GetPrimaryDisplay();
283 display2 = ScreenUtil::GetSecondaryDisplay(); 286 display2 = display_manager()->GetSecondaryDisplay();
284 magnifier->SetEnabled(true); 287 magnifier->SetEnabled(true);
285 EXPECT_EQ(2.0f, magnifier->GetScale()); 288 EXPECT_EQ(2.0f, magnifier->GetScale());
286 EXPECT_EQ("0,0 375x250", display1.bounds().ToString()); 289 EXPECT_EQ("0,0 375x250", display1.bounds().ToString());
287 EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString()); 290 EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString());
288 EXPECT_EQ("375,0 500x300", display2.bounds().ToString()); 291 EXPECT_EQ("375,0 500x300", display2.bounds().ToString());
289 EXPECT_EQ(1.25f, GetStoredUIScale(display1.id())); 292 EXPECT_EQ(1.25f, GetStoredUIScale(display1.id()));
290 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); 293 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id()));
291 magnifier->SetEnabled(false); 294 magnifier->SetEnabled(false);
292 295
293 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); 296 Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 magnifier->SetEnabled(false); 415 magnifier->SetEnabled(false);
413 EXPECT_FLOAT_EQ(1.0f, magnifier->GetScale()); 416 EXPECT_FLOAT_EQ(1.0f, magnifier->GetScale());
414 417
415 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); 418 Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
416 } 419 }
417 420
418 TEST_F(RootWindowTransformersTest, LetterBoxPillarBox) { 421 TEST_F(RootWindowTransformersTest, LetterBoxPillarBox) {
419 if (!SupportsMultipleDisplays()) 422 if (!SupportsMultipleDisplays())
420 return; 423 return;
421 test::MirrorWindowTestApi test_api; 424 test::MirrorWindowTestApi test_api;
422 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 425 display_manager()->SetMultiDisplayMode(DisplayManager::MIRRORING);
423 display_manager->SetMultiDisplayMode(DisplayManager::MIRRORING);
424 UpdateDisplay("400x200,500x500"); 426 UpdateDisplay("400x200,500x500");
425 std::unique_ptr<RootWindowTransformer> transformer( 427 std::unique_ptr<RootWindowTransformer> transformer(
426 CreateCurrentRootWindowTransformerForMirroring()); 428 CreateCurrentRootWindowTransformerForMirroring());
427 // Y margin must be margin is (500 - 500/400 * 200) / 2 = 125. 429 // Y margin must be margin is (500 - 500/400 * 200) / 2 = 125.
428 EXPECT_EQ("0,125,0,125", transformer->GetHostInsets().ToString()); 430 EXPECT_EQ("0,125,0,125", transformer->GetHostInsets().ToString());
429 431
430 UpdateDisplay("200x400,500x500"); 432 UpdateDisplay("200x400,500x500");
431 // The aspect ratio is flipped, so X margin is now 125. 433 // The aspect ratio is flipped, so X margin is now 125.
432 transformer = CreateCurrentRootWindowTransformerForMirroring(); 434 transformer = CreateCurrentRootWindowTransformerForMirroring();
433 EXPECT_EQ("125,0,125,0", transformer->GetHostInsets().ToString()); 435 EXPECT_EQ("125,0,125,0", transformer->GetHostInsets().ToString());
434 } 436 }
435 437
436 } // namespace ash 438 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698