Use pointer for the TestHelper argument.
In the style guide, it is recommended to use pointer for the parameter if the referred instance needs to outlive the function call. https://google.github.io/styleguide/cppguide.html#Inputs_and_Outputs BUG=278643115 TEST=Tryjob Change-Id: I6eeb48627569a140f184a9e017741581f898f07f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6406833 Commit-Queue: Hidehiko Abe <hidehiko@chromium.org> Reviewed-by: Jun Ishiguro <junis@google.com> Commit-Queue: Jun Ishiguro <junis@google.com> Auto-Submit: Hidehiko Abe <hidehiko@chromium.org> Cr-Commit-Position: refs/heads/main@{#1439212}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
2170f041a7
commit
8f4d03acf9
chrome/browser
ash
accessibility
account_manager
app_list
arc
bluetooth
login
profiles
ui
webui
ash
settings
pages
chromeos
ash
experiences
services
bluetooth_config
components
kiosk
components/user_manager
@ -1825,7 +1825,7 @@ class AccessibilityManagerLoginTest : public OobeBaseTest {
|
||||
}
|
||||
|
||||
void CreateSession(const AccountId& account_id) {
|
||||
ASSERT_TRUE(user_manager::TestHelper(*user_manager::UserManager::Get())
|
||||
ASSERT_TRUE(user_manager::TestHelper(user_manager::UserManager::Get())
|
||||
.AddRegularUser(account_id));
|
||||
|
||||
auto* session_manager = session_manager::SessionManager::Get();
|
||||
|
@ -85,7 +85,7 @@ bool GetScreenMagnifierEnabledFromPref() {
|
||||
}
|
||||
|
||||
[[nodiscard]] bool AddRegularUser(const AccountId& account_id) {
|
||||
return user_manager::TestHelper(*user_manager::UserManager::Get())
|
||||
return user_manager::TestHelper(user_manager::UserManager::Get())
|
||||
.AddRegularUser(account_id);
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ class AccountManagerPolicyControllerTest : public InProcessBrowserTest {
|
||||
const AccountId account_id = AccountId::FromUserEmailGaiaId(
|
||||
kFakePrimaryUsername,
|
||||
signin::GetTestGaiaIdForEmail(kFakePrimaryUsername));
|
||||
ASSERT_TRUE(user_manager::TestHelper(*user_manager::UserManager::Get())
|
||||
ASSERT_TRUE(user_manager::TestHelper(user_manager::UserManager::Get())
|
||||
.AddRegularUser(account_id));
|
||||
session_manager::SessionManager::Get()->CreateSession(
|
||||
account_id, user_manager::TestHelper::GetFakeUsernameHash(account_id),
|
||||
|
@ -1295,7 +1295,7 @@ class AppListClientNewUserTest : public InProcessBrowserTest,
|
||||
ash::ProfileHelper::SetProfileToUserForTestingEnabled(true);
|
||||
account_id_ =
|
||||
AccountId::FromUserEmailGaiaId("test@test-user", GaiaId("gaia-id"));
|
||||
auto* user = user_manager::TestHelper(*user_manager::UserManager::Get())
|
||||
auto* user = user_manager::TestHelper(user_manager::UserManager::Get())
|
||||
.AddRegularUser(account_id_);
|
||||
ASSERT_TRUE(user);
|
||||
session_manager::SessionManager::Get()->CreateSession(
|
||||
|
@ -358,7 +358,7 @@ class ArcAuthServiceTest : public InProcessBrowserTest {
|
||||
void SetAccountAndProfile(const user_manager::UserType user_type) {
|
||||
const user_manager::User* user = nullptr;
|
||||
{
|
||||
user_manager::TestHelper test_helper(*user_manager::UserManager::Get());
|
||||
user_manager::TestHelper test_helper(user_manager::UserManager::Get());
|
||||
switch (user_type) {
|
||||
case user_manager::UserType::kChild:
|
||||
user = test_helper.AddChildUser(AccountId::FromUserEmailGaiaId(
|
||||
|
@ -79,8 +79,8 @@ class ArcLockedFullscreenManagerTest
|
||||
|
||||
const AccountId account_id(
|
||||
AccountId::FromUserEmailGaiaId(kUserEmail, GaiaId(kUserGaiaId)));
|
||||
ASSERT_TRUE(
|
||||
user_manager::TestHelper(*user_manager_).AddRegularUser(account_id));
|
||||
ASSERT_TRUE(user_manager::TestHelper(user_manager_.get())
|
||||
.AddRegularUser(account_id));
|
||||
const std::string user_id_hash =
|
||||
user_manager::TestHelper::GetFakeUsernameHash(account_id);
|
||||
user_manager_->UserLoggedIn(account_id, user_id_hash);
|
||||
|
@ -74,7 +74,7 @@ TEST_F(BluetoothLogControllerTest, NonRegularUser) {
|
||||
auto* upstart_client = FakeUpstartClient::Get();
|
||||
upstart_client->StartRecordingUpstartOperations();
|
||||
|
||||
auto* user = user_manager::TestHelper(user_manager())
|
||||
auto* user = user_manager::TestHelper(&user_manager())
|
||||
.AddKioskAppUser("test@kiosk-apps.device-local.localhost");
|
||||
// TODO(b/278643115): use UserManager::UserLoggedIn() to notify observer.
|
||||
controller().OnUserLoggedIn(*user);
|
||||
|
@ -488,7 +488,7 @@ TEST_F(UserManagerTest, DoNotSaveKioskAccountsToKRegularUsersPref) {
|
||||
kKioskAccountId,
|
||||
user_manager::TestHelper::GetFakeUsernameHash(kKioskAccountId));
|
||||
ResetUserManager();
|
||||
ASSERT_TRUE(user_manager::TestHelper(*user_manager::UserManager::Get())
|
||||
ASSERT_TRUE(user_manager::TestHelper(user_manager::UserManager::Get())
|
||||
.AddRegularUser(kAccountId0));
|
||||
user_manager::UserManager::Get()->UserLoggedIn(
|
||||
kAccountId0, user_manager::TestHelper::GetFakeUsernameHash(kAccountId0));
|
||||
@ -512,8 +512,8 @@ TEST_F(UserManagerTest, DoNotSaveKioskAccountsToKRegularUsersPref) {
|
||||
|
||||
TEST_F(UserManagerTest, RemoveUser) {
|
||||
// Create owner account and login in.
|
||||
ASSERT_TRUE(
|
||||
user_manager::TestHelper(*user_manager_).AddRegularUser(kOwnerAccountId));
|
||||
ASSERT_TRUE(user_manager::TestHelper(user_manager_.get())
|
||||
.AddRegularUser(kOwnerAccountId));
|
||||
user_manager_->UserLoggedIn(
|
||||
kOwnerAccountId,
|
||||
user_manager::TestHelper::GetFakeUsernameHash(kOwnerAccountId));
|
||||
@ -522,8 +522,8 @@ TEST_F(UserManagerTest, RemoveUser) {
|
||||
ResetUserManager();
|
||||
|
||||
// Create non-owner account and login in.
|
||||
ASSERT_TRUE(
|
||||
user_manager::TestHelper(*user_manager_).AddRegularUser(kAccountId0));
|
||||
ASSERT_TRUE(user_manager::TestHelper(user_manager_.get())
|
||||
.AddRegularUser(kAccountId0));
|
||||
user_manager_->UserLoggedIn(
|
||||
kAccountId0, user_manager::TestHelper::GetFakeUsernameHash(kAccountId0));
|
||||
// Log-in owner account.
|
||||
@ -578,18 +578,18 @@ TEST_F(UserManagerTest, RemoveUser) {
|
||||
}
|
||||
|
||||
TEST_F(UserManagerTest, RemoveRegularUsersExceptOwnerFromList) {
|
||||
ASSERT_TRUE(user_manager::TestHelper(*user_manager::UserManager::Get())
|
||||
ASSERT_TRUE(user_manager::TestHelper(user_manager::UserManager::Get())
|
||||
.AddRegularUser(kOwnerAccountId));
|
||||
user_manager::UserManager::Get()->UserLoggedIn(
|
||||
kOwnerAccountId,
|
||||
user_manager::TestHelper::GetFakeUsernameHash(kOwnerAccountId));
|
||||
ResetUserManager();
|
||||
ASSERT_TRUE(user_manager::TestHelper(*user_manager::UserManager::Get())
|
||||
ASSERT_TRUE(user_manager::TestHelper(user_manager::UserManager::Get())
|
||||
.AddRegularUser(kAccountId0));
|
||||
user_manager::UserManager::Get()->UserLoggedIn(
|
||||
kAccountId0, user_manager::TestHelper::GetFakeUsernameHash(kAccountId0));
|
||||
ResetUserManager();
|
||||
ASSERT_TRUE(user_manager::TestHelper(*user_manager::UserManager::Get())
|
||||
ASSERT_TRUE(user_manager::TestHelper(user_manager::UserManager::Get())
|
||||
.AddRegularUser(kAccountId1));
|
||||
user_manager::UserManager::Get()->UserLoggedIn(
|
||||
kAccountId1, user_manager::TestHelper::GetFakeUsernameHash(kAccountId1));
|
||||
@ -627,13 +627,13 @@ TEST_F(UserManagerTest, RegularUserLoggedInAsEphemeral) {
|
||||
/* owner= */ kOwnerAccountId.GetUserEmail());
|
||||
RetrieveTrustedDevicePolicies();
|
||||
|
||||
ASSERT_TRUE(user_manager::TestHelper(*user_manager::UserManager::Get())
|
||||
ASSERT_TRUE(user_manager::TestHelper(user_manager::UserManager::Get())
|
||||
.AddRegularUser(kOwnerAccountId));
|
||||
user_manager::UserManager::Get()->UserLoggedIn(
|
||||
kOwnerAccountId,
|
||||
user_manager::TestHelper::GetFakeUsernameHash(kOwnerAccountId));
|
||||
ResetUserManager();
|
||||
ASSERT_TRUE(user_manager::TestHelper(*user_manager::UserManager::Get())
|
||||
ASSERT_TRUE(user_manager::TestHelper(user_manager::UserManager::Get())
|
||||
.AddRegularUser(kAccountId0));
|
||||
user_manager::UserManager::Get()->UserLoggedIn(
|
||||
kAccountId0, user_manager::TestHelper::GetFakeUsernameHash(kAccountId0));
|
||||
@ -647,7 +647,7 @@ TEST_F(UserManagerTest, RegularUserLoggedInAsEphemeral) {
|
||||
|
||||
TEST_F(UserManagerTest, ScreenLockAvailability) {
|
||||
// Log in the user and create the profile.
|
||||
ASSERT_TRUE(user_manager::TestHelper(*user_manager::UserManager::Get())
|
||||
ASSERT_TRUE(user_manager::TestHelper(user_manager::UserManager::Get())
|
||||
.AddRegularUser(kOwnerAccountId));
|
||||
user_manager::UserManager::Get()->UserLoggedIn(
|
||||
kOwnerAccountId,
|
||||
@ -676,7 +676,7 @@ TEST_F(UserManagerTest, ScreenLockAvailability) {
|
||||
}
|
||||
|
||||
TEST_F(UserManagerTest, ProfileRequiresPolicyUnknown) {
|
||||
ASSERT_TRUE(user_manager::TestHelper(*user_manager::UserManager::Get())
|
||||
ASSERT_TRUE(user_manager::TestHelper(user_manager::UserManager::Get())
|
||||
.AddRegularUser(kOwnerAccountId));
|
||||
user_manager::UserManager::Get()->UserLoggedIn(
|
||||
kOwnerAccountId,
|
||||
@ -747,8 +747,8 @@ TEST_F(UserManagerTest,
|
||||
// callback.
|
||||
TEST_F(UserManagerTest, ProfilePrefs) {
|
||||
// Simulates login.
|
||||
ASSERT_TRUE(
|
||||
user_manager::TestHelper(*user_manager_).AddRegularUser(kAccountId0));
|
||||
ASSERT_TRUE(user_manager::TestHelper(user_manager_.get())
|
||||
.AddRegularUser(kAccountId0));
|
||||
user_manager_->UserLoggedIn(
|
||||
kAccountId0, user_manager::TestHelper::GetFakeUsernameHash(kAccountId0));
|
||||
|
||||
|
@ -302,7 +302,7 @@ class ProfileManagerTest : public testing::Test {
|
||||
|
||||
// Add user for testing.
|
||||
{
|
||||
user_manager::TestHelper test_helper(*user_manager);
|
||||
user_manager::TestHelper test_helper(user_manager);
|
||||
if (account_id == user_manager::GuestAccountId()) {
|
||||
ASSERT_TRUE(test_helper.AddGuestUser());
|
||||
} else {
|
||||
@ -337,7 +337,7 @@ class ProfileManagerTest : public testing::Test {
|
||||
profile_helper->GetProfilePathByUserIdHash(user_id_hash);
|
||||
|
||||
{
|
||||
user_manager::TestHelper test_helper(*user_manager);
|
||||
user_manager::TestHelper test_helper(user_manager);
|
||||
if (user_is_child) {
|
||||
CHECK(test_helper.AddChildUser(account_id));
|
||||
} else {
|
||||
@ -473,7 +473,7 @@ TEST_F(ProfileManagerTest, UserProfileLoading) {
|
||||
user_manager::TestHelper::GetFakeUsernameHash(account_id);
|
||||
auto* user_manager = user_manager::UserManager::Get();
|
||||
ASSERT_TRUE(
|
||||
user_manager::TestHelper(*user_manager).AddRegularUser(account_id));
|
||||
user_manager::TestHelper(user_manager).AddRegularUser(account_id));
|
||||
user_manager->UserLoggedIn(account_id, user_id_hash);
|
||||
|
||||
// Sign-in profile should be returned at this stage. Otherwise, login code
|
||||
|
@ -179,7 +179,7 @@ class AccountManagerUIHandlerTest
|
||||
GetDeviceAccountInfo().email, GaiaId(GetDeviceAccountInfo().id));
|
||||
const user_manager::User* user;
|
||||
{
|
||||
user_manager::TestHelper test_helper(*user_manager::UserManager::Get());
|
||||
user_manager::TestHelper test_helper(user_manager::UserManager::Get());
|
||||
if (GetDeviceAccountInfo().user_type == user_manager::UserType::kChild) {
|
||||
user = test_helper.AddChildUser(account_id);
|
||||
} else {
|
||||
|
@ -341,7 +341,7 @@ TEST_F(ArcUtilTest, IsArcAllowedForUser) {
|
||||
fake_user_manager->AddPublicAccountUser(AccountId::FromUserEmailGaiaId(
|
||||
"user3@test.com", GaiaId("1234567890-3")))));
|
||||
EXPECT_FALSE(IsArcAllowedForUser(
|
||||
user_manager::TestHelper(*fake_user_manager)
|
||||
user_manager::TestHelper(fake_user_manager.Get())
|
||||
.AddKioskAppUser("user4@kiosk-apps.device-local.localhost")));
|
||||
EXPECT_TRUE(IsArcAllowedForUser(fake_user_manager->AddGaiaUser(
|
||||
AccountId::FromUserEmailGaiaId("user5@test.com", GaiaId("1234567890-5")),
|
||||
|
@ -71,7 +71,7 @@ class BluetoothPowerControllerImplTest : public testing::Test {
|
||||
bool is_new_profile = false) {
|
||||
const user_manager::User* user;
|
||||
if (is_user_kiosk) {
|
||||
user = user_manager::TestHelper(*fake_user_manager_)
|
||||
user = user_manager::TestHelper(fake_user_manager_.Get())
|
||||
.AddKioskAppUser(display_email);
|
||||
} else {
|
||||
user = fake_user_manager_->AddGaiaUser(
|
||||
|
@ -18,7 +18,7 @@ void SetUpFakeKioskSession(std::string_view email) {
|
||||
<< "UserManager instance needs to be set up to start Kiosk session.";
|
||||
|
||||
auto* user_manager = user_manager::UserManager::Get();
|
||||
auto* user = user_manager::TestHelper(*user_manager).AddKioskAppUser(email);
|
||||
auto* user = user_manager::TestHelper(user_manager).AddKioskAppUser(email);
|
||||
CHECK_EQ(user_manager->GetLoggedInUsers().size(), 0u);
|
||||
user_manager->UserLoggedIn(
|
||||
user->GetAccountId(),
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "components/user_manager/test_helper.h"
|
||||
|
||||
#include "base/check_deref.h"
|
||||
#include "chromeos/ash/components/cryptohome/cryptohome_parameters.h"
|
||||
#include "chromeos/ash/components/dbus/userdataauth/userdataauth_client.h"
|
||||
#include "components/account_id/account_id.h"
|
||||
@ -91,8 +92,8 @@ std::string TestHelper::GetFakeUsernameHash(const AccountId& account_id) {
|
||||
cryptohome::CreateAccountIdentifierFromAccountId(account_id));
|
||||
}
|
||||
|
||||
TestHelper::TestHelper(UserManager& user_manager)
|
||||
: user_manager_(user_manager) {}
|
||||
TestHelper::TestHelper(UserManager* user_manager)
|
||||
: user_manager_(CHECK_DEREF(user_manager)) {}
|
||||
|
||||
TestHelper::~TestHelper() = default;
|
||||
|
||||
|
@ -51,7 +51,8 @@ class TestHelper {
|
||||
// Valid AccountId must be used, otherwise CHECKed.
|
||||
static std::string GetFakeUsernameHash(const AccountId& account_id);
|
||||
|
||||
explicit TestHelper(UserManager& user_manager);
|
||||
// `user_manager` must outlive the instance of the TestHelper.
|
||||
explicit TestHelper(UserManager* user_manager);
|
||||
~TestHelper();
|
||||
|
||||
// Creates and adds a regular (persisted) user, and returns it.
|
||||
|
Reference in New Issue
Block a user