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_layout_store.h"
8 #include "ash/display/display_manager.h"
9 #include "ash/display/mouse_cursor_event_filter.h"
10 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h"
12 #include "ash/test/display_manager_test_api.h"
13 #include "ui/aura/env.h"
14 #include "ui/events/test/event_generator.h"
15 #include "ui/gfx/display.h"
16 #include "ui/gfx/screen.h"
20 class UnifiedMouseWarpControllerTest
: public test::AshTestBase
{
22 UnifiedMouseWarpControllerTest() {}
23 ~UnifiedMouseWarpControllerTest() override
{}
25 void SetUp() override
{
26 test::AshTestBase::SetUp();
27 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
28 test::DisplayManagerTestApi
test_api(display_manager
);
29 test_api
.SetDefaultMultiDisplayMode(DisplayManager::UNIFIED
);
30 display_manager
->SetMultiDisplayMode(DisplayManager::UNIFIED
);
34 bool TestIfMouseWarpsAt(const gfx::Point
& point_in_screen
) {
35 return test::DisplayManagerTestApi::TestIfMouseWarpsAt(GetEventGenerator(),
39 MouseCursorEventFilter
* event_filter() {
40 return Shell::GetInstance()->mouse_cursor_filter();
43 UnifiedMouseWarpController
* mouse_warp_controller() {
44 return static_cast<UnifiedMouseWarpController
*>(
45 event_filter()->mouse_warp_controller_for_test());
49 DISALLOW_COPY_AND_ASSIGN(UnifiedMouseWarpControllerTest
);
52 // Verifies if MouseCursorEventFilter's bounds calculation works correctly.
53 TEST_F(UnifiedMouseWarpControllerTest
, BoundaryTest
) {
54 if (!SupportsMultipleDisplays())
57 UpdateDisplay("400x400,0+450-700x500");
58 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
59 // Let the UnifiedMouseWarpController compute the bounds by
60 // generating a mouse move event.
61 GetEventGenerator().MoveMouseTo(gfx::Point(0, 0));
63 EXPECT_EQ("399,0 1x400",
64 mouse_warp_controller()->first_edge_bounds_in_native_
.ToString());
65 EXPECT_EQ("0,450 1x400",
66 mouse_warp_controller()->second_edge_bounds_in_native_
.ToString());
69 // Verifies if the mouse pointer correctly moves to another display in
70 // unified desktop mode.
71 TEST_F(UnifiedMouseWarpControllerTest
, WarpMouse
) {
72 if (!SupportsMultipleDisplays())
75 UpdateDisplay("500x500,500x500");
76 ASSERT_EQ(1, gfx::Screen::GetScreenFor(Shell::GetPrimaryRootWindow())
79 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 11)));
81 // Touch the right edge of the first display. Pointer should warp.
82 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(499, 11)));
83 EXPECT_EQ("501,11", // by 2px.
84 aura::Env::GetInstance()->last_mouse_location().ToString());
86 // Touch the left edge of the second display. Pointer should warp.
87 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(500, 11)));
88 EXPECT_EQ("498,11", // by 2px.
89 aura::Env::GetInstance()->last_mouse_location().ToString());
91 // Touch the left edge of the first display.
92 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(0, 11)));
93 // Touch the top edge of the first display.
94 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 0)));
95 // Touch the bottom edge of the first display.
96 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 499)));
97 // Touch the right edge of the second display.
98 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(999, 11)));
99 // Touch the top edge of the second display.
100 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 0)));
101 // Touch the bottom edge of the second display.
102 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 499)));