OLD | NEW |
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 "ash/display/display_info.h" | 7 #include "ash/display/display_info.h" |
8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
9 #include "ash/host/root_window_transformer.h" | 9 #include "ash/host/root_window_transformer.h" |
10 #include "ash/magnifier/magnification_controller.h" | 10 #include "ash/magnifier/magnification_controller.h" |
11 #include "ash/screen_util.h" | 11 #include "ash/screen_util.h" |
12 #include "ash/shelf/shelf.h" | 12 #include "ash/shelf/shelf.h" |
13 #include "ash/shelf/shelf_widget.h" | 13 #include "ash/shelf/shelf_widget.h" |
14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
15 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
16 #include "ash/test/cursor_manager_test_api.h" | 16 #include "ash/test/cursor_manager_test_api.h" |
17 #include "ash/test/mirror_window_test_api.h" | 17 #include "ash/test/mirror_window_test_api.h" |
18 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
19 #include "ui/aura/env.h" | 19 #include "ui/aura/env.h" |
20 #include "ui/aura/test/event_generator.h" | |
21 #include "ui/aura/window_event_dispatcher.h" | 20 #include "ui/aura/window_event_dispatcher.h" |
22 #include "ui/aura/window_tracker.h" | 21 #include "ui/aura/window_tracker.h" |
23 #include "ui/events/event_handler.h" | 22 #include "ui/events/event_handler.h" |
| 23 #include "ui/events/test/event_generator.h" |
24 #include "ui/gfx/display.h" | 24 #include "ui/gfx/display.h" |
25 #include "ui/gfx/rect_conversions.h" | 25 #include "ui/gfx/rect_conversions.h" |
26 #include "ui/gfx/screen.h" | 26 #include "ui/gfx/screen.h" |
27 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
28 | 28 |
29 namespace ash { | 29 namespace ash { |
30 namespace { | 30 namespace { |
31 | 31 |
32 const char kDesktopBackgroundView[] = "DesktopBackgroundView"; | 32 const char kDesktopBackgroundView[] = "DesktopBackgroundView"; |
33 | 33 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 137 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
138 | 138 |
139 TestEventHandler event_handler; | 139 TestEventHandler event_handler; |
140 Shell::GetInstance()->AddPreTargetHandler(&event_handler); | 140 Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
141 | 141 |
142 UpdateDisplay("120x200,300x400*2"); | 142 UpdateDisplay("120x200,300x400*2"); |
143 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); | 143 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); |
144 int64 display2_id = ScreenUtil::GetSecondaryDisplay().id(); | 144 int64 display2_id = ScreenUtil::GetSecondaryDisplay().id(); |
145 | 145 |
146 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 146 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
147 aura::test::EventGenerator generator1(root_windows[0]); | 147 ui::test::EventGenerator generator1(root_windows[0]); |
148 aura::test::EventGenerator generator2(root_windows[1]); | 148 ui::test::EventGenerator generator2(root_windows[1]); |
149 | 149 |
150 magnifier->SetEnabled(true); | 150 magnifier->SetEnabled(true); |
151 EXPECT_EQ(2.0f, magnifier->GetScale()); | 151 EXPECT_EQ(2.0f, magnifier->GetScale()); |
152 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); | 152 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); |
153 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); | 153 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); |
154 EXPECT_EQ("120,0 150x200", | 154 EXPECT_EQ("120,0 150x200", |
155 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); | 155 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); |
156 generator1.MoveMouseToInHost(40, 80); | 156 generator1.MoveMouseToInHost(40, 80); |
157 EXPECT_EQ("50,90", event_handler.GetLocationAndReset()); | 157 EXPECT_EQ("50,90", event_handler.GetLocationAndReset()); |
158 EXPECT_EQ("50,90", | 158 EXPECT_EQ("50,90", |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 Shell::GetInstance()->magnification_controller(); | 240 Shell::GetInstance()->magnification_controller(); |
241 | 241 |
242 magnifier->SetEnabled(true); | 242 magnifier->SetEnabled(true); |
243 EXPECT_EQ(2.0f, magnifier->GetScale()); | 243 EXPECT_EQ(2.0f, magnifier->GetScale()); |
244 EXPECT_EQ("0,0 450x300", display1.bounds().ToString()); | 244 EXPECT_EQ("0,0 450x300", display1.bounds().ToString()); |
245 EXPECT_EQ("0,0 450x300", root_windows[0]->bounds().ToString()); | 245 EXPECT_EQ("0,0 450x300", root_windows[0]->bounds().ToString()); |
246 EXPECT_EQ("450,0 500x300", display2.bounds().ToString()); | 246 EXPECT_EQ("450,0 500x300", display2.bounds().ToString()); |
247 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id())); | 247 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id())); |
248 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); | 248 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); |
249 | 249 |
250 aura::test::EventGenerator generator(root_windows[0]); | 250 ui::test::EventGenerator generator(root_windows[0]); |
251 generator.MoveMouseToInHost(500, 200); | 251 generator.MoveMouseToInHost(500, 200); |
252 EXPECT_EQ("299,150", event_handler.GetLocationAndReset()); | 252 EXPECT_EQ("299,150", event_handler.GetLocationAndReset()); |
253 magnifier->SetEnabled(false); | 253 magnifier->SetEnabled(false); |
254 | 254 |
255 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 255 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
256 display_manager->SetDisplayUIScale(display1.id(), 1.25); | 256 display_manager->SetDisplayUIScale(display1.id(), 1.25); |
257 display1 = Shell::GetScreen()->GetPrimaryDisplay(); | 257 display1 = Shell::GetScreen()->GetPrimaryDisplay(); |
258 display2 = ScreenUtil::GetSecondaryDisplay(); | 258 display2 = ScreenUtil::GetSecondaryDisplay(); |
259 magnifier->SetEnabled(true); | 259 magnifier->SetEnabled(true); |
260 EXPECT_EQ(2.0f, magnifier->GetScale()); | 260 EXPECT_EQ(2.0f, magnifier->GetScale()); |
261 EXPECT_EQ("0,0 375x250", display1.bounds().ToString()); | 261 EXPECT_EQ("0,0 375x250", display1.bounds().ToString()); |
262 EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString()); | 262 EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString()); |
263 EXPECT_EQ("375,0 500x300", display2.bounds().ToString()); | 263 EXPECT_EQ("375,0 500x300", display2.bounds().ToString()); |
264 EXPECT_EQ(1.25f, GetStoredUIScale(display1.id())); | 264 EXPECT_EQ(1.25f, GetStoredUIScale(display1.id())); |
265 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); | 265 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); |
266 magnifier->SetEnabled(false); | 266 magnifier->SetEnabled(false); |
267 | 267 |
268 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); | 268 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
269 } | 269 } |
270 | 270 |
271 TEST_F(RootWindowTransformersTest, MAYBE_TouchScaleAndMagnify) { | 271 TEST_F(RootWindowTransformersTest, MAYBE_TouchScaleAndMagnify) { |
272 TestEventHandler event_handler; | 272 TestEventHandler event_handler; |
273 Shell::GetInstance()->AddPreTargetHandler(&event_handler); | 273 Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
274 | 274 |
275 UpdateDisplay("200x200*2"); | 275 UpdateDisplay("200x200*2"); |
276 gfx::Display display = Shell::GetScreen()->GetPrimaryDisplay(); | 276 gfx::Display display = Shell::GetScreen()->GetPrimaryDisplay(); |
277 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 277 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
278 aura::Window* root_window = root_windows[0]; | 278 aura::Window* root_window = root_windows[0]; |
279 aura::test::EventGenerator generator(root_window); | 279 ui::test::EventGenerator generator(root_window); |
280 MagnificationController* magnifier = | 280 MagnificationController* magnifier = |
281 Shell::GetInstance()->magnification_controller(); | 281 Shell::GetInstance()->magnification_controller(); |
282 | 282 |
283 magnifier->SetEnabled(true); | 283 magnifier->SetEnabled(true); |
284 EXPECT_FLOAT_EQ(2.0f, magnifier->GetScale()); | 284 EXPECT_FLOAT_EQ(2.0f, magnifier->GetScale()); |
285 magnifier->SetScale(2.5f, false); | 285 magnifier->SetScale(2.5f, false); |
286 EXPECT_FLOAT_EQ(2.5f, magnifier->GetScale()); | 286 EXPECT_FLOAT_EQ(2.5f, magnifier->GetScale()); |
287 generator.PressMoveAndReleaseTouchTo(50, 50); | 287 generator.PressMoveAndReleaseTouchTo(50, 50); |
288 // Default test touches have radius_x/y = 1.0, with device scale | 288 // Default test touches have radius_x/y = 1.0, with device scale |
289 // factor = 2, the scaled radius_x/y should be 0.5. | 289 // factor = 2, the scaled radius_x/y should be 0.5. |
(...skipping 22 matching lines...) Expand all Loading... |
312 | 312 |
313 // Test 1 | 313 // Test 1 |
314 UpdateDisplay("600x400*2/r@1.5"); | 314 UpdateDisplay("600x400*2/r@1.5"); |
315 | 315 |
316 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); | 316 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); |
317 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 317 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
318 EXPECT_EQ("0,0 300x450", display1.bounds().ToString()); | 318 EXPECT_EQ("0,0 300x450", display1.bounds().ToString()); |
319 EXPECT_EQ("0,0 300x450", root_windows[0]->bounds().ToString()); | 319 EXPECT_EQ("0,0 300x450", root_windows[0]->bounds().ToString()); |
320 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id())); | 320 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id())); |
321 | 321 |
322 aura::test::EventGenerator generator(root_windows[0]); | 322 ui::test::EventGenerator generator(root_windows[0]); |
323 generator.MoveMouseToInHost(300, 200); | 323 generator.MoveMouseToInHost(300, 200); |
324 magnifier->SetEnabled(true); | 324 magnifier->SetEnabled(true); |
325 EXPECT_EQ("150,224", event_handler.GetLocationAndReset()); | 325 EXPECT_EQ("150,224", event_handler.GetLocationAndReset()); |
326 EXPECT_FLOAT_EQ(2.0f, magnifier->GetScale()); | 326 EXPECT_FLOAT_EQ(2.0f, magnifier->GetScale()); |
327 | 327 |
328 generator.MoveMouseToInHost(300, 200); | 328 generator.MoveMouseToInHost(300, 200); |
329 EXPECT_EQ("150,224", event_handler.GetLocationAndReset()); | 329 EXPECT_EQ("150,224", event_handler.GetLocationAndReset()); |
330 generator.MoveMouseToInHost(200, 300); | 330 generator.MoveMouseToInHost(200, 300); |
331 EXPECT_EQ("187,261", event_handler.GetLocationAndReset()); | 331 EXPECT_EQ("187,261", event_handler.GetLocationAndReset()); |
332 generator.MoveMouseToInHost(100, 400); | 332 generator.MoveMouseToInHost(100, 400); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 // Y margin must be margin is (500 - 500/400 * 200) / 2 = 125. | 402 // Y margin must be margin is (500 - 500/400 * 200) / 2 = 125. |
403 EXPECT_EQ("0,125,0,125", transformer->GetHostInsets().ToString()); | 403 EXPECT_EQ("0,125,0,125", transformer->GetHostInsets().ToString()); |
404 | 404 |
405 UpdateDisplay("200x400,500x500"); | 405 UpdateDisplay("200x400,500x500"); |
406 // The aspect ratio is flipped, so X margin is now 125. | 406 // The aspect ratio is flipped, so X margin is now 125. |
407 transformer = test_api.CreateCurrentRootWindowTransformer(); | 407 transformer = test_api.CreateCurrentRootWindowTransformer(); |
408 EXPECT_EQ("125,0,125,0", transformer->GetHostInsets().ToString()); | 408 EXPECT_EQ("125,0,125,0", transformer->GetHostInsets().ToString()); |
409 } | 409 } |
410 | 410 |
411 } // namespace ash | 411 } // namespace ash |
OLD | NEW |