forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault_window_resizer_unittest.cc
133 lines (106 loc) · 4.86 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
// Copyright 2018 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/wm/default_window_resizer.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/window_factory.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/base/hit_test.h"
#include "ui/base/ui_base_types.h"
namespace ash {
class DefaultWindowResizerTest : public AshTestBase {
public:
DefaultWindowResizerTest() = default;
~DefaultWindowResizerTest() override = default;
void SetUp() override {
AshTestBase::SetUp();
UpdateDisplay("1000x1000");
delegate_.set_minimum_size(gfx::Size(10, 10));
delegate_.set_maximum_size(gfx::Size(500, 500));
aspect_ratio_window_ =
window_factory::NewWindow(&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::Point& 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_;
private:
DISALLOW_COPY_AND_ASSIGN(DefaultWindowResizerTest);
};
// Tests window dragging 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::Point(), HTTOPLEFT));
ASSERT_TRUE(resizer.get());
// Move the mouse near the top left edge.
resizer->Drag(gfx::Point(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 dragging 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::Point(), HTBOTTOMRIGHT));
ASSERT_TRUE(resizer.get());
// Move the mouse near the top left edge.
resizer->Drag(gfx::Point(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 dragging 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::Point(), HTBOTTOM));
ASSERT_TRUE(resizer.get());
// Move the mouse near the top left edge.
resizer->Drag(gfx::Point(50, 50), 0);
resizer->CompleteDrag();
EXPECT_EQ(root_windows[0], aspect_ratio_window_->GetRootWindow());
EXPECT_EQ("200,200 225x450", aspect_ratio_window_->bounds().ToString());
}
} // namespace ash