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
3 // found in the LICENSE file.
5 #include "ash/display/unified_mouse_warp_controller.h"
7 #include "ash/display/display_manager.h"
8 #include "ash/display/mouse_cursor_event_filter.h"
10 #include "ash/test/ash_test_base.h"
11 #include "ash/test/display_manager_test_api.h"
12 #include "ui/aura/env.h"
13 #include "ui/events/test/event_generator.h"
14 #include "ui/gfx/display.h"
15 #include "ui/gfx/screen.h"
19 class UnifiedMouseWarpControllerTest
: public test::AshTestBase
{
21 UnifiedMouseWarpControllerTest() {}
22 ~UnifiedMouseWarpControllerTest() override
{}
24 void SetUp() override
{
25 test::AshTestBase::SetUp();
26 Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled(true);
30 bool TestIfMouseWarpsAt(const gfx::Point
& point_in_screen
) {
31 return test::DisplayManagerTestApi::TestIfMouseWarpsAt(GetEventGenerator(),
35 MouseCursorEventFilter
* event_filter() {
36 return Shell::GetInstance()->mouse_cursor_filter();
39 UnifiedMouseWarpController
* mouse_warp_controller() {
40 return static_cast<UnifiedMouseWarpController
*>(
41 event_filter()->mouse_warp_controller_for_test());
44 void BoundaryTestBody(const std::string
& displays_with_same_height
,
45 const std::string
& displays_with_different_heights
) {
46 UpdateDisplay(displays_with_same_height
);
47 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
48 // Let the UnifiedMouseWarpController compute the bounds by
49 // generating a mouse move event.
50 GetEventGenerator().MoveMouseTo(gfx::Point(0, 0));
51 EXPECT_EQ("399,0 1x400",
52 mouse_warp_controller()->first_edge_bounds_in_native_
.ToString());
55 mouse_warp_controller()->second_edge_bounds_in_native_
.ToString());
58 UpdateDisplay(displays_with_different_heights
);
59 root_windows
= Shell::GetAllRootWindows();
60 // Let the UnifiedMouseWarpController compute the bounds by
61 // generating a mouse move event.
62 GetEventGenerator().MoveMouseTo(gfx::Point(1, 1));
64 EXPECT_EQ("399,0 1x400",
65 mouse_warp_controller()->first_edge_bounds_in_native_
.ToString());
68 mouse_warp_controller()->second_edge_bounds_in_native_
.ToString());
72 DISALLOW_COPY_AND_ASSIGN(UnifiedMouseWarpControllerTest
);
75 // Verifies if MouseCursorEventFilter's bounds calculation works correctly.
76 TEST_F(UnifiedMouseWarpControllerTest
, BoundaryTest
) {
77 if (!SupportsMultipleDisplays())
82 BoundaryTestBody("400x400,0+450-700x400", "400x400,0+450-700x600");
86 BoundaryTestBody("400x400*2,0+450-700x400", "400x400*2,0+450-700x600");
90 BoundaryTestBody("400x400,0+450-700x400*2", "400x400,0+450-700x600*2");
94 BoundaryTestBody("400x400*2,0+450-700x400*2", "400x400*2,0+450-700x600*2");
98 // Verifies if the mouse pointer correctly moves to another display in
99 // unified desktop mode.
100 TEST_F(UnifiedMouseWarpControllerTest
, WarpMouse
) {
101 if (!SupportsMultipleDisplays())
104 UpdateDisplay("500x500,500x500");
105 ASSERT_EQ(1, gfx::Screen::GetScreenFor(Shell::GetPrimaryRootWindow())
108 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 11)));
110 // Touch the right edge of the first display. Pointer should warp.
111 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(499, 11)));
112 EXPECT_EQ("501,11", // by 2px.
113 aura::Env::GetInstance()->last_mouse_location().ToString());
115 // Touch the left edge of the second display. Pointer should warp.
116 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(500, 11)));
117 EXPECT_EQ("498,11", // by 2px.
118 aura::Env::GetInstance()->last_mouse_location().ToString());
120 // Touch the left edge of the first display.
121 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(0, 11)));
122 // Touch the top edge of the first display.
123 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 0)));
124 // Touch the bottom edge of the first display.
125 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 499)));
126 // Touch the right edge of the second display.
127 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(999, 11)));
128 // Touch the top edge of the second display.
129 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 0)));
130 // Touch the bottom edge of the second display.
131 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 499)));