| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/aura_shell/default_container_layout_manager.h" | |
| 6 | |
| 7 #include "base/basictypes.h" | |
| 8 #include "base/compiler_specific.h" | |
| 9 #include "base/memory/scoped_vector.h" | |
| 10 #include "ui/aura/client/aura_constants.h" | |
| 11 #include "ui/aura/root_window.h" | |
| 12 #include "ui/aura/screen_aura.h" | |
| 13 #include "ui/aura/test/aura_test_base.h" | |
| 14 #include "ui/aura/window.h" | |
| 15 #include "ui/aura_shell/workspace/workspace.h" | |
| 16 #include "ui/aura_shell/workspace/workspace_manager.h" | |
| 17 #include "ui/aura_shell/workspace_controller.h" | |
| 18 #include "ui/base/ui_base_types.h" | |
| 19 #include "ui/views/widget/native_widget_aura.h" | |
| 20 | |
| 21 namespace aura_shell { | |
| 22 namespace test { | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 using views::Widget; | |
| 27 using aura_shell::internal::DefaultContainerLayoutManager; | |
| 28 | |
| 29 class DefaultContainerLayoutManagerTest : public aura::test::AuraTestBase { | |
| 30 public: | |
| 31 DefaultContainerLayoutManagerTest() : layout_manager_(NULL) {} | |
| 32 virtual ~DefaultContainerLayoutManagerTest() {} | |
| 33 | |
| 34 virtual void SetUp() OVERRIDE { | |
| 35 aura::test::AuraTestBase::SetUp(); | |
| 36 aura::RootWindow* root_window = aura::RootWindow::GetInstance(); | |
| 37 container_.reset( | |
| 38 CreateTestWindow(gfx::Rect(0, 0, 500, 400), root_window)); | |
| 39 workspace_controller_.reset( | |
| 40 new aura_shell::internal::WorkspaceController(container_.get())); | |
| 41 layout_manager_ = new DefaultContainerLayoutManager( | |
| 42 workspace_controller_->workspace_manager()); | |
| 43 container_->SetLayoutManager(layout_manager_); | |
| 44 | |
| 45 root_window->SetHostSize(gfx::Size(500, 400)); | |
| 46 } | |
| 47 | |
| 48 aura::Window* CreateTestWindowWithType(const gfx::Rect& bounds, | |
| 49 aura::Window* parent, | |
| 50 aura::client::WindowType type) { | |
| 51 aura::Window* window = new aura::Window(NULL); | |
| 52 window->SetType(type); | |
| 53 window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); | |
| 54 window->SetBounds(bounds); | |
| 55 window->Show(); | |
| 56 window->SetParent(parent); | |
| 57 return window; | |
| 58 } | |
| 59 | |
| 60 aura::Window* CreateTestWindow(const gfx::Rect& bounds, | |
| 61 aura::Window* parent) { | |
| 62 return CreateTestWindowWithType(bounds, | |
| 63 parent, | |
| 64 aura::client::WINDOW_TYPE_NORMAL); | |
| 65 } | |
| 66 | |
| 67 aura::Window* container() { return container_.get(); } | |
| 68 | |
| 69 DefaultContainerLayoutManager* default_container_layout_manager() { | |
| 70 return layout_manager_; | |
| 71 } | |
| 72 | |
| 73 protected: | |
| 74 aura_shell::internal::WorkspaceManager* workspace_manager() { | |
| 75 return workspace_controller_->workspace_manager(); | |
| 76 } | |
| 77 | |
| 78 private: | |
| 79 scoped_ptr<aura::Window> container_; | |
| 80 scoped_ptr<aura_shell::internal::WorkspaceController> workspace_controller_; | |
| 81 // LayoutManager is owned by |container|. | |
| 82 aura_shell::internal::DefaultContainerLayoutManager* layout_manager_; | |
| 83 | |
| 84 private: | |
| 85 DISALLOW_COPY_AND_ASSIGN(DefaultContainerLayoutManagerTest); | |
| 86 }; | |
| 87 | |
| 88 // Utility functions to set and get show state on |window|. | |
| 89 void Maximize(aura::Window* window) { | |
| 90 window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | |
| 91 } | |
| 92 | |
| 93 void Fullscreen(aura::Window* window) { | |
| 94 window->SetIntProperty(aura::client::kShowStateKey, | |
| 95 ui::SHOW_STATE_FULLSCREEN); | |
| 96 } | |
| 97 | |
| 98 void Restore(aura::Window* window) { | |
| 99 window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
| 100 } | |
| 101 | |
| 102 ui::WindowShowState GetShowState(aura::Window* window) { | |
| 103 return static_cast<ui::WindowShowState>( | |
| 104 window->GetIntProperty(aura::client::kShowStateKey)); | |
| 105 } | |
| 106 | |
| 107 } // namespace | |
| 108 | |
| 109 TEST_F(DefaultContainerLayoutManagerTest, SetBounds) { | |
| 110 // Layout Manager moves the window to (0,0) to fit to draggable area. | |
| 111 scoped_ptr<aura::Window> child( | |
| 112 CreateTestWindow(gfx::Rect(0, -1000, 100, 100), container())); | |
| 113 // Window is centered in workspace. | |
| 114 EXPECT_EQ("200,0 100x100", child->bounds().ToString()); | |
| 115 | |
| 116 // DCLM enforces the window height can't be taller than its owner's height. | |
| 117 child->SetBounds(gfx::Rect(0, 0, 100, 500)); | |
| 118 EXPECT_EQ("200,0 100x400", child->bounds().ToString()); | |
| 119 | |
| 120 // DCLM enforces the window width can't be wider than its owner's width. | |
| 121 child->SetBounds(gfx::Rect(0, 0, 900, 500)); | |
| 122 EXPECT_EQ("0,0 500x400", child->bounds().ToString()); | |
| 123 | |
| 124 // Y origin must always be the top of drag area. | |
| 125 child->SetBounds(gfx::Rect(0, 500, 900, 500)); | |
| 126 EXPECT_EQ("0,0 500x400", child->bounds().ToString()); | |
| 127 child->SetBounds(gfx::Rect(0, -500, 900, 500)); | |
| 128 EXPECT_EQ("0,0 500x400", child->bounds().ToString()); | |
| 129 } | |
| 130 | |
| 131 TEST_F(DefaultContainerLayoutManagerTest, DragWindow) { | |
| 132 scoped_ptr<aura::Window> child( | |
| 133 CreateTestWindow(gfx::Rect(0, -1000, 50, 50), container())); | |
| 134 gfx::Rect original_bounds = child->bounds(); | |
| 135 | |
| 136 default_container_layout_manager()->PrepareForMoveOrResize( | |
| 137 child.get(), NULL); | |
| 138 // X origin must fit within viewport. | |
| 139 child->SetBounds(gfx::Rect(-100, 500, 50, 50)); | |
| 140 EXPECT_EQ("0,0 50x50", child->GetTargetBounds().ToString()); | |
| 141 child->SetBounds(gfx::Rect(1000, 500, 50, 50)); | |
| 142 EXPECT_EQ("450,0 50x50", child->GetTargetBounds().ToString()); | |
| 143 default_container_layout_manager()->EndMove(child.get(), NULL); | |
| 144 EXPECT_EQ(original_bounds.ToString(), child->GetTargetBounds().ToString()); | |
| 145 } | |
| 146 | |
| 147 TEST_F(DefaultContainerLayoutManagerTest, Popup) { | |
| 148 scoped_ptr<aura::Window> popup( | |
| 149 CreateTestWindowWithType(gfx::Rect(0, -1000, 100, 100), | |
| 150 container(), | |
| 151 aura::client::WINDOW_TYPE_POPUP)); | |
| 152 // A popup window can be placed outside of draggable area. | |
| 153 EXPECT_EQ("0,-1000 100x100", popup->bounds().ToString()); | |
| 154 | |
| 155 // A popup window can be moved to outside of draggable area. | |
| 156 popup->SetBounds(gfx::Rect(-100, 0, 100, 100)); | |
| 157 EXPECT_EQ("-100,0 100x100", popup->bounds().ToString()); | |
| 158 | |
| 159 // A popup window can be resized to the size bigger than draggable area. | |
| 160 popup->SetBounds(gfx::Rect(0, 0, 1000, 1000)); | |
| 161 EXPECT_EQ("0,0 1000x1000", popup->bounds().ToString()); | |
| 162 } | |
| 163 | |
| 164 // Make sure a window with a transient parent isn't resized by the layout | |
| 165 // manager. | |
| 166 TEST_F(DefaultContainerLayoutManagerTest, IgnoreTransient) { | |
| 167 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | |
| 168 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | |
| 169 window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); | |
| 170 aura::RootWindow::GetInstance()->AddTransientChild(window.get()); | |
| 171 window->SetBounds(gfx::Rect(0, 0, 200, 200)); | |
| 172 window->Show(); | |
| 173 window->SetParent(container()); | |
| 174 | |
| 175 EXPECT_EQ("0,0 200x200", window->bounds().ToString()); | |
| 176 } | |
| 177 | |
| 178 TEST_F(DefaultContainerLayoutManagerTest, Fullscreen) { | |
| 179 scoped_ptr<aura::Window> w( | |
| 180 CreateTestWindow(gfx::Rect(0, 0, 100, 100), container())); | |
| 181 gfx::Rect fullscreen_bounds = | |
| 182 workspace_manager()->FindBy(w.get())->bounds(); | |
| 183 gfx::Rect original_bounds = w->GetTargetBounds(); | |
| 184 | |
| 185 // Restoreing the restored window. | |
| 186 Restore(w.get()); | |
| 187 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | |
| 188 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); | |
| 189 | |
| 190 // Fullscreen | |
| 191 Fullscreen(w.get()); | |
| 192 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetShowState(w.get())); | |
| 193 EXPECT_EQ(fullscreen_bounds.ToString(), w->bounds().ToString()); | |
| 194 w->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
| 195 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | |
| 196 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); | |
| 197 | |
| 198 Fullscreen(w.get()); | |
| 199 // Setting |ui::SHOW_STATE_FULLSCREEN| should have no additional effect. | |
| 200 Fullscreen(w.get()); | |
| 201 EXPECT_EQ(fullscreen_bounds, w->bounds()); | |
| 202 Restore(w.get()); | |
| 203 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | |
| 204 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); | |
| 205 | |
| 206 // Calling SetBounds() in fullscreen mode should only update the | |
| 207 // restore bounds not change the bounds of the window. | |
| 208 gfx::Rect new_bounds(50, 50, 50, 50); | |
| 209 Fullscreen(w.get()); | |
| 210 w->SetBounds(new_bounds); | |
| 211 EXPECT_EQ(fullscreen_bounds.ToString(), w->bounds().ToString()); | |
| 212 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetShowState(w.get())); | |
| 213 Restore(w.get()); | |
| 214 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | |
| 215 EXPECT_EQ(50, w->bounds().height()); | |
| 216 } | |
| 217 | |
| 218 TEST_F(DefaultContainerLayoutManagerTest, Maximized) { | |
| 219 scoped_ptr<aura::Window> w( | |
| 220 CreateTestWindow(gfx::Rect(0, 0, 100, 100), container())); | |
| 221 gfx::Rect original_bounds = w->GetTargetBounds(); | |
| 222 gfx::Rect fullscreen_bounds = | |
| 223 workspace_manager()->FindBy(w.get())->bounds(); | |
| 224 gfx::Rect work_area_bounds = | |
| 225 workspace_manager()->FindBy(w.get())->GetWorkAreaBounds(); | |
| 226 | |
| 227 // Maximized | |
| 228 Maximize(w.get()); | |
| 229 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get())); | |
| 230 EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString()); | |
| 231 Restore(w.get()); | |
| 232 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | |
| 233 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); | |
| 234 | |
| 235 // Maximize twice | |
| 236 Maximize(w.get()); | |
| 237 Maximize(w.get()); | |
| 238 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get())); | |
| 239 EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString()); | |
| 240 Restore(w.get()); | |
| 241 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | |
| 242 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); | |
| 243 | |
| 244 // Maximized -> Fullscreen -> Maximized -> Normal | |
| 245 Maximize(w.get()); | |
| 246 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get())); | |
| 247 EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString()); | |
| 248 Fullscreen(w.get()); | |
| 249 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, GetShowState(w.get())); | |
| 250 EXPECT_EQ(fullscreen_bounds.ToString(), w->bounds().ToString()); | |
| 251 Maximize(w.get()); | |
| 252 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, GetShowState(w.get())); | |
| 253 EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString()); | |
| 254 Restore(w.get()); | |
| 255 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | |
| 256 EXPECT_EQ(original_bounds.ToString(), w->bounds().ToString()); | |
| 257 | |
| 258 // Calling SetBounds() in maximized mode mode should only update the | |
| 259 // restore bounds not change the bounds of the window. | |
| 260 gfx::Rect new_bounds(50, 50, 50, 50); | |
| 261 Maximize(w.get()); | |
| 262 w->SetBounds(new_bounds); | |
| 263 EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString()); | |
| 264 Restore(w.get()); | |
| 265 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | |
| 266 EXPECT_EQ(50, w->bounds().height()); | |
| 267 } | |
| 268 | |
| 269 // Tests that fullscreen windows get resized after root window is resized. | |
| 270 TEST_F(DefaultContainerLayoutManagerTest, FullscreenAfterRootWindowResize) { | |
| 271 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(300, 400), | |
| 272 container())); | |
| 273 gfx::Rect window_bounds = w1->GetTargetBounds(); | |
| 274 gfx::Rect fullscreen_bounds = | |
| 275 workspace_manager()->FindBy(w1.get())->bounds(); | |
| 276 | |
| 277 w1->Show(); | |
| 278 EXPECT_EQ(window_bounds.ToString(), w1->bounds().ToString()); | |
| 279 | |
| 280 Fullscreen(w1.get()); | |
| 281 EXPECT_EQ(fullscreen_bounds.ToString(), w1->bounds().ToString()); | |
| 282 | |
| 283 // Resize the root window. | |
| 284 aura::RootWindow* root_window = aura::RootWindow::GetInstance(); | |
| 285 gfx::Size new_root_window_size = root_window->GetHostSize(); | |
| 286 new_root_window_size.Enlarge(100, 200); | |
| 287 root_window->OnHostResized(new_root_window_size); | |
| 288 | |
| 289 gfx::Rect new_fullscreen_bounds = | |
| 290 workspace_manager()->FindBy(w1.get())->bounds(); | |
| 291 EXPECT_NE(fullscreen_bounds.size().ToString(), | |
| 292 new_fullscreen_bounds.size().ToString()); | |
| 293 | |
| 294 EXPECT_EQ(new_fullscreen_bounds.ToString(), | |
| 295 w1->GetTargetBounds().ToString()); | |
| 296 | |
| 297 Restore(w1.get()); | |
| 298 | |
| 299 // The following test does not pass due to crbug.com/102413. | |
| 300 // TODO(oshima): Re-enable this once the bug is fixed. | |
| 301 // EXPECT_EQ(window_bounds.size().ToString(), | |
| 302 // w1->GetTargetBounds().size().ToString()); | |
| 303 } | |
| 304 | |
| 305 // Tests that maximized windows get resized after root_window is resized. | |
| 306 TEST_F(DefaultContainerLayoutManagerTest, MaximizeAfterRootWindowResize) { | |
| 307 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(300, 400), | |
| 308 container())); | |
| 309 gfx::Rect window_bounds = w1->GetTargetBounds(); | |
| 310 gfx::Rect work_area_bounds = | |
| 311 workspace_manager()->FindBy(w1.get())->GetWorkAreaBounds(); | |
| 312 | |
| 313 w1->Show(); | |
| 314 EXPECT_EQ(window_bounds.ToString(), w1->bounds().ToString()); | |
| 315 | |
| 316 Maximize(w1.get()); | |
| 317 EXPECT_EQ(work_area_bounds.ToString(), w1->bounds().ToString()); | |
| 318 | |
| 319 // Resize the root window. | |
| 320 aura::RootWindow* root_window = aura::RootWindow::GetInstance(); | |
| 321 gfx::Size new_root_window_size = root_window->GetHostSize(); | |
| 322 new_root_window_size.Enlarge(100, 200); | |
| 323 root_window->OnHostResized(new_root_window_size); | |
| 324 | |
| 325 gfx::Rect new_work_area_bounds = | |
| 326 workspace_manager()->FindBy(w1.get())->bounds(); | |
| 327 EXPECT_NE(work_area_bounds.size().ToString(), | |
| 328 new_work_area_bounds.size().ToString()); | |
| 329 | |
| 330 EXPECT_EQ(new_work_area_bounds.ToString(), | |
| 331 w1->GetTargetBounds().ToString()); | |
| 332 | |
| 333 Restore(w1.get()); | |
| 334 // The following test does not pass due to crbug.com/102413. | |
| 335 // TODO(oshima): Re-enable this once the bug is fixed. | |
| 336 // EXPECT_EQ(window_bounds.size().ToString(), | |
| 337 // w1->GetTargetBounds().size().ToString()); | |
| 338 } | |
| 339 | |
| 340 } // namespace test | |
| 341 } // namespace aura_shell | |
| OLD | NEW |