0

Use lockscreen in TestSessoinControllerImpl instead of custom widget

This is one step to cleanup PrefService in TestSessionContrlllerClient

This also makes TestSessoinControllerClient final

Bug: 384740500

Change-Id: I0ee8afb5e84e8c19292957b51d30f9186889a818
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6200009
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1411704}
This commit is contained in:
Mitsuru Oshima
2025-01-27 09:52:19 -08:00
committed by Chromium LUCI CQ
parent c1e8145125
commit 5ba832c5e1
3 changed files with 12 additions and 78 deletions

@ -16,6 +16,7 @@
#include "ash/wm/lock_state_controller.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "chromeos/ash/components/login/auth/auth_events_recorder.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/window_parenting_client.h"
#include "ui/aura/window.h"
@ -30,73 +31,6 @@ namespace ash {
namespace {
// Defines a |SessionControllerClient| that is used to create and destroy the
// test lock screen widget.
class LockScreenSessionControllerClient : public TestSessionControllerClient {
public:
LockScreenSessionControllerClient(SessionControllerImpl* controller,
TestPrefServiceProvider* prefs_provider)
: TestSessionControllerClient(controller,
prefs_provider,
/*create_signin_pref_service=*/true) {
InitializeAndSetClient();
Reset();
AddUserSession("user0@tray");
SetSessionState(session_manager::SessionState::ACTIVE);
}
LockScreenSessionControllerClient(const LockScreenSessionControllerClient&) =
delete;
LockScreenSessionControllerClient& operator=(
const LockScreenSessionControllerClient&) = delete;
~LockScreenSessionControllerClient() override = default;
// TestSessionControllerClient:
void RequestLockScreen() override {
TestSessionControllerClient::RequestLockScreen();
CreateLockScreen();
Shelf::UpdateShelfVisibility();
}
void UnlockScreen() override {
TestSessionControllerClient::UnlockScreen();
if (lock_screen_widget_.get()) {
lock_screen_widget_->Close();
lock_screen_widget_.reset(nullptr);
}
Shelf::UpdateShelfVisibility();
}
private:
void CreateLockScreen() {
auto lock_view = std::make_unique<views::View>();
lock_screen_widget_ = std::make_unique<views::Widget>();
views::Widget::InitParams params(
views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET,
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
gfx::Size ps = lock_view->GetPreferredSize();
gfx::Size root_window_size = Shell::GetPrimaryRootWindow()->bounds().size();
params.bounds = gfx::Rect((root_window_size.width() - ps.width()) / 2,
(root_window_size.height() - ps.height()) / 2,
ps.width(), ps.height());
params.parent = Shell::GetContainer(Shell::GetPrimaryRootWindow(),
kShellWindowId_LockScreenContainer);
lock_screen_widget_->Init(std::move(params));
lock_screen_widget_->SetContentsView(std::move(lock_view));
lock_screen_widget_->Show();
lock_screen_widget_->GetNativeView()->SetName("LockView");
lock_screen_widget_->GetNativeView()->Focus();
}
std::unique_ptr<views::Widget> lock_screen_widget_;
};
////////////////////////////////////////////////////////////////////////////////
// Defines a class that will be used to test the correct behavior of
// |AshFocusRules| when locking and unlocking the screen.
class LockScreenAshFocusRulesTest : public AshTestBase {
@ -111,10 +45,14 @@ class LockScreenAshFocusRulesTest : public AshTestBase {
void SetUp() override {
AshTestBase::SetUp();
ash_test_helper()->set_test_session_controller_client(
std::make_unique<LockScreenSessionControllerClient>(
Shell::Get()->session_controller(),
ash_test_helper()->prefs_provider()));
// Showing LockScreen requires auth event recorder.
auth_events_recorder_ = AuthEventsRecorder::CreateForTesting();
GetSessionControllerClient()->set_show_lock_screen_views(true);
}
void TearDown() override {
auth_events_recorder_.reset();
AshTestBase::TearDown();
}
aura::Window* CreateWindowInActiveDesk() {
@ -172,7 +110,7 @@ class LockScreenAshFocusRulesTest : public AshTestBase {
return window;
}
std::unique_ptr<LockScreenSessionControllerClient> session_controller_client_;
std::unique_ptr<AuthEventsRecorder> auth_events_recorder_;
};
} // namespace

@ -40,7 +40,7 @@ class TestPrefServiceProvider;
// SessionControllerClient created, e.g. InProcessBrowserTest based tests. On
// the other hand, tests code in chrome can use this class as long as it does
// not run BrowserMain, e.g. testing::Test based test.
class TestSessionControllerClient : public SessionControllerClient {
class TestSessionControllerClient final : public SessionControllerClient {
public:
TestSessionControllerClient(SessionControllerImpl* controller,
TestPrefServiceProvider* prefs_provider,
@ -123,7 +123,7 @@ class TestSessionControllerClient : public SessionControllerClient {
// Simulates screen unlocking. It is virtual so that test cases can override
// it. The default implementation sets the session state of SessionController
// to be ACTIVE.
virtual void UnlockScreen();
void UnlockScreen();
// Spins message loop to finish pending lock screen request if any.
void FlushForTest();

@ -145,10 +145,6 @@ class AshTestHelper : public aura::test::AuraTestHelper {
TestSessionControllerClient* test_session_controller_client() {
return session_controller_client_.get();
}
void set_test_session_controller_client(
std::unique_ptr<TestSessionControllerClient> session_controller_client) {
session_controller_client_ = std::move(session_controller_client);
}
TestNotifierSettingsController* notifier_settings_controller() {
return notifier_settings_controller_.get();
}