0

ash: Simulate NotifyFirstSessionReady for AshTestBase

So that tests exercising this code path does not need to
explicitly do it.

Bug: b:358168568
Change-Id: Iff82a29324dede3dd1b68966afe4c34f9751eba4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5943328
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Auto-Submit: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1371221}
This commit is contained in:
Xiyuan Xia
2024-10-21 07:41:36 +00:00
committed by Chromium LUCI CQ
parent 41a1ad2de4
commit ae8efdce35
3 changed files with 19 additions and 8 deletions

@@ -73,6 +73,7 @@ void TestSessionControllerClient::Reset() {
session_info_.should_lock_screen_automatically = false;
session_info_.add_user_session_policy = AddUserSessionPolicy::ALLOWED;
session_info_.state = session_manager::SessionState::LOGIN_PRIMARY;
first_session_ready_fired_ = false;
controller_->ClearUserSessionsForTest();
controller_->SetSessionInfo(session_info_);
@@ -102,6 +103,8 @@ void TestSessionControllerClient::SetSessionState(
session_manager::SessionState state) {
session_info_.state = state;
controller_->SetSessionInfo(session_info_);
MaybeNotifyFirstSessionReady();
}
void TestSessionControllerClient::SetIsRunningInAppMode(bool app_mode) {
@@ -179,6 +182,8 @@ void TestSessionControllerClient::AddUserSession(
!controller_->GetUserPrefServiceForUser(account_id)) {
ProvidePrefServiceForUser(account_id);
}
MaybeNotifyFirstSessionReady();
}
void TestSessionControllerClient::ProvidePrefServiceForUser(
@@ -355,4 +360,13 @@ void TestSessionControllerClient::DoSwitchUser(const AccountId& account_id,
controller_->SetUserSessionOrder(session_order);
}
void TestSessionControllerClient::MaybeNotifyFirstSessionReady() {
if (!first_session_ready_fired_ &&
controller_->IsActiveUserSessionStarted() &&
session_info_.state == session_manager::SessionState::ACTIVE) {
first_session_ready_fired_ = true;
controller_->NotifyFirstSessionReady();
}
}
} // namespace ash

@@ -170,11 +170,16 @@ class TestSessionControllerClient : public SessionControllerClient {
private:
void DoSwitchUser(const AccountId& account_id, bool switch_user);
// Notify first session ready if the notification has not sent, there
// is at least one user session created, and session state is ACTIVE.
void MaybeNotifyFirstSessionReady();
const raw_ptr<SessionControllerImpl, DanglingUntriaged> controller_;
const raw_ptr<TestPrefServiceProvider> prefs_provider_;
int fake_session_id_ = 0;
SessionInfo session_info_;
bool first_session_ready_fired_ = false;
bool use_lower_case_user_id_ = true;
int request_hide_lock_screen_count_ = 0;

@@ -42,14 +42,6 @@ class FirmwareUpdateNotificationControllerTest : public AshTestBase {
const FirmwareUpdateNotificationControllerTest&) = delete;
~FirmwareUpdateNotificationControllerTest() override = default;
void SetUp() override {
AshTestBase::SetUp();
// Call NotifyFirstSessionReady to cause FirmwareUpdateManager to be
// initialized since it is only meant to be initialized after core startup
// tasks have been completed.
Shell::Get()->session_controller()->NotifyFirstSessionReady();
}
FirmwareUpdateNotificationController* controller() {
return Shell::Get()->firmware_update_notification_controller();
}