1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/display/display_controller.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ui/aura/display_manager.h"
#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
namespace ash {
namespace test {
namespace {
gfx::Display GetPrimaryDisplay() {
return gfx::Screen::GetDisplayNearestWindow(
Shell::GetAllRootWindows()[0]);
}
gfx::Display GetSecondaryDisplay() {
return gfx::Screen::GetDisplayNearestWindow(
Shell::GetAllRootWindows()[1]);
}
} // namespace
typedef test::AshTestBase DisplayControllerTest;
#if defined(OS_WIN)
// TOD(oshima): Windows creates a window with smaller client area.
// Fix this and enable tests.
#define MAYBE_SecondaryDisplayLayout DISABLED_SecondaryDisplayLayout
#define MAYBE_BoundsUpdated DISABLED_BoundsUpdated
#else
#define MAYBE_SecondaryDisplayLayout SecondaryDisplayLayout
#define MAYBE_BoundsUpdated BoundsUpdated
#endif
TEST_F(DisplayControllerTest, MAYBE_SecondaryDisplayLayout) {
UpdateDisplay("500x500,400x400");
gfx::Display* secondary_display =
aura::Env::GetInstance()->display_manager()->GetDisplayAt(1);
gfx::Insets insets(5, 5, 5, 5);
secondary_display->UpdateWorkAreaFromInsets(insets);
// Default layout is LEFT.
EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString());
EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString());
// Layout the secondary display to the bottom of the primary.
Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout(
internal::DisplayController::BOTTOM);
EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString());
EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString());
// Layout the secondary display to the left of the primary.
Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout(
internal::DisplayController::LEFT);
EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
EXPECT_EQ("-400,0 400x400", GetSecondaryDisplay().bounds().ToString());
EXPECT_EQ("-395,5 390x390", GetSecondaryDisplay().work_area().ToString());
// Layout the secondary display to the top of the primary.
Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout(
internal::DisplayController::TOP);
EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
EXPECT_EQ("0,-400 400x400", GetSecondaryDisplay().bounds().ToString());
EXPECT_EQ("5,-395 390x390", GetSecondaryDisplay().work_area().ToString());
}
TEST_F(DisplayControllerTest, MAYBE_BoundsUpdated) {
Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout(
internal::DisplayController::BOTTOM);
UpdateDisplay("500x500,400x400");
gfx::Display* secondary_display =
aura::Env::GetInstance()->display_manager()->GetDisplayAt(1);
gfx::Insets insets(5, 5, 5, 5);
secondary_display->UpdateWorkAreaFromInsets(insets);
EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString());
EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString());
UpdateDisplay("600x600,400x400");
EXPECT_EQ("0,0 600x600", GetPrimaryDisplay().bounds().ToString());
EXPECT_EQ("0,600 400x400", GetSecondaryDisplay().bounds().ToString());
EXPECT_EQ("5,605 390x390", GetSecondaryDisplay().work_area().ToString());
UpdateDisplay("600x600,500x500");
EXPECT_EQ("0,0 600x600", GetPrimaryDisplay().bounds().ToString());
EXPECT_EQ("0,600 500x500", GetSecondaryDisplay().bounds().ToString());
EXPECT_EQ("5,605 490x490", GetSecondaryDisplay().work_area().ToString());
UpdateDisplay("600x600");
EXPECT_EQ("0,0 600x600", GetPrimaryDisplay().bounds().ToString());
EXPECT_EQ(1, gfx::Screen::GetNumDisplays());
UpdateDisplay("700x700,1000x1000");
ASSERT_EQ(2, gfx::Screen::GetNumDisplays());
EXPECT_EQ("0,0 700x700", GetPrimaryDisplay().bounds().ToString());
EXPECT_EQ("0,700 1000x1000", GetSecondaryDisplay().bounds().ToString());
}
// Verifies if the mouse pointer correctly moves to another display when there
// are two displays.
TEST_F(DisplayControllerTest, WarpMouse) {
UpdateDisplay("500x500,500x500");
ash::internal::DisplayController* controller =
Shell::GetInstance()->display_controller();
EXPECT_EQ(internal::DisplayController::RIGHT,
controller->secondary_display_layout());
Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
bool is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0],
gfx::Point(11, 11));
EXPECT_FALSE(is_warped);
is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1],
gfx::Point(11, 11));
EXPECT_FALSE(is_warped);
// Touch the right edge of the primary root window. Pointer should warp.
is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0],
gfx::Point(499, 11));
EXPECT_TRUE(is_warped);
EXPECT_EQ("501,11", // by 2px.
aura::Env::GetInstance()->last_mouse_location().ToString());
// Touch the left edge of the secondary root window. Pointer should warp.
is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1],
gfx::Point(0, 11));
EXPECT_TRUE(is_warped);
EXPECT_EQ("498,11", // by 2px.
aura::Env::GetInstance()->last_mouse_location().ToString());
// Touch the left edge of the primary root window.
is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0],
gfx::Point(0, 11));
EXPECT_FALSE(is_warped);
// Touch the top edge of the primary root window.
is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0],
gfx::Point(11, 0));
EXPECT_FALSE(is_warped);
// Touch the bottom edge of the primary root window.
is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0],
gfx::Point(11, 499));
EXPECT_FALSE(is_warped);
// Touch the right edge of the secondary root window.
is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1],
gfx::Point(499, 11));
EXPECT_FALSE(is_warped);
// Touch the top edge of the secondary root window.
is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1],
gfx::Point(11, 0));
EXPECT_FALSE(is_warped);
// Touch the bottom edge of the secondary root window.
is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1],
gfx::Point(11, 499));
EXPECT_FALSE(is_warped);
}
// Verifies if the mouse pointer correctly moves to another display even when
// two displays are not the same size.
TEST_F(DisplayControllerTest, WarpMouseDifferentSizeDisplays) {
UpdateDisplay("500x500,600x600"); // the second one is larger.
ash::internal::DisplayController* controller =
Shell::GetInstance()->display_controller();
EXPECT_EQ(internal::DisplayController::RIGHT,
controller->secondary_display_layout());
Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
aura::Env::GetInstance()->SetLastMouseLocation(*root_windows[1],
gfx::Point(123, 123));
// Touch the left edge of the secondary root window. Pointer should NOT warp
// because 1px left of (0, 500) is outside the primary root window.
bool is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1],
gfx::Point(0, 500));
EXPECT_FALSE(is_warped);
EXPECT_EQ("623,123", // by 2px.
aura::Env::GetInstance()->last_mouse_location().ToString());
// Touch the left edge of the secondary root window. Pointer should warp
// because 1px left of (0, 499) is inside the primary root window.
is_warped = controller->WarpMouseCursorIfNecessary(root_windows[1],
gfx::Point(0, 499));
EXPECT_TRUE(is_warped);
EXPECT_EQ("498,499", // by 2px.
aura::Env::GetInstance()->last_mouse_location().ToString());
}
// Verifies if DisplayController::dont_warp_mouse() works as expected.
TEST_F(DisplayControllerTest, SetUnsetDontWarpMousedFlag) {
UpdateDisplay("500x500,500x500");
ash::internal::DisplayController* controller =
Shell::GetInstance()->display_controller();
Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
aura::Env::GetInstance()->SetLastMouseLocation(*root_windows[0],
gfx::Point(1, 1));
controller->set_dont_warp_mouse(true);
bool is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0],
gfx::Point(499, 11));
EXPECT_FALSE(is_warped);
EXPECT_EQ("1,1",
aura::Env::GetInstance()->last_mouse_location().ToString());
controller->set_dont_warp_mouse(false);
is_warped = controller->WarpMouseCursorIfNecessary(root_windows[0],
gfx::Point(499, 11));
EXPECT_TRUE(is_warped);
EXPECT_EQ("501,11",
aura::Env::GetInstance()->last_mouse_location().ToString());
}
} // namespace test
} // namespace ash
|