Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Side by Side Diff: ui/aura_shell/default_container_layout_manager_unittest.cc

Issue 8400063: Move maximize/fullscreen/restore to shell (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments, property_util Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura_shell/default_container_layout_manager.h" 5 #include "ui/aura_shell/default_container_layout_manager.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "ui/aura/test/aura_test_base.h" 10 #include "ui/aura/aura_constants.h"
11 #include "ui/aura/desktop.h" 11 #include "ui/aura/desktop.h"
12 #include "ui/aura/screen_aura.h" 12 #include "ui/aura/screen_aura.h"
13 #include "ui/aura/test/aura_test_base.h"
13 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
15 #include "ui/aura_shell/workspace/workspace.h"
14 #include "ui/aura_shell/workspace/workspace_controller.h" 16 #include "ui/aura_shell/workspace/workspace_controller.h"
17 #include "ui/aura_shell/workspace/workspace_manager.h"
18 #include "ui/base/ui_base_types.h"
15 #include "ui/base/view_prop.h" 19 #include "ui/base/view_prop.h"
16 #include "views/widget/native_widget_aura.h" 20 #include "views/widget/native_widget_aura.h"
17 21
18 namespace aura_shell { 22 namespace aura_shell {
19 namespace test { 23 namespace test {
20 24
21 namespace { 25 namespace {
22 26
23 using views::Widget; 27 using views::Widget;
24 using aura_shell::internal::DefaultContainerLayoutManager; 28 using aura_shell::internal::DefaultContainerLayoutManager;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 aura::WINDOW_TYPE_NORMAL); 62 aura::WINDOW_TYPE_NORMAL);
59 } 63 }
60 64
61 aura::Window* container() { return container_.get(); } 65 aura::Window* container() { return container_.get(); }
62 66
63 DefaultContainerLayoutManager* default_container_layout_manager() { 67 DefaultContainerLayoutManager* default_container_layout_manager() {
64 return workspace_controller_->layout_manager(); 68 return workspace_controller_->layout_manager();
65 } 69 }
66 70
67 protected: 71 protected:
72 aura_shell::internal::WorkspaceManager* workspace_manager() {
73 return workspace_controller_->layout_manager()->workspace_manager();
74 }
75
76 private:
68 scoped_ptr<aura::Window> container_; 77 scoped_ptr<aura::Window> container_;
69 scoped_ptr<aura_shell::internal::WorkspaceController> workspace_controller_; 78 scoped_ptr<aura_shell::internal::WorkspaceController> workspace_controller_;
70 79
71 private: 80 private:
72 DISALLOW_COPY_AND_ASSIGN(DefaultContainerLayoutManagerTest); 81 DISALLOW_COPY_AND_ASSIGN(DefaultContainerLayoutManagerTest);
73 }; 82 };
74 83
84 // Utility functions to set and get show state on |window|.
85 void Maximize(aura::Window* window) {
86 window->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
87 }
88
89 void Fullscreen(aura::Window* window) {
90 window->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
91 }
92
93 void Restore(aura::Window* window) {
94 window->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_NORMAL);
95 }
96
97 ui::WindowShowState GetShowState(aura::Window* window) {
98 return static_cast<ui::WindowShowState>(
99 window->GetIntProperty(aura::kShowStateKey));
100 }
101
75 } // namespace 102 } // namespace
76 103
77 #if !defined(OS_WIN) 104 #if !defined(OS_WIN)
78 TEST_F(DefaultContainerLayoutManagerTest, SetBounds) { 105 TEST_F(DefaultContainerLayoutManagerTest, SetBounds) {
79 // Layout Manager moves the window to (0,0) to fit to draggable area. 106 // Layout Manager moves the window to (0,0) to fit to draggable area.
80 scoped_ptr<aura::Window> child( 107 scoped_ptr<aura::Window> child(
81 CreateTestWindow(gfx::Rect(0, -1000, 100, 100), container())); 108 CreateTestWindow(gfx::Rect(0, -1000, 100, 100), container()));
82 // Window is centered in workspace. 109 // Window is centered in workspace.
83 EXPECT_EQ("200,0 100x100", child->bounds().ToString()); 110 EXPECT_EQ("200,0 100x100", child->bounds().ToString());
84 111
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 window->SetType(aura::WINDOW_TYPE_NORMAL); 167 window->SetType(aura::WINDOW_TYPE_NORMAL);
141 window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); 168 window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE);
142 aura::Desktop::GetInstance()->AddTransientChild(window.get()); 169 aura::Desktop::GetInstance()->AddTransientChild(window.get());
143 window->SetBounds(gfx::Rect(0, 0, 200, 200)); 170 window->SetBounds(gfx::Rect(0, 0, 200, 200));
144 window->Show(); 171 window->Show();
145 window->SetParent(container()); 172 window->SetParent(container());
146 173
147 EXPECT_EQ("0,0 200x200", window->bounds().ToString()); 174 EXPECT_EQ("0,0 200x200", window->bounds().ToString());
148 } 175 }
149 176
177 TEST_F(DefaultContainerLayoutManagerTest, Fullscreen) {
178 scoped_ptr<aura::Window> w(
179 CreateTestWindow(gfx::Rect(0, 0, 100, 100), container()));
180 gfx::Rect fullscreen_bounds =
181 workspace_manager()->FindBy(w.get())->bounds();
182 gfx::Rect original_bounds = w->GetTargetBounds();
183
184 // Restoreing the restored window.
185 Restore(w.get());
186 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get()));
187 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString());
188
189 // Fullscreen
190 Fullscreen(w.get());
191 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetShowState(w.get()));
192 EXPECT_EQ(fullscreen_bounds.ToString(), w->bounds().ToString());
193 w->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_NORMAL);
194 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get()));
195 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString());
196
197 Fullscreen(w.get());
198 // Setting |ui::SHOW_STATE_FULLSCREEN| should have no additional effect.
199 Fullscreen(w.get());
200 EXPECT_EQ(fullscreen_bounds, w->bounds());
201 Restore(w.get());
202 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get()));
203 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString());
204
205 // Calling SetBounds() in fullscreen mode should only update the
206 // restore bounds not change the bounds of the window.
207 gfx::Rect new_bounds(50, 50, 50, 50);
208 Fullscreen(w.get());
209 w->SetBounds(new_bounds);
210 EXPECT_EQ(fullscreen_bounds.ToString(), w->bounds().ToString());
211 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetShowState(w.get()));
212 Restore(w.get());
213 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get()));
214 EXPECT_EQ(50, w->bounds().height());
215 }
216
217 TEST_F(DefaultContainerLayoutManagerTest, Maximized) {
218 scoped_ptr<aura::Window> w(
219 CreateTestWindow(gfx::Rect(0, 0, 100, 100), container()));
220 gfx::Rect original_bounds = w->GetTargetBounds();
221 gfx::Rect fullscreen_bounds =
222 workspace_manager()->FindBy(w.get())->bounds();
223 gfx::Rect work_area_bounds =
224 workspace_manager()->FindBy(w.get())->GetWorkAreaBounds();
225
226 // Maximized
227 Maximize(w.get());
228 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get()));
229 EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString());
230 Restore(w.get());
231 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get()));
232 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString());
233
234 // Maximize twice
235 Maximize(w.get());
236 Maximize(w.get());
237 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get()));
238 EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString());
239 Restore(w.get());
240 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get()));
241 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString());
242
243 // Maximized -> Fullscreen -> Maximized -> Normal
244 Maximize(w.get());
245 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get()));
246 EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString());
247 Fullscreen(w.get());
248 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetShowState(w.get()));
249 EXPECT_EQ(fullscreen_bounds.ToString(), w->bounds().ToString());
250 Maximize(w.get());
251 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get()));
252 EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString());
253 Restore(w.get());
254 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get()));
255 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString());
256
257 // Calling SetBounds() in maximized mode mode should only update the
258 // restore bounds not change the bounds of the window.
259 gfx::Rect new_bounds(50, 50, 50, 50);
260 Maximize(w.get());
261 w->SetBounds(new_bounds);
262 EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString());
263 Restore(w.get());
264 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get()));
265 EXPECT_EQ(50, w->bounds().height());
266 }
267
268 // Tests that fullscreen windows get resized after desktop is resized.
269 TEST_F(DefaultContainerLayoutManagerTest, FullscreenAfterDesktopResize) {
270 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(300, 400),
271 container()));
272 gfx::Rect window_bounds = w1->GetTargetBounds();
273 gfx::Rect fullscreen_bounds =
274 workspace_manager()->FindBy(w1.get())->bounds();
275
276 w1->Show();
277 EXPECT_EQ(window_bounds.ToString(), w1->bounds().ToString());
278
279 Fullscreen(w1.get());
280 EXPECT_EQ(fullscreen_bounds.ToString(), w1->bounds().ToString());
281
282 // Resize the desktop.
283 aura::Desktop* desktop = aura::Desktop::GetInstance();
284 gfx::Size new_desktop_size = desktop->GetHostSize();
285 new_desktop_size.Enlarge(100, 200);
286 desktop->OnHostResized(new_desktop_size);
287
288 gfx::Rect new_fullscreen_bounds =
289 workspace_manager()->FindBy(w1.get())->bounds();
290 EXPECT_NE(fullscreen_bounds.size().ToString(),
291 new_fullscreen_bounds.size().ToString());
292
293 EXPECT_EQ(new_fullscreen_bounds.ToString(),
294 w1->GetTargetBounds().ToString());
295
296 Restore(w1.get());
297
298 // The following test does not pass due to crbug.com/102413.
299 // TODO(oshima): Re-enable this once the bug is fixed.
300 // EXPECT_EQ(window_bounds.size().ToString(),
301 // w1->GetTargetBounds().size().ToString());
302 }
303
304 // Tests that maximized windows get resized after desktop is resized.
305 TEST_F(DefaultContainerLayoutManagerTest, MaximizeAfterDesktopResize) {
306 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(300, 400),
307 container()));
308 gfx::Rect window_bounds = w1->GetTargetBounds();
309 gfx::Rect work_area_bounds =
310 workspace_manager()->FindBy(w1.get())->GetWorkAreaBounds();
311
312 w1->Show();
313 EXPECT_EQ(window_bounds.ToString(), w1->bounds().ToString());
314
315 Maximize(w1.get());
316 EXPECT_EQ(work_area_bounds.ToString(), w1->bounds().ToString());
317
318 // Resize the desktop.
319 aura::Desktop* desktop = aura::Desktop::GetInstance();
320 gfx::Size new_desktop_size = desktop->GetHostSize();
321 new_desktop_size.Enlarge(100, 200);
322 desktop->OnHostResized(new_desktop_size);
323
324 gfx::Rect new_work_area_bounds =
325 workspace_manager()->FindBy(w1.get())->bounds();
326 EXPECT_NE(work_area_bounds.size().ToString(),
327 new_work_area_bounds.size().ToString());
328
329 EXPECT_EQ(new_work_area_bounds.ToString(),
330 w1->GetTargetBounds().ToString());
331
332 Restore(w1.get());
333 // The following test does not pass due to crbug.com/102413.
334 // TODO(oshima): Re-enable this once the bug is fixed.
335 // EXPECT_EQ(window_bounds.size().ToString(),
336 // w1->GetTargetBounds().size().ToString());
337 }
338
150 } // namespace test 339 } // namespace test
151 } // namespace aura_shell 340 } // namespace aura_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698