Correct and consistent login sequence in cros unit_tests
This CL enforces cros login sequence in the following order, which should be consistent with production. 1) ChromeOS Login 2) Create Profile 3) Post Profile Creation Steps 4) AdduserSession Bug: 384740500 Change-Id: I8a7265441342af6c1bcd543b2bd43d149aa6eed8 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6215313 Reviewed-by: Peter Kasting <pkasting@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Mitsuru Oshima <oshima@chromium.org> Reviewed-by: Xiyuan Xia <xiyuan@chromium.org> Reviewed-by: Finnur Thorarinsson <finnur@chromium.org> Cr-Commit-Position: refs/heads/main@{#1414987}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
e83b777388
commit
fd16f0f02c
ash/session
chrome
browser
ash
hats
input_method
note_taking
chromeos
extensions
extensions
api
enterprise_platform_keys
enterprise_platform_keys_private
quick_unlock_private
sessions
ui
ash
birch
glanceables
holding_space
quick_insert
shelf
tab_contents
test
@ -5,9 +5,9 @@
|
||||
#ifndef ASH_SESSION_TEST_PREF_SERVICE_PROVIDER_H_
|
||||
#define ASH_SESSION_TEST_PREF_SERVICE_PROVIDER_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include "base/containers/flat_map.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
|
||||
class AccountId;
|
||||
@ -45,8 +45,8 @@ class TestPrefServiceProvider {
|
||||
|
||||
private:
|
||||
std::unique_ptr<PrefService> signin_prefs_;
|
||||
std::map<AccountId, std::unique_ptr<PrefService>> user_prefs_map_;
|
||||
std::map<AccountId, raw_ptr<PrefService>> unowned_user_prefs_map_;
|
||||
base::flat_map<AccountId, std::unique_ptr<PrefService>> user_prefs_map_;
|
||||
base::flat_map<AccountId, raw_ptr<PrefService>> unowned_user_prefs_map_;
|
||||
};
|
||||
|
||||
} // namespace ash
|
||||
|
@ -141,8 +141,9 @@ void TestSessionControllerClient::AddUserSession(
|
||||
|
||||
if (std::holds_alternative<bool>(provide_or_pref_service)) {
|
||||
bool provide = std::get<bool>(provide_or_pref_service);
|
||||
if (provide && default_provide_pref_service_ &&
|
||||
!controller_->GetUserPrefServiceForUser(account_id)) {
|
||||
if (!default_provide_pref_service_) {
|
||||
CHECK(GetUserPrefService(account_id));
|
||||
} else if (provide && !controller_->GetUserPrefServiceForUser(account_id)) {
|
||||
ProvidePrefServiceForUser(account_id, /*notify*=*/false);
|
||||
}
|
||||
} else {
|
||||
@ -213,7 +214,6 @@ void TestSessionControllerClient::SetUnownedUserPrefService(
|
||||
|
||||
prefs_provider_->SetUnownedUserPrefs(account_id,
|
||||
std::move(unowned_pref_service));
|
||||
NotifyUserPrefServiceInitialized(account_id);
|
||||
}
|
||||
|
||||
void TestSessionControllerClient::RequestLockScreen() {
|
||||
|
@ -158,10 +158,14 @@ class HatsNotificationControllerTest
|
||||
auto* profile = profile_manager()->CreateTestingProfile(
|
||||
profile_name, std::move(prefs), std::u16string(), 0,
|
||||
TestingProfile::TestingFactories());
|
||||
OnUserProfileCreated(profile_name, profile);
|
||||
return profile;
|
||||
}
|
||||
|
||||
void OnUserProfileCreated(const std::string& profile_name,
|
||||
Profile* profile) override {
|
||||
BrowserWithTestWindowTest::OnUserProfileCreated(profile_name, profile);
|
||||
user_manager()->SetOwnerId(
|
||||
ProfileHelper::Get()->GetUserByProfile(profile)->GetAccountId());
|
||||
return profile;
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
|
@ -1538,8 +1538,6 @@ class InputMethodManagerImplKioskTest : public InputMethodManagerImplTest {
|
||||
|
||||
void LogIn(std::string_view email, const GaiaId& gaia_id) override {
|
||||
chromeos::SetUpFakeKioskSession(email);
|
||||
ash_test_helper()->test_session_controller_client()->AddUserSession(
|
||||
std::string(email), user_manager::UserType::kKioskApp);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -382,7 +382,6 @@ class NoteTakingHelperTest : public BrowserWithTestWindowTest {
|
||||
user_manager::FakeUserManager::GetFakeUsernameHash(account_id),
|
||||
/*browser_restart=*/false,
|
||||
/*is_child=*/false);
|
||||
ash_test_helper()->test_session_controller_client()->AddUserSession(email);
|
||||
}
|
||||
|
||||
TestingProfile* CreateProfile(const std::string& profile_name) override {
|
||||
@ -393,7 +392,6 @@ class NoteTakingHelperTest : public BrowserWithTestWindowTest {
|
||||
auto* profile = profile_manager()->CreateTestingProfile(
|
||||
profile_name, std::move(prefs), u"Test profile", 1 /*avatar_id*/,
|
||||
TestingProfile::TestingFactories());
|
||||
OnUserProfileCreated(profile_name, profile);
|
||||
return profile;
|
||||
}
|
||||
|
||||
@ -407,7 +405,6 @@ class NoteTakingHelperTest : public BrowserWithTestWindowTest {
|
||||
TestingProfile* profile = profile_manager()->CreateTestingProfile(
|
||||
kSecondProfileName, std::move(prefs), u"second-profile-username",
|
||||
/*avatar_id=*/1, TestingProfile::TestingFactories());
|
||||
OnUserProfileCreated(kSecondProfileName, profile);
|
||||
|
||||
InitExtensionService(profile);
|
||||
InitWebAppProvider(profile);
|
||||
|
@ -372,8 +372,6 @@ class ChromeContentBrowserClientWindowKioskTest
|
||||
|
||||
void LogIn(std::string_view email, const GaiaId& gaia_id) override {
|
||||
chromeos::SetUpFakeKioskSession(email);
|
||||
ash_test_helper()->test_session_controller_client()->AddUserSession(
|
||||
std::string(email));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -111,9 +111,11 @@ class ScopedTestingProfile {
|
||||
public:
|
||||
ScopedTestingProfile(TestingProfile* profile,
|
||||
TestingProfileManager* profile_manager,
|
||||
ash::TestPrefServiceProvider* pref_service_provider,
|
||||
const AccountId& account_id)
|
||||
: profile_(profile),
|
||||
profile_manager_(profile_manager),
|
||||
pref_service_provider_(pref_service_provider),
|
||||
account_id_(account_id) {
|
||||
user_manager::UserManager::Get()->OnUserProfileCreated(account_id,
|
||||
profile->GetPrefs());
|
||||
@ -126,6 +128,8 @@ class ScopedTestingProfile {
|
||||
~ScopedTestingProfile() {
|
||||
user_manager::UserManager::Get()->OnUserProfileWillBeDestroyed(account_id_);
|
||||
std::string user_name = profile_->GetProfileUserName();
|
||||
pref_service_provider_->ClearUnownedUserPrefs(
|
||||
AccountId::FromUserEmail(user_name));
|
||||
profile_ = nullptr;
|
||||
profile_manager_->DeleteTestingProfile(user_name);
|
||||
}
|
||||
@ -135,6 +139,7 @@ class ScopedTestingProfile {
|
||||
private:
|
||||
raw_ptr<TestingProfile> profile_;
|
||||
const raw_ptr<TestingProfileManager> profile_manager_;
|
||||
const raw_ptr<ash::TestPrefServiceProvider> pref_service_provider_;
|
||||
const AccountId account_id_;
|
||||
};
|
||||
|
||||
@ -191,6 +196,7 @@ class LoginApiUnittest : public ExtensionApiUnittest {
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
mock_lock_handler_.reset();
|
||||
mock_existing_user_controller_.reset();
|
||||
mock_login_display_host_.reset();
|
||||
scoped_user_manager_.reset();
|
||||
@ -205,8 +211,9 @@ class LoginApiUnittest : public ExtensionApiUnittest {
|
||||
AccountId::FromUserEmail(email));
|
||||
TestingProfile* profile = profile_manager()->CreateTestingProfile(email);
|
||||
|
||||
return std::make_unique<ScopedTestingProfile>(profile, profile_manager(),
|
||||
user->GetAccountId());
|
||||
return std::make_unique<ScopedTestingProfile>(
|
||||
profile, profile_manager(), ash_test_helper()->prefs_provider(),
|
||||
user->GetAccountId());
|
||||
}
|
||||
|
||||
raw_ptr<ash::FakeChromeUserManager, DanglingUntriaged>
|
||||
@ -633,8 +640,9 @@ class LoginApiUserSessionUnittest : public LoginApiUnittest {
|
||||
/* is_affiliated= */ true);
|
||||
TestingProfile* profile = profile_manager()->CreateTestingProfile(email);
|
||||
|
||||
return std::make_unique<ScopedTestingProfile>(profile, profile_manager(),
|
||||
user->GetAccountId());
|
||||
return std::make_unique<ScopedTestingProfile>(
|
||||
profile, profile_manager(), ash_test_helper()->prefs_provider(),
|
||||
user->GetAccountId());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -346,7 +346,6 @@ class ApiGuardDelegateAffiliatedUserTest : public ApiGuardDelegateTest {
|
||||
AccountId::FromUserEmailGaiaId(email, gaia_id),
|
||||
/*is_managed=*/true,
|
||||
/*is_affiliated=*/true);
|
||||
ash_test_helper()->test_session_controller_client()->AddUserSession(email);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -116,7 +116,6 @@ class EPKChallengeKeyTestBase : public BrowserWithTestWindowTest {
|
||||
AccountId::FromUserEmailGaiaId(email, gaia_id),
|
||||
/*is_managed=*/true,
|
||||
/*is_affiliated=*/true);
|
||||
ash_test_helper()->test_session_controller_client()->AddUserSession(email);
|
||||
}
|
||||
|
||||
std::unique_ptr<KeyedService> CreateKeyPermissionsManagerService(
|
||||
|
@ -56,7 +56,6 @@ class EPKPChallengeKeyTestBase : public BrowserWithTestWindowTest {
|
||||
AccountId::FromUserEmailGaiaId(email, gaia_id),
|
||||
/*is_managed=*/true,
|
||||
/*is_affiliated=*/true);
|
||||
ash_test_helper()->test_session_controller_client()->AddUserSession(email);
|
||||
}
|
||||
|
||||
// Derived classes can override this method to set the required authenticated
|
||||
|
@ -224,7 +224,6 @@ class QuickUnlockPrivateUnitTest
|
||||
TestingProfile* profile = profile_manager()->CreateTestingProfile(
|
||||
profile_name, std::move(pref_service), u"Test profile",
|
||||
1 /* avatar_id */, GetTestingFactories());
|
||||
OnUserProfileCreated(profile_name, profile);
|
||||
|
||||
// Setup a primary user.
|
||||
ash::ProfileHelper::Get()->SetUserToProfileMappingForTesting(
|
||||
|
@ -1468,10 +1468,6 @@ class SessionServiceKioskTest : public SessionServiceTest {
|
||||
|
||||
void LogIn(std::string_view email, const GaiaId& gaia_id) override {
|
||||
chromeos::SetUpFakeKioskSession(std::string(email));
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
ash_test_helper()->test_session_controller_client()->AddUserSession(
|
||||
std::string(email), user_manager::UserType::kKioskApp);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -473,14 +473,11 @@ class BirchKeyedServiceTest : public BrowserWithTestWindowTest {
|
||||
const AccountId account_id(AccountId::FromUserEmailGaiaId(email, gaia_id));
|
||||
fake_user_manager_->AddUser(account_id);
|
||||
fake_user_manager_->LoginUser(account_id);
|
||||
GetSessionControllerClient()->AddUserSession(std::string(email));
|
||||
GetSessionControllerClient()->SwitchActiveUser(account_id);
|
||||
}
|
||||
|
||||
TestingProfile* CreateProfile(const std::string& profile_name) override {
|
||||
auto* testing_profile = profile_manager()->CreateTestingProfile(
|
||||
profile_name, {}, u"user_name", /*avatar_id=*/0, GetTestingFactories());
|
||||
OnUserProfileCreated(profile_name, testing_profile);
|
||||
return testing_profile;
|
||||
}
|
||||
|
||||
|
@ -18,11 +18,8 @@ namespace ash {
|
||||
class GlanceablesKeyedServiceFactoryTest : public BrowserWithTestWindowTest {
|
||||
public:
|
||||
TestingProfile* CreateProfile(const std::string& profile_name) override {
|
||||
auto* profile =
|
||||
profile_manager()->CreateTestingProfile(profile_name,
|
||||
/*is_main_profile=*/true);
|
||||
OnUserProfileCreated(profile_name, profile);
|
||||
return profile;
|
||||
return profile_manager()->CreateTestingProfile(profile_name,
|
||||
/*is_main_profile=*/true);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -32,11 +32,9 @@ class GlanceablesKeyedServiceTest : public BrowserWithTestWindowTest {
|
||||
|
||||
// BrowserWithTestWindowTest:
|
||||
TestingProfile* CreateProfile(const std::string& profile_name) override {
|
||||
auto* const profile =
|
||||
profile_manager()->CreateTestingProfile(kPrimaryProfileName,
|
||||
/*is_main_profile=*/true);
|
||||
OnUserProfileCreated(profile_name, profile);
|
||||
return profile;
|
||||
EXPECT_EQ(kPrimaryProfileName, profile_name);
|
||||
return profile_manager()->CreateTestingProfile(profile_name,
|
||||
/*is_main_profile=*/true);
|
||||
}
|
||||
};
|
||||
|
||||
@ -66,8 +64,6 @@ TEST_F(GlanceablesKeyedServiceTest, RegisterClientsInAshForNonPrimaryUser) {
|
||||
auto* secondary_profile =
|
||||
profile_manager()->CreateTestingProfile(kSecondaryProfileName,
|
||||
/*is_main_profile=*/false);
|
||||
OnUserProfileCreated(kSecondaryProfileName, secondary_profile);
|
||||
|
||||
SwitchActiveUser(kSecondaryProfileName);
|
||||
auto service_secondary =
|
||||
std::make_unique<GlanceablesKeyedService>(secondary_profile);
|
||||
|
@ -607,11 +607,9 @@ class HoldingSpaceKeyedServiceTest : public BrowserWithTestWindowTest {
|
||||
constexpr char kSecondaryProfileName[] = "secondary_profile";
|
||||
constexpr char kFakeGaia2[] = "fakegaia2";
|
||||
LogIn(kSecondaryProfileName, GaiaId(kFakeGaia2));
|
||||
auto* profile = profile_manager()->CreateTestingProfile(
|
||||
return profile_manager()->CreateTestingProfile(
|
||||
kSecondaryProfileName, std::move(prefs), /*user_name=*/std::u16string(),
|
||||
/*avatar_id=*/0, GetTestingFactories());
|
||||
OnUserProfileCreated(kSecondaryProfileName, profile);
|
||||
return profile;
|
||||
}
|
||||
|
||||
using PopulatePrefStoreCallback = base::OnceCallback<void(TestingPrefStore*)>;
|
||||
@ -635,7 +633,6 @@ class HoldingSpaceKeyedServiceTest : public BrowserWithTestWindowTest {
|
||||
void ActivateSecondaryProfile() {
|
||||
const std::string kSecondaryProfileName = "secondary_profile";
|
||||
const AccountId account_id(AccountId::FromUserEmail(kSecondaryProfileName));
|
||||
GetSessionControllerClient()->AddUserSession(kSecondaryProfileName);
|
||||
GetSessionControllerClient()->SwitchActiveUser(account_id);
|
||||
}
|
||||
|
||||
@ -785,7 +782,6 @@ class HoldingSpaceKeyedServiceWithExperimentalFeatureForGuestTest
|
||||
user->GetAccountId()),
|
||||
/*browser_restart=*/false,
|
||||
/*is_child=*/false);
|
||||
ash_test_helper()->test_session_controller_client()->AddUserSession(email);
|
||||
}
|
||||
|
||||
TestingProfile* CreateProfile(const std::string& profile_name) override {
|
||||
@ -805,7 +801,6 @@ class HoldingSpaceKeyedServiceWithExperimentalFeatureForGuestTest
|
||||
base::BindRepeating(&BuildVolumeManager)}});
|
||||
profile_ =
|
||||
profile_manager()->CreateGuestProfile(std::move(guest_profile_builder));
|
||||
OnUserProfileCreated(profile_name, profile_);
|
||||
return profile_;
|
||||
}
|
||||
|
||||
|
@ -191,11 +191,9 @@ class QuickInsertClientImplTest : public BrowserWithTestWindowTest {
|
||||
}
|
||||
|
||||
TestingProfile* CreateProfile(const std::string& profile_name) override {
|
||||
auto* profile = profile_manager()->CreateTestingProfile(
|
||||
return profile_manager()->CreateTestingProfile(
|
||||
profile_name, GetTestingFactories(), /*is_main_profile=*/false,
|
||||
test_shared_url_loader_factory_);
|
||||
OnUserProfileCreated(profile_name, profile);
|
||||
return profile;
|
||||
}
|
||||
|
||||
TestingProfile::TestingFactories GetTestingFactories() override {
|
||||
@ -227,8 +225,6 @@ class QuickInsertClientImplTest : public BrowserWithTestWindowTest {
|
||||
// DriveFS needs the account to have an ID.
|
||||
const AccountId account_id = AccountId::FromUserEmailGaiaId(email, gaia_id);
|
||||
user_manager()->AddGaiaUser(account_id, user_manager::UserType::kRegular);
|
||||
ash_test_helper()->test_session_controller_client()->AddUserSession(
|
||||
std::string(email));
|
||||
user_manager()->UserLoggedIn(
|
||||
account_id,
|
||||
user_manager::FakeUserManager::GetFakeUsernameHash(account_id),
|
||||
|
@ -1660,10 +1660,7 @@ class MultiProfileMultiBrowserShelfLayoutChromeShelfControllerTest
|
||||
// TODO(crbug.com/40286020): Merge into BrowserWithTestWindowTest.
|
||||
const AccountId account_id = AccountId::FromUserEmailGaiaId(email, gaia_id);
|
||||
// Add a user to the fake user manager.
|
||||
auto* user = user_manager()->AddGaiaUser(account_id,
|
||||
user_manager::UserType::kRegular);
|
||||
ash_test_helper()->test_session_controller_client()->AddUserSession(
|
||||
user->GetDisplayEmail());
|
||||
user_manager()->AddGaiaUser(account_id, user_manager::UserType::kRegular);
|
||||
user_manager()->UserLoggedIn(
|
||||
account_id,
|
||||
user_manager::FakeUserManager::GetFakeUsernameHash(account_id),
|
||||
|
@ -39,9 +39,6 @@ class ChromeWebContentsMenuHelperUnitTest : public BrowserWithTestWindowTest {
|
||||
auto* profile = profile_manager()->CreateTestingProfile(
|
||||
profile_name, std::move(prefs), std::u16string(), 0,
|
||||
TestingProfile::TestingFactories());
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
OnUserProfileCreated(profile_name, profile);
|
||||
#endif
|
||||
return profile;
|
||||
}
|
||||
|
||||
|
@ -42,9 +42,10 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
#include "chrome/browser/ash/crosapi/crosapi_manager.h"
|
||||
#include "chrome/browser/ash/crosapi/idle_service_ash.h"
|
||||
#include "chrome/browser/ash/profiles/profile_helper.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chromeos/ash/components/browser_context_helper/annotated_account_id.h"
|
||||
#include "chromeos/ash/components/dbus/cros_disks/cros_disks_client.h"
|
||||
@ -53,13 +54,10 @@
|
||||
#include "components/user_manager/fake_user_manager.h"
|
||||
#include "components/user_manager/scoped_user_manager.h"
|
||||
#include "components/user_manager/user_manager.h"
|
||||
#include "google_apis/gaia/gaia_auth_util.h"
|
||||
#include "google_apis/gaia/gaia_id.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_LACROS)
|
||||
#include "chromeos/lacros/lacros_test_helper.h"
|
||||
#endif
|
||||
|
||||
using content::NavigationController;
|
||||
using content::RenderFrameHost;
|
||||
using content::RenderFrameHostTester;
|
||||
@ -75,7 +73,7 @@ void BrowserWithTestWindowTest::SetUp() {
|
||||
SetUpProfileManager();
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
ash::CrosDisksClient::InitializeFake();
|
||||
if (!ash::disks::DiskMountManager::GetInstance()) {
|
||||
ash::disks::DiskMountManager::InitializeForTesting(
|
||||
@ -98,13 +96,6 @@ void BrowserWithTestWindowTest::SetUp() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_LACROS)
|
||||
if (!chromeos::LacrosService::Get()) {
|
||||
lacros_service_test_helper_ =
|
||||
std::make_unique<chromeos::ScopedLacrosServiceTestHelper>();
|
||||
}
|
||||
#endif
|
||||
|
||||
// This must be created after |ash_test_helper_| is set up so that it doesn't
|
||||
// create a DeviceDataManager.
|
||||
rvh_test_enabler_ = std::make_unique<content::RenderViewHostTestEnabler>();
|
||||
@ -116,7 +107,7 @@ void BrowserWithTestWindowTest::SetUp() {
|
||||
user_performance_tuning_manager_environment_.SetUp(
|
||||
profile_manager_->local_state()->Get());
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
crosapi::IdleServiceAsh::DisableForTesting();
|
||||
manager_ = std::make_unique<crosapi::CrosapiManager>();
|
||||
kiosk_chrome_app_manager_ = std::make_unique<ash::KioskChromeAppManager>();
|
||||
@ -161,14 +152,14 @@ void BrowserWithTestWindowTest::TearDown() {
|
||||
SystemNetworkContextManager::DeleteInstance();
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
manager_.reset();
|
||||
kiosk_chrome_app_manager_.reset();
|
||||
#endif
|
||||
|
||||
user_performance_tuning_manager_environment_.TearDown();
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
ash_test_helper_.TearDown();
|
||||
#endif
|
||||
|
||||
@ -181,7 +172,7 @@ void BrowserWithTestWindowTest::TearDown() {
|
||||
lacros_service_test_helper_.reset();
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
test_views_delegate_.reset();
|
||||
user_manager_.Reset();
|
||||
ash::disks::DiskMountManager::Shutdown();
|
||||
@ -203,13 +194,17 @@ void BrowserWithTestWindowTest::SetUpProfileManager(
|
||||
std::unique_ptr<ProfileManager> profile_manager) {
|
||||
profile_manager_ = std::make_unique<TestingProfileManager>(
|
||||
TestingBrowserProcess::GetGlobal());
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
profile_manager_->set_on_profile_created_callback(
|
||||
base::BindRepeating(&BrowserWithTestWindowTest::PostUserProfileCreation,
|
||||
base::Unretained(this)));
|
||||
#endif
|
||||
ASSERT_TRUE(
|
||||
profile_manager_->SetUp(profiles_path, std::move(profile_manager)));
|
||||
}
|
||||
|
||||
gfx::NativeWindow BrowserWithTestWindowTest::GetContext() {
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
return ash_test_helper_.GetContext();
|
||||
#elif defined(TOOLKIT_VIEWS)
|
||||
return views_test_helper_->GetContext();
|
||||
@ -275,9 +270,6 @@ TestingProfile* BrowserWithTestWindowTest::CreateProfile(
|
||||
auto* profile = profile_manager_->CreateTestingProfile(
|
||||
profile_name, /*prefs=*/nullptr, /*user_name=*/std::u16string(),
|
||||
/*avatar_id=*/0, GetTestingFactories());
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
OnUserProfileCreated(profile_name, profile);
|
||||
#endif
|
||||
return profile;
|
||||
}
|
||||
|
||||
@ -326,19 +318,16 @@ void BrowserWithTestWindowTest::LogIn(std::string_view email,
|
||||
const GaiaId& gaia_id) {
|
||||
const AccountId account_id = AccountId::FromUserEmailGaiaId(email, gaia_id);
|
||||
user_manager_->AddGaiaUser(account_id, user_manager::UserType::kRegular);
|
||||
ash_test_helper()->test_session_controller_client()->AddUserSession(
|
||||
std::string(email));
|
||||
user_manager_->UserLoggedIn(
|
||||
account_id,
|
||||
user_manager::FakeUserManager::GetFakeUsernameHash(account_id),
|
||||
/*browser_restart=*/false,
|
||||
/*is_child=*/false);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
void BrowserWithTestWindowTest::OnUserProfileCreated(const std::string& email,
|
||||
Profile* profile) {
|
||||
CHECK(profile);
|
||||
// TODO(b/40225390): Unset for_test explicit param after subclasses are
|
||||
// migrated.
|
||||
AccountId account_id = AccountId::FromUserEmail(email);
|
||||
@ -384,7 +373,24 @@ BrowserWithTestWindowTest::GetCrosSettingsHelper() {
|
||||
ash::StubInstallAttributes* BrowserWithTestWindowTest::GetInstallAttributes() {
|
||||
return GetCrosSettingsHelper()->InstallAttributes();
|
||||
}
|
||||
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
|
||||
void BrowserWithTestWindowTest::PostUserProfileCreation(
|
||||
const std::string& email,
|
||||
Profile* profile) {
|
||||
// The test profile is not for gaia login.
|
||||
if (email != gaia::CanonicalizeEmail(email)) {
|
||||
return;
|
||||
}
|
||||
auto* user = user_manager::UserManager::Get()->FindUser(
|
||||
AccountId::FromUserEmail(email));
|
||||
if (user) {
|
||||
OnUserProfileCreated(email, profile);
|
||||
ash_test_helper()->test_session_controller_client()->AddUserSession(
|
||||
email, user->GetType());
|
||||
}
|
||||
}
|
||||
|
||||
#endif // BUILDFLAG(IS_CHROMEOS)
|
||||
|
||||
BrowserWithTestWindowTest::BrowserWithTestWindowTest(
|
||||
std::unique_ptr<content::BrowserTaskEnvironment> task_environment,
|
||||
|
@ -29,7 +29,7 @@
|
||||
#if defined(TOOLKIT_VIEWS)
|
||||
#include "chrome/test/views/chrome_test_views_delegate.h"
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
#include "ash/test/ash_test_helper.h"
|
||||
#include "ash/test/ash_test_views_delegate.h"
|
||||
#include "base/scoped_observation.h"
|
||||
@ -50,15 +50,11 @@
|
||||
class GURL;
|
||||
class GaiaId;
|
||||
|
||||
namespace chromeos {
|
||||
class ScopedLacrosServiceTestHelper;
|
||||
} // namespace chromeos
|
||||
|
||||
namespace content {
|
||||
class NavigationController;
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
namespace crosapi {
|
||||
class CrosapiManager;
|
||||
}
|
||||
@ -172,7 +168,7 @@ class BrowserWithTestWindowTest : public testing::Test, public ProfileObserver {
|
||||
return std::move(window_);
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
ash::AshTestHelper* ash_test_helper() { return &ash_test_helper_; }
|
||||
user_manager::FakeUserManager* user_manager() { return user_manager_.Get(); }
|
||||
#endif
|
||||
@ -242,7 +238,7 @@ class BrowserWithTestWindowTest : public testing::Test, public ProfileObserver {
|
||||
|
||||
#if defined(TOOLKIT_VIEWS)
|
||||
views::TestViewsDelegate* test_views_delegate() {
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
return test_views_delegate_.get();
|
||||
#else
|
||||
return views_test_helper_->test_views_delegate();
|
||||
@ -253,9 +249,7 @@ class BrowserWithTestWindowTest : public testing::Test, public ProfileObserver {
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
// Logs in an User as `email`.
|
||||
virtual void LogIn(std::string_view email, const GaiaId& gaia_id);
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
// Handles the post-process for the newly created Profile.
|
||||
// Expected to be called on customizing CreateProfile for ash.
|
||||
virtual void OnUserProfileCreated(const std::string& email, Profile* profile);
|
||||
@ -281,12 +275,11 @@ class BrowserWithTestWindowTest : public testing::Test, public ProfileObserver {
|
||||
// We need to create a MessageLoop, otherwise a bunch of things fails.
|
||||
std::unique_ptr<content::BrowserTaskEnvironment> task_environment_;
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_LACROS)
|
||||
std::unique_ptr<chromeos::ScopedLacrosServiceTestHelper>
|
||||
lacros_service_test_helper_;
|
||||
#endif
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
// A template method (in Design Pattern) that execute post profile creation
|
||||
// steps.
|
||||
void PostUserProfileCreation(const std::string& email, Profile* profile);
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
ash::ScopedCrosSettingsTestHelper cros_settings_test_helper_;
|
||||
user_manager::TypedScopedUserManager<user_manager::FakeUserManager>
|
||||
user_manager_;
|
||||
@ -307,7 +300,7 @@ class BrowserWithTestWindowTest : public testing::Test, public ProfileObserver {
|
||||
std::unique_ptr<BrowserWindow> window_; // Usually a TestBrowserWindow.
|
||||
std::unique_ptr<Browser> browser_;
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
ash::AshTestHelper ash_test_helper_;
|
||||
std::unique_ptr<views::TestViewsDelegate> test_views_delegate_ =
|
||||
std::make_unique<ChromeTestViewsDelegate<ash::AshTestViewsDelegate>>();
|
||||
|
@ -148,6 +148,11 @@ TestingProfile* TestingProfileManager::CreateTestingProfile(
|
||||
testing_profiles_.insert(std::make_pair(profile_name, profile_ptr));
|
||||
profile_observations_.AddObservation(profile_ptr);
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
if (!callback_.is_null()) {
|
||||
callback_.Run(profile_name, profile_ptr);
|
||||
}
|
||||
#endif
|
||||
return profile_ptr;
|
||||
}
|
||||
|
||||
@ -200,6 +205,11 @@ TestingProfile* TestingProfileManager::CreateGuestProfile(
|
||||
testing_profiles_.insert(std::make_pair(kGuestProfileName, profile_ptr));
|
||||
profile_observations_.AddObservation(profile_ptr);
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
if (!callback_.is_null()) {
|
||||
callback_.Run(kGuestProfileName, profile_ptr);
|
||||
}
|
||||
#endif
|
||||
return profile_ptr;
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,15 @@ class TestingProfileManager : public ProfileObserver {
|
||||
const base::FilePath& profiles_path = base::FilePath(),
|
||||
std::unique_ptr<ProfileManager> profile_manager = nullptr);
|
||||
|
||||
#if BUILDFLAG(IS_CHROMEOS)
|
||||
using OnProfileCreatedCallback =
|
||||
base::RepeatingCallback<void(const std::string&, Profile*)>;
|
||||
void set_on_profile_created_callback(OnProfileCreatedCallback callback) {
|
||||
callback_ = callback;
|
||||
}
|
||||
OnProfileCreatedCallback callback_;
|
||||
#endif
|
||||
|
||||
// Creates a new TestingProfile whose data lives in a directory related to
|
||||
// profile_name, which is a non-user-visible key for the test environment.
|
||||
// |prefs| is the PrefService used by the profile. If it is NULL, the profile
|
||||
|
Reference in New Issue
Block a user