| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/common/wm/window_state.h" | 5 #include "ash/common/wm/window_state.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/wm/window_state.h" | 9 #include "ash/common/wm/window_state.h" |
| 10 #include "ash/common/wm/window_state_util.h" | 10 #include "ash/common/wm/window_state_util.h" |
| 11 #include "ash/common/wm/wm_event.h" | 11 #include "ash/common/wm/wm_event.h" |
| 12 #include "ash/common/wm_shell.h" |
| 12 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
| 13 #include "ash/wm/window_state_aura.h" | 14 #include "ash/wm/window_state_aura.h" |
| 14 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
| 15 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | 16 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
| 16 #include "ui/aura/client/aura_constants.h" | 17 #include "ui/aura/client/aura_constants.h" |
| 17 #include "ui/aura/test/test_window_delegate.h" | 18 #include "ui/aura/test/test_window_delegate.h" |
| 18 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 19 #include "ui/display/manager/display_manager.h" | |
| 20 #include "ui/display/screen.h" | 20 #include "ui/display/screen.h" |
| 21 | 21 |
| 22 namespace ash { | 22 namespace ash { |
| 23 namespace wm { | 23 namespace wm { |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 class AlwaysMaximizeTestState : public WindowState::State { | 26 class AlwaysMaximizeTestState : public WindowState::State { |
| 27 public: | 27 public: |
| 28 explicit AlwaysMaximizeTestState(WindowStateType initial_state_type) | 28 explicit AlwaysMaximizeTestState(WindowStateType initial_state_type) |
| 29 : state_type_(initial_state_type) {} | 29 : state_type_(initial_state_type) {} |
| (...skipping 24 matching lines...) Expand all Loading... |
| 54 | 54 |
| 55 using WindowStateTest = test::AshTestBase; | 55 using WindowStateTest = test::AshTestBase; |
| 56 | 56 |
| 57 // Test that a window gets properly snapped to the display's edges in a | 57 // Test that a window gets properly snapped to the display's edges in a |
| 58 // multi monitor environment. | 58 // multi monitor environment. |
| 59 TEST_F(WindowStateTest, SnapWindowBasic) { | 59 TEST_F(WindowStateTest, SnapWindowBasic) { |
| 60 UpdateDisplay("0+0-500x400, 0+500-600x400"); | 60 UpdateDisplay("0+0-500x400, 0+500-600x400"); |
| 61 const gfx::Rect kPrimaryDisplayWorkAreaBounds = | 61 const gfx::Rect kPrimaryDisplayWorkAreaBounds = |
| 62 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 62 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
| 63 const gfx::Rect kSecondaryDisplayWorkAreaBounds = | 63 const gfx::Rect kSecondaryDisplayWorkAreaBounds = |
| 64 display_manager()->GetSecondaryDisplay().work_area(); | 64 GetSecondaryDisplay().work_area(); |
| 65 | 65 |
| 66 std::unique_ptr<aura::Window> window( | 66 std::unique_ptr<aura::Window> window( |
| 67 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); | 67 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); |
| 68 WindowState* window_state = GetWindowState(window.get()); | 68 WindowState* window_state = GetWindowState(window.get()); |
| 69 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); | 69 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); |
| 70 window_state->OnWMEvent(&snap_left); | 70 window_state->OnWMEvent(&snap_left); |
| 71 gfx::Rect expected = gfx::Rect(kPrimaryDisplayWorkAreaBounds.x(), | 71 gfx::Rect expected = gfx::Rect(kPrimaryDisplayWorkAreaBounds.x(), |
| 72 kPrimaryDisplayWorkAreaBounds.y(), | 72 kPrimaryDisplayWorkAreaBounds.y(), |
| 73 kPrimaryDisplayWorkAreaBounds.width() / 2, | 73 kPrimaryDisplayWorkAreaBounds.width() / 2, |
| 74 kPrimaryDisplayWorkAreaBounds.height()); | 74 kPrimaryDisplayWorkAreaBounds.height()); |
| 75 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 75 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 76 | 76 |
| 77 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT); | 77 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT); |
| 78 window_state->OnWMEvent(&snap_right); | 78 window_state->OnWMEvent(&snap_right); |
| 79 expected.set_x(kPrimaryDisplayWorkAreaBounds.right() - expected.width()); | 79 expected.set_x(kPrimaryDisplayWorkAreaBounds.right() - expected.width()); |
| 80 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 80 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 81 | 81 |
| 82 // Move the window to the secondary display. | 82 // Move the window to the secondary display. |
| 83 window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100), | 83 window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100), GetSecondaryDisplay()); |
| 84 display_manager()->GetSecondaryDisplay()); | |
| 85 | 84 |
| 86 window_state->OnWMEvent(&snap_right); | 85 window_state->OnWMEvent(&snap_right); |
| 87 expected = gfx::Rect(kSecondaryDisplayWorkAreaBounds.x() + | 86 expected = gfx::Rect(kSecondaryDisplayWorkAreaBounds.x() + |
| 88 kSecondaryDisplayWorkAreaBounds.width() / 2, | 87 kSecondaryDisplayWorkAreaBounds.width() / 2, |
| 89 kSecondaryDisplayWorkAreaBounds.y(), | 88 kSecondaryDisplayWorkAreaBounds.y(), |
| 90 kSecondaryDisplayWorkAreaBounds.width() / 2, | 89 kSecondaryDisplayWorkAreaBounds.width() / 2, |
| 91 kSecondaryDisplayWorkAreaBounds.height()); | 90 kSecondaryDisplayWorkAreaBounds.height()); |
| 92 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 91 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 93 | 92 |
| 94 window_state->OnWMEvent(&snap_left); | 93 window_state->OnWMEvent(&snap_left); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 EXPECT_TRUE(window_state->IsMaximized()); | 313 EXPECT_TRUE(window_state->IsMaximized()); |
| 315 EXPECT_EQ(work_area.ToString(), window->bounds().ToString()); | 314 EXPECT_EQ(work_area.ToString(), window->bounds().ToString()); |
| 316 | 315 |
| 317 window_state->Restore(); | 316 window_state->Restore(); |
| 318 EXPECT_FALSE(window_state->IsMaximized()); | 317 EXPECT_FALSE(window_state->IsMaximized()); |
| 319 EXPECT_NE(work_area.ToString(), window->bounds().ToString()); | 318 EXPECT_NE(work_area.ToString(), window->bounds().ToString()); |
| 320 EXPECT_TRUE(work_area.Contains(window->bounds())); | 319 EXPECT_TRUE(work_area.Contains(window->bounds())); |
| 321 } | 320 } |
| 322 | 321 |
| 323 TEST_F(WindowStateTest, DoNotResizeMaximizedWindowInFullscreen) { | 322 TEST_F(WindowStateTest, DoNotResizeMaximizedWindowInFullscreen) { |
| 323 // TODO: investigate failure. http://crbug.com/698914. |
| 324 if (WmShell::Get()->IsRunningInMash()) |
| 325 return; |
| 326 |
| 324 std::unique_ptr<aura::Window> maximized(CreateTestWindowInShellWithId(0)); | 327 std::unique_ptr<aura::Window> maximized(CreateTestWindowInShellWithId(0)); |
| 325 std::unique_ptr<aura::Window> fullscreen(CreateTestWindowInShellWithId(1)); | 328 std::unique_ptr<aura::Window> fullscreen(CreateTestWindowInShellWithId(1)); |
| 326 WindowState* maximized_state = GetWindowState(maximized.get()); | 329 WindowState* maximized_state = GetWindowState(maximized.get()); |
| 327 maximized_state->Maximize(); | 330 maximized_state->Maximize(); |
| 328 ASSERT_TRUE(maximized_state->IsMaximized()); | 331 ASSERT_TRUE(maximized_state->IsMaximized()); |
| 329 EXPECT_EQ(gfx::Rect(0, 0, 800, 552).ToString(), | 332 EXPECT_EQ(gfx::Rect(0, 0, 800, 552).ToString(), |
| 330 maximized->GetBoundsInScreen().ToString()); | 333 maximized->GetBoundsInScreen().ToString()); |
| 331 | 334 |
| 332 // Entering fullscreen mode will not update the maximized window's size | 335 // Entering fullscreen mode will not update the maximized window's size |
| 333 // under fullscreen. | 336 // under fullscreen. |
| 334 WMEvent fullscreen_event(WM_EVENT_FULLSCREEN); | 337 WMEvent fullscreen_event(WM_EVENT_FULLSCREEN); |
| 335 WindowState* fullscreen_state = GetWindowState(fullscreen.get()); | 338 WindowState* fullscreen_state = GetWindowState(fullscreen.get()); |
| 336 fullscreen_state->OnWMEvent(&fullscreen_event); | 339 fullscreen_state->OnWMEvent(&fullscreen_event); |
| 337 ASSERT_TRUE(fullscreen_state->IsFullscreen()); | 340 ASSERT_TRUE(fullscreen_state->IsFullscreen()); |
| 338 ASSERT_TRUE(maximized_state->IsMaximized()); | 341 ASSERT_TRUE(maximized_state->IsMaximized()); |
| 339 EXPECT_EQ(gfx::Rect(0, 0, 800, 552).ToString(), | 342 EXPECT_EQ(gfx::Rect(0, 0, 800, 552).ToString(), |
| 340 maximized->GetBoundsInScreen().ToString()); | 343 maximized->GetBoundsInScreen().ToString()); |
| 341 | 344 |
| 342 // Updating display size will update the maximum window size. | 345 // Updating display size will update the maximum window size. |
| 343 UpdateDisplay("900x700"); | 346 UpdateDisplay("900x700"); |
| 344 EXPECT_EQ("0,0 900x700", maximized->GetBoundsInScreen().ToString()); | 347 EXPECT_EQ("0,0 900x700", maximized->GetBoundsInScreen().ToString()); |
| 345 fullscreen.reset(); | 348 fullscreen.reset(); |
| 346 | 349 |
| 347 // Exiting fullscreen will update the maximized window to the work area. | 350 // Exiting fullscreen will update the maximized window to the work area. |
| 348 EXPECT_EQ(gfx::Rect(0, 0, 900, 652).ToString(), | 351 EXPECT_EQ(gfx::Rect(0, 0, 900, 652).ToString(), |
| 349 maximized->GetBoundsInScreen().ToString()); | 352 maximized->GetBoundsInScreen().ToString()); |
| 350 } | 353 } |
| 351 | 354 |
| 352 TEST_F(WindowStateTest, TrustedPinned) { | 355 TEST_F(WindowStateTest, TrustedPinned) { |
| 356 // TODO: investigate failure. http://crbug.com/698914. |
| 357 if (WmShell::Get()->IsRunningInMash()) |
| 358 return; |
| 359 |
| 353 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 360 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 354 WindowState* window_state = GetWindowState(window.get()); | 361 WindowState* window_state = GetWindowState(window.get()); |
| 355 EXPECT_FALSE(window_state->IsTrustedPinned()); | 362 EXPECT_FALSE(window_state->IsTrustedPinned()); |
| 356 wm::PinWindow(window.get(), true /* trusted */); | 363 wm::PinWindow(window.get(), true /* trusted */); |
| 357 EXPECT_TRUE(window_state->IsTrustedPinned()); | 364 EXPECT_TRUE(window_state->IsTrustedPinned()); |
| 358 | 365 |
| 359 gfx::Rect work_area = | 366 gfx::Rect work_area = |
| 360 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 367 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
| 361 EXPECT_EQ(work_area.ToString(), window->bounds().ToString()); | 368 EXPECT_EQ(work_area.ToString(), window->bounds().ToString()); |
| 362 | 369 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 // return to the state before minimizing and fullscreen. | 464 // return to the state before minimizing and fullscreen. |
| 458 ash::wm::ToggleFullScreen(window_state, nullptr); | 465 ash::wm::ToggleFullScreen(window_state, nullptr); |
| 459 ASSERT_TRUE(window_state->IsMaximized()); | 466 ASSERT_TRUE(window_state->IsMaximized()); |
| 460 } | 467 } |
| 461 | 468 |
| 462 // TODO(skuhne): Add more unit test to verify the correctness for the restore | 469 // TODO(skuhne): Add more unit test to verify the correctness for the restore |
| 463 // operation. | 470 // operation. |
| 464 | 471 |
| 465 } // namespace wm | 472 } // namespace wm |
| 466 } // namespace ash | 473 } // namespace ash |
| OLD | NEW |