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

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

Issue 10870036: Allow storing display preferences per device. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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/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(internal::DisplayLayout::Position position) {
30 internal::DisplayController* display_controller =
31 Shell::GetInstance()->display_controller();
32 internal::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(internal::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(internal::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(internal::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(internal::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 17 matching lines...) Expand all
109 EXPECT_EQ("0,700 1000x1000", GetSecondaryDisplay().bounds().ToString()); 113 EXPECT_EQ("0,700 1000x1000", GetSecondaryDisplay().bounds().ToString());
110 } 114 }
111 115
112 // Verifies if the mouse pointer correctly moves to another display when there 116 // Verifies if the mouse pointer correctly moves to another display when there
113 // are two displays. 117 // are two displays.
114 TEST_F(DisplayControllerTest, WarpMouse) { 118 TEST_F(DisplayControllerTest, WarpMouse) {
115 UpdateDisplay("500x500,500x500"); 119 UpdateDisplay("500x500,500x500");
116 120
117 ash::internal::DisplayController* controller = 121 ash::internal::DisplayController* controller =
118 Shell::GetInstance()->display_controller(); 122 Shell::GetInstance()->display_controller();
119 EXPECT_EQ(internal::DisplayController::RIGHT, 123 EXPECT_EQ(internal::DisplayLayout::RIGHT,
120 controller->secondary_display_layout()); 124 controller->default_display_layout().position);
121 125
122 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 126 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
123 bool is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0], 127 bool is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0],
124 gfx::Point(11, 11)); 128 gfx::Point(11, 11));
125 EXPECT_FALSE(is_warped); 129 EXPECT_FALSE(is_warped);
126 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1], 130 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1],
127 gfx::Point(11, 11)); 131 gfx::Point(11, 11));
128 EXPECT_FALSE(is_warped); 132 EXPECT_FALSE(is_warped);
129 133
130 // Touch the right edge of the primary root window. Pointer should warp. 134 // Touch the right edge of the primary root window. Pointer should warp.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 EXPECT_FALSE(is_warped); 171 EXPECT_FALSE(is_warped);
168 } 172 }
169 173
170 // Verifies if the mouse pointer correctly moves to another display even when 174 // Verifies if the mouse pointer correctly moves to another display even when
171 // two displays are not the same size. 175 // two displays are not the same size.
172 TEST_F(DisplayControllerTest, WarpMouseDifferentSizeDisplays) { 176 TEST_F(DisplayControllerTest, WarpMouseDifferentSizeDisplays) {
173 UpdateDisplay("500x500,600x600"); // the second one is larger. 177 UpdateDisplay("500x500,600x600"); // the second one is larger.
174 178
175 ash::internal::DisplayController* controller = 179 ash::internal::DisplayController* controller =
176 Shell::GetInstance()->display_controller(); 180 Shell::GetInstance()->display_controller();
177 EXPECT_EQ(internal::DisplayController::RIGHT, 181 EXPECT_EQ(internal::DisplayLayout::RIGHT,
178 controller->secondary_display_layout()); 182 controller->default_display_layout().position);
179 183
180 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 184 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
181 aura::Env::GetInstance()->SetLastMouseLocation(*root_windows[1], 185 aura::Env::GetInstance()->SetLastMouseLocation(*root_windows[1],
182 gfx::Point(123, 123)); 186 gfx::Point(123, 123));
183 187
184 // Touch the left edge of the secondary root window. Pointer should NOT warp 188 // Touch the left edge of the secondary root window. Pointer should NOT warp
185 // because 1px left of (0, 500) is outside the primary root window. 189 // because 1px left of (0, 500) is outside the primary root window.
186 bool is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1], 190 bool is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1],
187 gfx::Point(0, 500)); 191 gfx::Point(0, 500));
188 EXPECT_FALSE(is_warped); 192 EXPECT_FALSE(is_warped);
(...skipping 30 matching lines...) Expand all
219 controller->set_dont_warp_mouse(false); 223 controller->set_dont_warp_mouse(false);
220 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0], 224 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0],
221 gfx::Point(499, 11)); 225 gfx::Point(499, 11));
222 EXPECT_TRUE(is_warped); 226 EXPECT_TRUE(is_warped);
223 EXPECT_EQ("501,11", 227 EXPECT_EQ("501,11",
224 aura::Env::GetInstance()->last_mouse_location().ToString()); 228 aura::Env::GetInstance()->last_mouse_location().ToString());
225 } 229 }
226 230
227 } // namespace test 231 } // namespace test
228 } // namespace ash 232 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698