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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
// Copyright (c) 2011 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_container_layout_manager.h"
#include "ash/wm/workspace/workspace.h"
#include "ash/wm/workspace/workspace_manager.h"
#include "ash/wm/workspace_controller.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_vector.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/root_window.h"
#include "ui/aura/screen_aura.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/window.h"
#include "ui/base/ui_base_types.h"
#include "ui/views/widget/native_widget_aura.h"
namespace ash {
namespace test {
namespace {
using views::Widget;
using ash::internal::DefaultContainerLayoutManager;
class DefaultContainerLayoutManagerTest : public aura::test::AuraTestBase {
public:
DefaultContainerLayoutManagerTest() : layout_manager_(NULL) {}
virtual ~DefaultContainerLayoutManagerTest() {}
virtual void SetUp() OVERRIDE {
aura::test::AuraTestBase::SetUp();
aura::RootWindow* root_window = aura::RootWindow::GetInstance();
container_.reset(
CreateTestWindow(gfx::Rect(0, 0, 500, 400), root_window));
workspace_controller_.reset(
new ash::internal::WorkspaceController(container_.get()));
layout_manager_ = new DefaultContainerLayoutManager(
workspace_controller_->workspace_manager());
container_->SetLayoutManager(layout_manager_);
root_window->SetHostSize(gfx::Size(500, 400));
}
aura::Window* CreateTestWindowWithType(const gfx::Rect& bounds,
aura::Window* parent,
aura::client::WindowType type) {
aura::Window* window = new aura::Window(NULL);
window->SetType(type);
window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE);
window->SetBounds(bounds);
window->Show();
window->SetParent(parent);
return window;
}
aura::Window* CreateTestWindow(const gfx::Rect& bounds,
aura::Window* parent) {
return CreateTestWindowWithType(bounds,
parent,
aura::client::WINDOW_TYPE_NORMAL);
}
aura::Window* container() { return container_.get(); }
DefaultContainerLayoutManager* default_container_layout_manager() {
return layout_manager_;
}
protected:
ash::internal::WorkspaceManager* workspace_manager() {
return workspace_controller_->workspace_manager();
}
private:
scoped_ptr<aura::Window> container_;
scoped_ptr<ash::internal::WorkspaceController> workspace_controller_;
// LayoutManager is owned by |container|.
ash::internal::DefaultContainerLayoutManager* layout_manager_;
private:
DISALLOW_COPY_AND_ASSIGN(DefaultContainerLayoutManagerTest);
};
// Utility functions to set and get show state on |window|.
void Maximize(aura::Window* window) {
window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
}
void Fullscreen(aura::Window* window) {
window->SetIntProperty(aura::client::kShowStateKey,
ui::SHOW_STATE_FULLSCREEN);
}
void Restore(aura::Window* window) {
window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
}
ui::WindowShowState GetShowState(aura::Window* window) {
return static_cast<ui::WindowShowState>(
window->GetIntProperty(aura::client::kShowStateKey));
}
} // namespace
TEST_F(DefaultContainerLayoutManagerTest, SetBounds) {
// Layout Manager moves the window to (0,0) to fit to draggable area.
scoped_ptr<aura::Window> child(
CreateTestWindow(gfx::Rect(0, -1000, 100, 100), container()));
// Window is centered in workspace.
EXPECT_EQ("200,0 100x100", child->bounds().ToString());
// DCLM enforces the window height can't be taller than its owner's height.
child->SetBounds(gfx::Rect(0, 0, 100, 500));
EXPECT_EQ("200,0 100x400", child->bounds().ToString());
// DCLM enforces the window width can't be wider than its owner's width.
child->SetBounds(gfx::Rect(0, 0, 900, 500));
EXPECT_EQ("0,0 500x400", child->bounds().ToString());
// Y origin must always be the top of drag area.
child->SetBounds(gfx::Rect(0, 500, 900, 500));
EXPECT_EQ("0,0 500x400", child->bounds().ToString());
child->SetBounds(gfx::Rect(0, -500, 900, 500));
EXPECT_EQ("0,0 500x400", child->bounds().ToString());
}
TEST_F(DefaultContainerLayoutManagerTest, DragWindow) {
scoped_ptr<aura::Window> child(
CreateTestWindow(gfx::Rect(0, -1000, 50, 50), container()));
gfx::Rect original_bounds = child->bounds();
default_container_layout_manager()->PrepareForMoveOrResize(
child.get(), NULL);
// X origin must fit within viewport.
child->SetBounds(gfx::Rect(-100, 500, 50, 50));
EXPECT_EQ("0,0 50x50", child->GetTargetBounds().ToString());
child->SetBounds(gfx::Rect(1000, 500, 50, 50));
EXPECT_EQ("450,0 50x50", child->GetTargetBounds().ToString());
default_container_layout_manager()->EndMove(child.get(), NULL);
EXPECT_EQ(original_bounds.ToString(), child->GetTargetBounds().ToString());
}
TEST_F(DefaultContainerLayoutManagerTest, Popup) {
scoped_ptr<aura::Window> popup(
CreateTestWindowWithType(gfx::Rect(0, -1000, 100, 100),
container(),
aura::client::WINDOW_TYPE_POPUP));
// A popup window can be placed outside of draggable area.
EXPECT_EQ("0,-1000 100x100", popup->bounds().ToString());
// A popup window can be moved to outside of draggable area.
popup->SetBounds(gfx::Rect(-100, 0, 100, 100));
EXPECT_EQ("-100,0 100x100", popup->bounds().ToString());
// A popup window can be resized to the size bigger than draggable area.
popup->SetBounds(gfx::Rect(0, 0, 1000, 1000));
EXPECT_EQ("0,0 1000x1000", popup->bounds().ToString());
}
// Make sure a window with a transient parent isn't resized by the layout
// manager.
TEST_F(DefaultContainerLayoutManagerTest, IgnoreTransient) {
scoped_ptr<aura::Window> window(new aura::Window(NULL));
window->SetType(aura::client::WINDOW_TYPE_NORMAL);
window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE);
aura::RootWindow::GetInstance()->AddTransientChild(window.get());
window->SetBounds(gfx::Rect(0, 0, 200, 200));
window->Show();
window->SetParent(container());
EXPECT_EQ("0,0 200x200", window->bounds().ToString());
}
TEST_F(DefaultContainerLayoutManagerTest, Fullscreen) {
scoped_ptr<aura::Window> w(
CreateTestWindow(gfx::Rect(0, 0, 100, 100), container()));
gfx::Rect fullscreen_bounds =
workspace_manager()->FindBy(w.get())->bounds();
gfx::Rect original_bounds = w->GetTargetBounds();
// Restoreing the restored window.
Restore(w.get());
EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get()));
EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString());
// Fullscreen
Fullscreen(w.get());
EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetShowState(w.get()));
EXPECT_EQ(fullscreen_bounds.ToString(), w->bounds().ToString());
w->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get()));
EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString());
Fullscreen(w.get());
// Setting |ui::SHOW_STATE_FULLSCREEN| should have no additional effect.
Fullscreen(w.get());
EXPECT_EQ(fullscreen_bounds, w->bounds());
Restore(w.get());
EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get()));
EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString());
// Calling SetBounds() in fullscreen mode should only update the
// restore bounds not change the bounds of the window.
gfx::Rect new_bounds(50, 50, 50, 50);
Fullscreen(w.get());
w->SetBounds(new_bounds);
EXPECT_EQ(fullscreen_bounds.ToString(), w->bounds().ToString());
EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetShowState(w.get()));
Restore(w.get());
EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get()));
EXPECT_EQ(50, w->bounds().height());
}
TEST_F(DefaultContainerLayoutManagerTest, Maximized) {
scoped_ptr<aura::Window> w(
CreateTestWindow(gfx::Rect(0, 0, 100, 100), container()));
gfx::Rect original_bounds = w->GetTargetBounds();
gfx::Rect fullscreen_bounds =
workspace_manager()->FindBy(w.get())->bounds();
gfx::Rect work_area_bounds =
workspace_manager()->FindBy(w.get())->GetWorkAreaBounds();
// Maximized
Maximize(w.get());
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get()));
EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString());
Restore(w.get());
EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get()));
EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString());
// Maximize twice
Maximize(w.get());
Maximize(w.get());
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get()));
EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString());
Restore(w.get());
EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get()));
EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString());
// Maximized -> Fullscreen -> Maximized -> Normal
Maximize(w.get());
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get()));
EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString());
Fullscreen(w.get());
EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetShowState(w.get()));
EXPECT_EQ(fullscreen_bounds.ToString(), w->bounds().ToString());
Maximize(w.get());
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get()));
EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString());
Restore(w.get());
EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get()));
EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString());
// Calling SetBounds() in maximized mode mode should only update the
// restore bounds not change the bounds of the window.
gfx::Rect new_bounds(50, 50, 50, 50);
Maximize(w.get());
w->SetBounds(new_bounds);
EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString());
Restore(w.get());
EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get()));
EXPECT_EQ(50, w->bounds().height());
}
// Tests that fullscreen windows get resized after root window is resized.
TEST_F(DefaultContainerLayoutManagerTest, FullscreenAfterRootWindowResize) {
scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(300, 400),
container()));
gfx::Rect window_bounds = w1->GetTargetBounds();
gfx::Rect fullscreen_bounds =
workspace_manager()->FindBy(w1.get())->bounds();
w1->Show();
EXPECT_EQ(window_bounds.ToString(), w1->bounds().ToString());
Fullscreen(w1.get());
EXPECT_EQ(fullscreen_bounds.ToString(), w1->bounds().ToString());
// Resize the root window.
aura::RootWindow* root_window = aura::RootWindow::GetInstance();
gfx::Size new_root_window_size = root_window->GetHostSize();
new_root_window_size.Enlarge(100, 200);
root_window->OnHostResized(new_root_window_size);
gfx::Rect new_fullscreen_bounds =
workspace_manager()->FindBy(w1.get())->bounds();
EXPECT_NE(fullscreen_bounds.size().ToString(),
new_fullscreen_bounds.size().ToString());
EXPECT_EQ(new_fullscreen_bounds.ToString(),
w1->GetTargetBounds().ToString());
Restore(w1.get());
// The following test does not pass due to crbug.com/102413.
// TODO(oshima): Re-enable this once the bug is fixed.
// EXPECT_EQ(window_bounds.size().ToString(),
// w1->GetTargetBounds().size().ToString());
}
// Tests that maximized windows get resized after root_window is resized.
TEST_F(DefaultContainerLayoutManagerTest, MaximizeAfterRootWindowResize) {
scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(300, 400),
container()));
gfx::Rect window_bounds = w1->GetTargetBounds();
gfx::Rect work_area_bounds =
workspace_manager()->FindBy(w1.get())->GetWorkAreaBounds();
w1->Show();
EXPECT_EQ(window_bounds.ToString(), w1->bounds().ToString());
Maximize(w1.get());
EXPECT_EQ(work_area_bounds.ToString(), w1->bounds().ToString());
// Resize the root window.
aura::RootWindow* root_window = aura::RootWindow::GetInstance();
gfx::Size new_root_window_size = root_window->GetHostSize();
new_root_window_size.Enlarge(100, 200);
root_window->OnHostResized(new_root_window_size);
gfx::Rect new_work_area_bounds =
workspace_manager()->FindBy(w1.get())->bounds();
EXPECT_NE(work_area_bounds.size().ToString(),
new_work_area_bounds.size().ToString());
EXPECT_EQ(new_work_area_bounds.ToString(),
w1->GetTargetBounds().ToString());
Restore(w1.get());
// The following test does not pass due to crbug.com/102413.
// TODO(oshima): Re-enable this once the bug is fixed.
// EXPECT_EQ(window_bounds.size().ToString(),
// w1->GetTargetBounds().size().ToString());
}
} // namespace test
} // namespace ash
|