| OLD | NEW |
| 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/common/wm/workspace/workspace_layout_manager.h" | 5 #include "ash/common/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/common/wm/fullscreen_window_finder.h" | 10 #include "ash/common/wm/fullscreen_window_finder.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 } // namespace | 80 } // namespace |
| 81 | 81 |
| 82 using WorkspaceLayoutManagerTest = WmTestBase; | 82 using WorkspaceLayoutManagerTest = WmTestBase; |
| 83 | 83 |
| 84 // Verifies that a window containing a restore coordinate will be restored to | 84 // Verifies that a window containing a restore coordinate will be restored to |
| 85 // to the size prior to minimize, keeping the restore rectangle in tact (if | 85 // to the size prior to minimize, keeping the restore rectangle in tact (if |
| 86 // there is one). | 86 // there is one). |
| 87 TEST_F(WorkspaceLayoutManagerTest, RestoreFromMinimizeKeepsRestore) { | 87 TEST_F(WorkspaceLayoutManagerTest, RestoreFromMinimizeKeepsRestore) { |
| 88 ::ui::Window* mus_window = CreateTestWindow(gfx::Rect(1, 2, 3, 4)); | 88 ui::Window* mus_window = CreateTestWindow(gfx::Rect(1, 2, 3, 4)); |
| 89 WmWindow* window = WmWindowMus::Get(mus_window); | 89 WmWindow* window = WmWindowMus::Get(mus_window); |
| 90 gfx::Rect bounds(10, 15, 25, 35); | 90 gfx::Rect bounds(10, 15, 25, 35); |
| 91 window->SetBounds(bounds); | 91 window->SetBounds(bounds); |
| 92 | 92 |
| 93 wm::WindowState* window_state = window->GetWindowState(); | 93 wm::WindowState* window_state = window->GetWindowState(); |
| 94 | 94 |
| 95 // This will not be used for un-minimizing window. | 95 // This will not be used for un-minimizing window. |
| 96 window_state->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100)); | 96 window_state->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100)); |
| 97 window_state->Minimize(); | 97 window_state->Minimize(); |
| 98 window_state->Restore(); | 98 window_state->Restore(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 CreateTestWindowInShellWithBounds(gfx::Rect(10, -600, 200, 200))); | 142 CreateTestWindowInShellWithBounds(gfx::Rect(10, -600, 200, 200))); |
| 143 EXPECT_EQ("10,-500 200x200", window2->GetBoundsInScreen().ToString()); | 143 EXPECT_EQ("10,-500 200x200", window2->GetBoundsInScreen().ToString()); |
| 144 } | 144 } |
| 145 */ | 145 */ |
| 146 | 146 |
| 147 TEST_F(WorkspaceLayoutManagerTest, NoMinimumVisibilityForPopupWindows) { | 147 TEST_F(WorkspaceLayoutManagerTest, NoMinimumVisibilityForPopupWindows) { |
| 148 UpdateDisplay("300x400"); | 148 UpdateDisplay("300x400"); |
| 149 | 149 |
| 150 // Create a popup window out of display boundaries and make sure it is not | 150 // Create a popup window out of display boundaries and make sure it is not |
| 151 // moved to have minimum visibility. | 151 // moved to have minimum visibility. |
| 152 ::ui::Window* mus_window = | 152 ui::Window* mus_window = |
| 153 CreateTestWindow(gfx::Rect(400, 100, 50, 50), ui::wm::WINDOW_TYPE_POPUP); | 153 CreateTestWindow(gfx::Rect(400, 100, 50, 50), ui::wm::WINDOW_TYPE_POPUP); |
| 154 WmWindowMus* window = WmWindowMus::Get(mus_window); | 154 WmWindowMus* window = WmWindowMus::Get(mus_window); |
| 155 EXPECT_EQ("400,100 50x50", window->GetBoundsInScreen().ToString()); | 155 EXPECT_EQ("400,100 50x50", window->GetBoundsInScreen().ToString()); |
| 156 } | 156 } |
| 157 | 157 |
| 158 /* | 158 /* |
| 159 TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) { | 159 TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) { |
| 160 if (!SupportsHostWindowResize()) | 160 if (!SupportsHostWindowResize()) |
| 161 return; | 161 return; |
| 162 std::unique_ptr<aura::Window> window( | 162 std::unique_ptr<aura::Window> window( |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 window_observer.set_window(window2.get()); | 344 window_observer.set_window(window2.get()); |
| 345 window_state->Maximize(); | 345 window_state->Maximize(); |
| 346 EXPECT_EQ("10,20 30x40", | 346 EXPECT_EQ("10,20 30x40", |
| 347 window_state->GetRestoreBoundsInScreen().ToString()); | 347 window_state->GetRestoreBoundsInScreen().ToString()); |
| 348 window->RemoveObserver(&window_observer); | 348 window->RemoveObserver(&window_observer); |
| 349 } | 349 } |
| 350 */ | 350 */ |
| 351 | 351 |
| 352 // Verifies when a window is maximized all descendant windows have a size. | 352 // Verifies when a window is maximized all descendant windows have a size. |
| 353 TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) { | 353 TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) { |
| 354 ::ui::Window* mus_window = CreateTestWindow(gfx::Rect(10, 20, 30, 40)); | 354 ui::Window* mus_window = CreateTestWindow(gfx::Rect(10, 20, 30, 40)); |
| 355 WmWindow* window = WmWindowMus::Get(mus_window); | 355 WmWindow* window = WmWindowMus::Get(mus_window); |
| 356 | 356 |
| 357 wm::WindowState* window_state = window->GetWindowState(); | 357 wm::WindowState* window_state = window->GetWindowState(); |
| 358 window_state->Activate(); | 358 window_state->Activate(); |
| 359 ::ui::Window* child_window = | 359 ui::Window* child_window = |
| 360 CreateChildTestWindow(mus_window, gfx::Rect(5, 6, 7, 8)); | 360 CreateChildTestWindow(mus_window, gfx::Rect(5, 6, 7, 8)); |
| 361 window_state->Maximize(); | 361 window_state->Maximize(); |
| 362 EXPECT_EQ("5,6 7x8", child_window->bounds().ToString()); | 362 EXPECT_EQ("5,6 7x8", child_window->bounds().ToString()); |
| 363 } | 363 } |
| 364 | 364 |
| 365 // Verifies a window created with maximized state has the maximized | 365 // Verifies a window created with maximized state has the maximized |
| 366 // bounds. | 366 // bounds. |
| 367 TEST_F(WorkspaceLayoutManagerTest, MaximizeWithEmptySize) { | 367 TEST_F(WorkspaceLayoutManagerTest, MaximizeWithEmptySize) { |
| 368 ::ui::Window* mus_window = CreateTestWindow(gfx::Rect()); | 368 ui::Window* mus_window = CreateTestWindow(gfx::Rect()); |
| 369 WmWindowMus* window = WmWindowMus::Get(mus_window); | 369 WmWindowMus* window = WmWindowMus::Get(mus_window); |
| 370 window->GetWindowState()->Maximize(); | 370 window->GetWindowState()->Maximize(); |
| 371 gfx::Rect work_area(GetPrimaryDisplay().work_area()); | 371 gfx::Rect work_area(GetPrimaryDisplay().work_area()); |
| 372 EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString()); | 372 EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString()); |
| 373 } | 373 } |
| 374 | 374 |
| 375 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { | 375 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { |
| 376 // Normal window bounds shouldn't be changed. | 376 // Normal window bounds shouldn't be changed. |
| 377 gfx::Rect window_bounds(100, 100, 200, 200); | 377 gfx::Rect window_bounds(100, 100, 200, 200); |
| 378 ::ui::Window* mus_window = CreateTestWindow(window_bounds); | 378 ui::Window* mus_window = CreateTestWindow(window_bounds); |
| 379 WmWindow* window = WmWindowMus::Get(mus_window); | 379 WmWindow* window = WmWindowMus::Get(mus_window); |
| 380 EXPECT_EQ(window_bounds, mus_window->bounds()); | 380 EXPECT_EQ(window_bounds, mus_window->bounds()); |
| 381 | 381 |
| 382 // If the window is out of the workspace, it would be moved on screen. | 382 // If the window is out of the workspace, it would be moved on screen. |
| 383 gfx::Rect root_window_bounds = GetPrimaryRootWindow()->bounds(); | 383 gfx::Rect root_window_bounds = GetPrimaryRootWindow()->bounds(); |
| 384 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height()); | 384 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height()); |
| 385 ASSERT_FALSE(window_bounds.Intersects(root_window_bounds)); | 385 ASSERT_FALSE(window_bounds.Intersects(root_window_bounds)); |
| 386 ::ui::Window* out_mus_window = CreateTestWindow(window_bounds); | 386 ui::Window* out_mus_window = CreateTestWindow(window_bounds); |
| 387 WmWindow* out_window = WmWindowMus::Get(out_mus_window); | 387 WmWindow* out_window = WmWindowMus::Get(out_mus_window); |
| 388 EXPECT_EQ(window_bounds.size(), out_mus_window->bounds().size()); | 388 EXPECT_EQ(window_bounds.size(), out_mus_window->bounds().size()); |
| 389 gfx::Rect bounds = out_mus_window->bounds(); | 389 gfx::Rect bounds = out_mus_window->bounds(); |
| 390 bounds.Intersect(root_window_bounds); | 390 bounds.Intersect(root_window_bounds); |
| 391 | 391 |
| 392 // 30% of the window edge must be visible. | 392 // 30% of the window edge must be visible. |
| 393 EXPECT_GT(bounds.width(), out_mus_window->bounds().width() * 0.29); | 393 EXPECT_GT(bounds.width(), out_mus_window->bounds().width() * 0.29); |
| 394 EXPECT_GT(bounds.height(), out_mus_window->bounds().height() * 0.29); | 394 EXPECT_GT(bounds.height(), out_mus_window->bounds().height() * 0.29); |
| 395 | 395 |
| 396 ::ui::Window* mus_parent = out_mus_window->parent(); | 396 ui::Window* mus_parent = out_mus_window->parent(); |
| 397 mus_parent->RemoveChild(out_mus_window); | 397 mus_parent->RemoveChild(out_mus_window); |
| 398 out_window->SetBounds(gfx::Rect(-200, -200, 200, 200)); | 398 out_window->SetBounds(gfx::Rect(-200, -200, 200, 200)); |
| 399 // UserHasChangedWindowPositionOrSize flag shouldn't turn off this behavior. | 399 // UserHasChangedWindowPositionOrSize flag shouldn't turn off this behavior. |
| 400 window->GetWindowState()->set_bounds_changed_by_user(true); | 400 window->GetWindowState()->set_bounds_changed_by_user(true); |
| 401 mus_parent->AddChild(out_mus_window); | 401 mus_parent->AddChild(out_mus_window); |
| 402 EXPECT_GT(bounds.width(), out_mus_window->bounds().width() * 0.29); | 402 EXPECT_GT(bounds.width(), out_mus_window->bounds().width() * 0.29); |
| 403 EXPECT_GT(bounds.height(), out_mus_window->bounds().height() * 0.29); | 403 EXPECT_GT(bounds.height(), out_mus_window->bounds().height() * 0.29); |
| 404 | 404 |
| 405 // Make sure we always make more than 1/3 of the window edge visible even | 405 // Make sure we always make more than 1/3 of the window edge visible even |
| 406 // if the initial bounds intersects with display. | 406 // if the initial bounds intersects with display. |
| 407 window_bounds.SetRect(-150, -150, 200, 200); | 407 window_bounds.SetRect(-150, -150, 200, 200); |
| 408 bounds = window_bounds; | 408 bounds = window_bounds; |
| 409 bounds.Intersect(root_window_bounds); | 409 bounds.Intersect(root_window_bounds); |
| 410 | 410 |
| 411 // Make sure that the initial bounds' visible area is less than 26% | 411 // Make sure that the initial bounds' visible area is less than 26% |
| 412 // so that the auto adjustment logic kicks in. | 412 // so that the auto adjustment logic kicks in. |
| 413 ASSERT_LT(bounds.width(), out_mus_window->bounds().width() * 0.26); | 413 ASSERT_LT(bounds.width(), out_mus_window->bounds().width() * 0.26); |
| 414 ASSERT_LT(bounds.height(), out_mus_window->bounds().height() * 0.26); | 414 ASSERT_LT(bounds.height(), out_mus_window->bounds().height() * 0.26); |
| 415 ASSERT_TRUE(window_bounds.Intersects(root_window_bounds)); | 415 ASSERT_TRUE(window_bounds.Intersects(root_window_bounds)); |
| 416 | 416 |
| 417 ::ui::Window* partially_out_mus_window = CreateTestWindow(window_bounds); | 417 ui::Window* partially_out_mus_window = CreateTestWindow(window_bounds); |
| 418 EXPECT_EQ(window_bounds.size(), partially_out_mus_window->bounds().size()); | 418 EXPECT_EQ(window_bounds.size(), partially_out_mus_window->bounds().size()); |
| 419 bounds = partially_out_mus_window->bounds(); | 419 bounds = partially_out_mus_window->bounds(); |
| 420 bounds.Intersect(root_window_bounds); | 420 bounds.Intersect(root_window_bounds); |
| 421 EXPECT_GT(bounds.width(), out_mus_window->bounds().width() * 0.29); | 421 EXPECT_GT(bounds.width(), out_mus_window->bounds().width() * 0.29); |
| 422 EXPECT_GT(bounds.height(), out_mus_window->bounds().height() * 0.29); | 422 EXPECT_GT(bounds.height(), out_mus_window->bounds().height() * 0.29); |
| 423 | 423 |
| 424 // Make sure the window whose 30% width/height is bigger than display | 424 // Make sure the window whose 30% width/height is bigger than display |
| 425 // will be placed correctly. | 425 // will be placed correctly. |
| 426 window_bounds.SetRect(-1900, -1900, 3000, 3000); | 426 window_bounds.SetRect(-1900, -1900, 3000, 3000); |
| 427 ::ui::Window* mus_window_bigger_than_display = | 427 ui::Window* mus_window_bigger_than_display = CreateTestWindow(window_bounds); |
| 428 CreateTestWindow(window_bounds); | |
| 429 EXPECT_GE(root_window_bounds.width(), | 428 EXPECT_GE(root_window_bounds.width(), |
| 430 mus_window_bigger_than_display->bounds().width()); | 429 mus_window_bigger_than_display->bounds().width()); |
| 431 EXPECT_GE(root_window_bounds.height(), | 430 EXPECT_GE(root_window_bounds.height(), |
| 432 mus_window_bigger_than_display->bounds().height()); | 431 mus_window_bigger_than_display->bounds().height()); |
| 433 | 432 |
| 434 bounds = mus_window_bigger_than_display->bounds(); | 433 bounds = mus_window_bigger_than_display->bounds(); |
| 435 bounds.Intersect(root_window_bounds); | 434 bounds.Intersect(root_window_bounds); |
| 436 EXPECT_GT(bounds.width(), out_mus_window->bounds().width() * 0.29); | 435 EXPECT_GT(bounds.width(), out_mus_window->bounds().width() * 0.29); |
| 437 EXPECT_GT(bounds.height(), out_mus_window->bounds().height() * 0.29); | 436 EXPECT_GT(bounds.height(), out_mus_window->bounds().height() * 0.29); |
| 438 } | 437 } |
| 439 | 438 |
| 440 // Verifies the size of a window is enforced to be smaller than the work area. | 439 // Verifies the size of a window is enforced to be smaller than the work area. |
| 441 TEST_F(WorkspaceLayoutManagerTest, SizeToWorkArea) { | 440 TEST_F(WorkspaceLayoutManagerTest, SizeToWorkArea) { |
| 442 // Normal window bounds shouldn't be changed. | 441 // Normal window bounds shouldn't be changed. |
| 443 gfx::Size work_area(GetPrimaryDisplay().work_area().size()); | 442 gfx::Size work_area(GetPrimaryDisplay().work_area().size()); |
| 444 const gfx::Rect window_bounds(100, 101, work_area.width() + 1, | 443 const gfx::Rect window_bounds(100, 101, work_area.width() + 1, |
| 445 work_area.height() + 2); | 444 work_area.height() + 2); |
| 446 ::ui::Window* window = CreateTestWindow(window_bounds); | 445 ui::Window* window = CreateTestWindow(window_bounds); |
| 447 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), | 446 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), |
| 448 window->bounds().ToString()); | 447 window->bounds().ToString()); |
| 449 | 448 |
| 450 // Directly setting the bounds triggers a slightly different code path. Verify | 449 // Directly setting the bounds triggers a slightly different code path. Verify |
| 451 // that too. | 450 // that too. |
| 452 WmWindowMus::Get(window)->SetBounds(window_bounds); | 451 WmWindowMus::Get(window)->SetBounds(window_bounds); |
| 453 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), | 452 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), |
| 454 window->bounds().ToString()); | 453 window->bounds().ToString()); |
| 455 } | 454 } |
| 456 | 455 |
| 457 TEST_F(WorkspaceLayoutManagerTest, NotifyFullscreenChanges) { | 456 TEST_F(WorkspaceLayoutManagerTest, NotifyFullscreenChanges) { |
| 458 FullscreenObserver observer( | 457 FullscreenObserver observer( |
| 459 WmWindowMus::Get(GetPrimaryRootWindow())->GetRootWindowController()); | 458 WmWindowMus::Get(GetPrimaryRootWindow())->GetRootWindowController()); |
| 460 ::ui::Window* window1 = CreateTestWindow(gfx::Rect(1, 2, 30, 40)); | 459 ui::Window* window1 = CreateTestWindow(gfx::Rect(1, 2, 30, 40)); |
| 461 ::ui::Window* window2 = CreateTestWindow(gfx::Rect(1, 2, 30, 40)); | 460 ui::Window* window2 = CreateTestWindow(gfx::Rect(1, 2, 30, 40)); |
| 462 wm::WindowState* window_state1 = WmWindowMus::Get(window1)->GetWindowState(); | 461 wm::WindowState* window_state1 = WmWindowMus::Get(window1)->GetWindowState(); |
| 463 wm::WindowState* window_state2 = WmWindowMus::Get(window2)->GetWindowState(); | 462 wm::WindowState* window_state2 = WmWindowMus::Get(window2)->GetWindowState(); |
| 464 window_state2->Activate(); | 463 window_state2->Activate(); |
| 465 | 464 |
| 466 const wm::WMEvent toggle_fullscreen_event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | 465 const wm::WMEvent toggle_fullscreen_event(wm::WM_EVENT_TOGGLE_FULLSCREEN); |
| 467 window_state2->OnWMEvent(&toggle_fullscreen_event); | 466 window_state2->OnWMEvent(&toggle_fullscreen_event); |
| 468 EXPECT_EQ(1, observer.call_count()); | 467 EXPECT_EQ(1, observer.call_count()); |
| 469 EXPECT_TRUE(observer.is_fullscreen()); | 468 EXPECT_TRUE(observer.is_fullscreen()); |
| 470 | 469 |
| 471 // When window1 moves to the front the fullscreen state should change. | 470 // When window1 moves to the front the fullscreen state should change. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 490 window2->Destroy(); | 489 window2->Destroy(); |
| 491 EXPECT_EQ(6, observer.call_count()); | 490 EXPECT_EQ(6, observer.call_count()); |
| 492 EXPECT_FALSE(observer.is_fullscreen()); | 491 EXPECT_FALSE(observer.is_fullscreen()); |
| 493 } | 492 } |
| 494 // Following "Solo" tests were originally written for BaseLayoutManager. | 493 // Following "Solo" tests were originally written for BaseLayoutManager. |
| 495 using WorkspaceLayoutManagerSoloTest = WmTestBase; | 494 using WorkspaceLayoutManagerSoloTest = WmTestBase; |
| 496 | 495 |
| 497 // Tests normal->maximize->normal. | 496 // Tests normal->maximize->normal. |
| 498 TEST_F(WorkspaceLayoutManagerSoloTest, Maximize) { | 497 TEST_F(WorkspaceLayoutManagerSoloTest, Maximize) { |
| 499 gfx::Rect bounds(100, 100, 200, 200); | 498 gfx::Rect bounds(100, 100, 200, 200); |
| 500 ::ui::Window* mus_window = CreateTestWindow(bounds); | 499 ui::Window* mus_window = CreateTestWindow(bounds); |
| 501 WmWindow* window = WmWindowMus::Get(mus_window); | 500 WmWindow* window = WmWindowMus::Get(mus_window); |
| 502 window->SetShowState(ui::SHOW_STATE_MAXIMIZED); | 501 window->SetShowState(ui::SHOW_STATE_MAXIMIZED); |
| 503 // Maximized window fills the work area, not the whole display. | 502 // Maximized window fills the work area, not the whole display. |
| 504 EXPECT_EQ(wm::GetMaximizedWindowBoundsInParent(window).ToString(), | 503 EXPECT_EQ(wm::GetMaximizedWindowBoundsInParent(window).ToString(), |
| 505 mus_window->bounds().ToString()); | 504 mus_window->bounds().ToString()); |
| 506 window->SetShowState(ui::SHOW_STATE_NORMAL); | 505 window->SetShowState(ui::SHOW_STATE_NORMAL); |
| 507 EXPECT_EQ(bounds.ToString(), mus_window->bounds().ToString()); | 506 EXPECT_EQ(bounds.ToString(), mus_window->bounds().ToString()); |
| 508 } | 507 } |
| 509 | 508 |
| 510 // Tests normal->minimize->normal. | 509 // Tests normal->minimize->normal. |
| 511 TEST_F(WorkspaceLayoutManagerSoloTest, Minimize) { | 510 TEST_F(WorkspaceLayoutManagerSoloTest, Minimize) { |
| 512 gfx::Rect bounds(100, 100, 200, 200); | 511 gfx::Rect bounds(100, 100, 200, 200); |
| 513 ::ui::Window* mus_window = CreateTestWindow(bounds); | 512 ui::Window* mus_window = CreateTestWindow(bounds); |
| 514 WmWindow* window = WmWindowMus::Get(mus_window); | 513 WmWindow* window = WmWindowMus::Get(mus_window); |
| 515 window->SetShowState(ui::SHOW_STATE_MINIMIZED); | 514 window->SetShowState(ui::SHOW_STATE_MINIMIZED); |
| 516 // Note: Currently minimize doesn't do anything except set the state. | 515 // Note: Currently minimize doesn't do anything except set the state. |
| 517 // See crbug.com/104571. | 516 // See crbug.com/104571. |
| 518 EXPECT_EQ(bounds.ToString(), mus_window->bounds().ToString()); | 517 EXPECT_EQ(bounds.ToString(), mus_window->bounds().ToString()); |
| 519 window->SetShowState(ui::SHOW_STATE_NORMAL); | 518 window->SetShowState(ui::SHOW_STATE_NORMAL); |
| 520 EXPECT_EQ(bounds.ToString(), mus_window->bounds().ToString()); | 519 EXPECT_EQ(bounds.ToString(), mus_window->bounds().ToString()); |
| 521 } | 520 } |
| 522 | 521 |
| 523 // A WindowObserver which sets the focus when the window becomes visible. | 522 // A WindowObserver which sets the focus when the window becomes visible. |
| 524 class FocusObserver : public ::ui::WindowObserver { | 523 class FocusObserver : public ui::WindowObserver { |
| 525 public: | 524 public: |
| 526 explicit FocusObserver(::ui::Window* window) | 525 explicit FocusObserver(ui::Window* window) |
| 527 : window_(window), show_state_(ui::SHOW_STATE_END) { | 526 : window_(window), show_state_(ui::SHOW_STATE_END) { |
| 528 window_->AddObserver(this); | 527 window_->AddObserver(this); |
| 529 } | 528 } |
| 530 ~FocusObserver() override { window_->RemoveObserver(this); } | 529 ~FocusObserver() override { window_->RemoveObserver(this); } |
| 531 | 530 |
| 532 // aura::test::TestWindowDelegate overrides: | 531 // aura::test::TestWindowDelegate overrides: |
| 533 void OnWindowVisibilityChanged(::ui::Window* window) override { | 532 void OnWindowVisibilityChanged(ui::Window* window) override { |
| 534 if (window_->visible()) | 533 if (window_->visible()) |
| 535 window_->SetFocus(); | 534 window_->SetFocus(); |
| 536 show_state_ = WmWindowMus::Get(window_)->GetShowState(); | 535 show_state_ = WmWindowMus::Get(window_)->GetShowState(); |
| 537 } | 536 } |
| 538 | 537 |
| 539 ui::WindowShowState GetShowStateAndReset() { | 538 ui::WindowShowState GetShowStateAndReset() { |
| 540 ui::WindowShowState ret = show_state_; | 539 ui::WindowShowState ret = show_state_; |
| 541 show_state_ = ui::SHOW_STATE_END; | 540 show_state_ = ui::SHOW_STATE_END; |
| 542 return ret; | 541 return ret; |
| 543 } | 542 } |
| 544 | 543 |
| 545 private: | 544 private: |
| 546 ::ui::Window* window_; | 545 ui::Window* window_; |
| 547 ui::WindowShowState show_state_; | 546 ui::WindowShowState show_state_; |
| 548 | 547 |
| 549 DISALLOW_COPY_AND_ASSIGN(FocusObserver); | 548 DISALLOW_COPY_AND_ASSIGN(FocusObserver); |
| 550 }; | 549 }; |
| 551 | 550 |
| 552 // Make sure that the window's show state is correct in | 551 // Make sure that the window's show state is correct in |
| 553 // |ui::WindowObserver::OnWindowVisibilityChanged|, and setting | 552 // |ui::WindowObserver::OnWindowVisibilityChanged|, and setting |
| 554 // focus in this callback doesn't cause DCHECK error. See | 553 // focus in this callback doesn't cause DCHECK error. See |
| 555 // crbug.com/168383. | 554 // crbug.com/168383. |
| 556 // NOTE: this was adapted from the ash test of the same name, I suspect this | 555 // NOTE: this was adapted from the ash test of the same name, I suspect this |
| 557 // test isn't particularly useful for mash. | 556 // test isn't particularly useful for mash. |
| 558 TEST_F(WorkspaceLayoutManagerSoloTest, FocusDuringUnminimize) { | 557 TEST_F(WorkspaceLayoutManagerSoloTest, FocusDuringUnminimize) { |
| 559 ::ui::Window* mus_window = CreateTestWindow(gfx::Rect(100, 100, 100, 100)); | 558 ui::Window* mus_window = CreateTestWindow(gfx::Rect(100, 100, 100, 100)); |
| 560 WmWindow* window = WmWindowMus::Get(mus_window); | 559 WmWindow* window = WmWindowMus::Get(mus_window); |
| 561 FocusObserver observer(mus_window); | 560 FocusObserver observer(mus_window); |
| 562 window->SetShowState(ui::SHOW_STATE_MINIMIZED); | 561 window->SetShowState(ui::SHOW_STATE_MINIMIZED); |
| 563 EXPECT_FALSE(window->IsVisible()); | 562 EXPECT_FALSE(window->IsVisible()); |
| 564 EXPECT_EQ(ui::SHOW_STATE_MINIMIZED, observer.GetShowStateAndReset()); | 563 EXPECT_EQ(ui::SHOW_STATE_MINIMIZED, observer.GetShowStateAndReset()); |
| 565 window->Show(); | 564 window->Show(); |
| 566 EXPECT_TRUE(window->IsVisible()); | 565 EXPECT_TRUE(window->IsVisible()); |
| 567 EXPECT_EQ(ui::SHOW_STATE_NORMAL, observer.GetShowStateAndReset()); | 566 EXPECT_EQ(ui::SHOW_STATE_NORMAL, observer.GetShowStateAndReset()); |
| 568 } | 567 } |
| 569 | 568 |
| 570 // Tests maximized window size during root window resize. | 569 // Tests maximized window size during root window resize. |
| 571 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeRootWindowResize) { | 570 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeRootWindowResize) { |
| 572 gfx::Rect bounds(100, 100, 200, 200); | 571 gfx::Rect bounds(100, 100, 200, 200); |
| 573 ::ui::Window* mus_window = CreateTestWindow(bounds); | 572 ui::Window* mus_window = CreateTestWindow(bounds); |
| 574 WmWindow* window = WmWindowMus::Get(mus_window); | 573 WmWindow* window = WmWindowMus::Get(mus_window); |
| 575 window->SetShowState(ui::SHOW_STATE_MAXIMIZED); | 574 window->SetShowState(ui::SHOW_STATE_MAXIMIZED); |
| 576 gfx::Rect initial_work_area_bounds = | 575 gfx::Rect initial_work_area_bounds = |
| 577 wm::GetMaximizedWindowBoundsInParent(window); | 576 wm::GetMaximizedWindowBoundsInParent(window); |
| 578 EXPECT_EQ(initial_work_area_bounds.ToString(), | 577 EXPECT_EQ(initial_work_area_bounds.ToString(), |
| 579 mus_window->bounds().ToString()); | 578 mus_window->bounds().ToString()); |
| 580 // Enlarge the root window. We should still match the work area size. | 579 // Enlarge the root window. We should still match the work area size. |
| 581 UpdateDisplay("900x700"); | 580 UpdateDisplay("900x700"); |
| 582 EXPECT_EQ(wm::GetMaximizedWindowBoundsInParent(window).ToString(), | 581 EXPECT_EQ(wm::GetMaximizedWindowBoundsInParent(window).ToString(), |
| 583 mus_window->bounds().ToString()); | 582 mus_window->bounds().ToString()); |
| 584 EXPECT_NE(initial_work_area_bounds.ToString(), | 583 EXPECT_NE(initial_work_area_bounds.ToString(), |
| 585 wm::GetMaximizedWindowBoundsInParent(window).ToString()); | 584 wm::GetMaximizedWindowBoundsInParent(window).ToString()); |
| 586 } | 585 } |
| 587 | 586 |
| 588 // Tests normal->fullscreen->normal. | 587 // Tests normal->fullscreen->normal. |
| 589 TEST_F(WorkspaceLayoutManagerSoloTest, Fullscreen) { | 588 TEST_F(WorkspaceLayoutManagerSoloTest, Fullscreen) { |
| 590 gfx::Rect bounds(100, 100, 200, 200); | 589 gfx::Rect bounds(100, 100, 200, 200); |
| 591 ::ui::Window* mus_window = CreateTestWindow(bounds); | 590 ui::Window* mus_window = CreateTestWindow(bounds); |
| 592 WmWindow* window = WmWindowMus::Get(mus_window); | 591 WmWindow* window = WmWindowMus::Get(mus_window); |
| 593 window->SetShowState(ui::SHOW_STATE_FULLSCREEN); | 592 window->SetShowState(ui::SHOW_STATE_FULLSCREEN); |
| 594 // Fullscreen window fills the whole display. | 593 // Fullscreen window fills the whole display. |
| 595 EXPECT_EQ(window->GetDisplayNearestWindow().bounds().ToString(), | 594 EXPECT_EQ(window->GetDisplayNearestWindow().bounds().ToString(), |
| 596 mus_window->bounds().ToString()); | 595 mus_window->bounds().ToString()); |
| 597 window->SetShowState(ui::SHOW_STATE_NORMAL); | 596 window->SetShowState(ui::SHOW_STATE_NORMAL); |
| 598 EXPECT_EQ(bounds.ToString(), mus_window->bounds().ToString()); | 597 EXPECT_EQ(bounds.ToString(), mus_window->bounds().ToString()); |
| 599 } | 598 } |
| 600 | 599 |
| 601 // Tests that fullscreen window causes always_on_top windows to stack below. | 600 // Tests that fullscreen window causes always_on_top windows to stack below. |
| 602 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenSuspendsAlwaysOnTop) { | 601 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenSuspendsAlwaysOnTop) { |
| 603 gfx::Rect bounds(100, 100, 200, 200); | 602 gfx::Rect bounds(100, 100, 200, 200); |
| 604 ::ui::Window* mus_fullscreen_window = CreateTestWindow(bounds); | 603 ui::Window* mus_fullscreen_window = CreateTestWindow(bounds); |
| 605 WmWindowMus* fullscreen_window = WmWindowMus::Get(mus_fullscreen_window); | 604 WmWindowMus* fullscreen_window = WmWindowMus::Get(mus_fullscreen_window); |
| 606 ::ui::Window* mus_always_on_top_window1 = CreateTestWindow(bounds); | 605 ui::Window* mus_always_on_top_window1 = CreateTestWindow(bounds); |
| 607 WmWindowMus* always_on_top_window1 = | 606 WmWindowMus* always_on_top_window1 = |
| 608 WmWindowMus::Get(mus_always_on_top_window1); | 607 WmWindowMus::Get(mus_always_on_top_window1); |
| 609 ::ui::Window* mus_always_on_top_window2 = CreateTestWindow(bounds); | 608 ui::Window* mus_always_on_top_window2 = CreateTestWindow(bounds); |
| 610 WmWindowMus* always_on_top_window2 = | 609 WmWindowMus* always_on_top_window2 = |
| 611 WmWindowMus::Get(mus_always_on_top_window2); | 610 WmWindowMus::Get(mus_always_on_top_window2); |
| 612 always_on_top_window1->SetAlwaysOnTop(true); | 611 always_on_top_window1->SetAlwaysOnTop(true); |
| 613 always_on_top_window2->SetAlwaysOnTop(true); | 612 always_on_top_window2->SetAlwaysOnTop(true); |
| 614 // Making a window fullscreen temporarily suspends always on top state. | 613 // Making a window fullscreen temporarily suspends always on top state. |
| 615 fullscreen_window->SetShowState(ui::SHOW_STATE_FULLSCREEN); | 614 fullscreen_window->SetShowState(ui::SHOW_STATE_FULLSCREEN); |
| 616 EXPECT_FALSE(always_on_top_window1->IsAlwaysOnTop()); | 615 EXPECT_FALSE(always_on_top_window1->IsAlwaysOnTop()); |
| 617 EXPECT_FALSE(always_on_top_window2->IsAlwaysOnTop()); | 616 EXPECT_FALSE(always_on_top_window2->IsAlwaysOnTop()); |
| 618 EXPECT_TRUE(wm::GetWindowForFullscreenMode(fullscreen_window)); | 617 EXPECT_TRUE(wm::GetWindowForFullscreenMode(fullscreen_window)); |
| 619 // Making fullscreen window normal restores always on top windows. | 618 // Making fullscreen window normal restores always on top windows. |
| 620 fullscreen_window->SetShowState(ui::SHOW_STATE_NORMAL); | 619 fullscreen_window->SetShowState(ui::SHOW_STATE_NORMAL); |
| 621 EXPECT_TRUE(always_on_top_window1->IsAlwaysOnTop()); | 620 EXPECT_TRUE(always_on_top_window1->IsAlwaysOnTop()); |
| 622 EXPECT_TRUE(always_on_top_window2->IsAlwaysOnTop()); | 621 EXPECT_TRUE(always_on_top_window2->IsAlwaysOnTop()); |
| 623 EXPECT_FALSE(wm::GetWindowForFullscreenMode(fullscreen_window)); | 622 EXPECT_FALSE(wm::GetWindowForFullscreenMode(fullscreen_window)); |
| 624 } | 623 } |
| 625 | 624 |
| 626 // Tests fullscreen window size during root window resize. | 625 // Tests fullscreen window size during root window resize. |
| 627 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenRootWindowResize) { | 626 TEST_F(WorkspaceLayoutManagerSoloTest, FullscreenRootWindowResize) { |
| 628 gfx::Rect bounds(100, 100, 200, 200); | 627 gfx::Rect bounds(100, 100, 200, 200); |
| 629 ::ui::Window* mus_window = CreateTestWindow(bounds); | 628 ui::Window* mus_window = CreateTestWindow(bounds); |
| 630 WmWindow* window = WmWindowMus::Get(mus_window); | 629 WmWindow* window = WmWindowMus::Get(mus_window); |
| 631 // Fullscreen window fills the whole display. | 630 // Fullscreen window fills the whole display. |
| 632 window->SetShowState(ui::SHOW_STATE_FULLSCREEN); | 631 window->SetShowState(ui::SHOW_STATE_FULLSCREEN); |
| 633 EXPECT_EQ(window->GetDisplayNearestWindow().bounds().ToString(), | 632 EXPECT_EQ(window->GetDisplayNearestWindow().bounds().ToString(), |
| 634 mus_window->bounds().ToString()); | 633 mus_window->bounds().ToString()); |
| 635 // Enlarge the root window. We should still match the display size. | 634 // Enlarge the root window. We should still match the display size. |
| 636 UpdateDisplay("1001x1201"); | 635 UpdateDisplay("1001x1201"); |
| 637 EXPECT_EQ(window->GetDisplayNearestWindow().bounds().ToString(), | 636 EXPECT_EQ(window->GetDisplayNearestWindow().bounds().ToString(), |
| 638 mus_window->bounds().ToString()); | 637 mus_window->bounds().ToString()); |
| 639 } | 638 } |
| 640 | 639 |
| 641 // Tests that when the screen gets smaller the windows aren't bigger than | 640 // Tests that when the screen gets smaller the windows aren't bigger than |
| 642 // the screen. | 641 // the screen. |
| 643 TEST_F(WorkspaceLayoutManagerSoloTest, RootWindowResizeShrinksWindows) { | 642 TEST_F(WorkspaceLayoutManagerSoloTest, RootWindowResizeShrinksWindows) { |
| 644 ::ui::Window* mus_window = CreateTestWindow(gfx::Rect(10, 20, 500, 400)); | 643 ui::Window* mus_window = CreateTestWindow(gfx::Rect(10, 20, 500, 400)); |
| 645 WmWindow* window = WmWindowMus::Get(mus_window); | 644 WmWindow* window = WmWindowMus::Get(mus_window); |
| 646 gfx::Rect work_area = window->GetDisplayNearestWindow().work_area(); | 645 gfx::Rect work_area = window->GetDisplayNearestWindow().work_area(); |
| 647 // Invariant: Window is smaller than work area. | 646 // Invariant: Window is smaller than work area. |
| 648 EXPECT_LE(mus_window->bounds().width(), work_area.width()); | 647 EXPECT_LE(mus_window->bounds().width(), work_area.width()); |
| 649 EXPECT_LE(mus_window->bounds().height(), work_area.height()); | 648 EXPECT_LE(mus_window->bounds().height(), work_area.height()); |
| 650 | 649 |
| 651 // Make the root window narrower than our window. | 650 // Make the root window narrower than our window. |
| 652 UpdateDisplay("300x400"); | 651 UpdateDisplay("300x400"); |
| 653 work_area = window->GetDisplayNearestWindow().work_area(); | 652 work_area = window->GetDisplayNearestWindow().work_area(); |
| 654 EXPECT_LE(mus_window->bounds().width(), work_area.width()); | 653 EXPECT_LE(mus_window->bounds().width(), work_area.width()); |
| 655 EXPECT_LE(mus_window->bounds().height(), work_area.height()); | 654 EXPECT_LE(mus_window->bounds().height(), work_area.height()); |
| 656 | 655 |
| 657 // Make the root window shorter than our window. | 656 // Make the root window shorter than our window. |
| 658 UpdateDisplay("300x200"); | 657 UpdateDisplay("300x200"); |
| 659 work_area = window->GetDisplayNearestWindow().work_area(); | 658 work_area = window->GetDisplayNearestWindow().work_area(); |
| 660 EXPECT_LE(mus_window->bounds().width(), work_area.width()); | 659 EXPECT_LE(mus_window->bounds().width(), work_area.width()); |
| 661 EXPECT_LE(mus_window->bounds().height(), work_area.height()); | 660 EXPECT_LE(mus_window->bounds().height(), work_area.height()); |
| 662 | 661 |
| 663 // Enlarging the root window does not change the window bounds. | 662 // Enlarging the root window does not change the window bounds. |
| 664 gfx::Rect old_bounds = mus_window->bounds(); | 663 gfx::Rect old_bounds = mus_window->bounds(); |
| 665 UpdateDisplay("800x600"); | 664 UpdateDisplay("800x600"); |
| 666 EXPECT_EQ(old_bounds.width(), mus_window->bounds().width()); | 665 EXPECT_EQ(old_bounds.width(), mus_window->bounds().width()); |
| 667 EXPECT_EQ(old_bounds.height(), mus_window->bounds().height()); | 666 EXPECT_EQ(old_bounds.height(), mus_window->bounds().height()); |
| 668 } | 667 } |
| 669 | 668 |
| 670 // Verifies maximizing sets the restore bounds, and restoring | 669 // Verifies maximizing sets the restore bounds, and restoring |
| 671 // restores the bounds. | 670 // restores the bounds. |
| 672 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeSetsRestoreBounds) { | 671 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeSetsRestoreBounds) { |
| 673 ::ui::Window* mus_window = CreateTestWindow(gfx::Rect(10, 20, 30, 40)); | 672 ui::Window* mus_window = CreateTestWindow(gfx::Rect(10, 20, 30, 40)); |
| 674 WmWindow* window = WmWindowMus::Get(mus_window); | 673 WmWindow* window = WmWindowMus::Get(mus_window); |
| 675 wm::WindowState* window_state = window->GetWindowState(); | 674 wm::WindowState* window_state = window->GetWindowState(); |
| 676 | 675 |
| 677 // Maximize it, which will keep the previous restore bounds. | 676 // Maximize it, which will keep the previous restore bounds. |
| 678 window->SetShowState(ui::SHOW_STATE_MAXIMIZED); | 677 window->SetShowState(ui::SHOW_STATE_MAXIMIZED); |
| 679 EXPECT_EQ("10,20 30x40", window_state->GetRestoreBoundsInParent().ToString()); | 678 EXPECT_EQ("10,20 30x40", window_state->GetRestoreBoundsInParent().ToString()); |
| 680 | 679 |
| 681 // Restore it, which should restore bounds and reset restore bounds. | 680 // Restore it, which should restore bounds and reset restore bounds. |
| 682 window->SetShowState(ui::SHOW_STATE_NORMAL); | 681 window->SetShowState(ui::SHOW_STATE_NORMAL); |
| 683 EXPECT_EQ("10,20 30x40", mus_window->bounds().ToString()); | 682 EXPECT_EQ("10,20 30x40", mus_window->bounds().ToString()); |
| 684 EXPECT_FALSE(window_state->HasRestoreBounds()); | 683 EXPECT_FALSE(window_state->HasRestoreBounds()); |
| 685 } | 684 } |
| 686 | 685 |
| 687 // Verifies maximizing keeps the restore bounds if set. | 686 // Verifies maximizing keeps the restore bounds if set. |
| 688 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeResetsRestoreBounds) { | 687 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeResetsRestoreBounds) { |
| 689 ::ui::Window* mus_window = CreateTestWindow(gfx::Rect(1, 2, 3, 4)); | 688 ui::Window* mus_window = CreateTestWindow(gfx::Rect(1, 2, 3, 4)); |
| 690 WmWindow* window = WmWindowMus::Get(mus_window); | 689 WmWindow* window = WmWindowMus::Get(mus_window); |
| 691 | 690 |
| 692 wm::WindowState* window_state = window->GetWindowState(); | 691 wm::WindowState* window_state = window->GetWindowState(); |
| 693 window_state->SetRestoreBoundsInParent(gfx::Rect(10, 11, 12, 13)); | 692 window_state->SetRestoreBoundsInParent(gfx::Rect(10, 11, 12, 13)); |
| 694 | 693 |
| 695 // Maximize it, which will keep the previous restore bounds. | 694 // Maximize it, which will keep the previous restore bounds. |
| 696 window->SetShowState(ui::SHOW_STATE_MAXIMIZED); | 695 window->SetShowState(ui::SHOW_STATE_MAXIMIZED); |
| 697 EXPECT_EQ("10,11 12x13", window_state->GetRestoreBoundsInParent().ToString()); | 696 EXPECT_EQ("10,11 12x13", window_state->GetRestoreBoundsInParent().ToString()); |
| 698 } | 697 } |
| 699 | 698 |
| 700 // Verifies that the restore bounds do not get reset when restoring to a | 699 // Verifies that the restore bounds do not get reset when restoring to a |
| 701 // maximzied state from a minimized state. | 700 // maximzied state from a minimized state. |
| 702 TEST_F(WorkspaceLayoutManagerSoloTest, | 701 TEST_F(WorkspaceLayoutManagerSoloTest, |
| 703 BoundsAfterRestoringToMaximizeFromMinimize) { | 702 BoundsAfterRestoringToMaximizeFromMinimize) { |
| 704 ::ui::Window* mus_window = CreateTestWindow(gfx::Rect(1, 2, 3, 4)); | 703 ui::Window* mus_window = CreateTestWindow(gfx::Rect(1, 2, 3, 4)); |
| 705 WmWindow* window = WmWindowMus::Get(mus_window); | 704 WmWindow* window = WmWindowMus::Get(mus_window); |
| 706 gfx::Rect bounds(10, 15, 25, 35); | 705 gfx::Rect bounds(10, 15, 25, 35); |
| 707 window->SetBounds(bounds); | 706 window->SetBounds(bounds); |
| 708 | 707 |
| 709 wm::WindowState* window_state = window->GetWindowState(); | 708 wm::WindowState* window_state = window->GetWindowState(); |
| 710 // Maximize it, which should reset restore bounds. | 709 // Maximize it, which should reset restore bounds. |
| 711 window_state->Maximize(); | 710 window_state->Maximize(); |
| 712 EXPECT_EQ(bounds.ToString(), | 711 EXPECT_EQ(bounds.ToString(), |
| 713 window_state->GetRestoreBoundsInParent().ToString()); | 712 window_state->GetRestoreBoundsInParent().ToString()); |
| 714 // Minimize the window. The restore bounds should not change. | 713 // Minimize the window. The restore bounds should not change. |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1095 occluded_window_bounds.width(), | 1094 occluded_window_bounds.width(), |
| 1096 occluded_window_bounds.height()).ToString(), | 1095 occluded_window_bounds.height()).ToString(), |
| 1097 window->bounds().ToString()); | 1096 window->bounds().ToString()); |
| 1098 HideKeyboard(); | 1097 HideKeyboard(); |
| 1099 EXPECT_EQ(occluded_window_bounds.ToString(), window->bounds().ToString()); | 1098 EXPECT_EQ(occluded_window_bounds.ToString(), window->bounds().ToString()); |
| 1100 } | 1099 } |
| 1101 */ | 1100 */ |
| 1102 | 1101 |
| 1103 } // namespace mus | 1102 } // namespace mus |
| 1104 } // namespace ash | 1103 } // namespace ash |
| OLD | NEW |