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" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 UpdateDisplay("600x600"); | 100 UpdateDisplay("600x600"); |
101 EXPECT_EQ("0,0 600x600", GetPrimaryDisplay().bounds().ToString()); | 101 EXPECT_EQ("0,0 600x600", GetPrimaryDisplay().bounds().ToString()); |
102 EXPECT_EQ(1, gfx::Screen::GetNumDisplays()); | 102 EXPECT_EQ(1, gfx::Screen::GetNumDisplays()); |
103 | 103 |
104 UpdateDisplay("700x700,1000x1000"); | 104 UpdateDisplay("700x700,1000x1000"); |
105 ASSERT_EQ(2, gfx::Screen::GetNumDisplays()); | 105 ASSERT_EQ(2, gfx::Screen::GetNumDisplays()); |
106 EXPECT_EQ("0,0 700x700", GetPrimaryDisplay().bounds().ToString()); | 106 EXPECT_EQ("0,0 700x700", GetPrimaryDisplay().bounds().ToString()); |
107 EXPECT_EQ("0,700 1000x1000", GetSecondaryDisplay().bounds().ToString()); | 107 EXPECT_EQ("0,700 1000x1000", GetSecondaryDisplay().bounds().ToString()); |
108 } | 108 } |
109 | 109 |
| 110 // Verifies if the mouse pointer correctly moves to another display when there |
| 111 // are two displays. |
110 TEST_F(DisplayControllerTest, WarpMouse) { | 112 TEST_F(DisplayControllerTest, WarpMouse) { |
111 UpdateDisplay("500x500,500x500"); | 113 UpdateDisplay("500x500,500x500"); |
112 | 114 |
113 ash::internal::DisplayController* controller = | 115 ash::internal::DisplayController* controller = |
114 Shell::GetInstance()->display_controller(); | 116 Shell::GetInstance()->display_controller(); |
115 EXPECT_EQ(internal::DisplayController::RIGHT, | 117 EXPECT_EQ(internal::DisplayController::RIGHT, |
116 controller->secondary_display_layout()); | 118 controller->secondary_display_layout()); |
117 | 119 |
118 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 120 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
119 bool is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0], | 121 bool is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0], |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // Touch the top edge of the secondary root window. | 158 // Touch the top edge of the secondary root window. |
157 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1], | 159 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1], |
158 gfx::Point(11, 0)); | 160 gfx::Point(11, 0)); |
159 EXPECT_FALSE(is_warped); | 161 EXPECT_FALSE(is_warped); |
160 // Touch the bottom edge of the secondary root window. | 162 // Touch the bottom edge of the secondary root window. |
161 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1], | 163 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1], |
162 gfx::Point(11, 499)); | 164 gfx::Point(11, 499)); |
163 EXPECT_FALSE(is_warped); | 165 EXPECT_FALSE(is_warped); |
164 } | 166 } |
165 | 167 |
| 168 // Verifies if the mouse pointer correctly moves to another display even when |
| 169 // two displays are not the same size. |
| 170 TEST_F(DisplayControllerTest, WarpMouseDifferentSizeDisplays) { |
| 171 UpdateDisplay("500x500,600x600"); // the second one is larger. |
| 172 |
| 173 ash::internal::DisplayController* controller = |
| 174 Shell::GetInstance()->display_controller(); |
| 175 EXPECT_EQ(internal::DisplayController::RIGHT, |
| 176 controller->secondary_display_layout()); |
| 177 |
| 178 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 179 aura::Env::GetInstance()->SetLastMouseLocation(*root_windows[1], |
| 180 gfx::Point(123, 123)); |
| 181 |
| 182 // Touch the left edge of the secondary root window. Pointer should NOT warp |
| 183 // because 1px left of (0, 500) is outside the primary root window. |
| 184 bool is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1], |
| 185 gfx::Point(0, 500)); |
| 186 EXPECT_FALSE(is_warped); |
| 187 EXPECT_EQ("623,123", // by 2px. |
| 188 aura::Env::GetInstance()->last_mouse_location().ToString()); |
| 189 |
| 190 // Touch the left edge of the secondary root window. Pointer should warp |
| 191 // because 1px left of (0, 499) is inside the primary root window. |
| 192 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1], |
| 193 gfx::Point(0, 499)); |
| 194 EXPECT_TRUE(is_warped); |
| 195 EXPECT_EQ("498,499", // by 2px. |
| 196 aura::Env::GetInstance()->last_mouse_location().ToString()); |
| 197 } |
| 198 |
| 199 // Verifies if DisplayController::dont_warp_mouse() works as expected. |
166 TEST_F(DisplayControllerTest, SetUnsetDontWarpMousedFlag) { | 200 TEST_F(DisplayControllerTest, SetUnsetDontWarpMousedFlag) { |
167 UpdateDisplay("500x500,500x500"); | 201 UpdateDisplay("500x500,500x500"); |
168 | 202 |
169 ash::internal::DisplayController* controller = | 203 ash::internal::DisplayController* controller = |
170 Shell::GetInstance()->display_controller(); | 204 Shell::GetInstance()->display_controller(); |
171 | 205 |
172 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 206 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
173 aura::Env::GetInstance()->SetLastMouseLocation(*root_windows[0], | 207 aura::Env::GetInstance()->SetLastMouseLocation(*root_windows[0], |
174 gfx::Point(1, 1)); | 208 gfx::Point(1, 1)); |
175 | 209 |
176 controller->set_dont_warp_mouse(true); | 210 controller->set_dont_warp_mouse(true); |
177 bool is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0], | 211 bool is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0], |
178 gfx::Point(499, 11)); | 212 gfx::Point(499, 11)); |
179 EXPECT_FALSE(is_warped); | 213 EXPECT_FALSE(is_warped); |
180 EXPECT_EQ("1,1", | 214 EXPECT_EQ("1,1", |
181 aura::Env::GetInstance()->last_mouse_location().ToString()); | 215 aura::Env::GetInstance()->last_mouse_location().ToString()); |
182 | 216 |
183 controller->set_dont_warp_mouse(false); | 217 controller->set_dont_warp_mouse(false); |
184 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0], | 218 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0], |
185 gfx::Point(499, 11)); | 219 gfx::Point(499, 11)); |
186 EXPECT_TRUE(is_warped); | 220 EXPECT_TRUE(is_warped); |
187 EXPECT_EQ("501,11", | 221 EXPECT_EQ("501,11", |
188 aura::Env::GetInstance()->last_mouse_location().ToString()); | 222 aura::Env::GetInstance()->last_mouse_location().ToString()); |
189 } | 223 } |
190 | 224 |
191 } // namespace test | 225 } // namespace test |
192 } // namespace ash | 226 } // namespace ash |
OLD | NEW |