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" |
| 10 #include "ui/aura/env.h" |
9 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
10 #include "ui/gfx/display.h" | 12 #include "ui/gfx/display.h" |
11 #include "ui/gfx/screen.h" | 13 #include "ui/gfx/screen.h" |
12 | 14 |
13 #include "ui/aura/env.h" | |
14 #include "ui/aura/display_manager.h" | |
15 | |
16 namespace ash { | 15 namespace ash { |
17 namespace test { | 16 namespace test { |
18 namespace { | 17 namespace { |
19 | 18 |
20 gfx::Display GetPrimaryDisplay() { | 19 gfx::Display GetPrimaryDisplay() { |
21 return gfx::Screen::GetDisplayNearestWindow( | 20 return gfx::Screen::GetDisplayNearestWindow( |
22 Shell::GetAllRootWindows()[0]); | 21 Shell::GetAllRootWindows()[0]); |
23 } | 22 } |
24 | 23 |
25 gfx::Display GetSecondaryDisplay() { | 24 gfx::Display GetSecondaryDisplay() { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 UpdateDisplay("600x600"); | 117 UpdateDisplay("600x600"); |
119 EXPECT_EQ("0,0 600x600", GetPrimaryDisplay().bounds().ToString()); | 118 EXPECT_EQ("0,0 600x600", GetPrimaryDisplay().bounds().ToString()); |
120 EXPECT_EQ(1, gfx::Screen::GetNumDisplays()); | 119 EXPECT_EQ(1, gfx::Screen::GetNumDisplays()); |
121 | 120 |
122 UpdateDisplay("700x700,1000x1000"); | 121 UpdateDisplay("700x700,1000x1000"); |
123 ASSERT_EQ(2, gfx::Screen::GetNumDisplays()); | 122 ASSERT_EQ(2, gfx::Screen::GetNumDisplays()); |
124 EXPECT_EQ("0,0 700x700", GetPrimaryDisplay().bounds().ToString()); | 123 EXPECT_EQ("0,0 700x700", GetPrimaryDisplay().bounds().ToString()); |
125 EXPECT_EQ("0,700 1000x1000", GetSecondaryDisplay().bounds().ToString()); | 124 EXPECT_EQ("0,700 1000x1000", GetSecondaryDisplay().bounds().ToString()); |
126 } | 125 } |
127 | 126 |
| 127 TEST_F(DisplayControllerTest, WarpMouse) { |
| 128 UpdateDisplay("500x500,500x500"); |
| 129 |
| 130 ash::internal::DisplayController* controller = |
| 131 Shell::GetInstance()->display_controller(); |
| 132 EXPECT_EQ(internal::DisplayController::RIGHT, |
| 133 controller->secondary_display_layout()); |
| 134 |
| 135 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 136 bool is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0], |
| 137 gfx::Point(11, 11)); |
| 138 EXPECT_FALSE(is_warped); |
| 139 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1], |
| 140 gfx::Point(11, 11)); |
| 141 EXPECT_FALSE(is_warped); |
| 142 |
| 143 // Touch the right edge of the primary root window. Pointer should warp. |
| 144 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0], |
| 145 gfx::Point(499, 11)); |
| 146 EXPECT_TRUE(is_warped); |
| 147 EXPECT_EQ("501,11", // by 2px. |
| 148 aura::Env::GetInstance()->last_mouse_location().ToString()); |
| 149 |
| 150 // Touch the left edge of the secondary root window. Pointer should warp. |
| 151 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1], |
| 152 gfx::Point(0, 11)); |
| 153 EXPECT_TRUE(is_warped); |
| 154 EXPECT_EQ("498,11", // by 2px. |
| 155 aura::Env::GetInstance()->last_mouse_location().ToString()); |
| 156 |
| 157 // Touch the left edge of the primary root window. |
| 158 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0], |
| 159 gfx::Point(0, 11)); |
| 160 EXPECT_FALSE(is_warped); |
| 161 // Touch the top edge of the primary root window. |
| 162 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0], |
| 163 gfx::Point(11, 0)); |
| 164 EXPECT_FALSE(is_warped); |
| 165 // Touch the bottom edge of the primary root window. |
| 166 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0], |
| 167 gfx::Point(11, 499)); |
| 168 EXPECT_FALSE(is_warped); |
| 169 // Touch the right edge of the secondary root window. |
| 170 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1], |
| 171 gfx::Point(499, 11)); |
| 172 EXPECT_FALSE(is_warped); |
| 173 // Touch the top edge of the secondary root window. |
| 174 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1], |
| 175 gfx::Point(11, 0)); |
| 176 EXPECT_FALSE(is_warped); |
| 177 // Touch the bottom edge of the secondary root window. |
| 178 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1], |
| 179 gfx::Point(11, 499)); |
| 180 EXPECT_FALSE(is_warped); |
| 181 } |
| 182 |
| 183 TEST_F(DisplayControllerTest, SetUnsetDontWarpMousedFlag) { |
| 184 UpdateDisplay("500x500,500x500"); |
| 185 |
| 186 ash::internal::DisplayController* controller = |
| 187 Shell::GetInstance()->display_controller(); |
| 188 |
| 189 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 190 aura::Env::GetInstance()->SetLastMouseLocation(*root_windows[0], |
| 191 gfx::Point(1, 1)); |
| 192 |
| 193 controller->set_dont_warp_mouse(true); |
| 194 bool is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0], |
| 195 gfx::Point(499, 11)); |
| 196 EXPECT_FALSE(is_warped); |
| 197 EXPECT_EQ("1,1", |
| 198 aura::Env::GetInstance()->last_mouse_location().ToString()); |
| 199 |
| 200 controller->set_dont_warp_mouse(false); |
| 201 is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0], |
| 202 gfx::Point(499, 11)); |
| 203 EXPECT_TRUE(is_warped); |
| 204 EXPECT_EQ("501,11", |
| 205 aura::Env::GetInstance()->last_mouse_location().ToString()); |
| 206 } |
| 207 |
128 } // namespace test | 208 } // namespace test |
129 } // namespace ash | 209 } // namespace ash |
OLD | NEW |