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
|
// 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/wm/workspace/workspace_event_handler.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/property_util.h"
#include "ash/wm/window_util.h"
#include "ash/wm/workspace_controller_test_helper.h"
#include "ash/wm/workspace/workspace_manager.h"
#include "ash/wm/workspace_controller.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h"
#include "ui/base/hit_test.h"
#include "ui/gfx/screen.h"
namespace ash {
namespace internal {
class WorkspaceEventHandlerTest : public test::AshTestBase {
public:
WorkspaceEventHandlerTest() {}
virtual ~WorkspaceEventHandlerTest() {}
protected:
aura::Window* CreateTestWindow(aura::WindowDelegate* delegate,
const gfx::Rect& bounds) {
aura::Window* window = new aura::Window(delegate);
window->SetType(aura::client::WINDOW_TYPE_NORMAL);
window->Init(ui::LAYER_TEXTURED);
window->SetParent(NULL);
window->SetBounds(bounds);
window->Show();
return window;
}
private:
DISALLOW_COPY_AND_ASSIGN(WorkspaceEventHandlerTest);
};
TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) {
// Double clicking the vertical resize edge of a window should maximize it
// vertically.
gfx::Rect restored_bounds(10, 10, 50, 50);
aura::test::TestWindowDelegate wd;
scoped_ptr<aura::Window> window(CreateTestWindow(&wd, restored_bounds));
wm::ActivateWindow(window.get());
gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
window.get()).work_area();
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
window.get());
// Double-click the top resize edge.
wd.set_window_component(HTTOP);
// On X a double click actually generates a drag between each press/release.
// Explicitly trigger this path since we had bugs in dealing with it
// correctly.
generator.PressLeftButton();
generator.ReleaseLeftButton();
generator.set_flags(ui::EF_IS_DOUBLE_CLICK);
generator.PressLeftButton();
generator.MoveMouseTo(generator.current_location(), 1);
generator.ReleaseLeftButton();
EXPECT_EQ(work_area.y(), window->bounds().y());
EXPECT_EQ(work_area.height(), window->bounds().height());
// Single-axis maximization is not considered real maximization.
EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
// Restore.
generator.DoubleClickLeftButton();
EXPECT_EQ(restored_bounds.y(), window->bounds().y());
EXPECT_EQ(restored_bounds.height(), window->bounds().height());
// Note that it should not even be restored at this point, it should have
// also cleared the restore rectangle.
EXPECT_EQ(NULL, GetRestoreBoundsInScreen(window.get()));
// Double-click the top resize edge again to maximize vertically, then double
// click again to restore.
generator.DoubleClickLeftButton();
wd.set_window_component(HTCAPTION);
generator.DoubleClickLeftButton();
EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
EXPECT_EQ(restored_bounds.y(), window->bounds().y());
EXPECT_EQ(restored_bounds.height(), window->bounds().height());
// Double clicking the left resize edge should maximize horizontally.
wd.set_window_component(HTLEFT);
generator.DoubleClickLeftButton();
EXPECT_EQ(work_area.x(), window->bounds().x());
EXPECT_EQ(work_area.width(), window->bounds().width());
// Single-axis maximization is not considered real maximization.
EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
}
TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) {
aura::test::TestWindowDelegate wd;
scoped_ptr<aura::Window> window(CreateTestWindow(&wd, gfx::Rect(1, 2, 3, 4)));
wd.set_window_component(HTCAPTION);
EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
window.get());
generator.DoubleClickLeftButton();
EXPECT_NE("1,2 3x4", window->bounds().ToString());
EXPECT_TRUE(wm::IsWindowMaximized(window.get()));
generator.DoubleClickLeftButton();
EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
EXPECT_EQ("1,2 3x4", window->bounds().ToString());
}
TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) {
aura::test::TestWindowDelegate wd;
gfx::Rect bounds(10, 20, 30, 40);
scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds));
wd.set_window_component(HTCAPTION);
EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
window.get());
generator.GestureTapAt(gfx::Point(25, 25));
generator.GestureTapAt(gfx::Point(25, 25));
RunAllPendingInMessageLoop();
EXPECT_NE(bounds.ToString(), window->bounds().ToString());
EXPECT_TRUE(wm::IsWindowMaximized(window.get()));
generator.GestureTapAt(gfx::Point(5, 5));
generator.GestureTapAt(gfx::Point(10, 10));
EXPECT_FALSE(wm::IsWindowMaximized(window.get()));
EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
}
// Verifies deleting the window while dragging doesn't crash.
TEST_F(WorkspaceEventHandlerTest, DeleteWhenDragging) {
// Create a large window in the background. This is necessary so that when we
// delete |window| WorkspaceEventHandler is still the active event handler.
aura::test::TestWindowDelegate wd2;
scoped_ptr<aura::Window> window2(
CreateTestWindow(&wd2, gfx::Rect(0, 0, 500, 500)));
aura::test::TestWindowDelegate wd;
const gfx::Rect bounds(10, 20, 30, 40);
scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds));
wd.set_window_component(HTCAPTION);
aura::test::EventGenerator generator(window->GetRootWindow());
generator.MoveMouseToCenterOf(window.get());
generator.PressLeftButton();
generator.MoveMouseTo(generator.current_location().Add(gfx::Point(50, 50)));
DCHECK_NE(bounds.origin().ToString(), window->bounds().origin().ToString());
window.reset();
generator.MoveMouseTo(generator.current_location().Add(gfx::Point(50, 50)));
}
// Verifies deleting the window while in a run loop doesn't crash.
TEST_F(WorkspaceEventHandlerTest, DeleteWhileInRunLoop) {
aura::test::TestWindowDelegate wd;
const gfx::Rect bounds(10, 20, 30, 40);
scoped_ptr<aura::Window> window(CreateTestWindow(&wd, bounds));
wd.set_window_component(HTCAPTION);
ASSERT_TRUE(aura::client::GetWindowMoveClient(window->parent()));
MessageLoop::current()->DeleteSoon(FROM_HERE, window.get());
aura::client::GetWindowMoveClient(window->parent())->RunMoveLoop(
window.release(), gfx::Point());
}
} // namespace internal
} // namespace ash
|