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 // Make sure that the work area is the size we expect it to be. |
| 116 EXPECT_GT(kWorkAreaBounds.width() * 0.9, 768); |
| 117 |
| 118 // The first width should be 1024 * 0.9 because the larger ideal widths |
| 119 // (1280, 1024) > 1024 * 0.9. |
| 120 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); |
| 121 gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x(), |
| 122 kWorkAreaBounds.y(), |
| 123 kWorkAreaBounds.width() * 0.9, |
| 124 kWorkAreaBounds.height()); |
| 125 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 126 |
| 127 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); |
| 128 expected.set_width(768); |
| 129 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 130 |
| 131 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); |
| 132 expected.set_width(640); |
| 133 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 134 |
| 135 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); |
| 136 expected.set_width(kWorkAreaBounds.width() * 0.5); |
| 137 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 138 |
| 139 // Wrap around. |
| 140 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); |
| 141 expected.set_width(kWorkAreaBounds.width() * 0.9); |
| 142 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 143 } |
| 144 |
| 145 // Tests the SnapSizer's target bounds when resizing is disabled. |
| 146 TEST_F(SnapSizerTest, Default) { |
| 147 if (!SupportsHostWindowResize()) |
| 148 return; |
| 149 |
| 150 scoped_ptr<aura::Window> window( |
| 151 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); |
| 152 SnapSizer sizer(window.get(), gfx::Point(), SnapSizer::LEFT_EDGE, |
| 153 SnapSizer::OTHER_INPUT); |
| 154 |
| 155 // For small workspace widths, we should snap to 90% of the workspace width |
| 156 // because it is the largest width the window can snap to. |
| 157 UpdateDisplay("0+0-800x600"); |
| 158 sizer.SelectDefaultSizeAndDisableResize(); |
| 159 |
| 160 gfx::Rect work_area = |
| 161 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); |
| 162 gfx::Rect expected(work_area); |
| 163 expected.set_width(work_area.width() * 0.9); |
| 164 EXPECT_EQ(expected.ToString(), |
| 165 ScreenAsh::ConvertRectToScreen(window->parent(), |
| 166 sizer.target_bounds()).ToString()); |
| 167 |
| 168 // If the largest width the window can snap to is between 1024 and 1280, we |
| 169 // should snap to 1024. |
| 170 UpdateDisplay("0+0-1280x800"); |
| 171 sizer.SelectDefaultSizeAndDisableResize(); |
| 172 EXPECT_EQ(1024, sizer.target_bounds().width()); |
| 173 |
| 174 // We should snap to a width of 50% of the work area it is the largest width |
| 175 // the window can snap to. |
| 176 UpdateDisplay("0+0-2560x1080"); |
| 177 work_area = ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); |
| 178 sizer.SelectDefaultSizeAndDisableResize(); |
| 179 EXPECT_EQ(work_area.width() / 2, sizer.target_bounds().width()); |
| 180 } |
| 181 |
| 182 // Test that the window only snaps to 50% of the work area width when using the |
| 183 // alternate caption button style. |
| 184 TEST_F(SnapSizerTest, AlternateFrameCaptionButtonStyle) { |
| 185 if (!SupportsHostWindowResize()) |
| 186 return; |
| 187 |
| 188 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 189 ash::switches::kAshEnableAlternateFrameCaptionButtonStyle); |
| 190 ASSERT_TRUE(ash::switches::UseAlternateFrameCaptionButtonStyle()); |
| 191 |
| 192 UpdateDisplay("0+0-800x600"); |
| 193 const gfx::Rect kWorkAreaBounds = |
| 194 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); |
| 195 |
| 196 scoped_ptr<aura::Window> window( |
| 197 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); |
| 198 |
| 199 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); |
| 200 gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x(), |
| 201 kWorkAreaBounds.y(), |
| 202 kWorkAreaBounds.width() / 2, |
| 203 kWorkAreaBounds.height()); |
| 204 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 205 |
| 206 // Because a window can only be snapped to one size when using the alternate |
| 207 // caption button style, a second call to SnapSizer::SnapWindow() should have |
| 208 // no effect. |
| 209 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); |
| 210 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 211 |
| 212 // It should still be possible to switch a window from being snapped to the |
| 213 // left edge to being snapped to the right edge. |
| 214 SnapSizer::SnapWindow(window.get(), SnapSizer::RIGHT_EDGE); |
| 215 expected.set_x(kWorkAreaBounds.right() - expected.width()); |
| 216 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
| 217 |
| 218 // If resizing is disabled, the window should be snapped to 50% too. |
| 219 SnapSizer sizer(window.get(), gfx::Point(), SnapSizer::RIGHT_EDGE, |
| 220 SnapSizer::OTHER_INPUT); |
| 221 sizer.SelectDefaultSizeAndDisableResize(); |
| 222 EXPECT_EQ(expected.ToString(), |
| 223 ScreenAsh::ConvertRectToScreen(window->parent(), |
| 224 sizer.target_bounds()).ToString()); |
| 225 } |
| 226 |
100 } // namespace ash | 227 } // namespace ash |
OLD | NEW |