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/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
9 #include "ui/aura/display_manager.h" | 9 #include "ui/aura/display_manager.h" |
10 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
11 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
12 #include "ui/gfx/display.h" | 12 #include "ui/gfx/display.h" |
13 #include "ui/gfx/screen.h" | 13 #include "ui/gfx/screen.h" |
14 | 14 |
15 namespace ash { | 15 namespace ash { |
16 namespace test { | 16 namespace test { |
17 namespace { | 17 namespace { |
18 | 18 |
19 gfx::Display GetPrimaryDisplay() { | 19 gfx::Display GetPrimaryDisplay() { |
20 return gfx::Screen::GetDisplayNearestWindow( | 20 return gfx::Screen::GetDisplayNearestWindow( |
21 Shell::GetAllRootWindows()[0]); | 21 Shell::GetAllRootWindows()[0]); |
22 } | 22 } |
23 | 23 |
24 gfx::Display GetSecondaryDisplay() { | 24 gfx::Display GetSecondaryDisplay() { |
25 return gfx::Screen::GetDisplayNearestWindow( | 25 return gfx::Screen::GetDisplayNearestWindow( |
26 Shell::GetAllRootWindows()[1]); | 26 Shell::GetAllRootWindows()[1]); |
27 } | 27 } |
28 | 28 |
| 29 void SetSecondaryDisplayLayout(DisplayLayout::Position position) { |
| 30 DisplayController* display_controller = |
| 31 Shell::GetInstance()->display_controller(); |
| 32 DisplayLayout layout = display_controller->default_display_layout(); |
| 33 layout.position = position; |
| 34 display_controller->SetDefaultDisplayLayout(layout); |
| 35 } |
| 36 |
29 } // namespace | 37 } // namespace |
30 | 38 |
31 typedef test::AshTestBase DisplayControllerTest; | 39 typedef test::AshTestBase DisplayControllerTest; |
32 | 40 |
33 #if defined(OS_WIN) | 41 #if defined(OS_WIN) |
34 // TOD(oshima): Windows creates a window with smaller client area. | 42 // TOD(oshima): Windows creates a window with smaller client area. |
35 // Fix this and enable tests. | 43 // Fix this and enable tests. |
36 #define MAYBE_SecondaryDisplayLayout DISABLED_SecondaryDisplayLayout | 44 #define MAYBE_SecondaryDisplayLayout DISABLED_SecondaryDisplayLayout |
37 #else | 45 #else |
38 #define MAYBE_SecondaryDisplayLayout SecondaryDisplayLayout | 46 #define MAYBE_SecondaryDisplayLayout SecondaryDisplayLayout |
39 #endif | 47 #endif |
40 | 48 |
41 TEST_F(DisplayControllerTest, MAYBE_SecondaryDisplayLayout) { | 49 TEST_F(DisplayControllerTest, MAYBE_SecondaryDisplayLayout) { |
42 UpdateDisplay("500x500,400x400"); | 50 UpdateDisplay("500x500,400x400"); |
43 gfx::Display* secondary_display = | 51 gfx::Display* secondary_display = |
44 aura::Env::GetInstance()->display_manager()->GetDisplayAt(1); | 52 aura::Env::GetInstance()->display_manager()->GetDisplayAt(1); |
45 gfx::Insets insets(5, 5, 5, 5); | 53 gfx::Insets insets(5, 5, 5, 5); |
46 secondary_display->UpdateWorkAreaFromInsets(insets); | 54 secondary_display->UpdateWorkAreaFromInsets(insets); |
47 | 55 |
48 // Default layout is LEFT. | 56 // Default layout is LEFT. |
49 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 57 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
50 EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString()); | 58 EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString()); |
51 EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString()); | 59 EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString()); |
52 | 60 |
53 // Layout the secondary display to the bottom of the primary. | 61 // Layout the secondary display to the bottom of the primary. |
54 Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout( | 62 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); |
55 internal::DisplayController::BOTTOM); | |
56 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 63 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
57 EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString()); | 64 EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString()); |
58 EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString()); | 65 EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString()); |
59 | 66 |
60 // Layout the secondary display to the left of the primary. | 67 // Layout the secondary display to the left of the primary. |
61 Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout( | 68 SetSecondaryDisplayLayout(DisplayLayout::LEFT); |
62 internal::DisplayController::LEFT); | |
63 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 69 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
64 EXPECT_EQ("-400,0 400x400", GetSecondaryDisplay().bounds().ToString()); | 70 EXPECT_EQ("-400,0 400x400", GetSecondaryDisplay().bounds().ToString()); |
65 EXPECT_EQ("-395,5 390x390", GetSecondaryDisplay().work_area().ToString()); | 71 EXPECT_EQ("-395,5 390x390", GetSecondaryDisplay().work_area().ToString()); |
66 | 72 |
67 // Layout the secondary display to the top of the primary. | 73 // Layout the secondary display to the top of the primary. |
68 Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout( | 74 SetSecondaryDisplayLayout(DisplayLayout::TOP); |
69 internal::DisplayController::TOP); | |
70 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 75 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
71 EXPECT_EQ("0,-400 400x400", GetSecondaryDisplay().bounds().ToString()); | 76 EXPECT_EQ("0,-400 400x400", GetSecondaryDisplay().bounds().ToString()); |
72 EXPECT_EQ("5,-395 390x390", GetSecondaryDisplay().work_area().ToString()); | 77 EXPECT_EQ("5,-395 390x390", GetSecondaryDisplay().work_area().ToString()); |
73 } | 78 } |
74 | 79 |
75 // TODO(oshima,erg): I suspect this test is now failing because I've changed | 80 // TODO(oshima,erg): I suspect this test is now failing because I've changed |
76 // the timing of the RootWindow::Show to be synchronous. If true, this test has | 81 // the timing of the RootWindow::Show to be synchronous. If true, this test has |
77 // always been incorrect, but is now visibly broken now that we're processing | 82 // always been incorrect, but is now visibly broken now that we're processing |
78 // X11 configuration events while waiting for the MapNotify. | 83 // X11 configuration events while waiting for the MapNotify. |
79 TEST_F(DisplayControllerTest, DISABLED_BoundsUpdated) { | 84 TEST_F(DisplayControllerTest, DISABLED_BoundsUpdated) { |
80 Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout( | 85 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); |
81 internal::DisplayController::BOTTOM); | |
82 UpdateDisplay("500x500,400x400"); | 86 UpdateDisplay("500x500,400x400"); |
83 gfx::Display* secondary_display = | 87 gfx::Display* secondary_display = |
84 aura::Env::GetInstance()->display_manager()->GetDisplayAt(1); | 88 aura::Env::GetInstance()->display_manager()->GetDisplayAt(1); |
85 gfx::Insets insets(5, 5, 5, 5); | 89 gfx::Insets insets(5, 5, 5, 5); |
86 secondary_display->UpdateWorkAreaFromInsets(insets); | 90 secondary_display->UpdateWorkAreaFromInsets(insets); |
87 | 91 |
88 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 92 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
89 EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString()); | 93 EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString()); |
90 EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString()); | 94 EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString()); |
91 | 95 |
(...skipping 12 matching lines...) Expand all Loading... |
104 EXPECT_EQ(1, gfx::Screen::GetNumDisplays()); | 108 EXPECT_EQ(1, gfx::Screen::GetNumDisplays()); |
105 | 109 |
106 UpdateDisplay("700x700,1000x1000"); | 110 UpdateDisplay("700x700,1000x1000"); |
107 ASSERT_EQ(2, gfx::Screen::GetNumDisplays()); | 111 ASSERT_EQ(2, gfx::Screen::GetNumDisplays()); |
108 EXPECT_EQ("0,0 700x700", GetPrimaryDisplay().bounds().ToString()); | 112 EXPECT_EQ("0,0 700x700", GetPrimaryDisplay().bounds().ToString()); |
109 EXPECT_EQ("0,700 1000x1000", GetSecondaryDisplay().bounds().ToString()); | 113 EXPECT_EQ("0,700 1000x1000", GetSecondaryDisplay().bounds().ToString()); |
110 } | 114 } |
111 | 115 |
112 } // namespace test | 116 } // namespace test |
113 } // namespace ash | 117 } // namespace ash |
OLD | NEW |