| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/wm/base_layout_manager.h" | 5 #include "ash/wm/base_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/screen_ash.h" | 7 #include "ash/screen_ash.h" |
| 8 #include "ash/session_state_delegate.h" | 8 #include "ash/session_state_delegate.h" |
| 9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/shell_window_ids.h" | 11 #include "ash/shell_window_ids.h" |
| 12 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 13 #include "ash/wm/property_util.h" | 13 #include "ash/wm/window_state.h" |
| 14 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
| 15 #include "ash/wm/workspace/workspace_window_resizer.h" | 15 #include "ash/wm/workspace/workspace_window_resizer.h" |
| 16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 18 #include "ui/aura/client/aura_constants.h" | 18 #include "ui/aura/client/aura_constants.h" |
| 19 #include "ui/aura/root_window.h" | 19 #include "ui/aura/root_window.h" |
| 20 #include "ui/aura/test/test_windows.h" | 20 #include "ui/aura/test/test_windows.h" |
| 21 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 22 #include "ui/base/ui_base_types.h" | 22 #include "ui/base/ui_base_types.h" |
| 23 #include "ui/gfx/insets.h" | 23 #include "ui/gfx/insets.h" |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 gfx::Rect max_bounds = | 227 gfx::Rect max_bounds = |
| 228 ash::ScreenAsh::GetMaximizedWindowBoundsInParent(window.get()); | 228 ash::ScreenAsh::GetMaximizedWindowBoundsInParent(window.get()); |
| 229 max_bounds.Inset(grid_size, grid_size); | 229 max_bounds.Inset(grid_size, grid_size); |
| 230 EXPECT_EQ(max_bounds.ToString(), window->bounds().ToString()); | 230 EXPECT_EQ(max_bounds.ToString(), window->bounds().ToString()); |
| 231 } | 231 } |
| 232 | 232 |
| 233 // Verifies maximizing sets the restore bounds, and restoring | 233 // Verifies maximizing sets the restore bounds, and restoring |
| 234 // restores the bounds. | 234 // restores the bounds. |
| 235 TEST_F(BaseLayoutManagerTest, MaximizeSetsRestoreBounds) { | 235 TEST_F(BaseLayoutManagerTest, MaximizeSetsRestoreBounds) { |
| 236 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); | 236 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); |
| 237 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 237 | 238 |
| 238 // Maximize it, which will keep the previous restore bounds. | 239 // Maximize it, which will keep the previous restore bounds. |
| 239 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 240 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
| 240 EXPECT_EQ("1,2 3x4", GetRestoreBoundsInParent(window.get()).ToString()); | 241 EXPECT_EQ("1,2 3x4", window_state->GetRestoreBoundsInParent().ToString()); |
| 241 | 242 |
| 242 // Restore it, which should restore bounds and reset restore bounds. | 243 // Restore it, which should restore bounds and reset restore bounds. |
| 243 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 244 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 244 EXPECT_EQ("1,2 3x4", window->bounds().ToString()); | 245 EXPECT_EQ("1,2 3x4", window->bounds().ToString()); |
| 245 EXPECT_TRUE(GetRestoreBoundsInScreen(window.get()) == NULL); | 246 EXPECT_FALSE(window_state->HasRestoreBounds()); |
| 246 } | 247 } |
| 247 | 248 |
| 248 // Verifies maximizing keeps the restore bounds if set. | 249 // Verifies maximizing keeps the restore bounds if set. |
| 249 TEST_F(BaseLayoutManagerTest, MaximizeResetsRestoreBounds) { | 250 TEST_F(BaseLayoutManagerTest, MaximizeResetsRestoreBounds) { |
| 250 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); | 251 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); |
| 251 SetRestoreBoundsInParent(window.get(), gfx::Rect(10, 11, 12, 13)); | 252 |
| 253 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 254 window_state->SetRestoreBoundsInParent(gfx::Rect(10, 11, 12, 13)); |
| 252 | 255 |
| 253 // Maximize it, which will keep the previous restore bounds. | 256 // Maximize it, which will keep the previous restore bounds. |
| 254 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 257 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
| 255 EXPECT_EQ("10,11 12x13", GetRestoreBoundsInParent(window.get()).ToString()); | 258 EXPECT_EQ("10,11 12x13", window_state->GetRestoreBoundsInParent().ToString()); |
| 256 } | 259 } |
| 257 | 260 |
| 258 // Verifies that the restore bounds do not get reset when restoring to a | 261 // Verifies that the restore bounds do not get reset when restoring to a |
| 259 // maximzied state from a minimized state. | 262 // maximzied state from a minimized state. |
| 260 TEST_F(BaseLayoutManagerTest, BoundsAfterRestoringToMaximizeFromMinimize) { | 263 TEST_F(BaseLayoutManagerTest, BoundsAfterRestoringToMaximizeFromMinimize) { |
| 261 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); | 264 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); |
| 262 gfx::Rect bounds(10, 15, 25, 35); | 265 gfx::Rect bounds(10, 15, 25, 35); |
| 263 window->SetBounds(bounds); | 266 window->SetBounds(bounds); |
| 264 | 267 |
| 268 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 265 // Maximize it, which should reset restore bounds. | 269 // Maximize it, which should reset restore bounds. |
| 266 wm::MaximizeWindow(window.get()); | 270 window_state->Maximize(); |
| 267 EXPECT_EQ(bounds.ToString(), | 271 EXPECT_EQ(bounds.ToString(), |
| 268 GetRestoreBoundsInParent(window.get()).ToString()); | 272 window_state->GetRestoreBoundsInParent().ToString()); |
| 269 | 273 |
| 270 // Minimize the window. The restore bounds should not change. | 274 // Minimize the window. The restore bounds should not change. |
| 271 wm::MinimizeWindow(window.get()); | 275 window_state->Minimize(); |
| 272 EXPECT_EQ(bounds.ToString(), | 276 EXPECT_EQ(bounds.ToString(), |
| 273 GetRestoreBoundsInParent(window.get()).ToString()); | 277 window_state->GetRestoreBoundsInParent().ToString()); |
| 274 | 278 |
| 275 // Show the window again. The window should be maximized, and the restore | 279 // Show the window again. The window should be maximized, and the restore |
| 276 // bounds should not change. | 280 // bounds should not change. |
| 277 window->Show(); | 281 window->Show(); |
| 278 EXPECT_EQ(bounds.ToString(), | 282 EXPECT_EQ(bounds.ToString(), |
| 279 GetRestoreBoundsInParent(window.get()).ToString()); | 283 window_state->GetRestoreBoundsInParent().ToString()); |
| 280 EXPECT_TRUE(wm::IsWindowMaximized(window.get())); | 284 EXPECT_TRUE(window_state->IsMaximized()); |
| 281 | 285 |
| 282 wm::RestoreWindow(window.get()); | 286 window_state->Restore(); |
| 283 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); | 287 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); |
| 284 } | 288 } |
| 285 | 289 |
| 286 // Verify if the window is not resized during screen lock. See: crbug.com/173127 | 290 // Verify if the window is not resized during screen lock. See: crbug.com/173127 |
| 287 TEST_F(BaseLayoutManagerTest, NotResizeWhenScreenIsLocked) { | 291 TEST_F(BaseLayoutManagerTest, NotResizeWhenScreenIsLocked) { |
| 288 SetCanLockScreen(true); | 292 SetCanLockScreen(true); |
| 289 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); | 293 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); |
| 290 // window with AlwaysOnTop will be managed by BaseLayoutManager. | 294 // window with AlwaysOnTop will be managed by BaseLayoutManager. |
| 291 window->SetProperty(aura::client::kAlwaysOnTopKey, true); | 295 window->SetProperty(aura::client::kAlwaysOnTopKey, true); |
| 292 window->Show(); | 296 window->Show(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 307 ScreenAsh::GetMaximizedWindowBoundsInParent(window.get()).ToString(), | 311 ScreenAsh::GetMaximizedWindowBoundsInParent(window.get()).ToString(), |
| 308 window_bounds.ToString()); | 312 window_bounds.ToString()); |
| 309 | 313 |
| 310 Shell::GetInstance()->session_state_delegate()->UnlockScreen(); | 314 Shell::GetInstance()->session_state_delegate()->UnlockScreen(); |
| 311 shelf->UpdateVisibilityState(); | 315 shelf->UpdateVisibilityState(); |
| 312 EXPECT_EQ(window_bounds.ToString(), window->bounds().ToString()); | 316 EXPECT_EQ(window_bounds.ToString(), window->bounds().ToString()); |
| 313 } | 317 } |
| 314 | 318 |
| 315 } // namespace | 319 } // namespace |
| 316 } // namespace ash | 320 } // namespace ash |
| OLD | NEW |