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