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/screen_ash.h" | 8 #include "ash/screen_ash.h" |
8 #include "ash/shell.h" | 9 #include "ash/shell.h" |
9 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
10 #include "ash/wm/window_util.h" | 11 #include "ash/wm/window_util.h" |
| 12 #include "base/command_line.h" |
11 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
12 #include "ui/aura/test/test_window_delegate.h" | 14 #include "ui/aura/test/test_window_delegate.h" |
13 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
14 #include "ui/gfx/screen.h" | 16 #include "ui/gfx/screen.h" |
15 | 17 |
16 namespace ash { | 18 namespace ash { |
17 | 19 |
18 typedef test::AshTestBase SnapSizerTest; | 20 typedef test::AshTestBase SnapSizerTest; |
19 | 21 |
20 using internal::SnapSizer; | 22 using internal::SnapSizer; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 kWorkAreaBounds.width() - 1, | 92 kWorkAreaBounds.width() - 1, |
91 kWorkAreaBounds.height()); | 93 kWorkAreaBounds.height()); |
92 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 94 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
93 | 95 |
94 // It should not be possible to snap a window with a maximum size. | 96 // It should not be possible to snap a window with a maximum size. |
95 delegate.set_minimum_size(gfx::Size()); | 97 delegate.set_minimum_size(gfx::Size()); |
96 delegate.set_maximum_size(gfx::Size(kWorkAreaBounds.width() - 1, INT_MAX)); | 98 delegate.set_maximum_size(gfx::Size(kWorkAreaBounds.width() - 1, INT_MAX)); |
97 EXPECT_FALSE(ash::wm::CanSnapWindow(window.get())); | 99 EXPECT_FALSE(ash::wm::CanSnapWindow(window.get())); |
98 } | 100 } |
99 | 101 |
| 102 // 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 TEST_F(SnapSizerTest, StepThroughSizes) { |
| 105 if (!SupportsHostWindowResize()) |
| 106 return; |
| 107 |
| 108 UpdateDisplay("0+0-1024x800"); |
| 109 const gfx::Rect kWorkAreaBounds = |
| 110 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); |
| 111 |
| 112 scoped_ptr<aura::Window> window( |
| 113 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); |
| 114 |
| 115 // We start with the smallest width first before wrapping around. |
| 116 // TODO: Investigate whether this is intentional. |
| 117 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); |
| 118 gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x(), |
| 119 kWorkAreaBounds.y(), |
| 120 512, |
| 121 kWorkAreaBounds.height()); |
| 122 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 123 |
| 124 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); |
| 125 expected.set_width(921); |
| 126 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 127 |
| 128 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); |
| 129 expected.set_width(768); |
| 130 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 131 |
| 132 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); |
| 133 expected.set_width(640); |
| 134 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 135 |
| 136 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); |
| 137 expected.set_width(512); |
| 138 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 139 } |
| 140 |
| 141 // Test that the window only snaps to 50% of the work area width when using the |
| 142 // alternate caption button style. |
| 143 TEST_F(SnapSizerTest, AlternateFrameCaptionButtonStyle) { |
| 144 if (!SupportsHostWindowResize()) |
| 145 return; |
| 146 |
| 147 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 148 ash::switches::kAshEnableAlternateFrameCaptionButtonStyle); |
| 149 ASSERT_TRUE(ash::switches::UseAlternateFrameCaptionButtonStyle()); |
| 150 |
| 151 UpdateDisplay("0+0-800x600"); |
| 152 const gfx::Rect kWorkAreaBounds = |
| 153 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); |
| 154 |
| 155 scoped_ptr<aura::Window> window( |
| 156 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); |
| 157 |
| 158 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); |
| 159 gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x(), |
| 160 kWorkAreaBounds.y(), |
| 161 kWorkAreaBounds.width() / 2, |
| 162 kWorkAreaBounds.height()); |
| 163 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 164 |
| 165 // Because a window can only be snapped to one size when using the alternate |
| 166 // caption button style, a second call to SnapSizer::SnapWindow() should have |
| 167 // no effect. |
| 168 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); |
| 169 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 170 |
| 171 // It should still be possible to switch a window from being snapped to the |
| 172 // left edge to being snapped to the right edge. |
| 173 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); |
| 174 expected.set_x(expected.right() - expected.width()); |
| 175 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 176 } |
| 177 |
100 } // namespace ash | 178 } // namespace ash |
OLD | NEW |