| 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 gfx::Rect max_bounds = | 220 gfx::Rect max_bounds = |
| 221 ash::ScreenAsh::GetMaximizedWindowBoundsInParent(window.get()); | 221 ash::ScreenAsh::GetMaximizedWindowBoundsInParent(window.get()); |
| 222 max_bounds.Inset(grid_size, grid_size); | 222 max_bounds.Inset(grid_size, grid_size); |
| 223 EXPECT_EQ(max_bounds.ToString(), window->bounds().ToString()); | 223 EXPECT_EQ(max_bounds.ToString(), window->bounds().ToString()); |
| 224 } | 224 } |
| 225 | 225 |
| 226 // Verifies maximizing sets the restore bounds, and restoring | 226 // Verifies maximizing sets the restore bounds, and restoring |
| 227 // restores the bounds. | 227 // restores the bounds. |
| 228 TEST_F(BaseLayoutManagerTest, MaximizeSetsRestoreBounds) { | 228 TEST_F(BaseLayoutManagerTest, MaximizeSetsRestoreBounds) { |
| 229 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); | 229 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); |
| 230 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 230 | 231 |
| 231 // Maximize it, which will keep the previous restore bounds. | 232 // Maximize it, which will keep the previous restore bounds. |
| 232 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 233 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
| 233 EXPECT_EQ("1,2 3x4", GetRestoreBoundsInParent(window.get()).ToString()); | 234 EXPECT_EQ("1,2 3x4", window_state->GetRestoreBoundsInParent().ToString()); |
| 234 | 235 |
| 235 // Restore it, which should restore bounds and reset restore bounds. | 236 // Restore it, which should restore bounds and reset restore bounds. |
| 236 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 237 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 237 EXPECT_EQ("1,2 3x4", window->bounds().ToString()); | 238 EXPECT_EQ("1,2 3x4", window->bounds().ToString()); |
| 238 EXPECT_TRUE(GetRestoreBoundsInScreen(window.get()) == NULL); | 239 EXPECT_FALSE(window_state->HasRestoreBounds()); |
| 239 } | 240 } |
| 240 | 241 |
| 241 // Verifies maximizing keeps the restore bounds if set. | 242 // Verifies maximizing keeps the restore bounds if set. |
| 242 TEST_F(BaseLayoutManagerTest, MaximizeResetsRestoreBounds) { | 243 TEST_F(BaseLayoutManagerTest, MaximizeResetsRestoreBounds) { |
| 243 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); | 244 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); |
| 244 SetRestoreBoundsInParent(window.get(), gfx::Rect(10, 11, 12, 13)); | 245 |
| 246 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 247 window_state->SetRestoreBoundsInParent(gfx::Rect(10, 11, 12, 13)); |
| 245 | 248 |
| 246 // Maximize it, which will keep the previous restore bounds. | 249 // Maximize it, which will keep the previous restore bounds. |
| 247 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 250 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
| 248 EXPECT_EQ("10,11 12x13", GetRestoreBoundsInParent(window.get()).ToString()); | 251 EXPECT_EQ("10,11 12x13", window_state->GetRestoreBoundsInParent().ToString()); |
| 249 } | 252 } |
| 250 | 253 |
| 251 // Verifies that the restore bounds do not get reset when restoring to a | 254 // Verifies that the restore bounds do not get reset when restoring to a |
| 252 // maximzied state from a minimized state. | 255 // maximzied state from a minimized state. |
| 253 TEST_F(BaseLayoutManagerTest, BoundsAfterRestoringToMaximizeFromMinimize) { | 256 TEST_F(BaseLayoutManagerTest, BoundsAfterRestoringToMaximizeFromMinimize) { |
| 254 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); | 257 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); |
| 255 gfx::Rect bounds(10, 15, 25, 35); | 258 gfx::Rect bounds(10, 15, 25, 35); |
| 256 window->SetBounds(bounds); | 259 window->SetBounds(bounds); |
| 257 | 260 |
| 261 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 258 // Maximize it, which should reset restore bounds. | 262 // Maximize it, which should reset restore bounds. |
| 259 wm::MaximizeWindow(window.get()); | 263 window_state->Maximize(); |
| 260 EXPECT_EQ(bounds.ToString(), | 264 EXPECT_EQ(bounds.ToString(), |
| 261 GetRestoreBoundsInParent(window.get()).ToString()); | 265 window_state->GetRestoreBoundsInParent().ToString()); |
| 262 | 266 |
| 263 // Minimize the window. The restore bounds should not change. | 267 // Minimize the window. The restore bounds should not change. |
| 264 wm::MinimizeWindow(window.get()); | 268 window_state->Minimize(); |
| 265 EXPECT_EQ(bounds.ToString(), | 269 EXPECT_EQ(bounds.ToString(), |
| 266 GetRestoreBoundsInParent(window.get()).ToString()); | 270 window_state->GetRestoreBoundsInParent().ToString()); |
| 267 | 271 |
| 268 // Show the window again. The window should be maximized, and the restore | 272 // Show the window again. The window should be maximized, and the restore |
| 269 // bounds should not change. | 273 // bounds should not change. |
| 270 window->Show(); | 274 window->Show(); |
| 271 EXPECT_EQ(bounds.ToString(), | 275 EXPECT_EQ(bounds.ToString(), |
| 272 GetRestoreBoundsInParent(window.get()).ToString()); | 276 window_state->GetRestoreBoundsInParent().ToString()); |
| 273 EXPECT_TRUE(wm::IsWindowMaximized(window.get())); | 277 EXPECT_TRUE(window_state->IsMaximized()); |
| 274 | 278 |
| 275 wm::RestoreWindow(window.get()); | 279 window_state->Restore(); |
| 276 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); | 280 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); |
| 277 } | 281 } |
| 278 | 282 |
| 279 // Verify if the window is not resized during screen lock. See: crbug.com/173127 | 283 // Verify if the window is not resized during screen lock. See: crbug.com/173127 |
| 280 TEST_F(BaseLayoutManagerTest, NotResizeWhenScreenIsLocked) { | 284 TEST_F(BaseLayoutManagerTest, NotResizeWhenScreenIsLocked) { |
| 281 SetCanLockScreen(true); | 285 SetCanLockScreen(true); |
| 282 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); | 286 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); |
| 283 // window with AlwaysOnTop will be managed by BaseLayoutManager. | 287 // window with AlwaysOnTop will be managed by BaseLayoutManager. |
| 284 window->SetProperty(aura::client::kAlwaysOnTopKey, true); | 288 window->SetProperty(aura::client::kAlwaysOnTopKey, true); |
| 285 window->Show(); | 289 window->Show(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 300 ScreenAsh::GetMaximizedWindowBoundsInParent(window.get()).ToString(), | 304 ScreenAsh::GetMaximizedWindowBoundsInParent(window.get()).ToString(), |
| 301 window_bounds.ToString()); | 305 window_bounds.ToString()); |
| 302 | 306 |
| 303 Shell::GetInstance()->session_state_delegate()->UnlockScreen(); | 307 Shell::GetInstance()->session_state_delegate()->UnlockScreen(); |
| 304 shelf->UpdateVisibilityState(); | 308 shelf->UpdateVisibilityState(); |
| 305 EXPECT_EQ(window_bounds.ToString(), window->bounds().ToString()); | 309 EXPECT_EQ(window_bounds.ToString(), window->bounds().ToString()); |
| 306 } | 310 } |
| 307 | 311 |
| 308 } // namespace | 312 } // namespace |
| 309 } // namespace ash | 313 } // namespace ash |
| OLD | NEW |