| 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/root_window_controller.h" | 5 #include "ash/root_window_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/aura/wm_window_aura.h" | 9 #include "ash/aura/wm_window_aura.h" |
| 10 #include "ash/common/material_design/material_design_controller.h" | 10 #include "ash/common/material_design/material_design_controller.h" |
| 11 #include "ash/common/session/session_state_delegate.h" | 11 #include "ash/common/session/session_state_delegate.h" |
| 12 #include "ash/common/system/tray/system_tray_delegate.h" | 12 #include "ash/common/system/tray/system_tray_delegate.h" |
| 13 #include "ash/common/wm/system_modal_container_layout_manager.h" | 13 #include "ash/common/wm/system_modal_container_layout_manager.h" |
| 14 #include "ash/common/wm/window_state.h" | 14 #include "ash/common/wm/window_state.h" |
| 15 #include "ash/common/wm_lookup.h" | 15 #include "ash/common/wm_lookup.h" |
| 16 #include "ash/common/wm_root_window_controller.h" | |
| 17 #include "ash/common/wm_shell.h" | 16 #include "ash/common/wm_shell.h" |
| 18 #include "ash/common/wm_window.h" | 17 #include "ash/common/wm_window.h" |
| 19 #include "ash/public/cpp/shell_window_ids.h" | 18 #include "ash/public/cpp/shell_window_ids.h" |
| 19 #include "ash/root_window_controller.h" |
| 20 #include "ash/shell.h" | 20 #include "ash/shell.h" |
| 21 #include "ash/test/ash_md_test_base.h" | 21 #include "ash/test/ash_md_test_base.h" |
| 22 #include "ash/test/ash_test_base.h" | 22 #include "ash/test/ash_test_base.h" |
| 23 #include "ash/wm/window_properties.h" | 23 #include "ash/wm/window_properties.h" |
| 24 #include "ash/wm/window_state_aura.h" | 24 #include "ash/wm/window_state_aura.h" |
| 25 #include "ash/wm/window_util.h" | 25 #include "ash/wm/window_util.h" |
| 26 #include "base/command_line.h" | 26 #include "base/command_line.h" |
| 27 #include "ui/aura/client/focus_change_observer.h" | 27 #include "ui/aura/client/focus_change_observer.h" |
| 28 #include "ui/aura/client/focus_client.h" | 28 #include "ui/aura/client/focus_client.h" |
| 29 #include "ui/aura/client/window_parenting_client.h" | 29 #include "ui/aura/client/window_parenting_client.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 aura::Window* lost_focus) override { | 92 aura::Window* lost_focus) override { |
| 93 if (window_ == lost_focus) | 93 if (window_ == lost_focus) |
| 94 delete window_; | 94 delete window_; |
| 95 } | 95 } |
| 96 | 96 |
| 97 aura::Window* window_; | 97 aura::Window* window_; |
| 98 | 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate); | 99 DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate); |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 WmLayoutManager* GetLayoutManager(RootWindowController* controller, int id) { |
| 103 return WmWindowAura::Get(controller->GetContainer(id))->GetLayoutManager(); |
| 104 } |
| 105 |
| 102 } // namespace | 106 } // namespace |
| 103 | 107 |
| 104 namespace test { | 108 namespace test { |
| 105 | 109 |
| 106 class RootWindowControllerTest : public AshMDTestBase { | 110 class RootWindowControllerTest : public AshMDTestBase { |
| 107 public: | 111 public: |
| 108 views::Widget* CreateTestWidget(const gfx::Rect& bounds) { | 112 views::Widget* CreateTestWidget(const gfx::Rect& bounds) { |
| 109 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( | 113 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 110 NULL, CurrentContext(), bounds); | 114 NULL, CurrentContext(), bounds); |
| 111 widget->Show(); | 115 widget->Show(); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 ASSERT_EQ(lock_screen->GetNativeWindow(), | 377 ASSERT_EQ(lock_screen->GetNativeWindow(), |
| 374 controller->GetRootWindow()->GetChildById(kLockScreenWindowId)); | 378 controller->GetRootWindow()->GetChildById(kLockScreenWindowId)); |
| 375 ASSERT_EQ(lock_wallpaper->GetNativeWindow(), | 379 ASSERT_EQ(lock_wallpaper->GetNativeWindow(), |
| 376 controller->GetRootWindow()->GetChildById(kLockWallpaperWindowId)); | 380 controller->GetRootWindow()->GetChildById(kLockWallpaperWindowId)); |
| 377 EXPECT_EQ("0,0 600x500", lock_screen->GetNativeWindow()->bounds().ToString()); | 381 EXPECT_EQ("0,0 600x500", lock_screen->GetNativeWindow()->bounds().ToString()); |
| 378 } | 382 } |
| 379 | 383 |
| 380 TEST_P(RootWindowControllerTest, ModalContainer) { | 384 TEST_P(RootWindowControllerTest, ModalContainer) { |
| 381 UpdateDisplay("600x600"); | 385 UpdateDisplay("600x600"); |
| 382 WmShell* wm_shell = WmShell::Get(); | 386 WmShell* wm_shell = WmShell::Get(); |
| 383 WmRootWindowController* controller = | 387 RootWindowController* controller = wm_shell->GetPrimaryRootWindowController(); |
| 384 wm_shell->GetPrimaryRootWindowController(); | |
| 385 EXPECT_EQ(LoginStatus::USER, | 388 EXPECT_EQ(LoginStatus::USER, |
| 386 wm_shell->system_tray_delegate()->GetUserLoginStatus()); | 389 wm_shell->system_tray_delegate()->GetUserLoginStatus()); |
| 387 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) | 390 EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer), |
| 388 ->GetLayoutManager(), | |
| 389 controller->GetSystemModalLayoutManager(NULL)); | 391 controller->GetSystemModalLayoutManager(NULL)); |
| 390 | 392 |
| 391 views::Widget* session_modal_widget = | 393 views::Widget* session_modal_widget = |
| 392 CreateModalWidget(gfx::Rect(300, 10, 100, 100)); | 394 CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
| 393 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) | 395 EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer), |
| 394 ->GetLayoutManager(), | |
| 395 controller->GetSystemModalLayoutManager( | 396 controller->GetSystemModalLayoutManager( |
| 396 WmLookup::Get()->GetWindowForWidget(session_modal_widget))); | 397 WmLookup::Get()->GetWindowForWidget(session_modal_widget))); |
| 397 | 398 |
| 398 wm_shell->GetSessionStateDelegate()->LockScreen(); | 399 wm_shell->GetSessionStateDelegate()->LockScreen(); |
| 399 EXPECT_EQ(LoginStatus::LOCKED, | 400 EXPECT_EQ(LoginStatus::LOCKED, |
| 400 wm_shell->system_tray_delegate()->GetUserLoginStatus()); | 401 wm_shell->system_tray_delegate()->GetUserLoginStatus()); |
| 401 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) | 402 EXPECT_EQ( |
| 402 ->GetLayoutManager(), | 403 GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer), |
| 403 controller->GetSystemModalLayoutManager(NULL)); | 404 controller->GetSystemModalLayoutManager(NULL)); |
| 404 | 405 |
| 405 aura::Window* lock_container = WmWindowAura::GetAuraWindow( | 406 aura::Window* lock_container = |
| 406 controller->GetContainer(kShellWindowId_LockScreenContainer)); | 407 controller->GetContainer(kShellWindowId_LockScreenContainer); |
| 407 views::Widget* lock_modal_widget = | 408 views::Widget* lock_modal_widget = |
| 408 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container); | 409 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container); |
| 409 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) | 410 EXPECT_EQ( |
| 410 ->GetLayoutManager(), | 411 GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer), |
| 411 controller->GetSystemModalLayoutManager( | 412 controller->GetSystemModalLayoutManager( |
| 412 WmLookup::Get()->GetWindowForWidget(lock_modal_widget))); | 413 WmLookup::Get()->GetWindowForWidget(lock_modal_widget))); |
| 413 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) | 414 EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer), |
| 414 ->GetLayoutManager(), | |
| 415 controller->GetSystemModalLayoutManager( | 415 controller->GetSystemModalLayoutManager( |
| 416 WmLookup::Get()->GetWindowForWidget(session_modal_widget))); | 416 WmLookup::Get()->GetWindowForWidget(session_modal_widget))); |
| 417 | 417 |
| 418 wm_shell->GetSessionStateDelegate()->UnlockScreen(); | 418 wm_shell->GetSessionStateDelegate()->UnlockScreen(); |
| 419 } | 419 } |
| 420 | 420 |
| 421 TEST_P(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) { | 421 TEST_P(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) { |
| 422 UpdateDisplay("600x600"); | 422 UpdateDisplay("600x600"); |
| 423 | 423 |
| 424 // Configure login screen environment. | 424 // Configure login screen environment. |
| 425 SessionStateDelegate* session_state_delegate = | 425 SessionStateDelegate* session_state_delegate = |
| 426 WmShell::Get()->GetSessionStateDelegate(); | 426 WmShell::Get()->GetSessionStateDelegate(); |
| 427 SetUserLoggedIn(false); | 427 SetUserLoggedIn(false); |
| 428 EXPECT_EQ(LoginStatus::NOT_LOGGED_IN, | 428 EXPECT_EQ(LoginStatus::NOT_LOGGED_IN, |
| 429 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()); | 429 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()); |
| 430 EXPECT_EQ(0, session_state_delegate->NumberOfLoggedInUsers()); | 430 EXPECT_EQ(0, session_state_delegate->NumberOfLoggedInUsers()); |
| 431 EXPECT_FALSE(session_state_delegate->IsActiveUserSessionStarted()); | 431 EXPECT_FALSE(session_state_delegate->IsActiveUserSessionStarted()); |
| 432 | 432 |
| 433 WmRootWindowController* controller = | 433 RootWindowController* controller = |
| 434 WmShell::Get()->GetPrimaryRootWindowController(); | 434 WmShell::Get()->GetPrimaryRootWindowController(); |
| 435 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) | 435 EXPECT_EQ( |
| 436 ->GetLayoutManager(), | 436 GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer), |
| 437 controller->GetSystemModalLayoutManager(NULL)); | 437 controller->GetSystemModalLayoutManager(NULL)); |
| 438 | 438 |
| 439 aura::Window* lock_container = WmWindowAura::GetAuraWindow( | 439 aura::Window* lock_container = |
| 440 controller->GetContainer(kShellWindowId_LockScreenContainer)); | 440 controller->GetContainer(kShellWindowId_LockScreenContainer); |
| 441 views::Widget* login_modal_widget = | 441 views::Widget* login_modal_widget = |
| 442 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container); | 442 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container); |
| 443 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) | 443 EXPECT_EQ( |
| 444 ->GetLayoutManager(), | 444 GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer), |
| 445 controller->GetSystemModalLayoutManager( | 445 controller->GetSystemModalLayoutManager( |
| 446 WmLookup::Get()->GetWindowForWidget(login_modal_widget))); | 446 WmLookup::Get()->GetWindowForWidget(login_modal_widget))); |
| 447 login_modal_widget->Close(); | 447 login_modal_widget->Close(); |
| 448 | 448 |
| 449 // Configure user session environment. | 449 // Configure user session environment. |
| 450 SetUserLoggedIn(true); | 450 SetUserLoggedIn(true); |
| 451 SetSessionStarted(true); | 451 SetSessionStarted(true); |
| 452 EXPECT_EQ(LoginStatus::USER, | 452 EXPECT_EQ(LoginStatus::USER, |
| 453 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()); | 453 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()); |
| 454 EXPECT_EQ(1, session_state_delegate->NumberOfLoggedInUsers()); | 454 EXPECT_EQ(1, session_state_delegate->NumberOfLoggedInUsers()); |
| 455 EXPECT_TRUE(session_state_delegate->IsActiveUserSessionStarted()); | 455 EXPECT_TRUE(session_state_delegate->IsActiveUserSessionStarted()); |
| 456 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) | 456 EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer), |
| 457 ->GetLayoutManager(), | |
| 458 controller->GetSystemModalLayoutManager(NULL)); | 457 controller->GetSystemModalLayoutManager(NULL)); |
| 459 | 458 |
| 460 views::Widget* session_modal_widget = | 459 views::Widget* session_modal_widget = |
| 461 CreateModalWidget(gfx::Rect(300, 10, 100, 100)); | 460 CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
| 462 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) | 461 EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer), |
| 463 ->GetLayoutManager(), | |
| 464 controller->GetSystemModalLayoutManager( | 462 controller->GetSystemModalLayoutManager( |
| 465 WmLookup::Get()->GetWindowForWidget(session_modal_widget))); | 463 WmLookup::Get()->GetWindowForWidget(session_modal_widget))); |
| 466 } | 464 } |
| 467 | 465 |
| 468 TEST_P(RootWindowControllerTest, ModalContainerBlockedSession) { | 466 TEST_P(RootWindowControllerTest, ModalContainerBlockedSession) { |
| 469 UpdateDisplay("600x600"); | 467 UpdateDisplay("600x600"); |
| 470 WmRootWindowController* controller = | 468 RootWindowController* controller = |
| 471 WmShell::Get()->GetPrimaryRootWindowController(); | 469 WmShell::Get()->GetPrimaryRootWindowController(); |
| 472 aura::Window* lock_container = WmWindowAura::GetAuraWindow( | 470 aura::Window* lock_container = |
| 473 controller->GetContainer(kShellWindowId_LockScreenContainer)); | 471 controller->GetContainer(kShellWindowId_LockScreenContainer); |
| 474 for (int block_reason = FIRST_BLOCK_REASON; | 472 for (int block_reason = FIRST_BLOCK_REASON; |
| 475 block_reason < NUMBER_OF_BLOCK_REASONS; ++block_reason) { | 473 block_reason < NUMBER_OF_BLOCK_REASONS; ++block_reason) { |
| 476 views::Widget* session_modal_widget = | 474 views::Widget* session_modal_widget = |
| 477 CreateModalWidget(gfx::Rect(300, 10, 100, 100)); | 475 CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
| 478 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) | 476 EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer), |
| 479 ->GetLayoutManager(), | |
| 480 controller->GetSystemModalLayoutManager( | 477 controller->GetSystemModalLayoutManager( |
| 481 WmLookup::Get()->GetWindowForWidget(session_modal_widget))); | 478 WmLookup::Get()->GetWindowForWidget(session_modal_widget))); |
| 482 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) | 479 EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer), |
| 483 ->GetLayoutManager(), | |
| 484 controller->GetSystemModalLayoutManager(NULL)); | 480 controller->GetSystemModalLayoutManager(NULL)); |
| 485 session_modal_widget->Close(); | 481 session_modal_widget->Close(); |
| 486 | 482 |
| 487 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); | 483 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 488 | 484 |
| 489 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) | 485 EXPECT_EQ( |
| 490 ->GetLayoutManager(), | 486 GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer), |
| 491 controller->GetSystemModalLayoutManager(NULL)); | 487 controller->GetSystemModalLayoutManager(NULL)); |
| 492 | 488 |
| 493 views::Widget* lock_modal_widget = CreateModalWidgetWithParent( | 489 views::Widget* lock_modal_widget = CreateModalWidgetWithParent( |
| 494 gfx::Rect(300, 10, 100, 100), lock_container); | 490 gfx::Rect(300, 10, 100, 100), lock_container); |
| 495 EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) | 491 EXPECT_EQ( |
| 496 ->GetLayoutManager(), | 492 GetLayoutManager(controller, kShellWindowId_LockSystemModalContainer), |
| 497 controller->GetSystemModalLayoutManager( | 493 controller->GetSystemModalLayoutManager( |
| 498 WmLookup::Get()->GetWindowForWidget(lock_modal_widget))); | 494 WmLookup::Get()->GetWindowForWidget(lock_modal_widget))); |
| 499 | 495 |
| 500 session_modal_widget = CreateModalWidget(gfx::Rect(300, 10, 100, 100)); | 496 session_modal_widget = CreateModalWidget(gfx::Rect(300, 10, 100, 100)); |
| 501 EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) | 497 EXPECT_EQ(GetLayoutManager(controller, kShellWindowId_SystemModalContainer), |
| 502 ->GetLayoutManager(), | |
| 503 controller->GetSystemModalLayoutManager( | 498 controller->GetSystemModalLayoutManager( |
| 504 WmLookup::Get()->GetWindowForWidget(session_modal_widget))); | 499 WmLookup::Get()->GetWindowForWidget(session_modal_widget))); |
| 505 session_modal_widget->Close(); | 500 session_modal_widget->Close(); |
| 506 | 501 |
| 507 lock_modal_widget->Close(); | 502 lock_modal_widget->Close(); |
| 508 UnblockUserSession(); | 503 UnblockUserSession(); |
| 509 } | 504 } |
| 510 } | 505 } |
| 511 | 506 |
| 512 TEST_P(RootWindowControllerTest, GetWindowForFullscreenMode) { | 507 TEST_P(RootWindowControllerTest, GetWindowForFullscreenMode) { |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 keyboard_controller->ui()->GetKeyboardWindow()->SetBounds( | 1241 keyboard_controller->ui()->GetKeyboardWindow()->SetBounds( |
| 1247 gfx::Rect(0, 400, 800, 200)); | 1242 gfx::Rect(0, 400, 800, 200)); |
| 1248 EXPECT_EQ("0,400 800x200", keyboard_container->bounds().ToString()); | 1243 EXPECT_EQ("0,400 800x200", keyboard_container->bounds().ToString()); |
| 1249 | 1244 |
| 1250 UpdateDisplay("600x800"); | 1245 UpdateDisplay("600x800"); |
| 1251 EXPECT_EQ("0,600 600x200", keyboard_container->bounds().ToString()); | 1246 EXPECT_EQ("0,600 600x200", keyboard_container->bounds().ToString()); |
| 1252 } | 1247 } |
| 1253 | 1248 |
| 1254 } // namespace test | 1249 } // namespace test |
| 1255 } // namespace ash | 1250 } // namespace ash |
| OLD | NEW |