0

Update UserManagerImpl::UserLoggedIn condition.

The condition to check whether or not multi-sign-in is updated.
Some assumption that UserManagerImpl has is not explicit assertion
with CHECK.

This is preparation to switch Fake{,Chrome}UserManager into
UserManagerImpl.

BUG=278643115
TEST=tryjob

Change-Id: I80d47a588dc8dbec1fb93cd27008b0ddaf0e9eee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6196999
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1412459}
This commit is contained in:
Hidehiko Abe
2025-01-28 11:49:18 -08:00
committed by Chromium LUCI CQ
parent 5fa48150ab
commit f45e2828c4
14 changed files with 207 additions and 90 deletions

@ -90,6 +90,8 @@ if (is_chromeos) {
"fake_user_manager.h",
"fake_user_manager_delegate.cc",
"fake_user_manager_delegate.h",
"test_helper.cc",
"test_helper.h",
]
public_deps = [
@ -99,7 +101,10 @@ if (is_chromeos) {
"//components/account_id",
]
deps = [ "//chromeos/ash/components/settings" ]
deps = [
"//chromeos/ash/components/settings",
"//components/prefs",
]
}
source_set("unit_tests") {

@ -0,0 +1,27 @@
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/user_manager/test_helper.h"
#include "components/account_id/account_id.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/user_manager/known_user.h"
#include "components/user_manager/user_manager_pref_names.h"
namespace user_manager {
// static
void TestHelper::RegisterPersistedUser(PrefService& local_state,
const AccountId& account_id) {
{
ScopedListPrefUpdate update(&local_state, prefs::kRegularUsersPref);
update->Append(account_id.GetUserEmail());
}
{
KnownUser known_user(&local_state);
known_user.UpdateId(account_id);
}
}
} // namespace user_manager

@ -0,0 +1,32 @@
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_USER_MANAGER_TEST_HELPER_H_
#define COMPONENTS_USER_MANAGER_TEST_HELPER_H_
class AccountId;
class PrefService;
namespace user_manager {
// Utilities to set up UserManager related environment.
class TestHelper {
public:
// Records the `account_id` as a persisted user to the given `local_state`.
// `local_state` must be properly set up, specifically it needs UserManager
// related registration.
// In most cases, this registration needs to be done before UserManager
// is created. Specifically, for browser_tests, SetUpLocalStatePrefService()
// is a recommended function to call this.
static void RegisterPersistedUser(PrefService& local_state,
const AccountId& account_id);
private:
// Currently, this has only static methods.
TestHelper() = delete;
};
} // namespace user_manager
#endif // COMPONENTS_USER_MANAGER_TEST_HELPER_H_

@ -275,9 +275,13 @@ void UserManagerImpl::UserLoggedIn(const AccountId& account_id,
User* user = FindUserInListAndModify(account_id);
const UserType user_type =
CalculateUserType(account_id, user, browser_restart, is_child);
if (active_user_ && user) {
if (!logged_in_users_.empty()) {
// Handle multi sign-in case. For multi-sign in, there already should be
// active_user_ set, and the user to be logged in should be found
// in the persistent user list.
CHECK(active_user_);
CHECK(user);
user->set_is_logged_in(true);
user->set_username_hash(username_hash);
logged_in_users_.push_back(user);
@ -300,7 +304,12 @@ void UserManagerImpl::UserLoggedIn(const AccountId& account_id,
return;
}
// There are no logged in users. `active_user_` should not be set.
CHECK(!active_user_);
// Ensure User is there.
const UserType user_type =
CalculateUserType(account_id, user, browser_restart, is_child);
switch (user_type) {
case UserType::kRegular:
case UserType::kChild: