Make app list recommendations ignore KnownResults.
[chromium-blink-merge.git] / ash / display / extended_mouse_warp_controller_unittest.cc
blobb3a0fe90a592ce0043c03652d557ddb85dcd0c60
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/extended_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 "ui/events/test/event_generator.h"
13 #include "ui/gfx/display.h"
14 #include "ui/gfx/screen.h"
16 namespace ash {
18 class ExtendedMouseWarpControllerTest : public test::AshTestBase {
19 public:
20 ExtendedMouseWarpControllerTest() {}
21 ~ExtendedMouseWarpControllerTest() override {}
23 protected:
24 MouseCursorEventFilter* event_filter() {
25 return Shell::GetInstance()->mouse_cursor_filter();
28 ExtendedMouseWarpController* mouse_warp_controller() {
29 return static_cast<ExtendedMouseWarpController*>(
30 event_filter()->mouse_warp_controller_for_test());
33 private:
34 DISALLOW_COPY_AND_ASSIGN(ExtendedMouseWarpControllerTest);
37 // Verifies if MouseCursorEventFilter's bounds calculation works correctly.
38 TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestOnRight) {
39 if (!SupportsMultipleDisplays())
40 return;
42 UpdateDisplay("360x360,700x700");
43 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
45 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
46 DisplayLayout layout(DisplayLayout::RIGHT, 0);
47 display_manager->SetLayoutForCurrentDisplays(layout);
48 event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);
49 EXPECT_EQ("359,16 1x344",
50 mouse_warp_controller()->src_indicator_bounds_.ToString());
51 EXPECT_EQ("360,0 1x360",
52 mouse_warp_controller()->dst_indicator_bounds_.ToString());
53 event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
54 EXPECT_EQ("360,16 1x344",
55 mouse_warp_controller()->src_indicator_bounds_.ToString());
56 EXPECT_EQ("359,0 1x360",
57 mouse_warp_controller()->dst_indicator_bounds_.ToString());
59 // Move 2nd display downwards a bit.
60 layout.offset = 5;
61 display_manager->SetLayoutForCurrentDisplays(layout);
62 event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);
63 // This is same as before because the 2nd display's y is above
64 // the indicator's x.
65 EXPECT_EQ("359,16 1x344",
66 mouse_warp_controller()->src_indicator_bounds_.ToString());
67 EXPECT_EQ("360,5 1x355",
68 mouse_warp_controller()->dst_indicator_bounds_.ToString());
69 event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
70 EXPECT_EQ("360,21 1x339",
71 mouse_warp_controller()->src_indicator_bounds_.ToString());
72 EXPECT_EQ("359,5 1x355",
73 mouse_warp_controller()->dst_indicator_bounds_.ToString());
75 // Move it down further so that the shared edge is shorter than
76 // minimum hole size (160).
77 layout.offset = 200;
78 display_manager->SetLayoutForCurrentDisplays(layout);
79 event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);
80 EXPECT_EQ("359,200 1x160",
81 mouse_warp_controller()->src_indicator_bounds_.ToString());
82 EXPECT_EQ("360,200 1x160",
83 mouse_warp_controller()->dst_indicator_bounds_.ToString());
84 event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
85 EXPECT_EQ("360,200 1x160",
86 mouse_warp_controller()->src_indicator_bounds_.ToString());
87 EXPECT_EQ("359,200 1x160",
88 mouse_warp_controller()->dst_indicator_bounds_.ToString());
90 // Now move 2nd display upwards
91 layout.offset = -5;
92 display_manager->SetLayoutForCurrentDisplays(layout);
93 event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);
94 EXPECT_EQ("359,16 1x344",
95 mouse_warp_controller()->src_indicator_bounds_.ToString());
96 EXPECT_EQ("360,0 1x360",
97 mouse_warp_controller()->dst_indicator_bounds_.ToString());
98 event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
99 // 16 px are reserved on 2nd display from top, so y must be
100 // (16 - 5) = 11
101 EXPECT_EQ("360,11 1x349",
102 mouse_warp_controller()->src_indicator_bounds_.ToString());
103 EXPECT_EQ("359,0 1x360",
104 mouse_warp_controller()->dst_indicator_bounds_.ToString());
106 event_filter()->HideSharedEdgeIndicator();
109 TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestOnLeft) {
110 if (!SupportsMultipleDisplays())
111 return;
113 UpdateDisplay("360x360,700x700");
114 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
116 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
117 DisplayLayout layout(DisplayLayout::LEFT, 0);
118 display_manager->SetLayoutForCurrentDisplays(layout);
119 event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);
120 EXPECT_EQ("0,16 1x344",
121 mouse_warp_controller()->src_indicator_bounds_.ToString());
122 EXPECT_EQ("-1,0 1x360",
123 mouse_warp_controller()->dst_indicator_bounds_.ToString());
124 event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
125 EXPECT_EQ("-1,16 1x344",
126 mouse_warp_controller()->src_indicator_bounds_.ToString());
127 EXPECT_EQ("0,0 1x360",
128 mouse_warp_controller()->dst_indicator_bounds_.ToString());
130 layout.offset = 250;
131 display_manager->SetLayoutForCurrentDisplays(layout);
132 event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);
133 EXPECT_EQ("0,250 1x110",
134 mouse_warp_controller()->src_indicator_bounds_.ToString());
135 EXPECT_EQ("-1,250 1x110",
136 mouse_warp_controller()->dst_indicator_bounds_.ToString());
137 event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
138 EXPECT_EQ("-1,250 1x110",
139 mouse_warp_controller()->src_indicator_bounds_.ToString());
140 EXPECT_EQ("0,250 1x110",
141 mouse_warp_controller()->dst_indicator_bounds_.ToString());
142 event_filter()->HideSharedEdgeIndicator();
145 TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestOnTopBottom) {
146 if (!SupportsMultipleDisplays())
147 return;
149 UpdateDisplay("360x360,700x700");
150 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
152 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
153 DisplayLayout layout(DisplayLayout::TOP, 0);
154 display_manager->SetLayoutForCurrentDisplays(layout);
155 event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);
156 EXPECT_EQ("0,0 360x1",
157 mouse_warp_controller()->src_indicator_bounds_.ToString());
158 EXPECT_EQ("0,-1 360x1",
159 mouse_warp_controller()->dst_indicator_bounds_.ToString());
160 event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
161 EXPECT_EQ("0,-1 360x1",
162 mouse_warp_controller()->src_indicator_bounds_.ToString());
163 EXPECT_EQ("0,0 360x1",
164 mouse_warp_controller()->dst_indicator_bounds_.ToString());
166 layout.offset = 250;
167 display_manager->SetLayoutForCurrentDisplays(layout);
168 event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);
169 EXPECT_EQ("250,0 110x1",
170 mouse_warp_controller()->src_indicator_bounds_.ToString());
171 EXPECT_EQ("250,-1 110x1",
172 mouse_warp_controller()->dst_indicator_bounds_.ToString());
173 event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
174 EXPECT_EQ("250,-1 110x1",
175 mouse_warp_controller()->src_indicator_bounds_.ToString());
176 EXPECT_EQ("250,0 110x1",
177 mouse_warp_controller()->dst_indicator_bounds_.ToString());
179 layout.position = DisplayLayout::BOTTOM;
180 layout.offset = 0;
181 display_manager->SetLayoutForCurrentDisplays(layout);
182 event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);
183 EXPECT_EQ("0,359 360x1",
184 mouse_warp_controller()->src_indicator_bounds_.ToString());
185 EXPECT_EQ("0,360 360x1",
186 mouse_warp_controller()->dst_indicator_bounds_.ToString());
187 event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
188 EXPECT_EQ("0,360 360x1",
189 mouse_warp_controller()->src_indicator_bounds_.ToString());
190 EXPECT_EQ("0,359 360x1",
191 mouse_warp_controller()->dst_indicator_bounds_.ToString());
193 event_filter()->HideSharedEdgeIndicator();
196 } // namespace ash