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-700x500");
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 // Verifies if the mouse pointer correctly moves to another display in
65 // unified desktop mode.
66 TEST_F(UnifiedMouseWarpControllerTest
, WarpMouse
) {
67 if (!SupportsMultipleDisplays())
70 UpdateDisplay("500x500,500x500");
71 ASSERT_EQ(1, gfx::Screen::GetScreenFor(Shell::GetPrimaryRootWindow())
74 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 11)));
76 // Touch the right edge of the first display. Pointer should warp.
77 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(499, 11)));
78 EXPECT_EQ("501,11", // by 2px.
79 aura::Env::GetInstance()->last_mouse_location().ToString());
81 // Touch the left edge of the second display. Pointer should warp.
82 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(500, 11)));
83 EXPECT_EQ("498,11", // by 2px.
84 aura::Env::GetInstance()->last_mouse_location().ToString());
86 // Touch the left edge of the first display.
87 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(0, 11)));
88 // Touch the top edge of the first display.
89 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 0)));
90 // Touch the bottom edge of the first display.
91 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 499)));
92 // Touch the right edge of the second display.
93 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(999, 11)));
94 // Touch the top edge of the second display.
95 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 0)));
96 // Touch the bottom edge of the second display.
97 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 499)));