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/mouse_cursor_event_filter.h"
9 #include "ash/test/ash_test_base.h"
10 #include "ash/test/display_manager_test_api.h"
11 #include "ui/aura/env.h"
12 #include "ui/events/test/event_generator.h"
13 #include "ui/gfx/display.h"
14 #include "ui/gfx/screen.h"
18 class UnifiedMouseWarpControllerTest
: public test::AshTestBase
{
20 UnifiedMouseWarpControllerTest() {}
21 ~UnifiedMouseWarpControllerTest() override
{}
23 void SetUp() override
{
24 test::AshTestBase::SetUp();
25 test::DisplayManagerTestApi::EnableUnifiedDesktopForTest();
29 bool TestIfMouseWarpsAt(const gfx::Point
& point_in_screen
) {
30 return test::DisplayManagerTestApi::TestIfMouseWarpsAt(GetEventGenerator(),
34 MouseCursorEventFilter
* event_filter() {
35 return Shell::GetInstance()->mouse_cursor_filter();
38 UnifiedMouseWarpController
* mouse_warp_controller() {
39 return static_cast<UnifiedMouseWarpController
*>(
40 event_filter()->mouse_warp_controller_for_test());
44 DISALLOW_COPY_AND_ASSIGN(UnifiedMouseWarpControllerTest
);
47 // Verifies if MouseCursorEventFilter's bounds calculation works correctly.
48 TEST_F(UnifiedMouseWarpControllerTest
, BoundaryTest
) {
49 if (!SupportsMultipleDisplays())
52 UpdateDisplay("400x400,0+450-700x400");
53 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
54 // Let the UnifiedMouseWarpController compute the bounds by
55 // generating a mouse move event.
56 GetEventGenerator().MoveMouseTo(gfx::Point(0, 0));
58 EXPECT_EQ("399,0 1x400",
59 mouse_warp_controller()->first_edge_bounds_in_native_
.ToString());
60 EXPECT_EQ("0,450 1x400",
61 mouse_warp_controller()->second_edge_bounds_in_native_
.ToString());
64 UpdateDisplay("400x400,0+450-700x600");
65 root_windows
= Shell::GetAllRootWindows();
66 // Let the UnifiedMouseWarpController compute the bounds by
67 // generating a mouse move event.
68 GetEventGenerator().MoveMouseTo(gfx::Point(1, 1));
70 EXPECT_EQ("399,0 1x400",
71 mouse_warp_controller()->first_edge_bounds_in_native_
.ToString());
72 EXPECT_EQ("0,450 1x600",
73 mouse_warp_controller()->second_edge_bounds_in_native_
.ToString());
75 // Shell::GetInstace()->display_manager()
78 // Verifies if the mouse pointer correctly moves to another display in
79 // unified desktop mode.
80 TEST_F(UnifiedMouseWarpControllerTest
, WarpMouse
) {
81 if (!SupportsMultipleDisplays())
84 UpdateDisplay("500x500,500x500");
85 ASSERT_EQ(1, gfx::Screen::GetScreenFor(Shell::GetPrimaryRootWindow())
88 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 11)));
90 // Touch the right edge of the first display. Pointer should warp.
91 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(499, 11)));
92 EXPECT_EQ("501,11", // by 2px.
93 aura::Env::GetInstance()->last_mouse_location().ToString());
95 // Touch the left edge of the second display. Pointer should warp.
96 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(500, 11)));
97 EXPECT_EQ("498,11", // by 2px.
98 aura::Env::GetInstance()->last_mouse_location().ToString());
100 // Touch the left edge of the first display.
101 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(0, 11)));
102 // Touch the top edge of the first display.
103 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 0)));
104 // Touch the bottom edge of the first display.
105 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 499)));
106 // Touch the right edge of the second display.
107 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(999, 11)));
108 // Touch the top edge of the second display.
109 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 0)));
110 // Touch the bottom edge of the second display.
111 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 499)));