OLD | NEW |
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/display/display_controller.h" | 5 #include "ash/display/display_controller.h" |
6 | 6 |
| 7 #include "ash/display/display_manager.h" |
7 #include "ash/launcher/launcher.h" | 8 #include "ash/launcher/launcher.h" |
8 #include "ash/screen_ash.h" | 9 #include "ash/screen_ash.h" |
9 #include "ash/shell.h" | 10 #include "ash/shell.h" |
10 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
11 #include "ash/test/cursor_manager_test_api.h" | 12 #include "ash/test/cursor_manager_test_api.h" |
12 #include "ui/aura/display_manager.h" | |
13 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
14 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
15 #include "ui/aura/window_tracker.h" | 15 #include "ui/aura/window_tracker.h" |
16 #include "ui/gfx/display.h" | 16 #include "ui/gfx/display.h" |
17 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
18 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
19 | 19 |
20 namespace ash { | 20 namespace ash { |
21 namespace test { | 21 namespace test { |
22 namespace { | 22 namespace { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 #define MAYBE_SecondaryDisplayLayout SecondaryDisplayLayout | 85 #define MAYBE_SecondaryDisplayLayout SecondaryDisplayLayout |
86 #define MAYBE_BoundsUpdated BoundsUpdated | 86 #define MAYBE_BoundsUpdated BoundsUpdated |
87 #define MAYBE_UpdateDisplayWithHostOrigin UpdateDisplayWithHostOrigin | 87 #define MAYBE_UpdateDisplayWithHostOrigin UpdateDisplayWithHostOrigin |
88 #endif | 88 #endif |
89 | 89 |
90 TEST_F(DisplayControllerTest, MAYBE_SecondaryDisplayLayout) { | 90 TEST_F(DisplayControllerTest, MAYBE_SecondaryDisplayLayout) { |
91 TestObserver observer; | 91 TestObserver observer; |
92 UpdateDisplay("500x500,400x400"); | 92 UpdateDisplay("500x500,400x400"); |
93 EXPECT_EQ(2, observer.CountAndReset()); // resize and add | 93 EXPECT_EQ(2, observer.CountAndReset()); // resize and add |
94 gfx::Display* secondary_display = | 94 gfx::Display* secondary_display = |
95 aura::Env::GetInstance()->display_manager()->GetDisplayAt(1); | 95 Shell::GetInstance()->display_manager()->GetDisplayAt(1); |
96 gfx::Insets insets(5, 5, 5, 5); | 96 gfx::Insets insets(5, 5, 5, 5); |
97 secondary_display->UpdateWorkAreaFromInsets(insets); | 97 secondary_display->UpdateWorkAreaFromInsets(insets); |
98 | 98 |
99 // Default layout is RIGHT. | 99 // Default layout is RIGHT. |
100 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 100 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
101 EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString()); | 101 EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString()); |
102 EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString()); | 102 EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString()); |
103 | 103 |
104 // Layout the secondary display to the bottom of the primary. | 104 // Layout the secondary display to the bottom of the primary. |
105 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); | 105 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 | 158 |
159 } | 159 } |
160 | 160 |
161 TEST_F(DisplayControllerTest, MAYBE_BoundsUpdated) { | 161 TEST_F(DisplayControllerTest, MAYBE_BoundsUpdated) { |
162 TestObserver observer; | 162 TestObserver observer; |
163 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); | 163 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); |
164 UpdateDisplay("200x200,300x300"); // layout, resize and add. | 164 UpdateDisplay("200x200,300x300"); // layout, resize and add. |
165 EXPECT_EQ(3, observer.CountAndReset()); | 165 EXPECT_EQ(3, observer.CountAndReset()); |
166 | 166 |
167 gfx::Display* secondary_display = | 167 gfx::Display* secondary_display = |
168 aura::Env::GetInstance()->display_manager()->GetDisplayAt(1); | 168 Shell::GetInstance()->display_manager()->GetDisplayAt(1); |
169 gfx::Insets insets(5, 5, 5, 5); | 169 gfx::Insets insets(5, 5, 5, 5); |
170 secondary_display->UpdateWorkAreaFromInsets(insets); | 170 secondary_display->UpdateWorkAreaFromInsets(insets); |
171 | 171 |
172 EXPECT_EQ("0,0 200x200", GetPrimaryDisplay().bounds().ToString()); | 172 EXPECT_EQ("0,0 200x200", GetPrimaryDisplay().bounds().ToString()); |
173 EXPECT_EQ("0,200 300x300", GetSecondaryDisplay().bounds().ToString()); | 173 EXPECT_EQ("0,200 300x300", GetSecondaryDisplay().bounds().ToString()); |
174 EXPECT_EQ("5,205 290x290", GetSecondaryDisplay().work_area().ToString()); | 174 EXPECT_EQ("5,205 290x290", GetSecondaryDisplay().work_area().ToString()); |
175 | 175 |
176 UpdateDisplay("400x400,200x200"); | 176 UpdateDisplay("400x400,200x200"); |
177 EXPECT_EQ(2, observer.CountAndReset()); // two resizes | 177 EXPECT_EQ(2, observer.CountAndReset()); // two resizes |
178 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); | 178 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 } | 228 } |
229 | 229 |
230 TEST_F(DisplayControllerTest, SwapPrimary) { | 230 TEST_F(DisplayControllerTest, SwapPrimary) { |
231 DisplayController* display_controller = | 231 DisplayController* display_controller = |
232 Shell::GetInstance()->display_controller(); | 232 Shell::GetInstance()->display_controller(); |
233 | 233 |
234 UpdateDisplay("200x200,300x300"); | 234 UpdateDisplay("200x200,300x300"); |
235 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); | 235 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); |
236 gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay(); | 236 gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay(); |
237 | 237 |
238 std::string secondary_name = aura::Env::GetInstance()-> | 238 std::string secondary_name = Shell::GetInstance()-> |
239 display_manager()->GetDisplayNameFor(secondary_display); | 239 display_manager()->GetDisplayNameFor(secondary_display); |
240 DisplayLayout secondary_layout(DisplayLayout::RIGHT, 50); | 240 DisplayLayout secondary_layout(DisplayLayout::RIGHT, 50); |
241 display_controller->SetLayoutForDisplayName(secondary_name, secondary_layout); | 241 display_controller->SetLayoutForDisplayName(secondary_name, secondary_layout); |
242 | 242 |
243 EXPECT_NE(primary_display.id(), secondary_display.id()); | 243 EXPECT_NE(primary_display.id(), secondary_display.id()); |
244 aura::RootWindow* primary_root = | 244 aura::RootWindow* primary_root = |
245 display_controller->GetRootWindowForDisplayId(primary_display.id()); | 245 display_controller->GetRootWindowForDisplayId(primary_display.id()); |
246 aura::RootWindow* secondary_root = | 246 aura::RootWindow* secondary_root = |
247 display_controller->GetRootWindowForDisplayId(secondary_display.id()); | 247 display_controller->GetRootWindowForDisplayId(secondary_display.id()); |
248 EXPECT_NE(primary_root, secondary_root); | 248 EXPECT_NE(primary_root, secondary_root); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 } | 318 } |
319 | 319 |
320 TEST_F(DisplayControllerTest, SwapPrimaryById) { | 320 TEST_F(DisplayControllerTest, SwapPrimaryById) { |
321 DisplayController* display_controller = | 321 DisplayController* display_controller = |
322 Shell::GetInstance()->display_controller(); | 322 Shell::GetInstance()->display_controller(); |
323 | 323 |
324 UpdateDisplay("200x200,300x300"); | 324 UpdateDisplay("200x200,300x300"); |
325 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); | 325 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); |
326 gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay(); | 326 gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay(); |
327 | 327 |
328 std::string secondary_name = aura::Env::GetInstance()-> | 328 std::string secondary_name = Shell::GetInstance()-> |
329 display_manager()->GetDisplayNameFor(secondary_display); | 329 display_manager()->GetDisplayNameFor(secondary_display); |
330 DisplayLayout secondary_layout(DisplayLayout::RIGHT, 50); | 330 DisplayLayout secondary_layout(DisplayLayout::RIGHT, 50); |
331 display_controller->SetLayoutForDisplayName(secondary_name, secondary_layout); | 331 display_controller->SetLayoutForDisplayName(secondary_name, secondary_layout); |
332 | 332 |
333 EXPECT_NE(primary_display.id(), secondary_display.id()); | 333 EXPECT_NE(primary_display.id(), secondary_display.id()); |
334 aura::RootWindow* primary_root = | 334 aura::RootWindow* primary_root = |
335 display_controller->GetRootWindowForDisplayId(primary_display.id()); | 335 display_controller->GetRootWindowForDisplayId(primary_display.id()); |
336 aura::RootWindow* secondary_root = | 336 aura::RootWindow* secondary_root = |
337 display_controller->GetRootWindowForDisplayId(secondary_display.id()); | 337 display_controller->GetRootWindowForDisplayId(secondary_display.id()); |
338 aura::Window* launcher_window = | 338 aura::Window* launcher_window = |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); | 388 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); |
389 EXPECT_TRUE(tracker.Contains(primary_root)); | 389 EXPECT_TRUE(tracker.Contains(primary_root)); |
390 EXPECT_FALSE(tracker.Contains(secondary_root)); | 390 EXPECT_FALSE(tracker.Contains(secondary_root)); |
391 EXPECT_TRUE(primary_root->Contains(launcher_window)); | 391 EXPECT_TRUE(primary_root->Contains(launcher_window)); |
392 | 392 |
393 // Adding 2nd display with the same ID. The 2nd display should become primary | 393 // Adding 2nd display with the same ID. The 2nd display should become primary |
394 // since secondary id is still stored as desirable_primary_id. | 394 // since secondary id is still stored as desirable_primary_id. |
395 std::vector<gfx::Display> displays; | 395 std::vector<gfx::Display> displays; |
396 displays.push_back(primary_display); | 396 displays.push_back(primary_display); |
397 displays.push_back(secondary_display); | 397 displays.push_back(secondary_display); |
398 aura::DisplayManager* display_manager = | 398 internal::DisplayManager* display_manager = |
399 aura::Env::GetInstance()->display_manager(); | 399 Shell::GetInstance()->display_manager(); |
400 display_manager->OnNativeDisplaysChanged(displays); | 400 display_manager->OnNativeDisplaysChanged(displays); |
401 | 401 |
402 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays()); | 402 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays()); |
403 EXPECT_EQ(secondary_display.id(), | 403 EXPECT_EQ(secondary_display.id(), |
404 Shell::GetScreen()->GetPrimaryDisplay().id()); | 404 Shell::GetScreen()->GetPrimaryDisplay().id()); |
405 EXPECT_EQ(primary_display.id(), ScreenAsh::GetSecondaryDisplay().id()); | 405 EXPECT_EQ(primary_display.id(), ScreenAsh::GetSecondaryDisplay().id()); |
406 EXPECT_EQ( | 406 EXPECT_EQ( |
407 primary_root, | 407 primary_root, |
408 display_controller->GetRootWindowForDisplayId(secondary_display.id())); | 408 display_controller->GetRootWindowForDisplayId(secondary_display.id())); |
409 EXPECT_NE( | 409 EXPECT_NE( |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 UpdateDisplay("100+200-100x200,300+500-200x300"); | 515 UpdateDisplay("100+200-100x200,300+500-200x300"); |
516 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); | 516 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); |
517 EXPECT_EQ("100,200", root_windows[0]->GetHostOrigin().ToString()); | 517 EXPECT_EQ("100,200", root_windows[0]->GetHostOrigin().ToString()); |
518 EXPECT_EQ("100x200", root_windows[0]->GetHostSize().ToString()); | 518 EXPECT_EQ("100x200", root_windows[0]->GetHostSize().ToString()); |
519 EXPECT_EQ("300,500", root_windows[1]->GetHostOrigin().ToString()); | 519 EXPECT_EQ("300,500", root_windows[1]->GetHostOrigin().ToString()); |
520 EXPECT_EQ("200x300", root_windows[1]->GetHostSize().ToString()); | 520 EXPECT_EQ("200x300", root_windows[1]->GetHostSize().ToString()); |
521 } | 521 } |
522 | 522 |
523 } // namespace test | 523 } // namespace test |
524 } // namespace ash | 524 } // namespace ash |
OLD | NEW |