| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/workspace/snap_sizer.h" | 5 #include "ash/wm/workspace/snap_sizer.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/screen_ash.h" | 8 #include "ash/screen_util.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
| 11 #include "ash/wm/window_state.h" | 11 #include "ash/wm/window_state.h" |
| 12 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
| 15 #include "ui/aura/test/test_window_delegate.h" | 15 #include "ui/aura/test/test_window_delegate.h" |
| 16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
| 18 | 18 |
| 19 namespace ash { | 19 namespace ash { |
| 20 | 20 |
| 21 typedef test::AshTestBase SnapSizerTest; | 21 typedef test::AshTestBase SnapSizerTest; |
| 22 | 22 |
| 23 using internal::SnapSizer; | 23 using internal::SnapSizer; |
| 24 | 24 |
| 25 // Test that a window gets properly snapped to the display's edges in a | 25 // Test that a window gets properly snapped to the display's edges in a |
| 26 // multi monitor environment. | 26 // multi monitor environment. |
| 27 TEST_F(SnapSizerTest, MultipleDisplays) { | 27 TEST_F(SnapSizerTest, MultipleDisplays) { |
| 28 if (!SupportsMultipleDisplays()) | 28 if (!SupportsMultipleDisplays()) |
| 29 return; | 29 return; |
| 30 | 30 |
| 31 UpdateDisplay("0+0-500x400, 0+500-600x400"); | 31 UpdateDisplay("0+0-500x400, 0+500-600x400"); |
| 32 const gfx::Rect kPrimaryDisplayWorkAreaBounds = | 32 const gfx::Rect kPrimaryDisplayWorkAreaBounds = |
| 33 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); | 33 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); |
| 34 const gfx::Rect kSecondaryDisplayWorkAreaBounds = | 34 const gfx::Rect kSecondaryDisplayWorkAreaBounds = |
| 35 ScreenAsh::GetSecondaryDisplay().work_area(); | 35 ScreenUtil::GetSecondaryDisplay().work_area(); |
| 36 | 36 |
| 37 scoped_ptr<aura::Window> window( | 37 scoped_ptr<aura::Window> window( |
| 38 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); | 38 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); |
| 39 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 39 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 40 SnapSizer::SnapWindow(window_state, SnapSizer::LEFT_EDGE); | 40 SnapSizer::SnapWindow(window_state, SnapSizer::LEFT_EDGE); |
| 41 gfx::Rect expected = gfx::Rect( | 41 gfx::Rect expected = gfx::Rect( |
| 42 kPrimaryDisplayWorkAreaBounds.x(), | 42 kPrimaryDisplayWorkAreaBounds.x(), |
| 43 kPrimaryDisplayWorkAreaBounds.y(), | 43 kPrimaryDisplayWorkAreaBounds.y(), |
| 44 window->bounds().width(), // No expectation for the width. | 44 window->bounds().width(), // No expectation for the width. |
| 45 kPrimaryDisplayWorkAreaBounds.height()); | 45 kPrimaryDisplayWorkAreaBounds.height()); |
| 46 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 46 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 47 | 47 |
| 48 SnapSizer::SnapWindow(window_state, SnapSizer::RIGHT_EDGE); | 48 SnapSizer::SnapWindow(window_state, SnapSizer::RIGHT_EDGE); |
| 49 // The width should not change when a window switches from being snapped to | 49 // The width should not change when a window switches from being snapped to |
| 50 // the left edge to being snapped to the right edge. | 50 // the left edge to being snapped to the right edge. |
| 51 expected.set_x(kPrimaryDisplayWorkAreaBounds.right() - expected.width()); | 51 expected.set_x(kPrimaryDisplayWorkAreaBounds.right() - expected.width()); |
| 52 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 52 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 53 | 53 |
| 54 // Move the window to the secondary display. | 54 // Move the window to the secondary display. |
| 55 window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100), | 55 window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100), |
| 56 ScreenAsh::GetSecondaryDisplay()); | 56 ScreenUtil::GetSecondaryDisplay()); |
| 57 | 57 |
| 58 SnapSizer::SnapWindow(window_state, SnapSizer::RIGHT_EDGE); | 58 SnapSizer::SnapWindow(window_state, SnapSizer::RIGHT_EDGE); |
| 59 expected = gfx::Rect( | 59 expected = gfx::Rect( |
| 60 kSecondaryDisplayWorkAreaBounds.right() - window->bounds().width(), | 60 kSecondaryDisplayWorkAreaBounds.right() - window->bounds().width(), |
| 61 kSecondaryDisplayWorkAreaBounds.y(), | 61 kSecondaryDisplayWorkAreaBounds.y(), |
| 62 window->bounds().width(), // No expectation for the width. | 62 window->bounds().width(), // No expectation for the width. |
| 63 kSecondaryDisplayWorkAreaBounds.height()); | 63 kSecondaryDisplayWorkAreaBounds.height()); |
| 64 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 64 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 65 | 65 |
| 66 SnapSizer::SnapWindow(window_state, SnapSizer::LEFT_EDGE); | 66 SnapSizer::SnapWindow(window_state, SnapSizer::LEFT_EDGE); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 // For small workspace widths, we should snap to 90% of the workspace width | 247 // For small workspace widths, we should snap to 90% of the workspace width |
| 248 // because it is the largest width the window can snap to. | 248 // because it is the largest width the window can snap to. |
| 249 UpdateDisplay("0+0-800x600"); | 249 UpdateDisplay("0+0-800x600"); |
| 250 sizer.SelectDefaultSizeAndDisableResize(); | 250 sizer.SelectDefaultSizeAndDisableResize(); |
| 251 | 251 |
| 252 gfx::Rect work_area = | 252 gfx::Rect work_area = |
| 253 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); | 253 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); |
| 254 gfx::Rect expected(work_area); | 254 gfx::Rect expected(work_area); |
| 255 expected.set_width(work_area.width() * 0.9); | 255 expected.set_width(work_area.width() * 0.9); |
| 256 EXPECT_EQ(expected.ToString(), | 256 EXPECT_EQ(expected.ToString(), |
| 257 ScreenAsh::ConvertRectToScreen(window->parent(), | 257 ScreenUtil::ConvertRectToScreen(window->parent(), |
| 258 sizer.target_bounds()).ToString()); | 258 sizer.target_bounds()).ToString()); |
| 259 | 259 |
| 260 // If the largest width the window can snap to is between 1024 and 1280, we | 260 // If the largest width the window can snap to is between 1024 and 1280, we |
| 261 // should snap to 1024. | 261 // should snap to 1024. |
| 262 UpdateDisplay("0+0-1280x800"); | 262 UpdateDisplay("0+0-1280x800"); |
| 263 sizer.SelectDefaultSizeAndDisableResize(); | 263 sizer.SelectDefaultSizeAndDisableResize(); |
| 264 sizer.SnapWindowToTargetBounds(); | 264 sizer.SnapWindowToTargetBounds(); |
| 265 EXPECT_EQ(1024, window->bounds().width()); | 265 EXPECT_EQ(1024, window->bounds().width()); |
| 266 | 266 |
| 267 // We should snap to a width of 50% of the work area if it is the largest | 267 // We should snap to a width of 50% of the work area if it is the largest |
| 268 // width the window can snap to. | 268 // width the window can snap to. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 window->bounds().width(), // No expectation for the width. | 384 window->bounds().width(), // No expectation for the width. |
| 385 kWorkAreaBounds.height()); | 385 kWorkAreaBounds.height()); |
| 386 EXPECT_EQ(expected_snapped_bounds.ToString(), | 386 EXPECT_EQ(expected_snapped_bounds.ToString(), |
| 387 window->GetBoundsInScreen().ToString()); | 387 window->GetBoundsInScreen().ToString()); |
| 388 | 388 |
| 389 // The window should still be auto managed despite being right maximized. | 389 // The window should still be auto managed despite being right maximized. |
| 390 EXPECT_TRUE(window_state->window_position_managed()); | 390 EXPECT_TRUE(window_state->window_position_managed()); |
| 391 } | 391 } |
| 392 | 392 |
| 393 } // namespace ash | 393 } // namespace ash |
| OLD | NEW |