0

Reduce the usage of TestSessionControllerClient

Removed following methods that are no longer used.
 TestSessionControllerClient::NotifyUserPrefServiceInitialized
 InputDeviceSettingsControllerTest::SetActiveUser

Bug: 383442863

Change-Id: I2577aa0f8119c47493e2339dd5590ea078ad3f23
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6344538
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1431512}
This commit is contained in:
Mitsuru Oshima
2025-03-12 08:02:02 -07:00
committed by Chromium LUCI CQ
parent 18ae9994a3
commit 1a2dc35c45
21 changed files with 32 additions and 70 deletions

@ -1448,8 +1448,6 @@ TEST_F(AmbientControllerTest, SwitchActiveUsersDoesNotDoubleBindObservers) {
SimulateUserLogin({kUser1});
SetAmbientModeEnabled(true);
TestSessionControllerClient* session = GetSessionControllerClient();
// Observers are bound for primary user with Ambient mode enabled.
EXPECT_TRUE(AreSessionSpecificObserversBound());
EXPECT_TRUE(IsPrefObserved(ambient::prefs::kAmbientModeEnabled));
@ -1460,12 +1458,12 @@ TEST_F(AmbientControllerTest, SwitchActiveUsersDoesNotDoubleBindObservers) {
EXPECT_TRUE(IsPrefObserved(ambient::prefs::kAmbientModeEnabled));
// Observers are not re-bound for primary user when session is active.
session->SwitchActiveUser(AccountId::FromUserEmail(kUser1));
SwitchActiveUser(AccountId::FromUserEmail(kUser1));
EXPECT_TRUE(AreSessionSpecificObserversBound());
EXPECT_TRUE(IsPrefObserved(ambient::prefs::kAmbientModeEnabled));
// Switch back to secondary user.
session->SwitchActiveUser(AccountId::FromUserEmail(kUser2));
SwitchActiveUser(AccountId::FromUserEmail(kUser2));
}
TEST_F(AmbientControllerTest, BindsObserversWhenAmbientOn) {

@ -134,10 +134,7 @@ void AssistantAshTestBase::TearDown() {
void AssistantAshTestBase::CreateAndSwitchActiveUser(
const std::string& display_email,
const std::string& given_name) {
TestSessionControllerClient* session_controller_client =
GetSessionControllerClient();
session_controller_client->Reset();
ClearLogin();
SimulateUserLogin({.display_email = display_email, .given_name = given_name});
SetUpActiveUser();

@ -67,7 +67,7 @@ class ActiveSessionAuthControllerTest
NoSessionAshTestBase::SetUp();
GetSessionControllerClient()->Reset();
ClearLogin();
SimulateUserLogin({kUserEmail, user_manager::UserType::kRegular});
}

@ -67,12 +67,11 @@ class FeatureDiscoveryDurationReporterImplTest : public AshTestBase {
// Set up the primary account and the secondary account.
GetSessionController()->ClearUserSessionsForTest();
TestSessionControllerClient* session_client = GetSessionControllerClient();
SimulateUserLogin({kPrimaryUserEmail});
SimulateUserLogin({kSecondaryUserEmail});
// Switch to the primary account and lock the screen.
session_client->SwitchActiveUser(primary_account_id_);
SwitchActiveUser(primary_account_id_);
GetSessionControllerClient()->SetSessionState(
session_manager::SessionState::LOCKED);
}
@ -91,9 +90,7 @@ TEST_F(FeatureDiscoveryDurationReporterImplTest, OnlyRecordForNewPrimaryUser) {
EXPECT_TRUE(IsReporterActive());
// Switch to the secondary account. The session should still be active.
TestSessionControllerClient* session_controller =
GetSessionControllerClient();
session_controller->SwitchActiveUser(secondary_account_id_);
SwitchActiveUser(secondary_account_id_);
EXPECT_EQ(session_manager::SessionState::ACTIVE,
GetSessionController()->GetSessionState());

@ -74,7 +74,7 @@ TEST_F(UserMetricsRecorderTest, VerifyIsUserInActiveDesktopEnvironmentValues) {
EXPECT_FALSE(test_api().IsUserInActiveDesktopEnvironment());
// Kiosk logins are not considered active.
client->Reset();
ClearLogin();
SimulateUserLogin({"app@kiosk-apps.device-local.localhost",
user_manager::UserType::kKioskApp});
EXPECT_FALSE(test_api().IsUserInActiveDesktopEnvironment());

@ -157,10 +157,7 @@ class QuickPairMetricsLoggerTest : public NoSessionAshTestBase {
public:
void SetUp() override {
NoSessionAshTestBase::SetUp();
TestSessionControllerClient* session_controller =
GetSessionControllerClient();
session_controller->Reset();
ClearLogin();
// Inject our own PrefServices for each user which enables us to setup the
// desks restore data before the user signs in.

@ -338,11 +338,4 @@ void TestSessionControllerClient::MaybeNotifyFirstSessionReady() {
}
}
void TestSessionControllerClient::NotifyUserPrefServiceInitialized(
const AccountId& account_id) {
CHECK(controller_->IsActiveUserSessionStarted());
controller_->OnProfilePrefServiceInitialized(
account_id, prefs_provider_->GetUserPrefs(account_id));
}
} // namespace ash

@ -158,9 +158,6 @@ class TestSessionControllerClient final : public SessionControllerClient {
// is at least one user session created, and session state is ACTIVE.
void MaybeNotifyFirstSessionReady();
// Notify user prefs initialized if user session has started.
void NotifyUserPrefServiceInitialized(const AccountId& account_id);
const raw_ptr<SessionControllerImpl, DanglingUntriaged> controller_;
const raw_ptr<TestPrefServiceProvider> prefs_provider_;

@ -107,7 +107,7 @@ class ColorPaletteControllerTest : public NoSessionAshTestBase {
public:
void SetUp() override {
NoSessionAshTestBase::SetUp();
GetSessionControllerClient()->Reset();
ClearLogin();
SimulateUserLogin(kAccountId);
wallpaper_controller_ = Shell::Get()->wallpaper_controller();
color_palette_controller_ = Shell::Get()->color_palette_controller();
@ -631,7 +631,7 @@ class ColorPaletteControllerLocalPrefTest : public ColorPaletteControllerTest {
public:
void SetUp() override {
ColorPaletteControllerTest::SetUp();
GetSessionControllerClient()->Reset();
ClearLogin();
}
// Sets the local ColorScheme to kVibrant. The synced color scheme remains

@ -139,10 +139,7 @@ class FocusModeControllerMultiUserTest : public NoSessionAshTestBase {
CHECK(test_web_view_factory_.get());
NoSessionAshTestBase::SetUp();
TestSessionControllerClient* session_controller =
GetSessionControllerClient();
session_controller->Reset();
ClearLogin();
owned_user_1_prefs_ =
TestPrefServiceProvider::CreateUserPrefServiceSimple();
owned_user_2_prefs_ =

@ -165,7 +165,7 @@ class GeolocationControllerTest : public NoSessionAshTestBase {
}
void CreateTestUserSessions() {
GetSessionControllerClient()->Reset();
ClearLogin();
SimulateUserLogin({kUser1Email});
SimulateUserLogin({kUser2Email});
SwitchActiveUser({kUser1Email});

@ -675,14 +675,11 @@ class InputDeviceSettingsControllerTest : public NoSessionAshTestBase {
sample_keyboards_ = {kSampleKeyboardUsb, kSampleKeyboardInternal,
kSampleKeyboardBluetooth};
TestSessionControllerClient* session_controller =
GetSessionControllerClient();
session_controller->Reset();
ClearLogin();
if (should_sign_in_) {
SimulateUserLogin({kUserEmail1});
SimulateUserLogin({kUserEmail2});
session_controller->SwitchActiveUser(kAccountId1);
SwitchActiveUser(kAccountId1);
}
// Reset the `num_keyboard_settings_initialized_` to account for the
@ -704,13 +701,6 @@ class InputDeviceSettingsControllerTest : public NoSessionAshTestBase {
task_runner_.reset();
}
void SetActiveUser(const AccountId& account_id) {
TestSessionControllerClient* session_controller =
GetSessionControllerClient();
session_controller->SwitchActiveUser(account_id);
session_controller->SetSessionState(session_manager::SessionState::ACTIVE);
}
std::unique_ptr<device::MockBluetoothDevice> SetupMockBluetoothDevice(
uint32_t vendor_id,
uint32_t product_id,

@ -235,7 +235,7 @@ TEST_F(NetworkListNetworkItemViewTest, HasCorrectCellularSublabel) {
// Simulate user logout and check label for pSIM networks that are
// connected but not activated.
GetSessionControllerClient()->Reset();
ClearLogin();
base::RunLoop().RunUntilIdle();
UpdateViewForNetwork(cellular_network);
EXPECT_EQ(l10n_util::GetStringUTF16(
@ -282,7 +282,7 @@ TEST_F(NetworkListNetworkItemViewTest, HasCorrectCellularSublabel) {
network_list_network_item_view()->sub_text_label()->GetText());
// label for locked cellular network when user is not logged in.
GetSessionControllerClient()->Reset();
ClearLogin();
base::RunLoop().RunUntilIdle();
UpdateViewForNetwork(cellular_network);
EXPECT_EQ(l10n_util::GetStringUTF16(
@ -446,7 +446,7 @@ TEST_F(NetworkListNetworkItemViewTest, HasExpectedA11yText) {
// Simulate user logout and check label for pSIM networks that are
// connected but not activated.
GetSessionControllerClient()->Reset();
ClearLogin();
base::RunLoop().RunUntilIdle();
UpdateViewForNetwork(cellular_network);
EXPECT_EQ(
@ -585,7 +585,7 @@ TEST_F(NetworkListNetworkItemViewTest, HasExpectedDescriptionForCellular) {
IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CLICK_TO_ACTIVATE));
// Cellular is not activate and user is not logged in.
GetSessionControllerClient()->Reset();
ClearLogin();
base::RunLoop().RunUntilIdle();
AssertA11yDescription(
cellular_network,
@ -613,7 +613,7 @@ TEST_F(NetworkListNetworkItemViewTest, HasExpectedDescriptionForCellular) {
IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CLICK_TO_UNLOCK));
// User is not signed in.
GetSessionControllerClient()->Reset();
ClearLogin();
AssertA11yDescription(
cellular_network,
l10n_util::GetStringUTF16(

@ -297,7 +297,7 @@ class ScheduledFeatureTest : public NoSessionAshTestBase,
base::TimeTicks NowTicks() const override { return task_runner_->NowTicks(); }
void CreateTestUserSessions() {
GetSessionControllerClient()->Reset();
ClearLogin();
SimulateUserLoginWithCustomPrefs(kUser1Email);
SimulateUserLoginWithCustomPrefs(kUser2Email);
}

@ -193,8 +193,7 @@ class LastWindowClosedTest : public NoSessionAshTestBase {
// Simulate a managed guest session (non-demo session) login.
void StartManagedGuestSession() {
TestSessionControllerClient* session = GetSessionControllerClient();
session->Reset();
ClearLogin();
SimulateUserLogin({kUserEmail, user_manager::UserType::kPublicAccount});
}

@ -355,8 +355,7 @@ TEST_F(QuickSettingsHeaderTest, ChildVisible) {
// Simulate supervised user logging in.
SessionControllerImpl* session = Shell::Get()->session_controller();
TestSessionControllerClient* client = GetSessionControllerClient();
client->Reset();
ClearLogin();
SimulateUserLogin({"child@test.com", user_manager::UserType::kChild});
UserSession user_session = *session->GetUserSession(0);
user_session.custodian_email = "parent@test.com";
@ -383,9 +382,9 @@ TEST_F(QuickSettingsHeaderTest, ShowManagementDisclosure) {
AuthEventsRecorder::CreateForTesting();
// Setup to lock screen.
ClearLogin();
TestSessionControllerClient* client = GetSessionControllerClient();
client->Reset();
GetSessionControllerClient()->set_show_lock_screen_views(true);
client->set_show_lock_screen_views(true);
client->LockScreen();
client->SetSessionState(session_manager::SessionState::LOCKED);
@ -407,9 +406,9 @@ TEST_F(QuickSettingsHeaderTest, DoNotShowManagementDisclosure) {
AuthEventsRecorder::CreateForTesting();
// Setup to lock screen.
ClearLogin();
TestSessionControllerClient* client = GetSessionControllerClient();
client->Reset();
GetSessionControllerClient()->set_show_lock_screen_views(true);
client->set_show_lock_screen_views(true);
client->LockScreen();
client->SetSessionState(session_manager::SessionState::LOCKED);

@ -131,7 +131,7 @@ TEST_F(UserChooserDetailedViewControllerTest,
MultiProfileLoginDisabledForFamilyLinkUsers) {
EXPECT_TRUE(UserChooserDetailedViewController::IsUserChooserEnabled());
GetSessionControllerClient()->Reset();
ClearLogin();
// Log in as a child user.
SimulateUserLogin({"child@gmail.com", user_manager::UserType::kChild});

@ -77,7 +77,7 @@ class TouchDevicesControllerSigninTest : public NoSessionAshTestBase {
}
void CreateTestUserSessions() {
GetSessionControllerClient()->Reset();
ClearLogin();
SimulateUserLogin({kUser1Email});
SimulateUserLogin({kUser2Email});
SwitchActiveUser(kUser1Email);

@ -781,7 +781,6 @@ TEST_P(WelcomeTourControllerChromeVoxTest,
TEST_P(WelcomeTourControllerChromeVoxTest,
MaybePreventTourFromStartingIfChromeVoxEnabled) {
base::HistogramTester histogram_tester;
TestSessionControllerClient* const session = GetSessionControllerClient();
auto primary_account_id = SimulateUserLogin({.display_email = "primary@test",
.is_new_profile = true,
.activate_session = false});
@ -810,6 +809,7 @@ TEST_P(WelcomeTourControllerChromeVoxTest,
Eq(display::Screen::GetScreen()->GetPrimaryDisplay().id())))
.Times(expect_prevent ? 1 : 0);
TestSessionControllerClient* const session = GetSessionControllerClient();
session->SetSessionState(SessionState::ACTIVE);
Mock::VerifyAndClearExpectations(user_education_delegate());

@ -30,9 +30,7 @@ PrefService* InformedRestoreTestBase::GetTestPrefService() {
void InformedRestoreTestBase::SetUp() {
AshTestBase::SetUp();
TestSessionControllerClient* session_controller =
GetSessionControllerClient();
session_controller->Reset();
ClearLogin();
// Inject our own PrefService as the restore preference is normally
// registered in chrome/browser/ash/ and is not registered in ash unit

@ -472,11 +472,11 @@ TEST_F(MahiManagerImplTest, SetMahiPrefOnLogin) {
EXPECT_EQ(IsEnabled(), !mahi_enabled);
// Switching back to the previous user will update to correct pref.
GetSessionControllerClient()->SwitchActiveUser(user1_account_id);
SwitchActiveUser(user1_account_id);
EXPECT_EQ(IsEnabled(), mahi_enabled);
// Clears all logins and re-logins the default user.
GetSessionControllerClient()->Reset();
ClearLogin();
SimulateUserLogin(user1_account_id);
}
}