forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault_window_resizer_unittest.cc
229 lines (186 loc) · 8.97 KB
/
default_window_resizer_unittest.cc
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
227
228
229
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/wm/default_window_resizer.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "base/test/metrics/histogram_tester.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h"
#include "ui/base/hit_test.h"
#include "ui/base/ui_base_types.h"
#include "ui/compositor/test/test_utils.h"
namespace ash {
class DefaultWindowResizerTest : public AshTestBase {
public:
DefaultWindowResizerTest() = default;
DefaultWindowResizerTest(const DefaultWindowResizerTest&) = delete;
DefaultWindowResizerTest& operator=(const DefaultWindowResizerTest&) = delete;
~DefaultWindowResizerTest() override = default;
void SetUp() override {
AshTestBase::SetUp();
UpdateDisplay("1200x1000");
delegate_.set_minimum_size(gfx::Size(10, 10));
delegate_.set_maximum_size(gfx::Size(500, 500));
aspect_ratio_window_ = std::make_unique<aura::Window>(
&delegate_, aura::client::WINDOW_TYPE_NORMAL);
aspect_ratio_window_->Init(ui::LAYER_NOT_DRAWN);
ParentWindowInPrimaryRootWindow(aspect_ratio_window_.get());
}
void TearDown() override {
aspect_ratio_window_.reset();
AshTestBase::TearDown();
}
protected:
static WindowResizer* CreateDefaultWindowResizer(
aura::Window* window,
const gfx::PointF& point_in_parent,
int window_component) {
return CreateWindowResizer(window, point_in_parent, window_component,
::wm::WINDOW_MOVE_SOURCE_MOUSE)
.release();
}
aura::test::TestWindowDelegate delegate_;
std::unique_ptr<aura::Window> aspect_ratio_window_;
base::HistogramTester histograms_;
};
// Tests window resizing with a square aspect ratio.
TEST_F(DefaultWindowResizerTest, WindowResizeWithAspectRatioSquare) {
aspect_ratio_window_->SetProperty(aura::client::kAspectRatio,
new gfx::SizeF(1.0, 1.0));
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
ASSERT_EQ(1U, root_windows.size());
EXPECT_EQ(root_windows[0], aspect_ratio_window_->GetRootWindow());
aspect_ratio_window_->SetBoundsInScreen(
gfx::Rect(200, 200, 200, 200),
display::Screen::GetScreen()->GetDisplayNearestWindow(root_windows[0]));
EXPECT_EQ("200,200 200x200", aspect_ratio_window_->bounds().ToString());
std::unique_ptr<WindowResizer> resizer(CreateDefaultWindowResizer(
aspect_ratio_window_.get(), gfx::PointF(), HTTOPLEFT));
ASSERT_TRUE(resizer.get());
// Move the mouse near the top left edge.
resizer->Drag(gfx::PointF(50, 50), 0);
resizer->CompleteDrag();
EXPECT_EQ(root_windows[0], aspect_ratio_window_->GetRootWindow());
EXPECT_EQ("250,250 150x150", aspect_ratio_window_->bounds().ToString());
}
// Tests window resizing with a horizontal orientation aspect ratio.
TEST_F(DefaultWindowResizerTest, WindowResizeWithAspectRatioHorizontal) {
aspect_ratio_window_->SetProperty(aura::client::kAspectRatio,
new gfx::SizeF(2.0, 1.0));
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
ASSERT_EQ(1U, root_windows.size());
EXPECT_EQ(root_windows[0], aspect_ratio_window_->GetRootWindow());
aspect_ratio_window_->SetBoundsInScreen(
gfx::Rect(200, 200, 400, 200),
display::Screen::GetScreen()->GetDisplayNearestWindow(root_windows[0]));
EXPECT_EQ("200,200 400x200", aspect_ratio_window_->bounds().ToString());
std::unique_ptr<WindowResizer> resizer(CreateDefaultWindowResizer(
aspect_ratio_window_.get(), gfx::PointF(), HTBOTTOMRIGHT));
ASSERT_TRUE(resizer.get());
// Move the mouse near the top left edge.
resizer->Drag(gfx::PointF(50, 50), 0);
resizer->CompleteDrag();
EXPECT_EQ(root_windows[0], aspect_ratio_window_->GetRootWindow());
EXPECT_EQ("200,200 500x250", aspect_ratio_window_->bounds().ToString());
}
// Tests window resizing with a vertical orientation aspect ratio.
TEST_F(DefaultWindowResizerTest, WindowResizeWithAspectRatioVertical) {
aspect_ratio_window_->SetProperty(aura::client::kAspectRatio,
new gfx::SizeF(1.0, 2.0));
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
ASSERT_EQ(1U, root_windows.size());
EXPECT_EQ(root_windows[0], aspect_ratio_window_->GetRootWindow());
aspect_ratio_window_->SetBoundsInScreen(
gfx::Rect(200, 200, 200, 400),
display::Screen::GetScreen()->GetDisplayNearestWindow(root_windows[0]));
EXPECT_EQ("200,200 200x400", aspect_ratio_window_->bounds().ToString());
std::unique_ptr<WindowResizer> resizer(CreateDefaultWindowResizer(
aspect_ratio_window_.get(), gfx::PointF(), HTBOTTOM));
ASSERT_TRUE(resizer.get());
// Move the mouse near the top left edge.
resizer->Drag(gfx::PointF(50, 50), 0);
resizer->CompleteDrag();
EXPECT_EQ(root_windows[0], aspect_ratio_window_->GetRootWindow());
EXPECT_EQ("200,200 225x450", aspect_ratio_window_->bounds().ToString());
}
// Tests window dragging with a vertical orientation aspect ratio.
TEST_F(DefaultWindowResizerTest, WindowDragWithAspectRatioVertical) {
aspect_ratio_window_->SetProperty(aura::client::kAspectRatio,
new gfx::SizeF(1.0, 2.0));
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
ASSERT_EQ(1U, root_windows.size());
EXPECT_EQ(root_windows[0], aspect_ratio_window_->GetRootWindow());
aspect_ratio_window_->SetBoundsInScreen(
gfx::Rect(200, 200, 200, 400),
display::Screen::GetScreen()->GetDisplayNearestWindow(root_windows[0]));
EXPECT_EQ("200,200 200x400", aspect_ratio_window_->bounds().ToString());
std::unique_ptr<WindowResizer> resizer(CreateDefaultWindowResizer(
aspect_ratio_window_.get(), gfx::PointF(), HTCAPTION));
ASSERT_TRUE(resizer.get());
// Move the mouse near the top left edge.
resizer->Drag(gfx::PointF(50, 50), 0);
resizer->CompleteDrag();
EXPECT_EQ(root_windows[0], aspect_ratio_window_->GetRootWindow());
EXPECT_EQ("250,250 200x400", aspect_ratio_window_->bounds().ToString());
}
// Tests window dragging with a fixed aspect ratio, but without maximum limit.
// This is a regression test for b/322282313.
TEST_F(DefaultWindowResizerTest, WindowResizeWithAspectRationWithoutMaxLimit) {
// Remove the limit of the maximum size.
delegate_.set_maximum_size(gfx::Size(0, 0));
aspect_ratio_window_->SetProperty(aura::client::kAspectRatio,
new gfx::SizeF(1.0, 1.0));
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
ASSERT_EQ(1U, root_windows.size());
EXPECT_EQ(root_windows[0], aspect_ratio_window_->GetRootWindow());
aspect_ratio_window_->SetBoundsInScreen(
gfx::Rect(200, 200, 200, 200),
display::Screen::GetScreen()->GetDisplayNearestWindow(root_windows[0]));
EXPECT_EQ("200,200 200x200", aspect_ratio_window_->bounds().ToString());
std::unique_ptr<WindowResizer> resizer(CreateDefaultWindowResizer(
aspect_ratio_window_.get(), gfx::PointF(), HTTOPLEFT));
ASSERT_TRUE(resizer.get());
// Move the mouse near the top left edge.
resizer->Drag(gfx::PointF(50, 50), 0);
resizer->CompleteDrag();
EXPECT_EQ(root_windows[0], aspect_ratio_window_->GetRootWindow());
EXPECT_EQ("250,250 150x150", aspect_ratio_window_->bounds().ToString());
}
TEST_F(DefaultWindowResizerTest, NoResizeHistogramOnMove) {
std::unique_ptr<aura::Window> window = std::make_unique<aura::Window>(
&delegate_, aura::client::WINDOW_TYPE_NORMAL);
window->Init(ui::LAYER_NOT_DRAWN);
ParentWindowInPrimaryRootWindow(window.get());
window->SetBounds(gfx::Rect(0, 0, 50, 50));
std::unique_ptr<WindowResizer> resizer(
CreateDefaultWindowResizer(window.get(), gfx::PointF(), HTCAPTION));
ASSERT_TRUE(resizer.get());
// Move the window. A move should not generate a resize histogram.
resizer->Drag(gfx::PointF(50, 50), 0);
EXPECT_EQ(gfx::Point(50, 50), window->bounds().origin());
resizer->CompleteDrag();
EXPECT_TRUE(
ui::WaitForNextFrameToBePresented(window->GetHost()->compositor()));
histograms_.ExpectTotalCount("Ash.InteractiveWindowResize.TimeToPresent", 0);
}
TEST_F(DefaultWindowResizerTest, ResizeHistogram) {
std::unique_ptr<aura::Window> window = std::make_unique<aura::Window>(
&delegate_, aura::client::WINDOW_TYPE_NORMAL);
window->Init(ui::LAYER_NOT_DRAWN);
ParentWindowInPrimaryRootWindow(window.get());
window->SetBounds(gfx::Rect(0, 0, 50, 50));
std::unique_ptr<WindowResizer> resizer(
CreateDefaultWindowResizer(window.get(), gfx::PointF(), HTRIGHT));
ASSERT_TRUE(resizer.get());
// Resize the window, which should generate a resize histogram.
resizer->Drag(gfx::PointF(50, 50), 0);
EXPECT_NE(gfx::Size(50, 50), window->bounds().size());
resizer->CompleteDrag();
EXPECT_TRUE(
ui::WaitForNextFrameToBePresented(window->GetHost()->compositor()));
histograms_.ExpectTotalCount("Ash.InteractiveWindowResize.TimeToPresent", 1);
}
} // namespace ash