| 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_ash.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_util.h" | 11 #include "ash/wm/window_state.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
| 14 #include "ui/aura/test/test_window_delegate.h" | 14 #include "ui/aura/test/test_window_delegate.h" |
| 15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 16 #include "ui/gfx/screen.h" | 16 #include "ui/gfx/screen.h" |
| 17 | 17 |
| 18 namespace ash { | 18 namespace ash { |
| 19 | 19 |
| 20 typedef test::AshTestBase SnapSizerTest; | 20 typedef test::AshTestBase SnapSizerTest; |
| 21 | 21 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 UpdateDisplay("0+0-600x800"); | 78 UpdateDisplay("0+0-600x800"); |
| 79 const gfx::Rect kWorkAreaBounds = | 79 const gfx::Rect kWorkAreaBounds = |
| 80 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); | 80 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); |
| 81 | 81 |
| 82 aura::test::TestWindowDelegate delegate; | 82 aura::test::TestWindowDelegate delegate; |
| 83 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( | 83 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( |
| 84 &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100))); | 84 &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100))); |
| 85 | 85 |
| 86 // It should be possible to snap a window with a minimum size. | 86 // It should be possible to snap a window with a minimum size. |
| 87 delegate.set_minimum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0)); | 87 delegate.set_minimum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0)); |
| 88 EXPECT_TRUE(ash::wm::CanSnapWindow(window.get())); | 88 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 89 EXPECT_TRUE(window_state->CanSnap()); |
| 89 SnapSizer::SnapWindow(window.get(), SnapSizer::RIGHT_EDGE); | 90 SnapSizer::SnapWindow(window.get(), SnapSizer::RIGHT_EDGE); |
| 90 gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x() + 1, | 91 gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x() + 1, |
| 91 kWorkAreaBounds.y(), | 92 kWorkAreaBounds.y(), |
| 92 kWorkAreaBounds.width() - 1, | 93 kWorkAreaBounds.width() - 1, |
| 93 kWorkAreaBounds.height()); | 94 kWorkAreaBounds.height()); |
| 94 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 95 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 95 | 96 |
| 96 // It should not be possible to snap a window with a maximum size. | 97 // It should not be possible to snap a window with a maximum size. |
| 97 delegate.set_minimum_size(gfx::Size()); | 98 delegate.set_minimum_size(gfx::Size()); |
| 98 delegate.set_maximum_size(gfx::Size(kWorkAreaBounds.width() - 1, INT_MAX)); | 99 delegate.set_maximum_size(gfx::Size(kWorkAreaBounds.width() - 1, INT_MAX)); |
| 99 EXPECT_FALSE(ash::wm::CanSnapWindow(window.get())); | 100 EXPECT_FALSE(window_state->CanSnap()); |
| 100 } | 101 } |
| 101 | 102 |
| 102 // Test that repeadedly calling SnapSizer::SnapWindow() steps through the ideal | 103 // Test that repeadedly calling SnapSizer::SnapWindow() steps through the ideal |
| 103 // widths in descending order as well as 90% and 50% of the work area's width. | 104 // widths in descending order as well as 90% and 50% of the work area's width. |
| 104 TEST_F(SnapSizerTest, StepThroughSizes) { | 105 TEST_F(SnapSizerTest, StepThroughSizes) { |
| 105 if (!SupportsHostWindowResize()) | 106 if (!SupportsHostWindowResize()) |
| 106 return; | 107 return; |
| 107 | 108 |
| 108 UpdateDisplay("0+0-1024x800"); | 109 UpdateDisplay("0+0-1024x800"); |
| 109 const gfx::Rect kWorkAreaBounds = | 110 const gfx::Rect kWorkAreaBounds = |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 // If resizing is disabled, the window should be snapped to 50% too. | 219 // If resizing is disabled, the window should be snapped to 50% too. |
| 219 SnapSizer sizer(window.get(), gfx::Point(), SnapSizer::RIGHT_EDGE, | 220 SnapSizer sizer(window.get(), gfx::Point(), SnapSizer::RIGHT_EDGE, |
| 220 SnapSizer::OTHER_INPUT); | 221 SnapSizer::OTHER_INPUT); |
| 221 sizer.SelectDefaultSizeAndDisableResize(); | 222 sizer.SelectDefaultSizeAndDisableResize(); |
| 222 EXPECT_EQ(expected.ToString(), | 223 EXPECT_EQ(expected.ToString(), |
| 223 ScreenAsh::ConvertRectToScreen(window->parent(), | 224 ScreenAsh::ConvertRectToScreen(window->parent(), |
| 224 sizer.target_bounds()).ToString()); | 225 sizer.target_bounds()).ToString()); |
| 225 } | 226 } |
| 226 | 227 |
| 227 } // namespace ash | 228 } // namespace ash |
| OLD | NEW |