Chromium Code Reviews| 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 "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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 parent, | 64 parent, |
| 61 Widget::InitParams::TYPE_WINDOW); | 65 Widget::InitParams::TYPE_WINDOW); |
| 62 } | 66 } |
| 63 | 67 |
| 64 aura::Window* container() { return container_.get(); } | 68 aura::Window* container() { return container_.get(); } |
| 65 | 69 |
| 66 DefaultContainerLayoutManager* default_container_layout_manager() { | 70 DefaultContainerLayoutManager* default_container_layout_manager() { |
| 67 return workspace_controller_->layout_manager(); | 71 return workspace_controller_->layout_manager(); |
| 68 } | 72 } |
| 69 | 73 |
| 74 aura_shell::internal::WorkspaceManager* workspace_manager() { | |
| 75 return workspace_controller_->layout_manager()->workspace_manager(); | |
|
oshima
2011/10/31 22:10:21
I'd like to change the ownership so that
DCLM owns
| |
| 76 } | |
| 77 | |
| 70 private: | 78 private: |
| 71 scoped_ptr<aura::Window> container_; | 79 scoped_ptr<aura::Window> container_; |
| 72 ScopedVector<ui::ViewProp> props_; | 80 ScopedVector<ui::ViewProp> props_; |
| 73 scoped_ptr<aura_shell::internal::WorkspaceController> workspace_controller_; | 81 scoped_ptr<aura_shell::internal::WorkspaceController> workspace_controller_; |
| 74 | 82 |
| 75 DISALLOW_COPY_AND_ASSIGN(DefaultContainerLayoutManagerTest); | 83 DISALLOW_COPY_AND_ASSIGN(DefaultContainerLayoutManagerTest); |
| 76 }; | 84 }; |
| 77 | 85 |
| 86 // Utility functions to set and get show state on |window|. | |
| 87 void Maximize(aura::Window* window) { | |
| 88 window->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | |
| 89 } | |
| 90 | |
| 91 void Fullscreen(aura::Window* window) { | |
| 92 window->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 93 } | |
| 94 | |
| 95 void Restore(aura::Window* window) { | |
| 96 window->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
| 97 } | |
| 98 | |
| 99 ui::WindowShowState GetShowState(aura::Window* window) { | |
| 100 return static_cast<ui::WindowShowState>( | |
| 101 window->GetIntProperty(aura::kShowStateKey)); | |
| 102 } | |
| 103 | |
| 78 } // namespace | 104 } // namespace |
| 79 | 105 |
| 80 #if !defined(OS_WIN) | 106 #if !defined(OS_WIN) |
| 81 TEST_F(DefaultContainerLayoutManagerTest, SetBounds) { | 107 TEST_F(DefaultContainerLayoutManagerTest, SetBounds) { |
| 82 // Layout Manager moves the window to (0,0) to fit to draggable area. | 108 // Layout Manager moves the window to (0,0) to fit to draggable area. |
| 83 scoped_ptr<aura::Window> child( | 109 scoped_ptr<aura::Window> child( |
| 84 CreateTestWindow(gfx::Rect(0, -1000, 100, 100), container())); | 110 CreateTestWindow(gfx::Rect(0, -1000, 100, 100), container())); |
| 85 // Window is centered in workspace. | 111 // Window is centered in workspace. |
| 86 EXPECT_EQ("200,0 100x100", child->bounds().ToString()); | 112 EXPECT_EQ("200,0 100x100", child->bounds().ToString()); |
| 87 | 113 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 | 155 |
| 130 // A popup window can be moved to outside of draggable area. | 156 // A popup window can be moved to outside of draggable area. |
| 131 popup->SetBounds(gfx::Rect(-100, 0, 100, 100)); | 157 popup->SetBounds(gfx::Rect(-100, 0, 100, 100)); |
| 132 EXPECT_EQ("-100,0 100x100", popup->bounds().ToString()); | 158 EXPECT_EQ("-100,0 100x100", popup->bounds().ToString()); |
| 133 | 159 |
| 134 // A popup window can be resized to the size bigger than draggable area. | 160 // A popup window can be resized to the size bigger than draggable area. |
| 135 popup->SetBounds(gfx::Rect(0, 0, 1000, 1000)); | 161 popup->SetBounds(gfx::Rect(0, 0, 1000, 1000)); |
| 136 EXPECT_EQ("0,0 1000x1000", popup->bounds().ToString()); | 162 EXPECT_EQ("0,0 1000x1000", popup->bounds().ToString()); |
| 137 } | 163 } |
| 138 | 164 |
| 165 TEST_F(DefaultContainerLayoutManagerTest, Fullscreen) { | |
| 166 scoped_ptr<aura::Window> w( | |
| 167 CreateTestWindow(gfx::Rect(0, 0, 100, 100), container())); | |
| 168 gfx::Rect fullscreen_bounds = | |
| 169 workspace_manager()->FindBy(w.get())->bounds(); | |
| 170 gfx::Rect original_bounds = w->GetTargetBounds(); | |
| 171 | |
| 172 // Restoreing the restored window. | |
| 173 Restore(w.get()); | |
| 174 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | |
| 175 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); | |
| 176 | |
| 177 // Fullscreen | |
| 178 Fullscreen(w.get()); | |
| 179 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetShowState(w.get())); | |
| 180 EXPECT_EQ(fullscreen_bounds.ToString(), w->bounds().ToString()); | |
| 181 w->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
| 182 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | |
| 183 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); | |
| 184 | |
| 185 Fullscreen(w.get()); | |
| 186 // Setting |ui::SHOW_STATE_FULLSCREEN| should have no additional effect. | |
| 187 Fullscreen(w.get()); | |
| 188 EXPECT_EQ(fullscreen_bounds, w->bounds()); | |
| 189 Restore(w.get()); | |
| 190 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | |
| 191 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); | |
| 192 | |
| 193 // Calling SetBounds() in fullscreen mode should only update the | |
| 194 // restore bounds not change the bounds of the window. | |
| 195 gfx::Rect new_bounds(50, 50, 50, 50); | |
| 196 Fullscreen(w.get()); | |
| 197 w->SetBounds(new_bounds); | |
| 198 EXPECT_EQ(fullscreen_bounds.ToString(), w->bounds().ToString()); | |
| 199 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetShowState(w.get())); | |
| 200 Restore(w.get()); | |
| 201 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | |
| 202 EXPECT_EQ(50, w->bounds().height()); | |
| 203 } | |
| 204 | |
| 205 TEST_F(DefaultContainerLayoutManagerTest, Maximized) { | |
| 206 scoped_ptr<aura::Window> w( | |
| 207 CreateTestWindow(gfx::Rect(0, 0, 100, 100), container())); | |
| 208 gfx::Rect original_bounds = w->GetTargetBounds(); | |
| 209 gfx::Rect fullscreen_bounds = | |
| 210 workspace_manager()->FindBy(w.get())->bounds(); | |
| 211 gfx::Rect work_area_bounds = | |
| 212 workspace_manager()->FindBy(w.get())->GetWorkAreaBounds(); | |
| 213 | |
| 214 // Maximized | |
| 215 Maximize(w.get()); | |
| 216 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get())); | |
| 217 EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString()); | |
| 218 Restore(w.get()); | |
| 219 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | |
| 220 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); | |
| 221 | |
| 222 // Maximize twice | |
| 223 Maximize(w.get()); | |
| 224 Maximize(w.get()); | |
| 225 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get())); | |
| 226 EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString()); | |
| 227 Restore(w.get()); | |
| 228 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | |
| 229 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); | |
| 230 | |
| 231 // Maximized -> Fullscreen -> Maximized -> Normal | |
| 232 Maximize(w.get()); | |
| 233 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get())); | |
| 234 EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString()); | |
| 235 Fullscreen(w.get()); | |
| 236 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetShowState(w.get())); | |
| 237 EXPECT_EQ(fullscreen_bounds.ToString(), w->bounds().ToString()); | |
| 238 Maximize(w.get()); | |
| 239 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get())); | |
| 240 EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString()); | |
| 241 Restore(w.get()); | |
| 242 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | |
| 243 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); | |
| 244 | |
| 245 // Calling SetBounds() in maximized mode mode should only update the | |
| 246 // restore bounds not change the bounds of the window. | |
| 247 gfx::Rect new_bounds(50, 50, 50, 50); | |
| 248 Maximize(w.get()); | |
| 249 w->SetBounds(new_bounds); | |
| 250 EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString()); | |
| 251 Restore(w.get()); | |
| 252 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | |
| 253 EXPECT_EQ(50, w->bounds().height()); | |
| 254 } | |
| 255 | |
| 256 // Tests that fullscreen windows get resized after desktop is resized. | |
| 257 TEST_F(DefaultContainerLayoutManagerTest, FullscreenAfterDesktopResize) { | |
| 258 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(300, 400), | |
| 259 container())); | |
| 260 gfx::Rect window_bounds = w1->GetTargetBounds(); | |
| 261 gfx::Rect fullscreen_bounds = | |
| 262 workspace_manager()->FindBy(w1.get())->bounds(); | |
| 263 | |
| 264 w1->Show(); | |
| 265 EXPECT_EQ(window_bounds.ToString(), w1->bounds().ToString()); | |
| 266 | |
| 267 Fullscreen(w1.get()); | |
| 268 EXPECT_EQ(fullscreen_bounds.ToString(), w1->bounds().ToString()); | |
| 269 | |
| 270 // Resize the desktop. | |
| 271 aura::Desktop* desktop = aura::Desktop::GetInstance(); | |
| 272 gfx::Size new_desktop_size = desktop->GetHostSize(); | |
| 273 new_desktop_size.Enlarge(100, 200); | |
| 274 desktop->OnHostResized(new_desktop_size); | |
| 275 | |
| 276 gfx::Rect new_fullscreen_bounds = | |
| 277 workspace_manager()->FindBy(w1.get())->bounds(); | |
| 278 EXPECT_NE(fullscreen_bounds.size().ToString(), | |
| 279 new_fullscreen_bounds.size().ToString()); | |
| 280 | |
| 281 EXPECT_EQ(new_fullscreen_bounds.ToString(), | |
| 282 w1->GetTargetBounds().ToString()); | |
| 283 | |
| 284 Restore(w1.get()); | |
| 285 | |
| 286 // The following test does not pass due to crbug.com/102413. | |
| 287 // TODO(oshima): Re-enable this once the bug is fixed. | |
| 288 // EXPECT_EQ(window_bounds.size().ToString(), | |
| 289 // w1->GetTargetBounds().size().ToString()); | |
| 290 } | |
| 291 | |
| 292 // Tests that maximized windows get resized after desktop is resized. | |
| 293 TEST_F(DefaultContainerLayoutManagerTest, MaximizeAfterDesktopResize) { | |
| 294 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(300, 400), | |
| 295 container())); | |
| 296 gfx::Rect window_bounds = w1->GetTargetBounds(); | |
| 297 gfx::Rect work_area_bounds = | |
| 298 workspace_manager()->FindBy(w1.get())->GetWorkAreaBounds(); | |
| 299 | |
| 300 w1->Show(); | |
| 301 EXPECT_EQ(window_bounds.ToString(), w1->bounds().ToString()); | |
| 302 | |
| 303 Maximize(w1.get()); | |
| 304 EXPECT_EQ(work_area_bounds.ToString(), w1->bounds().ToString()); | |
| 305 | |
| 306 // Resize the desktop. | |
| 307 aura::Desktop* desktop = aura::Desktop::GetInstance(); | |
| 308 gfx::Size new_desktop_size = desktop->GetHostSize(); | |
| 309 new_desktop_size.Enlarge(100, 200); | |
| 310 desktop->OnHostResized(new_desktop_size); | |
| 311 | |
| 312 gfx::Rect new_work_area_bounds = | |
| 313 workspace_manager()->FindBy(w1.get())->bounds(); | |
| 314 EXPECT_NE(work_area_bounds.size().ToString(), | |
| 315 new_work_area_bounds.size().ToString()); | |
| 316 | |
| 317 EXPECT_EQ(new_work_area_bounds.ToString(), | |
| 318 w1->GetTargetBounds().ToString()); | |
| 319 | |
| 320 Restore(w1.get()); | |
| 321 // The following test does not pass due to crbug.com/102413. | |
| 322 // TODO(oshima): Re-enable this once the bug is fixed. | |
| 323 // EXPECT_EQ(window_bounds.size().ToString(), | |
| 324 // w1->GetTargetBounds().size().ToString()); | |
| 325 } | |
| 326 | |
| 139 } // namespace test | 327 } // namespace test |
| 140 } // namespace aura_shell | 328 } // namespace aura_shell |
| OLD | NEW |