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