| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/session/session_state_delegate.h" | 5 #include "ash/common/session/session_controller.h" |
| 6 #include "ash/common/test/test_session_state_delegate.h" | 6 #include "ash/common/test/test_session_controller_client.h" |
| 7 #include "ash/common/wm/window_state.h" | 7 #include "ash/common/wm/window_state.h" |
| 8 #include "ash/common/wm_shell.h" | 8 #include "ash/common/wm_shell.h" |
| 9 #include "ash/public/cpp/shell_window_ids.h" | 9 #include "ash/public/cpp/shell_window_ids.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/test/ash_test_helper.h" | 12 #include "ash/test/ash_test_helper.h" |
| 13 #include "ash/test/test_shell_delegate.h" | |
| 14 #include "ash/wm/lock_state_controller.h" | 13 #include "ash/wm/lock_state_controller.h" |
| 15 #include "ash/wm/window_state_aura.h" | 14 #include "ash/wm/window_state_aura.h" |
| 16 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
| 16 #include "base/memory/ptr_util.h" |
| 17 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | 17 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
| 18 #include "ui/aura/client/aura_constants.h" | 18 #include "ui/aura/client/aura_constants.h" |
| 19 #include "ui/aura/client/window_parenting_client.h" | 19 #include "ui/aura/client/window_parenting_client.h" |
| 20 #include "ui/views/test/widget_test.h" | 20 #include "ui/views/test/widget_test.h" |
| 21 #include "ui/views/view.h" | 21 #include "ui/views/view.h" |
| 22 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 23 | 23 |
| 24 namespace ash { | 24 namespace ash { |
| 25 namespace test { | 25 namespace test { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // Defines a |SessionStateDelegate| that is used to create and destroy the | 29 // Defines a |SessionControllerClient| that is used to create and destroy the |
| 30 // test lock screen widget. | 30 // test lock screen widget. |
| 31 class LockScreenSessionStateDelegate : public TestSessionStateDelegate { | 31 class LockScreenSessionControllerClient : public TestSessionControllerClient { |
| 32 public: | 32 public: |
| 33 LockScreenSessionStateDelegate() {} | 33 explicit LockScreenSessionControllerClient(SessionController* controller) |
| 34 ~LockScreenSessionStateDelegate() override {} | 34 : TestSessionControllerClient(controller) { |
| 35 InitializeAndBind(); |
| 36 } |
| 37 ~LockScreenSessionControllerClient() override {} |
| 35 | 38 |
| 36 void LockScreen() override { | 39 // TestSessionControllerClient: |
| 37 TestSessionStateDelegate::LockScreen(); | 40 void RequestLockScreen() override { |
| 41 TestSessionControllerClient::RequestLockScreen(); |
| 38 CreateLockScreen(); | 42 CreateLockScreen(); |
| 39 Shell::GetInstance()->UpdateShelfVisibility(); | 43 Shell::GetInstance()->UpdateShelfVisibility(); |
| 40 } | 44 } |
| 41 | 45 |
| 42 void UnlockScreen() override { | 46 void UnlockScreen() override { |
| 43 TestSessionStateDelegate::UnlockScreen(); | 47 TestSessionControllerClient::UnlockScreen(); |
| 44 if (lock_screen_widget_.get()) { | 48 if (lock_screen_widget_.get()) { |
| 45 lock_screen_widget_->Close(); | 49 lock_screen_widget_->Close(); |
| 46 lock_screen_widget_.reset(nullptr); | 50 lock_screen_widget_.reset(nullptr); |
| 47 } | 51 } |
| 48 | 52 |
| 49 Shell::GetInstance()->UpdateShelfVisibility(); | 53 Shell::GetInstance()->UpdateShelfVisibility(); |
| 50 } | 54 } |
| 51 | 55 |
| 52 private: | 56 private: |
| 53 void CreateLockScreen() { | 57 void CreateLockScreen() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 66 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 70 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 67 lock_screen_widget_->Init(params); | 71 lock_screen_widget_->Init(params); |
| 68 lock_screen_widget_->SetContentsView(lock_view); | 72 lock_screen_widget_->SetContentsView(lock_view); |
| 69 lock_screen_widget_->Show(); | 73 lock_screen_widget_->Show(); |
| 70 lock_screen_widget_->GetNativeView()->SetName("LockView"); | 74 lock_screen_widget_->GetNativeView()->SetName("LockView"); |
| 71 lock_screen_widget_->GetNativeView()->Focus(); | 75 lock_screen_widget_->GetNativeView()->Focus(); |
| 72 } | 76 } |
| 73 | 77 |
| 74 std::unique_ptr<views::Widget> lock_screen_widget_; | 78 std::unique_ptr<views::Widget> lock_screen_widget_; |
| 75 | 79 |
| 76 DISALLOW_COPY_AND_ASSIGN(LockScreenSessionStateDelegate); | 80 DISALLOW_COPY_AND_ASSIGN(LockScreenSessionControllerClient); |
| 77 }; | 81 }; |
| 78 | 82 |
| 79 //////////////////////////////////////////////////////////////////////////////// | 83 //////////////////////////////////////////////////////////////////////////////// |
| 80 | |
| 81 // Defines a |ShellDelegate| that is used to construct our lock screen | |
| 82 // |SessionStateDelegate|. | |
| 83 class LockScreenShellDelegate : public test::TestShellDelegate { | |
| 84 public: | |
| 85 LockScreenShellDelegate() {} | |
| 86 ~LockScreenShellDelegate() override {} | |
| 87 | |
| 88 TestSessionStateDelegate* CreateSessionStateDelegate() override { | |
| 89 return new LockScreenSessionStateDelegate(); | |
| 90 } | |
| 91 | |
| 92 private: | |
| 93 DISALLOW_COPY_AND_ASSIGN(LockScreenShellDelegate); | |
| 94 }; | |
| 95 | |
| 96 //////////////////////////////////////////////////////////////////////////////// | |
| 97 | 84 |
| 98 // Defines a class that will be used to test the correct behavior of | 85 // Defines a class that will be used to test the correct behavior of |
| 99 // |AshFocusRules| when locking and unlocking the screen. | 86 // |AshFocusRules| when locking and unlocking the screen. |
| 100 class LockScreenAshFocusRulesTest : public AshTestBase { | 87 class LockScreenAshFocusRulesTest : public AshTestBase { |
| 101 public: | 88 public: |
| 102 LockScreenAshFocusRulesTest() {} | 89 LockScreenAshFocusRulesTest() {} |
| 103 ~LockScreenAshFocusRulesTest() override {} | 90 ~LockScreenAshFocusRulesTest() override {} |
| 104 | 91 |
| 105 void SetUp() override { | 92 void SetUp() override { |
| 106 ash_test_helper()->set_test_shell_delegate(new LockScreenShellDelegate); | |
| 107 AshTestBase::SetUp(); | 93 AshTestBase::SetUp(); |
| 94 ash_test_helper()->set_test_session_controller_client( |
| 95 base::MakeUnique<LockScreenSessionControllerClient>( |
| 96 WmShell::Get()->session_controller())); |
| 108 } | 97 } |
| 109 | 98 |
| 110 void TearDown() override { AshTestBase::TearDown(); } | 99 void TearDown() override { AshTestBase::TearDown(); } |
| 111 | 100 |
| 112 aura::Window* CreateWindowInDefaultContainer() { | 101 aura::Window* CreateWindowInDefaultContainer() { |
| 113 return CreateWindowInContainer(kShellWindowId_DefaultContainer); | 102 return CreateWindowInContainer(kShellWindowId_DefaultContainer); |
| 114 } | 103 } |
| 115 | 104 |
| 116 aura::Window* CreateWindowInAlwaysOnTopContainer() { | 105 aura::Window* CreateWindowInAlwaysOnTopContainer() { |
| 117 aura::Window* window = | 106 aura::Window* window = |
| (...skipping 15 matching lines...) Expand all Loading... |
| 133 aura::client::ParentWindowWithContext(window, container, | 122 aura::client::ParentWindowWithContext(window, container, |
| 134 gfx::Rect(0, 0, 400, 400)); | 123 gfx::Rect(0, 0, 400, 400)); |
| 135 | 124 |
| 136 window->SetProperty(aura::client::kResizeBehaviorKey, | 125 window->SetProperty(aura::client::kResizeBehaviorKey, |
| 137 ui::mojom::kResizeBehaviorCanMaximize | | 126 ui::mojom::kResizeBehaviorCanMaximize | |
| 138 ui::mojom::kResizeBehaviorCanMinimize | | 127 ui::mojom::kResizeBehaviorCanMinimize | |
| 139 ui::mojom::kResizeBehaviorCanResize); | 128 ui::mojom::kResizeBehaviorCanResize); |
| 140 return window; | 129 return window; |
| 141 } | 130 } |
| 142 | 131 |
| 132 std::unique_ptr<LockScreenSessionControllerClient> session_controller_client_; |
| 133 |
| 143 DISALLOW_COPY_AND_ASSIGN(LockScreenAshFocusRulesTest); | 134 DISALLOW_COPY_AND_ASSIGN(LockScreenAshFocusRulesTest); |
| 144 }; | 135 }; |
| 145 | 136 |
| 146 } // namespace | 137 } // namespace |
| 147 | 138 |
| 148 // Verifies focus is returned (after unlocking the screen) to the most recent | 139 // Verifies focus is returned (after unlocking the screen) to the most recent |
| 149 // window that had it before locking the screen. | 140 // window that had it before locking the screen. |
| 150 TEST_F(LockScreenAshFocusRulesTest, RegainFocusAfterUnlock) { | 141 TEST_F(LockScreenAshFocusRulesTest, RegainFocusAfterUnlock) { |
| 151 std::unique_ptr<aura::Window> normal_window(CreateWindowInDefaultContainer()); | 142 std::unique_ptr<aura::Window> normal_window(CreateWindowInDefaultContainer()); |
| 152 std::unique_ptr<aura::Window> always_on_top_window( | 143 std::unique_ptr<aura::Window> always_on_top_window( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 164 wm::WindowState* normal_window_state = | 155 wm::WindowState* normal_window_state = |
| 165 wm::GetWindowState(normal_window.get()); | 156 wm::GetWindowState(normal_window.get()); |
| 166 wm::WindowState* always_on_top_window_state = | 157 wm::WindowState* always_on_top_window_state = |
| 167 wm::GetWindowState(always_on_top_window.get()); | 158 wm::GetWindowState(always_on_top_window.get()); |
| 168 | 159 |
| 169 EXPECT_TRUE(normal_window_state->CanActivate()); | 160 EXPECT_TRUE(normal_window_state->CanActivate()); |
| 170 EXPECT_TRUE(always_on_top_window_state->CanActivate()); | 161 EXPECT_TRUE(always_on_top_window_state->CanActivate()); |
| 171 | 162 |
| 172 BlockUserSession(BLOCKED_BY_LOCK_SCREEN); | 163 BlockUserSession(BLOCKED_BY_LOCK_SCREEN); |
| 173 | 164 |
| 174 EXPECT_TRUE(WmShell::Get()->GetSessionStateDelegate()->IsScreenLocked()); | 165 EXPECT_TRUE(WmShell::Get()->session_controller()->IsScreenLocked()); |
| 175 EXPECT_FALSE(normal_window->HasFocus()); | 166 EXPECT_FALSE(normal_window->HasFocus()); |
| 176 EXPECT_FALSE(always_on_top_window->HasFocus()); | 167 EXPECT_FALSE(always_on_top_window->HasFocus()); |
| 177 EXPECT_FALSE(normal_window_state->IsMinimized()); | 168 EXPECT_FALSE(normal_window_state->IsMinimized()); |
| 178 EXPECT_FALSE(always_on_top_window_state->IsMinimized()); | 169 EXPECT_FALSE(always_on_top_window_state->IsMinimized()); |
| 179 EXPECT_FALSE(normal_window_state->CanActivate()); | 170 EXPECT_FALSE(normal_window_state->CanActivate()); |
| 180 EXPECT_FALSE(always_on_top_window_state->CanActivate()); | 171 EXPECT_FALSE(always_on_top_window_state->CanActivate()); |
| 181 | 172 |
| 182 UnblockUserSession(); | 173 UnblockUserSession(); |
| 183 | 174 |
| 184 EXPECT_FALSE(WmShell::Get()->GetSessionStateDelegate()->IsScreenLocked()); | 175 EXPECT_FALSE(WmShell::Get()->session_controller()->IsScreenLocked()); |
| 185 EXPECT_FALSE(normal_window_state->IsMinimized()); | 176 EXPECT_FALSE(normal_window_state->IsMinimized()); |
| 186 EXPECT_FALSE(always_on_top_window_state->IsMinimized()); | 177 EXPECT_FALSE(always_on_top_window_state->IsMinimized()); |
| 187 EXPECT_TRUE(normal_window_state->CanActivate()); | 178 EXPECT_TRUE(normal_window_state->CanActivate()); |
| 188 EXPECT_TRUE(always_on_top_window_state->CanActivate()); | 179 EXPECT_TRUE(always_on_top_window_state->CanActivate()); |
| 189 EXPECT_FALSE(always_on_top_window->HasFocus()); | 180 EXPECT_FALSE(always_on_top_window->HasFocus()); |
| 190 EXPECT_TRUE(normal_window->HasFocus()); | 181 EXPECT_TRUE(normal_window->HasFocus()); |
| 191 } | 182 } |
| 192 | 183 |
| 193 // Tests that if a widget has a view which should be initially focused, this | 184 // Tests that if a widget has a view which should be initially focused, this |
| 194 // view doesn't get focused if the widget shows behind the lock screen. | 185 // view doesn't get focused if the widget shows behind the lock screen. |
| 195 TEST_F(LockScreenAshFocusRulesTest, PreventFocusChangeWithLockScreenPresent) { | 186 TEST_F(LockScreenAshFocusRulesTest, PreventFocusChangeWithLockScreenPresent) { |
| 196 BlockUserSession(BLOCKED_BY_LOCK_SCREEN); | 187 BlockUserSession(BLOCKED_BY_LOCK_SCREEN); |
| 197 EXPECT_TRUE(WmShell::Get()->GetSessionStateDelegate()->IsScreenLocked()); | 188 EXPECT_TRUE(WmShell::Get()->session_controller()->IsScreenLocked()); |
| 198 | 189 |
| 199 views::test::TestInitialFocusWidgetDelegate delegate(CurrentContext()); | 190 views::test::TestInitialFocusWidgetDelegate delegate(CurrentContext()); |
| 200 EXPECT_FALSE(delegate.view()->HasFocus()); | 191 EXPECT_FALSE(delegate.view()->HasFocus()); |
| 201 delegate.GetWidget()->Show(); | 192 delegate.GetWidget()->Show(); |
| 202 EXPECT_FALSE(delegate.GetWidget()->IsActive()); | 193 EXPECT_FALSE(delegate.GetWidget()->IsActive()); |
| 203 EXPECT_FALSE(delegate.view()->HasFocus()); | 194 EXPECT_FALSE(delegate.view()->HasFocus()); |
| 204 | 195 |
| 205 UnblockUserSession(); | 196 UnblockUserSession(); |
| 206 EXPECT_FALSE(WmShell::Get()->GetSessionStateDelegate()->IsScreenLocked()); | 197 EXPECT_FALSE(WmShell::Get()->session_controller()->IsScreenLocked()); |
| 207 EXPECT_TRUE(delegate.GetWidget()->IsActive()); | 198 EXPECT_TRUE(delegate.GetWidget()->IsActive()); |
| 208 EXPECT_TRUE(delegate.view()->HasFocus()); | 199 EXPECT_TRUE(delegate.view()->HasFocus()); |
| 209 } | 200 } |
| 210 | 201 |
| 211 } // namespace test | 202 } // namespace test |
| 212 } // namespace ash | 203 } // namespace ash |
| OLD | NEW |