Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: ash/wm/workspace/workspace_layout_manager2_unittest.cc

Issue 11085053: Improving window auto management between workspaces (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/workspace_layout_manager.h" 5 #include "ash/wm/workspace/workspace_layout_manager.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
9 #include "ash/wm/property_util.h" 9 #include "ash/wm/property_util.h"
10 #include "ash/wm/shelf_layout_manager.h" 10 #include "ash/wm/shelf_layout_manager.h"
11 #include "ash/wm/window_util.h" 11 #include "ash/wm/window_util.h"
12 #include "base/string_number_conversions.h"
12 #include "ui/aura/root_window.h" 13 #include "ui/aura/root_window.h"
13 #include "ui/aura/test/test_windows.h" 14 #include "ui/aura/test/test_windows.h"
14 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
15 #include "ui/gfx/insets.h" 16 #include "ui/gfx/insets.h"
16 17
17 namespace ash { 18 namespace ash {
18 19
19 namespace { 20 namespace {
20 21
21 class WorkspaceLayoutManager2Test : public test::AshTestBase { 22 class WorkspaceLayoutManager2Test : public test::AshTestBase {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 // If the window is out of the workspace, it would be moved on screen. 128 // If the window is out of the workspace, it would be moved on screen.
128 gfx::Rect root_window_bounds = 129 gfx::Rect root_window_bounds =
129 ash::Shell::GetInstance()->GetPrimaryRootWindow()->bounds(); 130 ash::Shell::GetInstance()->GetPrimaryRootWindow()->bounds();
130 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height()); 131 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height());
131 ASSERT_FALSE(window_bounds.Intersects(root_window_bounds)); 132 ASSERT_FALSE(window_bounds.Intersects(root_window_bounds));
132 scoped_ptr<aura::Window> out_window(CreateTestWindow(window_bounds)); 133 scoped_ptr<aura::Window> out_window(CreateTestWindow(window_bounds));
133 EXPECT_EQ(window_bounds.size(), out_window->bounds().size()); 134 EXPECT_EQ(window_bounds.size(), out_window->bounds().size());
134 EXPECT_TRUE(out_window->bounds().Intersects(root_window_bounds)); 135 EXPECT_TRUE(out_window->bounds().Intersects(root_window_bounds));
135 } 136 }
136 137
138 // Test the basic auto placement of one and or two window.
sky 2012/10/17 15:59:38 Since your patch doesn't touch WorkspaceLayoutMana
Mr4D (OOO till 08-26) 2012/10/17 18:43:56 Moved into WorkspaceManager2Test since the Workspa
139 TEST_F(WorkspaceLayoutManager2Test, BasicAutoPlacing) {
140 // Test 1: In case there is no manageable window, no window should shift.
141
142 scoped_ptr<aura::Window> window1(
143 aura::test::CreateTestWindowWithId(0, NULL));
144 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
145 gfx::Rect desktop_area = window1->parent()->bounds();
146
147 scoped_ptr<aura::Window> window2(
148 aura::test::CreateTestWindowWithId(1, NULL));
149 // Note: we need to perform an activation change to trigger the update.
sky 2012/10/17 15:59:38 Then why hide and show? Use Activate() if you need
Mr4D (OOO till 08-26) 2012/10/17 18:43:56 Added comments since the previous comments were no
150 // As such we initially hide the window and then showing it again.
151 window2->Hide();
152 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
153 window2->Show();
154
155 // Check the initial position of the windows is unchanged.
156 EXPECT_EQ("16,32 640x320", window1->bounds().ToString());
157 EXPECT_EQ("32,48 256x512", window2->bounds().ToString());
158
159 // Remove the second window and make sure that the first window
160 // does NOT get centered.
161 window2.reset();
162 EXPECT_EQ("16,32 640x320", window1->bounds().ToString());
163
164 // Test 2: Set up two managed windows and check their auto positioning.
sky 2012/10/17 15:59:38 Is there a compelling reason to combine so many as
Mr4D (OOO till 08-26) 2012/10/17 18:43:56 This is a "simulation: of a standard workflow" + i
165 ash::wm::SetWindowPositionManaged(window1.get(), true);
166 scoped_ptr<aura::Window> window3(
167 aura::test::CreateTestWindowWithId(2, NULL));
168 ash::wm::SetWindowPositionManaged(window3.get(), true);
169 // Note: we need to perform an activation change to trigger the update.
170 // As such we initially hide the window and then showing it again.
171 window3->Hide();
172 window3->SetBounds(gfx::Rect(32, 48, 256, 512));
173 window3->Show();
174 // |window1| should be flush right and |window3| flush left.
175 EXPECT_EQ(base::IntToString(
176 desktop_area.width() - window1->bounds().width()) +
177 ",32 640x320", window1->bounds().ToString());
178 EXPECT_EQ("0,48 256x512", window3->bounds().ToString());
179
180 // After removing |window3|, |window1| should be centered again.
181 window3.reset();
182 EXPECT_EQ(
183 base::IntToString(
184 (desktop_area.width() - window1->bounds().width()) / 2) +
185 ",32 640x320", window1->bounds().ToString());
186
187 // Test 3: Set up a manageable and a non manageable window and check
188 // positioning.
189 scoped_ptr<aura::Window> window4(
190 aura::test::CreateTestWindowWithId(3, NULL));
191 // Note: we need to perform an activation change to trigger the update.
192 // As such we initially hide the window and then showing it again.
193 window1->Hide();
194 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
195 window4->SetBounds(gfx::Rect(32, 48, 256, 512));
196 window1->Show();
197 // |window1| should be centered and |window4| untouched.
198 EXPECT_EQ(
199 base::IntToString(
200 (desktop_area.width() - window1->bounds().width()) / 2) +
201 ",32 640x320", window1->bounds().ToString());
202 EXPECT_EQ("32,48 256x512", window4->bounds().ToString());
203
204 // Test 4: Once a window gets moved by a user it does not get repositioned.
205 ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), true);
206 window1->SetBounds(gfx::Rect(52, 32, 640, 320));
207 // Note: we need to perform an activation change to trigger the update.
208 // As such we initially hide the window and then showing it again.
209 window4->Hide();
210 window4->Show();
211 EXPECT_EQ("52,32 640x320", window1->bounds().ToString());
212 EXPECT_EQ("32,48 256x512", window4->bounds().ToString());
213
214 // Test5: A single manageable window should get centered.
215 window4.reset();
216 ash::wm::SetUserHasChangedWindowPositionOrSize(window1.get(), false);
217 window1->Hide();
218 window1->Show();
219 // |window1| should be centered.
220 EXPECT_EQ(
221 base::IntToString(
222 (desktop_area.width() - window1->bounds().width()) / 2) +
223 ",32 640x320", window1->bounds().ToString());
224 }
225
226 // Test that a window from normal to minimize will repos the remaining.
227 TEST_F(WorkspaceLayoutManager2Test, ToMinimizeRepositionsRemaining) {
228 scoped_ptr<aura::Window> window1(
229 aura::test::CreateTestWindowWithId(0, NULL));
230 ash::wm::SetWindowPositionManaged(window1.get(), true);
231 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
232 gfx::Rect desktop_area = window1->parent()->bounds();
233
234 scoped_ptr<aura::Window> window2(
235 aura::test::CreateTestWindowWithId(1, NULL));
236 ash::wm::SetWindowPositionManaged(window2.get(), true);
237 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
238
239 ash::wm::MinimizeWindow(window1.get());
240
241 // |window2| should be centered now.
242 EXPECT_TRUE(window2->IsVisible());
243 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get()));
244 EXPECT_EQ(base::IntToString(
245 (desktop_area.width() - window2->bounds().width()) / 2) +
246 ",48 256x512", window2->bounds().ToString());
247
248 ash::wm::RestoreWindow(window1.get());
249 // |window1| should be flush right and |window3| flush left.
250 EXPECT_EQ(base::IntToString(
251 desktop_area.width() - window1->bounds().width()) +
252 ",32 640x320", window1->bounds().ToString());
253 EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
254 }
255
256 // Test that minimizing an initially maximized window will repos the remaining.
257 TEST_F(WorkspaceLayoutManager2Test, MaxToMinRepositionsRemaining) {
258 scoped_ptr<aura::Window> window1(
259 aura::test::CreateTestWindowWithId(0, NULL));
260 ash::wm::SetWindowPositionManaged(window1.get(), true);
261 gfx::Rect desktop_area = window1->parent()->bounds();
262
263 scoped_ptr<aura::Window> window2(
264 aura::test::CreateTestWindowWithId(1, NULL));
265 ash::wm::SetWindowPositionManaged(window2.get(), true);
266 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
267
268 ash::wm::MaximizeWindow(window1.get());
269 ash::wm::MinimizeWindow(window1.get());
270
271 // |window2| should be centered now.
272 EXPECT_TRUE(window2->IsVisible());
273 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get()));
274 EXPECT_EQ(base::IntToString(
275 (desktop_area.width() - window2->bounds().width()) / 2) +
276 ",48 256x512", window2->bounds().ToString());
277 }
278
279 // Test that nomral, maximize, minimizing will repos the remaining.
280 TEST_F(WorkspaceLayoutManager2Test, NormToMaxToMinRepositionsRemaining) {
281 scoped_ptr<aura::Window> window1(
282 aura::test::CreateTestWindowWithId(0, NULL));
283 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
284 ash::wm::SetWindowPositionManaged(window1.get(), true);
285 gfx::Rect desktop_area = window1->parent()->bounds();
286
287 scoped_ptr<aura::Window> window2(
288 aura::test::CreateTestWindowWithId(1, NULL));
289 ash::wm::SetWindowPositionManaged(window2.get(), true);
290 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
291
292 window1->Hide();
293 window1->Show();
294
295 // |window1| should be flush right and |window3| flush left.
296 EXPECT_EQ(base::IntToString(
297 desktop_area.width() - window1->bounds().width()) +
298 ",32 640x320", window1->bounds().ToString());
299 EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
300
301 ash::wm::MaximizeWindow(window1.get());
302 ash::wm::MinimizeWindow(window1.get());
303
304 // |window2| should be centered now.
305 EXPECT_TRUE(window2->IsVisible());
306 EXPECT_TRUE(ash::wm::IsWindowNormal(window2.get()));
307 EXPECT_EQ(base::IntToString(
308 (desktop_area.width() - window2->bounds().width()) / 2) +
309 ",48 256x512", window2->bounds().ToString());
310 }
311
312 // Test that nomral, maximize, normal will repos the remaining.
313 TEST_F(WorkspaceLayoutManager2Test, NormToMaxToNormRepositionsRemaining) {
314 scoped_ptr<aura::Window> window1(
315 aura::test::CreateTestWindowWithId(0, NULL));
316 window1->SetBounds(gfx::Rect(16, 32, 640, 320));
317 ash::wm::SetWindowPositionManaged(window1.get(), true);
318 gfx::Rect desktop_area = window1->parent()->bounds();
319
320 scoped_ptr<aura::Window> window2(
321 aura::test::CreateTestWindowWithId(1, NULL));
322 ash::wm::SetWindowPositionManaged(window2.get(), true);
323 window2->SetBounds(gfx::Rect(32, 48, 256, 512));
324
325 window1->Hide();
326 window1->Show();
327
328 // |window1| should be flush right and |window3| flush left.
329 EXPECT_EQ(base::IntToString(
330 desktop_area.width() - window1->bounds().width()) +
331 ",32 640x320", window1->bounds().ToString());
332 EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
333
334 ash::wm::MaximizeWindow(window1.get());
335 ash::wm::RestoreWindow(window1.get());
336
337 // |window1| should be flush right and |window2| flush left.
338 EXPECT_EQ(base::IntToString(
339 desktop_area.width() - window1->bounds().width()) +
340 ",32 640x320", window1->bounds().ToString());
341 EXPECT_EQ("0,48 256x512", window2->bounds().ToString());
342 }
343
344
137 } // namespace 345 } // namespace
138
139 } // namespace ash 346 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698