| 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/shell.h" | 5 #include "ash/shell.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/common/session/session_state_delegate.h" | 10 #include "ash/common/session/session_controller.h" |
| 11 #include "ash/common/shelf/shelf_layout_manager.h" | 11 #include "ash/common/shelf/shelf_layout_manager.h" |
| 12 #include "ash/common/shelf/shelf_widget.h" | 12 #include "ash/common/shelf/shelf_widget.h" |
| 13 #include "ash/common/shelf/wm_shelf.h" | 13 #include "ash/common/shelf/wm_shelf.h" |
| 14 #include "ash/common/test/test_session_controller_client.h" |
| 14 #include "ash/common/wallpaper/wallpaper_widget_controller.h" | 15 #include "ash/common/wallpaper/wallpaper_widget_controller.h" |
| 15 #include "ash/common/wm_shell.h" | 16 #include "ash/common/wm_shell.h" |
| 16 #include "ash/common/wm_window.h" | 17 #include "ash/common/wm_window.h" |
| 17 #include "ash/display/mouse_cursor_event_filter.h" | 18 #include "ash/display/mouse_cursor_event_filter.h" |
| 18 #include "ash/drag_drop/drag_drop_controller.h" | 19 #include "ash/drag_drop/drag_drop_controller.h" |
| 19 #include "ash/public/cpp/shell_window_ids.h" | 20 #include "ash/public/cpp/shell_window_ids.h" |
| 20 #include "ash/root_window_controller.h" | 21 #include "ash/root_window_controller.h" |
| 21 #include "ash/test/ash_test_base.h" | 22 #include "ash/test/ash_test_base.h" |
| 22 #include "ash/test/shell_test_api.h" | 23 #include "ash/test/shell_test_api.h" |
| 23 #include "ash/wm/window_util.h" | 24 #include "ash/wm/window_util.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 void LockScreenAndVerifyMenuClosed() { | 150 void LockScreenAndVerifyMenuClosed() { |
| 150 // Verify a menu is open before locking. | 151 // Verify a menu is open before locking. |
| 151 views::MenuController* menu_controller = | 152 views::MenuController* menu_controller = |
| 152 views::MenuController::GetActiveInstance(); | 153 views::MenuController::GetActiveInstance(); |
| 153 DCHECK(menu_controller); | 154 DCHECK(menu_controller); |
| 154 EXPECT_EQ(views::MenuController::EXIT_NONE, menu_controller->exit_type()); | 155 EXPECT_EQ(views::MenuController::EXIT_NONE, menu_controller->exit_type()); |
| 155 | 156 |
| 156 // Create a LockScreen window. | 157 // Create a LockScreen window. |
| 157 views::Widget::InitParams widget_params( | 158 views::Widget::InitParams widget_params( |
| 158 views::Widget::InitParams::TYPE_WINDOW); | 159 views::Widget::InitParams::TYPE_WINDOW); |
| 159 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate(); | 160 SessionController* controller = WmShell::Get()->session_controller(); |
| 160 delegate->LockScreen(); | 161 controller->LockScreenAndFlushForTest(); |
| 161 views::Widget* lock_widget = CreateTestWindow(widget_params); | 162 views::Widget* lock_widget = CreateTestWindow(widget_params); |
| 162 Shell::GetContainer(Shell::GetPrimaryRootWindow(), | 163 Shell::GetContainer(Shell::GetPrimaryRootWindow(), |
| 163 kShellWindowId_LockScreenContainer) | 164 kShellWindowId_LockScreenContainer) |
| 164 ->AddChild(lock_widget->GetNativeView()); | 165 ->AddChild(lock_widget->GetNativeView()); |
| 165 lock_widget->Show(); | 166 lock_widget->Show(); |
| 166 EXPECT_TRUE(delegate->IsScreenLocked()); | 167 EXPECT_TRUE(controller->IsScreenLocked()); |
| 167 EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus()); | 168 EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus()); |
| 168 | 169 |
| 169 // Verify menu is closed. | 170 // Verify menu is closed. |
| 170 EXPECT_EQ(nullptr, views::MenuController::GetActiveInstance()); | 171 EXPECT_EQ(nullptr, views::MenuController::GetActiveInstance()); |
| 171 lock_widget->Close(); | 172 lock_widget->Close(); |
| 172 delegate->UnlockScreen(); | 173 GetSessionControllerClient()->UnlockScreen(); |
| 173 } | 174 } |
| 174 }; | 175 }; |
| 175 | 176 |
| 176 TEST_F(ShellTest, CreateWindow) { | 177 TEST_F(ShellTest, CreateWindow) { |
| 177 // Normal window should be created in default container. | 178 // Normal window should be created in default container. |
| 178 TestCreateWindow(views::Widget::InitParams::TYPE_WINDOW, | 179 TestCreateWindow(views::Widget::InitParams::TYPE_WINDOW, |
| 179 false, // always_on_top | 180 false, // always_on_top |
| 180 GetDefaultContainer()); | 181 GetDefaultContainer()); |
| 181 TestCreateWindow(views::Widget::InitParams::TYPE_POPUP, | 182 TestCreateWindow(views::Widget::InitParams::TYPE_POPUP, |
| 182 false, // always_on_top | 183 false, // always_on_top |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 264 |
| 264 // Create a normal window. | 265 // Create a normal window. |
| 265 views::Widget* widget = CreateTestWindow(widget_params); | 266 views::Widget* widget = CreateTestWindow(widget_params); |
| 266 widget->Show(); | 267 widget->Show(); |
| 267 EXPECT_TRUE(widget->GetNativeView()->HasFocus()); | 268 EXPECT_TRUE(widget->GetNativeView()->HasFocus()); |
| 268 | 269 |
| 269 // It should be in default container. | 270 // It should be in default container. |
| 270 EXPECT_TRUE( | 271 EXPECT_TRUE( |
| 271 GetDefaultContainer()->Contains(widget->GetNativeWindow()->parent())); | 272 GetDefaultContainer()->Contains(widget->GetNativeWindow()->parent())); |
| 272 | 273 |
| 273 WmShell::Get()->GetSessionStateDelegate()->LockScreen(); | 274 WmShell::Get()->session_controller()->LockScreenAndFlushForTest(); |
| 274 // Create a LockScreen window. | 275 // Create a LockScreen window. |
| 275 views::Widget* lock_widget = CreateTestWindow(widget_params); | 276 views::Widget* lock_widget = CreateTestWindow(widget_params); |
| 276 Shell::GetContainer(Shell::GetPrimaryRootWindow(), | 277 Shell::GetContainer(Shell::GetPrimaryRootWindow(), |
| 277 kShellWindowId_LockScreenContainer) | 278 kShellWindowId_LockScreenContainer) |
| 278 ->AddChild(lock_widget->GetNativeView()); | 279 ->AddChild(lock_widget->GetNativeView()); |
| 279 lock_widget->Show(); | 280 lock_widget->Show(); |
| 280 EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus()); | 281 EXPECT_TRUE(lock_widget->GetNativeView()->HasFocus()); |
| 281 | 282 |
| 282 // It should be in LockScreen container. | 283 // It should be in LockScreen container. |
| 283 aura::Window* lock_screen = Shell::GetContainer( | 284 aura::Window* lock_screen = Shell::GetContainer( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 | 321 |
| 321 modal_dialog->Close(); | 322 modal_dialog->Close(); |
| 322 modal_widget->Close(); | 323 modal_widget->Close(); |
| 323 modal_widget->Close(); | 324 modal_widget->Close(); |
| 324 lock_modal_widget->Close(); | 325 lock_modal_widget->Close(); |
| 325 lock_widget->Close(); | 326 lock_widget->Close(); |
| 326 widget->Close(); | 327 widget->Close(); |
| 327 } | 328 } |
| 328 | 329 |
| 329 TEST_F(ShellTest, IsScreenLocked) { | 330 TEST_F(ShellTest, IsScreenLocked) { |
| 330 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate(); | 331 SessionController* controller = WmShell::Get()->session_controller(); |
| 331 delegate->LockScreen(); | 332 controller->LockScreenAndFlushForTest(); |
| 332 EXPECT_TRUE(delegate->IsScreenLocked()); | 333 EXPECT_TRUE(controller->IsScreenLocked()); |
| 333 delegate->UnlockScreen(); | 334 GetSessionControllerClient()->UnlockScreen(); |
| 334 EXPECT_FALSE(delegate->IsScreenLocked()); | 335 EXPECT_FALSE(controller->IsScreenLocked()); |
| 335 } | 336 } |
| 336 | 337 |
| 337 TEST_F(ShellTest, LockScreenClosesActiveMenu) { | 338 TEST_F(ShellTest, LockScreenClosesActiveMenu) { |
| 338 SimpleMenuDelegate menu_delegate; | 339 SimpleMenuDelegate menu_delegate; |
| 339 std::unique_ptr<ui::SimpleMenuModel> menu_model( | 340 std::unique_ptr<ui::SimpleMenuModel> menu_model( |
| 340 new ui::SimpleMenuModel(&menu_delegate)); | 341 new ui::SimpleMenuModel(&menu_delegate)); |
| 341 menu_model->AddItem(0, base::ASCIIToUTF16("Menu item")); | 342 menu_model->AddItem(0, base::ASCIIToUTF16("Menu item")); |
| 342 views::Widget* widget = WmShell::Get() | 343 views::Widget* widget = WmShell::Get() |
| 343 ->GetPrimaryRootWindow() | 344 ->GetPrimaryRootWindow() |
| 344 ->GetRootWindowController() | 345 ->GetRootWindowController() |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 // the case with classic-ash where embedders can separately create | 504 // the case with classic-ash where embedders can separately create |
| 504 // aura::Windows. | 505 // aura::Windows. |
| 505 if (WmShell::Get()->IsRunningInMash()) | 506 if (WmShell::Get()->IsRunningInMash()) |
| 506 return; | 507 return; |
| 507 | 508 |
| 508 window_.reset(new aura::Window(NULL)); | 509 window_.reset(new aura::Window(NULL)); |
| 509 window_->Init(ui::LAYER_NOT_DRAWN); | 510 window_->Init(ui::LAYER_NOT_DRAWN); |
| 510 } | 511 } |
| 511 | 512 |
| 512 } // namespace ash | 513 } // namespace ash |
| OLD | NEW |