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

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

Issue 1867223004: Convert //ash from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 8 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
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 <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 }; 93 };
94 94
95 } // namespace 95 } // namespace
96 96
97 typedef test::AshTestBase WorkspaceLayoutManagerTest; 97 typedef test::AshTestBase WorkspaceLayoutManagerTest;
98 98
99 // Verifies that a window containing a restore coordinate will be restored to 99 // Verifies that a window containing a restore coordinate will be restored to
100 // to the size prior to minimize, keeping the restore rectangle in tact (if 100 // to the size prior to minimize, keeping the restore rectangle in tact (if
101 // there is one). 101 // there is one).
102 TEST_F(WorkspaceLayoutManagerTest, RestoreFromMinimizeKeepsRestore) { 102 TEST_F(WorkspaceLayoutManagerTest, RestoreFromMinimizeKeepsRestore) {
103 scoped_ptr<aura::Window> window( 103 std::unique_ptr<aura::Window> window(
104 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); 104 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4)));
105 gfx::Rect bounds(10, 15, 25, 35); 105 gfx::Rect bounds(10, 15, 25, 35);
106 window->SetBounds(bounds); 106 window->SetBounds(bounds);
107 107
108 wm::WindowState* window_state = wm::GetWindowState(window.get()); 108 wm::WindowState* window_state = wm::GetWindowState(window.get());
109 109
110 // This will not be used for un-minimizing window. 110 // This will not be used for un-minimizing window.
111 window_state->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100)); 111 window_state->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100));
112 window_state->Minimize(); 112 window_state->Minimize();
113 window_state->Restore(); 113 window_state->Restore();
(...skipping 27 matching lines...) Expand all
141 if (!SupportsMultipleDisplays()) 141 if (!SupportsMultipleDisplays())
142 return; 142 return;
143 143
144 UpdateDisplay("300x400,400x500"); 144 UpdateDisplay("300x400,400x500");
145 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 145 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
146 146
147 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays( 147 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
148 test::CreateDisplayLayout(display::DisplayPlacement::TOP, 0)); 148 test::CreateDisplayLayout(display::DisplayPlacement::TOP, 0));
149 EXPECT_EQ("0,-500 400x500", root_windows[1]->GetBoundsInScreen().ToString()); 149 EXPECT_EQ("0,-500 400x500", root_windows[1]->GetBoundsInScreen().ToString());
150 150
151 scoped_ptr<aura::Window> window1( 151 std::unique_ptr<aura::Window> window1(
152 CreateTestWindowInShellWithBounds(gfx::Rect(10, -400, 200, 200))); 152 CreateTestWindowInShellWithBounds(gfx::Rect(10, -400, 200, 200)));
153 EXPECT_EQ("10,-400 200x200", window1->GetBoundsInScreen().ToString()); 153 EXPECT_EQ("10,-400 200x200", window1->GetBoundsInScreen().ToString());
154 154
155 // Make sure the caption is visible. 155 // Make sure the caption is visible.
156 scoped_ptr<aura::Window> window2( 156 std::unique_ptr<aura::Window> window2(
157 CreateTestWindowInShellWithBounds(gfx::Rect(10, -600, 200, 200))); 157 CreateTestWindowInShellWithBounds(gfx::Rect(10, -600, 200, 200)));
158 EXPECT_EQ("10,-500 200x200", window2->GetBoundsInScreen().ToString()); 158 EXPECT_EQ("10,-500 200x200", window2->GetBoundsInScreen().ToString());
159 } 159 }
160 160
161 TEST_F(WorkspaceLayoutManagerTest, NoMinimumVisibilityForPopupWindows) { 161 TEST_F(WorkspaceLayoutManagerTest, NoMinimumVisibilityForPopupWindows) {
162 UpdateDisplay("300x400"); 162 UpdateDisplay("300x400");
163 163
164 // Create a popup window out of display boundaries and make sure it is not 164 // Create a popup window out of display boundaries and make sure it is not
165 // moved to have minimum visibility. 165 // moved to have minimum visibility.
166 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegateAndType( 166 std::unique_ptr<aura::Window> window(
167 nullptr, ui::wm::WINDOW_TYPE_POPUP, 0, gfx::Rect(400, 100, 50, 50))); 167 CreateTestWindowInShellWithDelegateAndType(
168 nullptr, ui::wm::WINDOW_TYPE_POPUP, 0, gfx::Rect(400, 100, 50, 50)));
168 EXPECT_EQ("400,100 50x50", window->GetBoundsInScreen().ToString()); 169 EXPECT_EQ("400,100 50x50", window->GetBoundsInScreen().ToString());
169 } 170 }
170 171
171 TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) { 172 TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) {
172 if (!SupportsHostWindowResize()) 173 if (!SupportsHostWindowResize())
173 return; 174 return;
174 scoped_ptr<aura::Window> window( 175 std::unique_ptr<aura::Window> window(
175 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); 176 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
176 wm::WindowState* window_state = wm::GetWindowState(window.get()); 177 wm::WindowState* window_state = wm::GetWindowState(window.get());
177 178
178 // Maximized -> Normal transition. 179 // Maximized -> Normal transition.
179 window_state->Maximize(); 180 window_state->Maximize();
180 window_state->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40)); 181 window_state->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40));
181 window_state->Restore(); 182 window_state->Restore();
182 EXPECT_TRUE( 183 EXPECT_TRUE(
183 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); 184 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
184 // Y bounds should not be negative. 185 // Y bounds should not be negative.
(...skipping 24 matching lines...) Expand all
209 EXPECT_EQ("-5,0 30x40", window->bounds().ToString()); 210 EXPECT_EQ("-5,0 30x40", window->bounds().ToString());
210 } 211 }
211 212
212 TEST_F(WorkspaceLayoutManagerTest, MaximizeInDisplayToBeRestored) { 213 TEST_F(WorkspaceLayoutManagerTest, MaximizeInDisplayToBeRestored) {
213 if (!SupportsMultipleDisplays()) 214 if (!SupportsMultipleDisplays())
214 return; 215 return;
215 UpdateDisplay("300x400,400x500"); 216 UpdateDisplay("300x400,400x500");
216 217
217 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 218 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
218 219
219 scoped_ptr<aura::Window> window( 220 std::unique_ptr<aura::Window> window(
220 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); 221 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
221 EXPECT_EQ(root_windows[0], window->GetRootWindow()); 222 EXPECT_EQ(root_windows[0], window->GetRootWindow());
222 223
223 wm::WindowState* window_state = wm::GetWindowState(window.get()); 224 wm::WindowState* window_state = wm::GetWindowState(window.get());
224 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40)); 225 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40));
225 // Maximize the window in 2nd display as the restore bounds 226 // Maximize the window in 2nd display as the restore bounds
226 // is inside 2nd display. 227 // is inside 2nd display.
227 window_state->Maximize(); 228 window_state->Maximize();
228 EXPECT_EQ(root_windows[1], window->GetRootWindow()); 229 EXPECT_EQ(root_windows[1], window->GetRootWindow());
229 EXPECT_EQ("300,0 400x453", window->GetBoundsInScreen().ToString()); 230 EXPECT_EQ("300,0 400x453", window->GetBoundsInScreen().ToString());
230 231
231 window_state->Restore(); 232 window_state->Restore();
232 EXPECT_EQ(root_windows[1], window->GetRootWindow()); 233 EXPECT_EQ(root_windows[1], window->GetRootWindow());
233 EXPECT_EQ("400,0 30x40", window->GetBoundsInScreen().ToString()); 234 EXPECT_EQ("400,0 30x40", window->GetBoundsInScreen().ToString());
234 235
235 // If the restore bounds intersects with the current display, 236 // If the restore bounds intersects with the current display,
236 // don't move. 237 // don't move.
237 window_state->SetRestoreBoundsInScreen(gfx::Rect(295, 0, 30, 40)); 238 window_state->SetRestoreBoundsInScreen(gfx::Rect(295, 0, 30, 40));
238 window_state->Maximize(); 239 window_state->Maximize();
239 EXPECT_EQ(root_windows[1], window->GetRootWindow()); 240 EXPECT_EQ(root_windows[1], window->GetRootWindow());
240 EXPECT_EQ("300,0 400x453", window->GetBoundsInScreen().ToString()); 241 EXPECT_EQ("300,0 400x453", window->GetBoundsInScreen().ToString());
241 242
242 window_state->Restore(); 243 window_state->Restore();
243 EXPECT_EQ(root_windows[1], window->GetRootWindow()); 244 EXPECT_EQ(root_windows[1], window->GetRootWindow());
244 EXPECT_EQ("295,0 30x40", window->GetBoundsInScreen().ToString()); 245 EXPECT_EQ("295,0 30x40", window->GetBoundsInScreen().ToString());
245 246
246 // Restoring widget state. 247 // Restoring widget state.
247 scoped_ptr<views::Widget> w1(new views::Widget); 248 std::unique_ptr<views::Widget> w1(new views::Widget);
248 views::Widget::InitParams params; 249 views::Widget::InitParams params;
249 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 250 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
250 params.delegate = new MaximizeDelegateView(gfx::Rect(400, 0, 30, 40)); 251 params.delegate = new MaximizeDelegateView(gfx::Rect(400, 0, 30, 40));
251 params.context = root_windows[0]; 252 params.context = root_windows[0];
252 w1->Init(params); 253 w1->Init(params);
253 w1->Show(); 254 w1->Show();
254 EXPECT_TRUE(w1->IsMaximized()); 255 EXPECT_TRUE(w1->IsMaximized());
255 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); 256 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
256 EXPECT_EQ("300,0 400x453", w1->GetWindowBoundsInScreen().ToString()); 257 EXPECT_EQ("300,0 400x453", w1->GetWindowBoundsInScreen().ToString());
257 w1->Restore(); 258 w1->Restore();
258 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); 259 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow());
259 EXPECT_EQ("400,0 30x40", w1->GetWindowBoundsInScreen().ToString()); 260 EXPECT_EQ("400,0 30x40", w1->GetWindowBoundsInScreen().ToString());
260 } 261 }
261 262
262 TEST_F(WorkspaceLayoutManagerTest, FullscreenInDisplayToBeRestored) { 263 TEST_F(WorkspaceLayoutManagerTest, FullscreenInDisplayToBeRestored) {
263 if (!SupportsMultipleDisplays()) 264 if (!SupportsMultipleDisplays())
264 return; 265 return;
265 UpdateDisplay("300x400,400x500"); 266 UpdateDisplay("300x400,400x500");
266 267
267 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 268 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
268 269
269 scoped_ptr<aura::Window> window( 270 std::unique_ptr<aura::Window> window(
270 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); 271 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
271 EXPECT_EQ(root_windows[0], window->GetRootWindow()); 272 EXPECT_EQ(root_windows[0], window->GetRootWindow());
272 273
273 wm::WindowState* window_state = wm::GetWindowState(window.get()); 274 wm::WindowState* window_state = wm::GetWindowState(window.get());
274 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40)); 275 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40));
275 // Maximize the window in 2nd display as the restore bounds 276 // Maximize the window in 2nd display as the restore bounds
276 // is inside 2nd display. 277 // is inside 2nd display.
277 window->SetProperty(aura::client::kShowStateKey, 278 window->SetProperty(aura::client::kShowStateKey,
278 ui::SHOW_STATE_FULLSCREEN); 279 ui::SHOW_STATE_FULLSCREEN);
279 EXPECT_EQ(root_windows[1], window->GetRootWindow()); 280 EXPECT_EQ(root_windows[1], window->GetRootWindow());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 aura::Window* window_; 329 aura::Window* window_;
329 330
330 DISALLOW_COPY_AND_ASSIGN(DontClobberRestoreBoundsWindowObserver); 331 DISALLOW_COPY_AND_ASSIGN(DontClobberRestoreBoundsWindowObserver);
331 }; 332 };
332 333
333 // Creates a window, maximized the window and from within the maximized 334 // Creates a window, maximized the window and from within the maximized
334 // notification sets the bounds of a window to overlap the shelf. Verifies this 335 // notification sets the bounds of a window to overlap the shelf. Verifies this
335 // doesn't effect the restore bounds. 336 // doesn't effect the restore bounds.
336 TEST_F(WorkspaceLayoutManagerTest, DontClobberRestoreBounds) { 337 TEST_F(WorkspaceLayoutManagerTest, DontClobberRestoreBounds) {
337 DontClobberRestoreBoundsWindowObserver window_observer; 338 DontClobberRestoreBoundsWindowObserver window_observer;
338 scoped_ptr<aura::Window> window(new aura::Window(nullptr)); 339 std::unique_ptr<aura::Window> window(new aura::Window(nullptr));
339 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); 340 window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
340 window->Init(ui::LAYER_TEXTURED); 341 window->Init(ui::LAYER_TEXTURED);
341 window->SetBounds(gfx::Rect(10, 20, 30, 40)); 342 window->SetBounds(gfx::Rect(10, 20, 30, 40));
342 // NOTE: for this test to exercise the failure the observer needs to be added 343 // NOTE: for this test to exercise the failure the observer needs to be added
343 // before the parent set. This mimics what BrowserFrameAsh does. 344 // before the parent set. This mimics what BrowserFrameAsh does.
344 window->AddObserver(&window_observer); 345 window->AddObserver(&window_observer);
345 ParentWindowInPrimaryRootWindow(window.get()); 346 ParentWindowInPrimaryRootWindow(window.get());
346 window->Show(); 347 window->Show();
347 348
348 wm::WindowState* window_state = wm::GetWindowState(window.get()); 349 wm::WindowState* window_state = wm::GetWindowState(window.get());
349 window_state->Activate(); 350 window_state->Activate();
350 351
351 scoped_ptr<aura::Window> window2( 352 std::unique_ptr<aura::Window> window2(
352 CreateTestWindowInShellWithBounds(gfx::Rect(12, 20, 30, 40))); 353 CreateTestWindowInShellWithBounds(gfx::Rect(12, 20, 30, 40)));
353 ::wm::AddTransientChild(window.get(), window2.get()); 354 ::wm::AddTransientChild(window.get(), window2.get());
354 window2->Show(); 355 window2->Show();
355 356
356 window_observer.set_window(window2.get()); 357 window_observer.set_window(window2.get());
357 window_state->Maximize(); 358 window_state->Maximize();
358 EXPECT_EQ("10,20 30x40", 359 EXPECT_EQ("10,20 30x40",
359 window_state->GetRestoreBoundsInScreen().ToString()); 360 window_state->GetRestoreBoundsInScreen().ToString());
360 window->RemoveObserver(&window_observer); 361 window->RemoveObserver(&window_observer);
361 } 362 }
362 363
363 // Verifies when a window is maximized all descendant windows have a size. 364 // Verifies when a window is maximized all descendant windows have a size.
364 TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) { 365 TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) {
365 scoped_ptr<aura::Window> window( 366 std::unique_ptr<aura::Window> window(
366 CreateTestWindowInShellWithBounds(gfx::Rect(10, 20, 30, 40))); 367 CreateTestWindowInShellWithBounds(gfx::Rect(10, 20, 30, 40)));
367 window->Show(); 368 window->Show();
368 wm::WindowState* window_state = wm::GetWindowState(window.get()); 369 wm::WindowState* window_state = wm::GetWindowState(window.get());
369 window_state->Activate(); 370 window_state->Activate();
370 scoped_ptr<aura::Window> child_window( 371 std::unique_ptr<aura::Window> child_window(
371 aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 6, 7, 8), 372 aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 6, 7, 8),
372 window.get())); 373 window.get()));
373 child_window->Show(); 374 child_window->Show();
374 window_state->Maximize(); 375 window_state->Maximize();
375 EXPECT_EQ("5,6 7x8", child_window->bounds().ToString()); 376 EXPECT_EQ("5,6 7x8", child_window->bounds().ToString());
376 } 377 }
377 378
378 // Verifies a window created with maximized state has the maximized 379 // Verifies a window created with maximized state has the maximized
379 // bounds. 380 // bounds.
380 TEST_F(WorkspaceLayoutManagerTest, MaximizeWithEmptySize) { 381 TEST_F(WorkspaceLayoutManagerTest, MaximizeWithEmptySize) {
381 scoped_ptr<aura::Window> window( 382 std::unique_ptr<aura::Window> window(
382 aura::test::CreateTestWindowWithBounds(gfx::Rect(0, 0, 0, 0), nullptr)); 383 aura::test::CreateTestWindowWithBounds(gfx::Rect(0, 0, 0, 0), nullptr));
383 wm::GetWindowState(window.get())->Maximize(); 384 wm::GetWindowState(window.get())->Maximize();
384 aura::Window* default_container = Shell::GetContainer( 385 aura::Window* default_container = Shell::GetContainer(
385 Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer); 386 Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer);
386 default_container->AddChild(window.get()); 387 default_container->AddChild(window.get());
387 window->Show(); 388 window->Show();
388 gfx::Rect work_area( 389 gfx::Rect work_area(
389 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area()); 390 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area());
390 EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString()); 391 EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString());
391 } 392 }
392 393
393 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { 394 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) {
394 // Normal window bounds shouldn't be changed. 395 // Normal window bounds shouldn't be changed.
395 gfx::Rect window_bounds(100, 100, 200, 200); 396 gfx::Rect window_bounds(100, 100, 200, 200);
396 scoped_ptr<aura::Window> window( 397 std::unique_ptr<aura::Window> window(
397 CreateTestWindowInShellWithBounds(window_bounds)); 398 CreateTestWindowInShellWithBounds(window_bounds));
398 EXPECT_EQ(window_bounds, window->bounds()); 399 EXPECT_EQ(window_bounds, window->bounds());
399 400
400 // If the window is out of the workspace, it would be moved on screen. 401 // If the window is out of the workspace, it would be moved on screen.
401 gfx::Rect root_window_bounds = 402 gfx::Rect root_window_bounds =
402 Shell::GetInstance()->GetPrimaryRootWindow()->bounds(); 403 Shell::GetInstance()->GetPrimaryRootWindow()->bounds();
403 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height()); 404 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height());
404 ASSERT_FALSE(window_bounds.Intersects(root_window_bounds)); 405 ASSERT_FALSE(window_bounds.Intersects(root_window_bounds));
405 scoped_ptr<aura::Window> out_window( 406 std::unique_ptr<aura::Window> out_window(
406 CreateTestWindowInShellWithBounds(window_bounds)); 407 CreateTestWindowInShellWithBounds(window_bounds));
407 EXPECT_EQ(window_bounds.size(), out_window->bounds().size()); 408 EXPECT_EQ(window_bounds.size(), out_window->bounds().size());
408 gfx::Rect bounds = out_window->bounds(); 409 gfx::Rect bounds = out_window->bounds();
409 bounds.Intersect(root_window_bounds); 410 bounds.Intersect(root_window_bounds);
410 411
411 // 30% of the window edge must be visible. 412 // 30% of the window edge must be visible.
412 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29); 413 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29);
413 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29); 414 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29);
414 415
415 aura::Window* parent = out_window->parent(); 416 aura::Window* parent = out_window->parent();
(...skipping 10 matching lines...) Expand all
426 window_bounds.SetRect(-150, -150, 200, 200); 427 window_bounds.SetRect(-150, -150, 200, 200);
427 bounds = window_bounds; 428 bounds = window_bounds;
428 bounds.Intersect(root_window_bounds); 429 bounds.Intersect(root_window_bounds);
429 430
430 // Make sure that the initial bounds' visible area is less than 26% 431 // Make sure that the initial bounds' visible area is less than 26%
431 // so that the auto adjustment logic kicks in. 432 // so that the auto adjustment logic kicks in.
432 ASSERT_LT(bounds.width(), out_window->bounds().width() * 0.26); 433 ASSERT_LT(bounds.width(), out_window->bounds().width() * 0.26);
433 ASSERT_LT(bounds.height(), out_window->bounds().height() * 0.26); 434 ASSERT_LT(bounds.height(), out_window->bounds().height() * 0.26);
434 ASSERT_TRUE(window_bounds.Intersects(root_window_bounds)); 435 ASSERT_TRUE(window_bounds.Intersects(root_window_bounds));
435 436
436 scoped_ptr<aura::Window> partially_out_window( 437 std::unique_ptr<aura::Window> partially_out_window(
437 CreateTestWindowInShellWithBounds(window_bounds)); 438 CreateTestWindowInShellWithBounds(window_bounds));
438 EXPECT_EQ(window_bounds.size(), partially_out_window->bounds().size()); 439 EXPECT_EQ(window_bounds.size(), partially_out_window->bounds().size());
439 bounds = partially_out_window->bounds(); 440 bounds = partially_out_window->bounds();
440 bounds.Intersect(root_window_bounds); 441 bounds.Intersect(root_window_bounds);
441 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29); 442 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29);
442 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29); 443 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29);
443 444
444 // Make sure the window whose 30% width/height is bigger than display 445 // Make sure the window whose 30% width/height is bigger than display
445 // will be placed correctly. 446 // will be placed correctly.
446 window_bounds.SetRect(-1900, -1900, 3000, 3000); 447 window_bounds.SetRect(-1900, -1900, 3000, 3000);
447 scoped_ptr<aura::Window> window_bigger_than_display( 448 std::unique_ptr<aura::Window> window_bigger_than_display(
448 CreateTestWindowInShellWithBounds(window_bounds)); 449 CreateTestWindowInShellWithBounds(window_bounds));
449 EXPECT_GE(root_window_bounds.width(), 450 EXPECT_GE(root_window_bounds.width(),
450 window_bigger_than_display->bounds().width()); 451 window_bigger_than_display->bounds().width());
451 EXPECT_GE(root_window_bounds.height(), 452 EXPECT_GE(root_window_bounds.height(),
452 window_bigger_than_display->bounds().height()); 453 window_bigger_than_display->bounds().height());
453 454
454 bounds = window_bigger_than_display->bounds(); 455 bounds = window_bigger_than_display->bounds();
455 bounds.Intersect(root_window_bounds); 456 bounds.Intersect(root_window_bounds);
456 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29); 457 EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.29);
457 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29); 458 EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.29);
458 } 459 }
459 460
460 // Verifies the size of a window is enforced to be smaller than the work area. 461 // Verifies the size of a window is enforced to be smaller than the work area.
461 TEST_F(WorkspaceLayoutManagerTest, SizeToWorkArea) { 462 TEST_F(WorkspaceLayoutManagerTest, SizeToWorkArea) {
462 // Normal window bounds shouldn't be changed. 463 // Normal window bounds shouldn't be changed.
463 gfx::Size work_area( 464 gfx::Size work_area(
464 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area().size()); 465 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area().size());
465 const gfx::Rect window_bounds( 466 const gfx::Rect window_bounds(
466 100, 101, work_area.width() + 1, work_area.height() + 2); 467 100, 101, work_area.width() + 1, work_area.height() + 2);
467 scoped_ptr<aura::Window> window( 468 std::unique_ptr<aura::Window> window(
468 CreateTestWindowInShellWithBounds(window_bounds)); 469 CreateTestWindowInShellWithBounds(window_bounds));
469 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), 470 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(),
470 window->bounds().ToString()); 471 window->bounds().ToString());
471 472
472 // Directly setting the bounds triggers a slightly different code path. Verify 473 // Directly setting the bounds triggers a slightly different code path. Verify
473 // that too. 474 // that too.
474 window->SetBounds(window_bounds); 475 window->SetBounds(window_bounds);
475 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), 476 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(),
476 window->bounds().ToString()); 477 window->bounds().ToString());
477 } 478 }
478 479
479 TEST_F(WorkspaceLayoutManagerTest, NotifyFullscreenChanges) { 480 TEST_F(WorkspaceLayoutManagerTest, NotifyFullscreenChanges) {
480 TestShellObserver observer; 481 TestShellObserver observer;
481 scoped_ptr<aura::Window> window1( 482 std::unique_ptr<aura::Window> window1(
482 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); 483 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
483 scoped_ptr<aura::Window> window2( 484 std::unique_ptr<aura::Window> window2(
484 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); 485 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
485 wm::WindowState* window_state1 = wm::GetWindowState(window1.get()); 486 wm::WindowState* window_state1 = wm::GetWindowState(window1.get());
486 wm::WindowState* window_state2 = wm::GetWindowState(window2.get()); 487 wm::WindowState* window_state2 = wm::GetWindowState(window2.get());
487 window_state2->Activate(); 488 window_state2->Activate();
488 489
489 const wm::WMEvent toggle_fullscreen_event(wm::WM_EVENT_TOGGLE_FULLSCREEN); 490 const wm::WMEvent toggle_fullscreen_event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
490 window_state2->OnWMEvent(&toggle_fullscreen_event); 491 window_state2->OnWMEvent(&toggle_fullscreen_event);
491 EXPECT_EQ(1, observer.call_count()); 492 EXPECT_EQ(1, observer.call_count());
492 EXPECT_TRUE(observer.is_fullscreen()); 493 EXPECT_TRUE(observer.is_fullscreen());
493 494
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 530
530 private: 531 private:
531 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerSoloTest); 532 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerSoloTest);
532 }; 533 };
533 534
534 } // namespace 535 } // namespace
535 536
536 // Tests normal->maximize->normal. 537 // Tests normal->maximize->normal.
537 TEST_F(WorkspaceLayoutManagerSoloTest, Maximize) { 538 TEST_F(WorkspaceLayoutManagerSoloTest, Maximize) {
538 gfx::Rect bounds(100, 100, 200, 200); 539 gfx::Rect bounds(100, 100, 200, 200);
539 scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); 540 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds));
540 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 541 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
541 // Maximized window fills the work area, not the whole display. 542 // Maximized window fills the work area, not the whole display.
542 EXPECT_EQ( 543 EXPECT_EQ(
543 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(), 544 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(),
544 window->bounds().ToString()); 545 window->bounds().ToString());
545 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 546 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
546 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); 547 EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
547 } 548 }
548 549
549 // Tests normal->minimize->normal. 550 // Tests normal->minimize->normal.
550 TEST_F(WorkspaceLayoutManagerSoloTest, Minimize) { 551 TEST_F(WorkspaceLayoutManagerSoloTest, Minimize) {
551 gfx::Rect bounds(100, 100, 200, 200); 552 gfx::Rect bounds(100, 100, 200, 200);
552 scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); 553 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds));
553 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); 554 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
554 // Note: Currently minimize doesn't do anything except set the state. 555 // Note: Currently minimize doesn't do anything except set the state.
555 // See crbug.com/104571. 556 // See crbug.com/104571.
556 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); 557 EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
557 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 558 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
558 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); 559 EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
559 } 560 }
560 561
561 // A WindowDelegate which sets the focus when the window 562 // A WindowDelegate which sets the focus when the window
562 // becomes visible. 563 // becomes visible.
(...skipping 25 matching lines...) Expand all
588 589
589 DISALLOW_COPY_AND_ASSIGN(FocusDelegate); 590 DISALLOW_COPY_AND_ASSIGN(FocusDelegate);
590 }; 591 };
591 592
592 // Make sure that the window's show state is correct in 593 // Make sure that the window's show state is correct in
593 // |WindowDelegate::OnWindowTargetVisibilityChanged|, and setting 594 // |WindowDelegate::OnWindowTargetVisibilityChanged|, and setting
594 // focus in this callback doesn't cause DCHECK error. See 595 // focus in this callback doesn't cause DCHECK error. See
595 // crbug.com/168383. 596 // crbug.com/168383.
596 TEST_F(WorkspaceLayoutManagerSoloTest, FocusDuringUnminimize) { 597 TEST_F(WorkspaceLayoutManagerSoloTest, FocusDuringUnminimize) {
597 FocusDelegate delegate; 598 FocusDelegate delegate;
598 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 599 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
599 &delegate, 0, gfx::Rect(100, 100, 100, 100))); 600 &delegate, 0, gfx::Rect(100, 100, 100, 100)));
600 delegate.set_window(window.get()); 601 delegate.set_window(window.get());
601 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); 602 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
602 EXPECT_FALSE(window->IsVisible()); 603 EXPECT_FALSE(window->IsVisible());
603 EXPECT_EQ(ui::SHOW_STATE_MINIMIZED, delegate.GetShowStateAndReset()); 604 EXPECT_EQ(ui::SHOW_STATE_MINIMIZED, delegate.GetShowStateAndReset());
604 window->Show(); 605 window->Show();
605 EXPECT_TRUE(window->IsVisible()); 606 EXPECT_TRUE(window->IsVisible());
606 EXPECT_EQ(ui::SHOW_STATE_NORMAL, delegate.GetShowStateAndReset()); 607 EXPECT_EQ(ui::SHOW_STATE_NORMAL, delegate.GetShowStateAndReset());
607 } 608 }
608 609
609 // Tests maximized window size during root window resize. 610 // Tests maximized window size during root window resize.
610 #if defined(OS_WIN) && !defined(USE_ASH) 611 #if defined(OS_WIN) && !defined(USE_ASH)
611 // TODO(msw): Broken on Windows. http://crbug.com/584038 612 // TODO(msw): Broken on Windows. http://crbug.com/584038
612 #define MAYBE_MaximizeRootWindowResize DISABLED_MaximizeRootWindowResize 613 #define MAYBE_MaximizeRootWindowResize DISABLED_MaximizeRootWindowResize
613 #else 614 #else
614 #define MAYBE_MaximizeRootWindowResize MaximizeRootWindowResize 615 #define MAYBE_MaximizeRootWindowResize MaximizeRootWindowResize
615 #endif 616 #endif
616 TEST_F(WorkspaceLayoutManagerSoloTest, MAYBE_MaximizeRootWindowResize) { 617 TEST_F(WorkspaceLayoutManagerSoloTest, MAYBE_MaximizeRootWindowResize) {
617 gfx::Rect bounds(100, 100, 200, 200); 618 gfx::Rect bounds(100, 100, 200, 200);
618 scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); 619 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds));
619 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 620 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
620 gfx::Rect initial_work_area_bounds = 621 gfx::Rect initial_work_area_bounds =
621 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()); 622 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get());
622 EXPECT_EQ(initial_work_area_bounds.ToString(), window->bounds().ToString()); 623 EXPECT_EQ(initial_work_area_bounds.ToString(), window->bounds().ToString());
623 // Enlarge the root window. We should still match the work area size. 624 // Enlarge the root window. We should still match the work area size.
624 UpdateDisplay("900x700"); 625 UpdateDisplay("900x700");
625 EXPECT_EQ( 626 EXPECT_EQ(
626 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(), 627 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(),
627 window->bounds().ToString()); 628 window->bounds().ToString());
628 EXPECT_NE( 629 EXPECT_NE(
629 initial_work_area_bounds.ToString(), 630 initial_work_area_bounds.ToString(),
630 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString()); 631 ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString());
631 } 632 }
632 633
633 // Tests normal->fullscreen->normal. 634 // Tests normal->fullscreen->normal.
634 TEST_F(WorkspaceLayoutManagerSoloTest, Fullscreen) { 635 TEST_F(WorkspaceLayoutManagerSoloTest, Fullscreen) {
635 gfx::Rect bounds(100, 100, 200, 200); 636 gfx::Rect bounds(100, 100, 200, 200);
636 scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); 637 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds));
637 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); 638 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
638 // Fullscreen window fills the whole display. 639 // Fullscreen window fills the whole display.
639 EXPECT_EQ(gfx::Screen::GetScreen() 640 EXPECT_EQ(gfx::Screen::GetScreen()
640 ->GetDisplayNearestWindow(window.get()) 641 ->GetDisplayNearestWindow(window.get())
641 .bounds() 642 .bounds()
642 .ToString(), 643 .ToString(),
643 window->bounds().ToString()); 644 window->bounds().ToString());
644 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 645 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
645 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); 646 EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
646 } 647 }
647 648
648 // Tests that fullscreen window causes always_on_top windows to stack below. 649 // Tests that fullscreen window causes always_on_top windows to stack below.
649 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenSuspendsAlwaysOnTop) { 650 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenSuspendsAlwaysOnTop) {
650 gfx::Rect bounds(100, 100, 200, 200); 651 gfx::Rect bounds(100, 100, 200, 200);
651 scoped_ptr<aura::Window> fullscreen_window(CreateTestWindow(bounds)); 652 std::unique_ptr<aura::Window> fullscreen_window(CreateTestWindow(bounds));
652 scoped_ptr<aura::Window> always_on_top_window1(CreateTestWindow(bounds)); 653 std::unique_ptr<aura::Window> always_on_top_window1(CreateTestWindow(bounds));
653 scoped_ptr<aura::Window> always_on_top_window2(CreateTestWindow(bounds)); 654 std::unique_ptr<aura::Window> always_on_top_window2(CreateTestWindow(bounds));
654 always_on_top_window1->SetProperty(aura::client::kAlwaysOnTopKey, true); 655 always_on_top_window1->SetProperty(aura::client::kAlwaysOnTopKey, true);
655 always_on_top_window2->SetProperty(aura::client::kAlwaysOnTopKey, true); 656 always_on_top_window2->SetProperty(aura::client::kAlwaysOnTopKey, true);
656 // Making a window fullscreen temporarily suspends always on top state. 657 // Making a window fullscreen temporarily suspends always on top state.
657 fullscreen_window->SetProperty(aura::client::kShowStateKey, 658 fullscreen_window->SetProperty(aura::client::kShowStateKey,
658 ui::SHOW_STATE_FULLSCREEN); 659 ui::SHOW_STATE_FULLSCREEN);
659 EXPECT_FALSE( 660 EXPECT_FALSE(
660 always_on_top_window1->GetProperty(aura::client::kAlwaysOnTopKey)); 661 always_on_top_window1->GetProperty(aura::client::kAlwaysOnTopKey));
661 EXPECT_FALSE( 662 EXPECT_FALSE(
662 always_on_top_window2->GetProperty(aura::client::kAlwaysOnTopKey)); 663 always_on_top_window2->GetProperty(aura::client::kAlwaysOnTopKey));
663 EXPECT_NE(nullptr, GetRootWindowController(fullscreen_window->GetRootWindow()) 664 EXPECT_NE(nullptr, GetRootWindowController(fullscreen_window->GetRootWindow())
664 ->GetWindowForFullscreenMode()); 665 ->GetWindowForFullscreenMode());
665 // Making fullscreen window normal restores always on top windows. 666 // Making fullscreen window normal restores always on top windows.
666 fullscreen_window->SetProperty(aura::client::kShowStateKey, 667 fullscreen_window->SetProperty(aura::client::kShowStateKey,
667 ui::SHOW_STATE_NORMAL); 668 ui::SHOW_STATE_NORMAL);
668 EXPECT_TRUE( 669 EXPECT_TRUE(
669 always_on_top_window1->GetProperty(aura::client::kAlwaysOnTopKey)); 670 always_on_top_window1->GetProperty(aura::client::kAlwaysOnTopKey));
670 EXPECT_TRUE( 671 EXPECT_TRUE(
671 always_on_top_window2->GetProperty(aura::client::kAlwaysOnTopKey)); 672 always_on_top_window2->GetProperty(aura::client::kAlwaysOnTopKey));
672 EXPECT_EQ(nullptr, GetRootWindowController(fullscreen_window->GetRootWindow()) 673 EXPECT_EQ(nullptr, GetRootWindowController(fullscreen_window->GetRootWindow())
673 ->GetWindowForFullscreenMode()); 674 ->GetWindowForFullscreenMode());
674 } 675 }
675 676
676 // Tests fullscreen window size during root window resize. 677 // Tests fullscreen window size during root window resize.
677 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenRootWindowResize) { 678 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenRootWindowResize) {
678 gfx::Rect bounds(100, 100, 200, 200); 679 gfx::Rect bounds(100, 100, 200, 200);
679 scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); 680 std::unique_ptr<aura::Window> window(CreateTestWindow(bounds));
680 // Fullscreen window fills the whole display. 681 // Fullscreen window fills the whole display.
681 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); 682 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
682 EXPECT_EQ(gfx::Screen::GetScreen() 683 EXPECT_EQ(gfx::Screen::GetScreen()
683 ->GetDisplayNearestWindow(window.get()) 684 ->GetDisplayNearestWindow(window.get())
684 .bounds() 685 .bounds()
685 .ToString(), 686 .ToString(),
686 window->bounds().ToString()); 687 window->bounds().ToString());
687 // Enlarge the root window. We should still match the display size. 688 // Enlarge the root window. We should still match the display size.
688 UpdateDisplay("800x600"); 689 UpdateDisplay("800x600");
689 EXPECT_EQ(gfx::Screen::GetScreen() 690 EXPECT_EQ(gfx::Screen::GetScreen()
690 ->GetDisplayNearestWindow(window.get()) 691 ->GetDisplayNearestWindow(window.get())
691 .bounds() 692 .bounds()
692 .ToString(), 693 .ToString(),
693 window->bounds().ToString()); 694 window->bounds().ToString());
694 } 695 }
695 696
696 // Tests that when the screen gets smaller the windows aren't bigger than 697 // Tests that when the screen gets smaller the windows aren't bigger than
697 // the screen. 698 // the screen.
698 TEST_F(WorkspaceLayoutManagerSoloTest, RootWindowResizeShrinksWindows) { 699 TEST_F(WorkspaceLayoutManagerSoloTest, RootWindowResizeShrinksWindows) {
699 scoped_ptr<aura::Window> window( 700 std::unique_ptr<aura::Window> window(
700 CreateTestWindow(gfx::Rect(10, 20, 500, 400))); 701 CreateTestWindow(gfx::Rect(10, 20, 500, 400)));
701 gfx::Rect work_area = gfx::Screen::GetScreen() 702 gfx::Rect work_area = gfx::Screen::GetScreen()
702 ->GetDisplayNearestWindow(window.get()) 703 ->GetDisplayNearestWindow(window.get())
703 .work_area(); 704 .work_area();
704 // Invariant: Window is smaller than work area. 705 // Invariant: Window is smaller than work area.
705 EXPECT_LE(window->bounds().width(), work_area.width()); 706 EXPECT_LE(window->bounds().width(), work_area.width());
706 EXPECT_LE(window->bounds().height(), work_area.height()); 707 EXPECT_LE(window->bounds().height(), work_area.height());
707 708
708 // Make the root window narrower than our window. 709 // Make the root window narrower than our window.
709 UpdateDisplay("300x400"); 710 UpdateDisplay("300x400");
(...skipping 14 matching lines...) Expand all
724 // Enlarging the root window does not change the window bounds. 725 // Enlarging the root window does not change the window bounds.
725 gfx::Rect old_bounds = window->bounds(); 726 gfx::Rect old_bounds = window->bounds();
726 UpdateDisplay("800x600"); 727 UpdateDisplay("800x600");
727 EXPECT_EQ(old_bounds.width(), window->bounds().width()); 728 EXPECT_EQ(old_bounds.width(), window->bounds().width());
728 EXPECT_EQ(old_bounds.height(), window->bounds().height()); 729 EXPECT_EQ(old_bounds.height(), window->bounds().height());
729 } 730 }
730 731
731 // Verifies maximizing sets the restore bounds, and restoring 732 // Verifies maximizing sets the restore bounds, and restoring
732 // restores the bounds. 733 // restores the bounds.
733 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeSetsRestoreBounds) { 734 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeSetsRestoreBounds) {
734 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(10, 20, 30, 40))); 735 std::unique_ptr<aura::Window> window(
736 CreateTestWindow(gfx::Rect(10, 20, 30, 40)));
735 wm::WindowState* window_state = wm::GetWindowState(window.get()); 737 wm::WindowState* window_state = wm::GetWindowState(window.get());
736 738
737 // Maximize it, which will keep the previous restore bounds. 739 // Maximize it, which will keep the previous restore bounds.
738 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 740 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
739 EXPECT_EQ("10,20 30x40", window_state->GetRestoreBoundsInParent().ToString()); 741 EXPECT_EQ("10,20 30x40", window_state->GetRestoreBoundsInParent().ToString());
740 742
741 // Restore it, which should restore bounds and reset restore bounds. 743 // Restore it, which should restore bounds and reset restore bounds.
742 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 744 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
743 EXPECT_EQ("10,20 30x40", window->bounds().ToString()); 745 EXPECT_EQ("10,20 30x40", window->bounds().ToString());
744 EXPECT_FALSE(window_state->HasRestoreBounds()); 746 EXPECT_FALSE(window_state->HasRestoreBounds());
745 } 747 }
746 748
747 // Verifies maximizing keeps the restore bounds if set. 749 // Verifies maximizing keeps the restore bounds if set.
748 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeResetsRestoreBounds) { 750 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeResetsRestoreBounds) {
749 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); 751 std::unique_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
750 752
751 wm::WindowState* window_state = wm::GetWindowState(window.get()); 753 wm::WindowState* window_state = wm::GetWindowState(window.get());
752 window_state->SetRestoreBoundsInParent(gfx::Rect(10, 11, 12, 13)); 754 window_state->SetRestoreBoundsInParent(gfx::Rect(10, 11, 12, 13));
753 755
754 // Maximize it, which will keep the previous restore bounds. 756 // Maximize it, which will keep the previous restore bounds.
755 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 757 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
756 EXPECT_EQ("10,11 12x13", window_state->GetRestoreBoundsInParent().ToString()); 758 EXPECT_EQ("10,11 12x13", window_state->GetRestoreBoundsInParent().ToString());
757 } 759 }
758 760
759 // Verifies that the restore bounds do not get reset when restoring to a 761 // Verifies that the restore bounds do not get reset when restoring to a
760 // maximzied state from a minimized state. 762 // maximzied state from a minimized state.
761 TEST_F(WorkspaceLayoutManagerSoloTest, 763 TEST_F(WorkspaceLayoutManagerSoloTest,
762 BoundsAfterRestoringToMaximizeFromMinimize) { 764 BoundsAfterRestoringToMaximizeFromMinimize) {
763 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); 765 std::unique_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
764 gfx::Rect bounds(10, 15, 25, 35); 766 gfx::Rect bounds(10, 15, 25, 35);
765 window->SetBounds(bounds); 767 window->SetBounds(bounds);
766 768
767 wm::WindowState* window_state = wm::GetWindowState(window.get()); 769 wm::WindowState* window_state = wm::GetWindowState(window.get());
768 // Maximize it, which should reset restore bounds. 770 // Maximize it, which should reset restore bounds.
769 window_state->Maximize(); 771 window_state->Maximize();
770 EXPECT_EQ(bounds.ToString(), 772 EXPECT_EQ(bounds.ToString(),
771 window_state->GetRestoreBoundsInParent().ToString()); 773 window_state->GetRestoreBoundsInParent().ToString());
772 // Minimize the window. The restore bounds should not change. 774 // Minimize the window. The restore bounds should not change.
773 window_state->Minimize(); 775 window_state->Minimize();
774 EXPECT_EQ(bounds.ToString(), 776 EXPECT_EQ(bounds.ToString(),
775 window_state->GetRestoreBoundsInParent().ToString()); 777 window_state->GetRestoreBoundsInParent().ToString());
776 778
777 // Show the window again. The window should be maximized, and the restore 779 // Show the window again. The window should be maximized, and the restore
778 // bounds should not change. 780 // bounds should not change.
779 window->Show(); 781 window->Show();
780 EXPECT_EQ(bounds.ToString(), 782 EXPECT_EQ(bounds.ToString(),
781 window_state->GetRestoreBoundsInParent().ToString()); 783 window_state->GetRestoreBoundsInParent().ToString());
782 EXPECT_TRUE(window_state->IsMaximized()); 784 EXPECT_TRUE(window_state->IsMaximized());
783 785
784 window_state->Restore(); 786 window_state->Restore();
785 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); 787 EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
786 } 788 }
787 789
788 // Verify if the window is not resized during screen lock. See: crbug.com/173127 790 // Verify if the window is not resized during screen lock. See: crbug.com/173127
789 TEST_F(WorkspaceLayoutManagerSoloTest, NotResizeWhenScreenIsLocked) { 791 TEST_F(WorkspaceLayoutManagerSoloTest, NotResizeWhenScreenIsLocked) {
790 SetCanLockScreen(true); 792 SetCanLockScreen(true);
791 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); 793 std::unique_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
792 // window with AlwaysOnTop will be managed by BaseLayoutManager. 794 // window with AlwaysOnTop will be managed by BaseLayoutManager.
793 window->SetProperty(aura::client::kAlwaysOnTopKey, true); 795 window->SetProperty(aura::client::kAlwaysOnTopKey, true);
794 window->Show(); 796 window->Show();
795 797
796 ShelfLayoutManager* shelf_layout_manager = 798 ShelfLayoutManager* shelf_layout_manager =
797 Shelf::ForWindow(window.get())->shelf_layout_manager(); 799 Shelf::ForWindow(window.get())->shelf_layout_manager();
798 shelf_layout_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 800 shelf_layout_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
799 801
800 window->SetBounds(ScreenUtil::GetMaximizedWindowBoundsInParent(window.get())); 802 window->SetBounds(ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()));
801 gfx::Rect window_bounds = window->bounds(); 803 gfx::Rect window_bounds = window->bounds();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 kShellWindowId_DefaultContainer); 835 kShellWindowId_DefaultContainer);
834 } 836 }
835 837
836 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { 838 aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
837 aura::Window* window = CreateTestWindowInShellWithBounds(bounds); 839 aura::Window* window = CreateTestWindowInShellWithBounds(bounds);
838 return window; 840 return window;
839 } 841 }
840 842
841 // Turn the top window back drop on / off. 843 // Turn the top window back drop on / off.
842 void ShowTopWindowBackdrop(bool show) { 844 void ShowTopWindowBackdrop(bool show) {
843 scoped_ptr<ash::WorkspaceLayoutManagerDelegate> backdrop; 845 std::unique_ptr<ash::WorkspaceLayoutManagerDelegate> backdrop;
844 if (show) { 846 if (show) {
845 backdrop.reset(new ash::WorkspaceBackdropDelegate(default_container_)); 847 backdrop.reset(new ash::WorkspaceBackdropDelegate(default_container_));
846 } 848 }
847 (static_cast<WorkspaceLayoutManager*>(default_container_->layout_manager())) 849 (static_cast<WorkspaceLayoutManager*>(default_container_->layout_manager()))
848 ->SetMaximizeBackdropDelegate(std::move(backdrop)); 850 ->SetMaximizeBackdropDelegate(std::move(backdrop));
849 // Closing and / or opening can be a delayed operation. 851 // Closing and / or opening can be a delayed operation.
850 base::MessageLoop::current()->RunUntilIdle(); 852 base::MessageLoop::current()->RunUntilIdle();
851 } 853 }
852 854
853 // Return the default container. 855 // Return the default container.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 TEST_F(WorkspaceLayoutManagerBackdropTest, BasicBackdropTests) { 902 TEST_F(WorkspaceLayoutManagerBackdropTest, BasicBackdropTests) {
901 // Create a backdrop and see that there is one window (the backdrop) and 903 // Create a backdrop and see that there is one window (the backdrop) and
902 // that the size is the same as the default container as well as that it is 904 // that the size is the same as the default container as well as that it is
903 // not visible. 905 // not visible.
904 ShowTopWindowBackdrop(true); 906 ShowTopWindowBackdrop(true);
905 ASSERT_EQ(1U, default_container()->children().size()); 907 ASSERT_EQ(1U, default_container()->children().size());
906 EXPECT_FALSE(default_container()->children()[0]->IsVisible()); 908 EXPECT_FALSE(default_container()->children()[0]->IsVisible());
907 909
908 { 910 {
909 // Add a window and make sure that the backdrop is the second child. 911 // Add a window and make sure that the backdrop is the second child.
910 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); 912 std::unique_ptr<aura::Window> window(
913 CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
911 window->Show(); 914 window->Show();
912 ASSERT_EQ(2U, default_container()->children().size()); 915 ASSERT_EQ(2U, default_container()->children().size());
913 EXPECT_TRUE(default_container()->children()[0]->IsVisible()); 916 EXPECT_TRUE(default_container()->children()[0]->IsVisible());
914 EXPECT_TRUE(default_container()->children()[1]->IsVisible()); 917 EXPECT_TRUE(default_container()->children()[1]->IsVisible());
915 EXPECT_EQ(window.get(), default_container()->children()[1]); 918 EXPECT_EQ(window.get(), default_container()->children()[1]);
916 EXPECT_EQ(default_container()->bounds().ToString(), 919 EXPECT_EQ(default_container()->bounds().ToString(),
917 default_container()->children()[0]->bounds().ToString()); 920 default_container()->children()[0]->bounds().ToString());
918 } 921 }
919 922
920 // With the window gone the backdrop should be invisible again. 923 // With the window gone the backdrop should be invisible again.
921 ASSERT_EQ(1U, default_container()->children().size()); 924 ASSERT_EQ(1U, default_container()->children().size());
922 EXPECT_FALSE(default_container()->children()[0]->IsVisible()); 925 EXPECT_FALSE(default_container()->children()[0]->IsVisible());
923 926
924 // Destroying the Backdrop should empty the container. 927 // Destroying the Backdrop should empty the container.
925 ShowTopWindowBackdrop(false); 928 ShowTopWindowBackdrop(false);
926 ASSERT_EQ(0U, default_container()->children().size()); 929 ASSERT_EQ(0U, default_container()->children().size());
927 } 930 }
928 931
929 // Verify that the backdrop gets properly created and placed. 932 // Verify that the backdrop gets properly created and placed.
930 TEST_F(WorkspaceLayoutManagerBackdropTest, VerifyBackdropAndItsStacking) { 933 TEST_F(WorkspaceLayoutManagerBackdropTest, VerifyBackdropAndItsStacking) {
931 scoped_ptr<aura::Window> window1(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); 934 std::unique_ptr<aura::Window> window1(
935 CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
932 window1->Show(); 936 window1->Show();
933 937
934 // Get the default container and check that only a single window is in there. 938 // Get the default container and check that only a single window is in there.
935 ASSERT_EQ(1U, default_container()->children().size()); 939 ASSERT_EQ(1U, default_container()->children().size());
936 EXPECT_EQ(window1.get(), default_container()->children()[0]); 940 EXPECT_EQ(window1.get(), default_container()->children()[0]);
937 EXPECT_EQ("A", 941 EXPECT_EQ("A",
938 GetWindowOrderAsString(nullptr, window1.get(), nullptr, nullptr)); 942 GetWindowOrderAsString(nullptr, window1.get(), nullptr, nullptr));
939 943
940 // Create 2 more windows and check that they are also in the container. 944 // Create 2 more windows and check that they are also in the container.
941 scoped_ptr<aura::Window> window2(CreateTestWindow(gfx::Rect(10, 2, 3, 4))); 945 std::unique_ptr<aura::Window> window2(
942 scoped_ptr<aura::Window> window3(CreateTestWindow(gfx::Rect(20, 2, 3, 4))); 946 CreateTestWindow(gfx::Rect(10, 2, 3, 4)));
947 std::unique_ptr<aura::Window> window3(
948 CreateTestWindow(gfx::Rect(20, 2, 3, 4)));
943 window2->Show(); 949 window2->Show();
944 window3->Show(); 950 window3->Show();
945 951
946 aura::Window* backdrop = nullptr; 952 aura::Window* backdrop = nullptr;
947 EXPECT_EQ("C,B,A", 953 EXPECT_EQ("C,B,A",
948 GetWindowOrderAsString(backdrop, window1.get(), window2.get(), 954 GetWindowOrderAsString(backdrop, window1.get(), window2.get(),
949 window3.get())); 955 window3.get()));
950 956
951 // Turn on the backdrop mode and check that the window shows up where it 957 // Turn on the backdrop mode and check that the window shows up where it
952 // should be (second highest number). 958 // should be (second highest number).
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 gfx::Rect work_area( 1067 gfx::Rect work_area(
1062 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area()); 1068 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area());
1063 gfx::Rect keyboard_bounds(work_area.x(), 1069 gfx::Rect keyboard_bounds(work_area.x(),
1064 work_area.y() + work_area.height() / 2, 1070 work_area.y() + work_area.height() / 2,
1065 work_area.width(), 1071 work_area.width(),
1066 work_area.height() / 2); 1072 work_area.height() / 2);
1067 1073
1068 SetKeyboardBounds(keyboard_bounds); 1074 SetKeyboardBounds(keyboard_bounds);
1069 1075
1070 aura::test::TestWindowDelegate delegate1; 1076 aura::test::TestWindowDelegate delegate1;
1071 scoped_ptr<aura::Window> parent_window(CreateTestWindowInShellWithDelegate( 1077 std::unique_ptr<aura::Window> parent_window(
1072 &delegate1, -1, work_area)); 1078 CreateTestWindowInShellWithDelegate(&delegate1, -1, work_area));
1073 aura::test::TestWindowDelegate delegate2; 1079 aura::test::TestWindowDelegate delegate2;
1074 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 1080 std::unique_ptr<aura::Window> window(
1075 &delegate2, -1, work_area)); 1081 CreateTestWindowInShellWithDelegate(&delegate2, -1, work_area));
1076 parent_window->AddChild(window.get()); 1082 parent_window->AddChild(window.get());
1077 1083
1078 wm::ActivateWindow(window.get()); 1084 wm::ActivateWindow(window.get());
1079 1085
1080 int available_height = 1086 int available_height =
1081 gfx::Screen::GetScreen()->GetPrimaryDisplay().bounds().height() - 1087 gfx::Screen::GetScreen()->GetPrimaryDisplay().bounds().height() -
1082 keyboard_bounds.height(); 1088 keyboard_bounds.height();
1083 1089
1084 gfx::Rect initial_window_bounds(50, 50, 100, 500); 1090 gfx::Rect initial_window_bounds(50, 50, 100, 500);
1085 parent_window->SetBounds(initial_window_bounds); 1091 parent_window->SetBounds(initial_window_bounds);
(...skipping 11 matching lines...) Expand all
1097 gfx::Rect work_area( 1103 gfx::Rect work_area(
1098 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area()); 1104 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area());
1099 gfx::Rect keyboard_bounds(work_area.x(), 1105 gfx::Rect keyboard_bounds(work_area.x(),
1100 work_area.y() + work_area.height() / 2, 1106 work_area.y() + work_area.height() / 2,
1101 work_area.width(), 1107 work_area.width(),
1102 work_area.height() / 2); 1108 work_area.height() / 2);
1103 1109
1104 SetKeyboardBounds(keyboard_bounds); 1110 SetKeyboardBounds(keyboard_bounds);
1105 1111
1106 aura::test::TestWindowDelegate delegate; 1112 aura::test::TestWindowDelegate delegate;
1107 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 1113 std::unique_ptr<aura::Window> window(
1108 &delegate, -1, work_area)); 1114 CreateTestWindowInShellWithDelegate(&delegate, -1, work_area));
1109 1115
1110 int available_height = 1116 int available_height =
1111 gfx::Screen::GetScreen()->GetPrimaryDisplay().bounds().height() - 1117 gfx::Screen::GetScreen()->GetPrimaryDisplay().bounds().height() -
1112 keyboard_bounds.height(); 1118 keyboard_bounds.height();
1113 1119
1114 wm::ActivateWindow(window.get()); 1120 wm::ActivateWindow(window.get());
1115 1121
1116 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString()); 1122 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->bounds().ToString());
1117 ShowKeyboard(); 1123 ShowKeyboard();
1118 EXPECT_EQ(gfx::Rect(work_area.origin(), 1124 EXPECT_EQ(gfx::Rect(work_area.origin(),
(...skipping 21 matching lines...) Expand all
1140 EXPECT_EQ(gfx::Rect(50, 1146 EXPECT_EQ(gfx::Rect(50,
1141 keyboard_bounds.y() - keyboard_bounds.height()/2, 1147 keyboard_bounds.y() - keyboard_bounds.height()/2,
1142 occluded_window_bounds.width(), 1148 occluded_window_bounds.width(),
1143 occluded_window_bounds.height()).ToString(), 1149 occluded_window_bounds.height()).ToString(),
1144 window->bounds().ToString()); 1150 window->bounds().ToString());
1145 HideKeyboard(); 1151 HideKeyboard();
1146 EXPECT_EQ(occluded_window_bounds.ToString(), window->bounds().ToString()); 1152 EXPECT_EQ(occluded_window_bounds.ToString(), window->bounds().ToString());
1147 } 1153 }
1148 1154
1149 } // namespace ash 1155 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_layout_manager.cc ('k') | ash/wm/workspace/workspace_window_resizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698