OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/wm/workspace/snap_sizer.h" |
| 6 |
| 7 #include "ash/screen_ash.h" |
| 8 #include "ash/shell.h" |
| 9 #include "ash/test/ash_test_base.h" |
| 10 #include "ash/wm/window_util.h" |
| 11 #include "ui/aura/root_window.h" |
| 12 #include "ui/aura/test/test_window_delegate.h" |
| 13 #include "ui/aura/window.h" |
| 14 #include "ui/gfx/screen.h" |
| 15 |
| 16 namespace ash { |
| 17 |
| 18 typedef test::AshTestBase SnapSizerTest; |
| 19 |
| 20 using internal::SnapSizer; |
| 21 |
| 22 // Test that a window gets properly snapped to the display's edges in a |
| 23 // multi monitor environment. |
| 24 TEST_F(SnapSizerTest, MultipleDisplays) { |
| 25 if (!SupportsMultipleDisplays()) |
| 26 return; |
| 27 |
| 28 UpdateDisplay("0+0-500x400, 0+500-600x400"); |
| 29 const gfx::Rect kPrimaryDisplayWorkAreaBounds = |
| 30 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); |
| 31 const gfx::Rect kSecondaryDisplayWorkAreaBounds = |
| 32 ScreenAsh::GetSecondaryDisplay().work_area(); |
| 33 |
| 34 scoped_ptr<aura::Window> window( |
| 35 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); |
| 36 |
| 37 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); |
| 38 gfx::Rect expected = gfx::Rect( |
| 39 kPrimaryDisplayWorkAreaBounds.x(), |
| 40 kPrimaryDisplayWorkAreaBounds.y(), |
| 41 window->bounds().width(), // No expectation for the width. |
| 42 kPrimaryDisplayWorkAreaBounds.height()); |
| 43 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 44 |
| 45 SnapSizer::SnapWindow(window.get(), SnapSizer::RIGHT_EDGE); |
| 46 // The width should not change when a window switches from being snapped to |
| 47 // the left edge to being snapped to the right edge. |
| 48 expected.set_x(kPrimaryDisplayWorkAreaBounds.right() - expected.width()); |
| 49 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 50 |
| 51 // Move the window to the secondary display. |
| 52 window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100), |
| 53 ScreenAsh::GetSecondaryDisplay()); |
| 54 |
| 55 SnapSizer::SnapWindow(window.get(), SnapSizer::RIGHT_EDGE); |
| 56 expected = gfx::Rect( |
| 57 kSecondaryDisplayWorkAreaBounds.right() - window->bounds().width(), |
| 58 kSecondaryDisplayWorkAreaBounds.y(), |
| 59 window->bounds().width(), // No expectation for the width. |
| 60 kSecondaryDisplayWorkAreaBounds.height()); |
| 61 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 62 |
| 63 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); |
| 64 // The width should not change when a window switches from being snapped to |
| 65 // the right edge to being snapped to the left edge. |
| 66 expected.set_x(kSecondaryDisplayWorkAreaBounds.x()); |
| 67 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 68 } |
| 69 |
| 70 // Test how the minimum and maximum size specified by the aura::WindowDelegate |
| 71 // affect snapping. |
| 72 TEST_F(SnapSizerTest, MinimumSize) { |
| 73 if (!SupportsHostWindowResize()) |
| 74 return; |
| 75 |
| 76 UpdateDisplay("0+0-600x800"); |
| 77 const gfx::Rect kWorkAreaBounds = |
| 78 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); |
| 79 |
| 80 aura::test::TestWindowDelegate delegate; |
| 81 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( |
| 82 &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100))); |
| 83 |
| 84 // It should be possible to snap a window with a minimum size. |
| 85 delegate.set_minimum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0)); |
| 86 EXPECT_TRUE(ash::wm::CanSnapWindow(window.get())); |
| 87 SnapSizer::SnapWindow(window.get(), SnapSizer::RIGHT_EDGE); |
| 88 gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x() + 1, |
| 89 kWorkAreaBounds.y(), |
| 90 kWorkAreaBounds.width() - 1, |
| 91 kWorkAreaBounds.height()); |
| 92 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 93 |
| 94 // It should not be possible to snap a window with a maximum size. |
| 95 delegate.set_minimum_size(gfx::Size()); |
| 96 delegate.set_maximum_size(gfx::Size(kWorkAreaBounds.width() - 1, INT_MAX)); |
| 97 EXPECT_FALSE(ash::wm::CanSnapWindow(window.get())); |
| 98 } |
| 99 |
| 100 } // namespace ash |
OLD | NEW |