| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/extended_mouse_warp_controller.h" | 5 #include "ash/display/extended_mouse_warp_controller.h" |
| 6 | 6 |
| 7 #include "ash/display/display_layout_store.h" | 7 #include "ash/display/display_layout_store.h" |
| 8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
| 9 #include "ash/display/mouse_cursor_event_filter.h" | 9 #include "ash/display/mouse_cursor_event_filter.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/test/display_manager_test_api.h" | 12 #include "ash/test/display_manager_test_api.h" |
| 13 #include "ui/display/display.h" |
| 13 #include "ui/display/manager/display_layout.h" | 14 #include "ui/display/manager/display_layout.h" |
| 14 #include "ui/display/manager/display_layout_builder.h" | 15 #include "ui/display/manager/display_layout_builder.h" |
| 16 #include "ui/display/screen.h" |
| 15 #include "ui/events/test/event_generator.h" | 17 #include "ui/events/test/event_generator.h" |
| 16 #include "ui/gfx/display.h" | |
| 17 #include "ui/gfx/screen.h" | |
| 18 | 18 |
| 19 namespace ash { | 19 namespace ash { |
| 20 | 20 |
| 21 class ExtendedMouseWarpControllerTest : public test::AshTestBase { | 21 class ExtendedMouseWarpControllerTest : public test::AshTestBase { |
| 22 public: | 22 public: |
| 23 ExtendedMouseWarpControllerTest() {} | 23 ExtendedMouseWarpControllerTest() {} |
| 24 ~ExtendedMouseWarpControllerTest() override {} | 24 ~ExtendedMouseWarpControllerTest() override {} |
| 25 | 25 |
| 26 protected: | 26 protected: |
| 27 MouseCursorEventFilter* event_filter() { | 27 MouseCursorEventFilter* event_filter() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 49 DISALLOW_COPY_AND_ASSIGN(ExtendedMouseWarpControllerTest); | 49 DISALLOW_COPY_AND_ASSIGN(ExtendedMouseWarpControllerTest); |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 // Verifies if MouseCursorEventFilter's bounds calculation works correctly. | 52 // Verifies if MouseCursorEventFilter's bounds calculation works correctly. |
| 53 TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestOnRight) { | 53 TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestOnRight) { |
| 54 if (!SupportsMultipleDisplays()) | 54 if (!SupportsMultipleDisplays()) |
| 55 return; | 55 return; |
| 56 | 56 |
| 57 UpdateDisplay("360x360,700x700"); | 57 UpdateDisplay("360x360,700x700"); |
| 58 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 58 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 59 int64_t display_0_id = | 59 int64_t display_0_id = display::Screen::GetScreen() |
| 60 gfx::Screen::GetScreen()->GetDisplayNearestWindow(root_windows[0]).id(); | 60 ->GetDisplayNearestWindow(root_windows[0]) |
| 61 int64_t display_1_id = | 61 .id(); |
| 62 gfx::Screen::GetScreen()->GetDisplayNearestWindow(root_windows[1]).id(); | 62 int64_t display_1_id = display::Screen::GetScreen() |
| 63 ->GetDisplayNearestWindow(root_windows[1]) |
| 64 .id(); |
| 63 | 65 |
| 64 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 66 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 65 std::unique_ptr<display::DisplayLayout> layout( | 67 std::unique_ptr<display::DisplayLayout> layout( |
| 66 test::CreateDisplayLayout(display::DisplayPlacement::RIGHT, 0)); | 68 test::CreateDisplayLayout(display::DisplayPlacement::RIGHT, 0)); |
| 67 | 69 |
| 68 display_manager->SetLayoutForCurrentDisplays(layout->Copy()); | 70 display_manager->SetLayoutForCurrentDisplays(layout->Copy()); |
| 69 event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */); | 71 event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */); |
| 70 | 72 |
| 71 ASSERT_EQ(1U, GetWarpRegionsCount()); | 73 ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 72 EXPECT_EQ(gfx::Rect(359, 16, 1, 344), GetIndicatorBounds(display_0_id)); | 74 EXPECT_EQ(gfx::Rect(359, 16, 1, 344), GetIndicatorBounds(display_0_id)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 event_filter()->HideSharedEdgeIndicator(); | 123 event_filter()->HideSharedEdgeIndicator(); |
| 122 } | 124 } |
| 123 | 125 |
| 124 TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestOnLeft) { | 126 TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestOnLeft) { |
| 125 if (!SupportsMultipleDisplays()) | 127 if (!SupportsMultipleDisplays()) |
| 126 return; | 128 return; |
| 127 | 129 |
| 128 UpdateDisplay("360x360,700x700"); | 130 UpdateDisplay("360x360,700x700"); |
| 129 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 131 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 130 | 132 |
| 131 int64_t display_0_id = | 133 int64_t display_0_id = display::Screen::GetScreen() |
| 132 gfx::Screen::GetScreen()->GetDisplayNearestWindow(root_windows[0]).id(); | 134 ->GetDisplayNearestWindow(root_windows[0]) |
| 133 int64_t display_1_id = | 135 .id(); |
| 134 gfx::Screen::GetScreen()->GetDisplayNearestWindow(root_windows[1]).id(); | 136 int64_t display_1_id = display::Screen::GetScreen() |
| 137 ->GetDisplayNearestWindow(root_windows[1]) |
| 138 .id(); |
| 135 | 139 |
| 136 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 140 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 137 std::unique_ptr<display::DisplayLayout> layout( | 141 std::unique_ptr<display::DisplayLayout> layout( |
| 138 test::CreateDisplayLayout(display::DisplayPlacement::LEFT, 0)); | 142 test::CreateDisplayLayout(display::DisplayPlacement::LEFT, 0)); |
| 139 display_manager->SetLayoutForCurrentDisplays(layout->Copy()); | 143 display_manager->SetLayoutForCurrentDisplays(layout->Copy()); |
| 140 | 144 |
| 141 event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */); | 145 event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */); |
| 142 ASSERT_EQ(1U, GetWarpRegionsCount()); | 146 ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 143 EXPECT_EQ(gfx::Rect(0, 16, 1, 344), GetIndicatorBounds(display_0_id)); | 147 EXPECT_EQ(gfx::Rect(0, 16, 1, 344), GetIndicatorBounds(display_0_id)); |
| 144 EXPECT_EQ(gfx::Rect(-1, 0, 1, 360), GetIndicatorBounds(display_1_id)); | 148 EXPECT_EQ(gfx::Rect(-1, 0, 1, 360), GetIndicatorBounds(display_1_id)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 162 | 166 |
| 163 event_filter()->HideSharedEdgeIndicator(); | 167 event_filter()->HideSharedEdgeIndicator(); |
| 164 } | 168 } |
| 165 | 169 |
| 166 TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestOnTopBottom) { | 170 TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestOnTopBottom) { |
| 167 if (!SupportsMultipleDisplays()) | 171 if (!SupportsMultipleDisplays()) |
| 168 return; | 172 return; |
| 169 | 173 |
| 170 UpdateDisplay("360x360,700x700"); | 174 UpdateDisplay("360x360,700x700"); |
| 171 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 175 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 172 int64_t display_0_id = | 176 int64_t display_0_id = display::Screen::GetScreen() |
| 173 gfx::Screen::GetScreen()->GetDisplayNearestWindow(root_windows[0]).id(); | 177 ->GetDisplayNearestWindow(root_windows[0]) |
| 174 int64_t display_1_id = | 178 .id(); |
| 175 gfx::Screen::GetScreen()->GetDisplayNearestWindow(root_windows[1]).id(); | 179 int64_t display_1_id = display::Screen::GetScreen() |
| 180 ->GetDisplayNearestWindow(root_windows[1]) |
| 181 .id(); |
| 176 | 182 |
| 177 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 183 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 178 std::unique_ptr<display::DisplayLayout> layout( | 184 std::unique_ptr<display::DisplayLayout> layout( |
| 179 test::CreateDisplayLayout(display::DisplayPlacement::TOP, 0)); | 185 test::CreateDisplayLayout(display::DisplayPlacement::TOP, 0)); |
| 180 display_manager->SetLayoutForCurrentDisplays(layout->Copy()); | 186 display_manager->SetLayoutForCurrentDisplays(layout->Copy()); |
| 181 event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */); | 187 event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */); |
| 182 ASSERT_EQ(1U, GetWarpRegionsCount()); | 188 ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 183 EXPECT_EQ(gfx::Rect(0, 0, 360, 1), GetIndicatorBounds(display_0_id)); | 189 EXPECT_EQ(gfx::Rect(0, 0, 360, 1), GetIndicatorBounds(display_0_id)); |
| 184 EXPECT_EQ(gfx::Rect(0, -1, 360, 1), GetIndicatorBounds(display_1_id)); | 190 EXPECT_EQ(gfx::Rect(0, -1, 360, 1), GetIndicatorBounds(display_1_id)); |
| 185 | 191 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 216 event_filter()->HideSharedEdgeIndicator(); | 222 event_filter()->HideSharedEdgeIndicator(); |
| 217 } | 223 } |
| 218 | 224 |
| 219 // Verify indicators show up as expected with 3+ displays. | 225 // Verify indicators show up as expected with 3+ displays. |
| 220 TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestThreeDisplays) { | 226 TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestThreeDisplays) { |
| 221 if (!SupportsMultipleDisplays()) | 227 if (!SupportsMultipleDisplays()) |
| 222 return; | 228 return; |
| 223 | 229 |
| 224 UpdateDisplay("360x360,700x700,1000x1000"); | 230 UpdateDisplay("360x360,700x700,1000x1000"); |
| 225 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 231 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 226 gfx::Screen* screen = gfx::Screen::GetScreen(); | 232 display::Screen* screen = display::Screen::GetScreen(); |
| 227 int64_t display_0_id = screen->GetDisplayNearestWindow(root_windows[0]).id(); | 233 int64_t display_0_id = screen->GetDisplayNearestWindow(root_windows[0]).id(); |
| 228 int64_t display_1_id = screen->GetDisplayNearestWindow(root_windows[1]).id(); | 234 int64_t display_1_id = screen->GetDisplayNearestWindow(root_windows[1]).id(); |
| 229 int64_t display_2_id = screen->GetDisplayNearestWindow(root_windows[2]).id(); | 235 int64_t display_2_id = screen->GetDisplayNearestWindow(root_windows[2]).id(); |
| 230 | 236 |
| 231 // Drag from left most display | 237 // Drag from left most display |
| 232 event_filter()->ShowSharedEdgeIndicator(root_windows[0]); | 238 event_filter()->ShowSharedEdgeIndicator(root_windows[0]); |
| 233 ASSERT_EQ(2U, GetWarpRegionsCount()); | 239 ASSERT_EQ(2U, GetWarpRegionsCount()); |
| 234 const ExtendedMouseWarpController::WarpRegion* region_0 = GetWarpRegion(0); | 240 const ExtendedMouseWarpController::WarpRegion* region_0 = GetWarpRegion(0); |
| 235 const ExtendedMouseWarpController::WarpRegion* region_1 = GetWarpRegion(1); | 241 const ExtendedMouseWarpController::WarpRegion* region_1 = GetWarpRegion(1); |
| 236 EXPECT_EQ(gfx::Rect(359, 16, 1, 344), | 242 EXPECT_EQ(gfx::Rect(359, 16, 1, 344), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 event_filter()->HideSharedEdgeIndicator(); | 278 event_filter()->HideSharedEdgeIndicator(); |
| 273 // TODO(oshima): Add test cases primary swap. | 279 // TODO(oshima): Add test cases primary swap. |
| 274 } | 280 } |
| 275 | 281 |
| 276 TEST_F(ExtendedMouseWarpControllerTest, | 282 TEST_F(ExtendedMouseWarpControllerTest, |
| 277 IndicatorBoundsTestThreeDisplaysWithLayout) { | 283 IndicatorBoundsTestThreeDisplaysWithLayout) { |
| 278 if (!SupportsMultipleDisplays()) | 284 if (!SupportsMultipleDisplays()) |
| 279 return; | 285 return; |
| 280 UpdateDisplay("700x500,500x500,1000x1000"); | 286 UpdateDisplay("700x500,500x500,1000x1000"); |
| 281 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 287 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 282 gfx::Screen* screen = gfx::Screen::GetScreen(); | 288 display::Screen* screen = display::Screen::GetScreen(); |
| 283 int64_t display_0_id = screen->GetDisplayNearestWindow(root_windows[0]).id(); | 289 int64_t display_0_id = screen->GetDisplayNearestWindow(root_windows[0]).id(); |
| 284 int64_t display_1_id = screen->GetDisplayNearestWindow(root_windows[1]).id(); | 290 int64_t display_1_id = screen->GetDisplayNearestWindow(root_windows[1]).id(); |
| 285 int64_t display_2_id = screen->GetDisplayNearestWindow(root_windows[2]).id(); | 291 int64_t display_2_id = screen->GetDisplayNearestWindow(root_windows[2]).id(); |
| 286 | 292 |
| 287 // Layout so that all displays touches togter like this: | 293 // Layout so that all displays touches togter like this: |
| 288 // +-----+---+ | 294 // +-----+---+ |
| 289 // | 0 | 1 | | 295 // | 0 | 1 | |
| 290 // +-+---+--++ | 296 // +-+---+--++ |
| 291 // | 2 | | 297 // | 2 | |
| 292 // +------+ | 298 // +------+ |
| (...skipping 30 matching lines...) Expand all Loading... |
| 323 region_2->GetIndicatorBoundsForTest(display_1_id)); | 329 region_2->GetIndicatorBoundsForTest(display_1_id)); |
| 324 event_filter()->HideSharedEdgeIndicator(); | 330 event_filter()->HideSharedEdgeIndicator(); |
| 325 } | 331 } |
| 326 | 332 |
| 327 TEST_F(ExtendedMouseWarpControllerTest, | 333 TEST_F(ExtendedMouseWarpControllerTest, |
| 328 IndicatorBoundsTestThreeDisplaysWithLayout2) { | 334 IndicatorBoundsTestThreeDisplaysWithLayout2) { |
| 329 if (!SupportsMultipleDisplays()) | 335 if (!SupportsMultipleDisplays()) |
| 330 return; | 336 return; |
| 331 UpdateDisplay("700x500,500x500,1000x1000"); | 337 UpdateDisplay("700x500,500x500,1000x1000"); |
| 332 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 338 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 333 gfx::Screen* screen = gfx::Screen::GetScreen(); | 339 display::Screen* screen = display::Screen::GetScreen(); |
| 334 int64_t display_0_id = screen->GetDisplayNearestWindow(root_windows[0]).id(); | 340 int64_t display_0_id = screen->GetDisplayNearestWindow(root_windows[0]).id(); |
| 335 int64_t display_1_id = screen->GetDisplayNearestWindow(root_windows[1]).id(); | 341 int64_t display_1_id = screen->GetDisplayNearestWindow(root_windows[1]).id(); |
| 336 int64_t display_2_id = screen->GetDisplayNearestWindow(root_windows[2]).id(); | 342 int64_t display_2_id = screen->GetDisplayNearestWindow(root_windows[2]).id(); |
| 337 | 343 |
| 338 // Layout so that 0 and 1 displays are disconnected. | 344 // Layout so that 0 and 1 displays are disconnected. |
| 339 // +-----+ +---+ | 345 // +-----+ +---+ |
| 340 // | 0 | |1 | | 346 // | 0 | |1 | |
| 341 // +-+---+-+++ | 347 // +-+---+-+++ |
| 342 // | 2 | | 348 // | 2 | |
| 343 // +------+ | 349 // +------+ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 363 region_0->GetIndicatorBoundsForTest(display_2_id)); | 369 region_0->GetIndicatorBoundsForTest(display_2_id)); |
| 364 // between 2 and 1 | 370 // between 2 and 1 |
| 365 EXPECT_EQ(gfx::Rect(900, 499, 200, 1), | 371 EXPECT_EQ(gfx::Rect(900, 499, 200, 1), |
| 366 region_1->GetIndicatorBoundsForTest(display_1_id)); | 372 region_1->GetIndicatorBoundsForTest(display_1_id)); |
| 367 EXPECT_EQ(gfx::Rect(900, 500, 200, 1), | 373 EXPECT_EQ(gfx::Rect(900, 500, 200, 1), |
| 368 region_1->GetIndicatorBoundsForTest(display_2_id)); | 374 region_1->GetIndicatorBoundsForTest(display_2_id)); |
| 369 event_filter()->HideSharedEdgeIndicator(); | 375 event_filter()->HideSharedEdgeIndicator(); |
| 370 } | 376 } |
| 371 | 377 |
| 372 } // namespace ash | 378 } // namespace ash |
| OLD | NEW |