Commit 543a8cd1 authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Update ProfileManager unittest for ephemeral Guest profiles.

ProfileManager unittests are updated to cover ephemeral Guest profiles,
and Guest profile names are updated to be different from regular profile
names.

Please see go/ephemeral-guest-profiles for more context.

Bug: 1125474
Change-Id: I11b868925e47135e6773b75f0d298f3311f52e3a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2483827Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819801}
parent ee392622
...@@ -798,13 +798,29 @@ base::FilePath ProfileManager::GetGuestProfilePath() { ...@@ -798,13 +798,29 @@ base::FilePath ProfileManager::GetGuestProfilePath() {
ProfileManager* profile_manager = g_browser_process->profile_manager(); ProfileManager* profile_manager = g_browser_process->profile_manager();
// TODO(https://crbug.com/1125474): Consider adding a different naming system
// for Guest profiles.
if (profile_manager->guest_profile_path_.empty()) { if (profile_manager->guest_profile_path_.empty()) {
profile_manager->guest_profile_path_ = if (Profile::IsEphemeralGuestProfileEnabled()) {
Profile::IsEphemeralGuestProfileEnabled() PrefService* local_state = g_browser_process->local_state();
? profile_manager->GenerateNextProfileDirectoryPath() DCHECK(local_state);
: profile_manager->user_data_dir().Append(chrome::kGuestProfileDir);
// Create the next Guest profile in the next available directory slot.
int next_directory =
local_state->GetInteger(prefs::kGuestProfilesNumCreated);
std::string profile_name = chrome::kEphemeralGuestProfileDirPrefix;
profile_name.append(base::NumberToString(next_directory));
base::FilePath new_path = profile_manager->user_data_dir();
#if defined(OS_WIN)
new_path = new_path.Append(base::ASCIIToUTF16(profile_name));
#else
new_path = new_path.Append(profile_name);
#endif
local_state->SetInteger(prefs::kGuestProfilesNumCreated,
++next_directory);
profile_manager->guest_profile_path_ = new_path;
} else {
profile_manager->guest_profile_path_ =
profile_manager->user_data_dir().Append(chrome::kGuestProfileDir);
}
} }
return profile_manager->guest_profile_path_; return profile_manager->guest_profile_path_;
......
...@@ -541,13 +541,6 @@ TEST_F(ProfileManagerTest, AddProfileToStorageCheckOmitted) { ...@@ -541,13 +541,6 @@ TEST_F(ProfileManagerTest, AddProfileToStorageCheckOmitted) {
EXPECT_FALSE(entry->IsOmitted()); EXPECT_FALSE(entry->IsOmitted());
} }
TEST_F(ProfileManagerTest, GetGuestProfilePath) {
base::FilePath guest_path = ProfileManager::GetGuestProfilePath();
base::FilePath expected_path = temp_dir_.GetPath();
expected_path = expected_path.Append(chrome::kGuestProfileDir);
EXPECT_EQ(expected_path, guest_path);
}
TEST_F(ProfileManagerTest, GetSystemProfilePath) { TEST_F(ProfileManagerTest, GetSystemProfilePath) {
base::FilePath system_profile_path = ProfileManager::GetSystemProfilePath(); base::FilePath system_profile_path = ProfileManager::GetSystemProfilePath();
base::FilePath expected_path = temp_dir_.GetPath(); base::FilePath expected_path = temp_dir_.GetPath();
...@@ -570,9 +563,17 @@ class UnittestGuestProfileManager : public UnittestProfileManager { ...@@ -570,9 +563,17 @@ class UnittestGuestProfileManager : public UnittestProfileManager {
} }
}; };
class ProfileManagerGuestTest : public ProfileManagerTest { class ProfileManagerGuestTest : public ProfileManagerTest,
public ::testing::WithParamInterface<bool> {
public: public:
ProfileManagerGuestTest() = default; ProfileManagerGuestTest() {
is_ephemeral = GetParam();
// Update |is_ephemeral| if it's not supported on platform.
is_ephemeral &=
TestingProfile::SetScopedFeatureListForEphemeralGuestProfiles(
scoped_feature_list_, is_ephemeral);
}
ProfileManagerGuestTest(const ProfileManagerGuestTest&) = delete; ProfileManagerGuestTest(const ProfileManagerGuestTest&) = delete;
ProfileManagerGuestTest& operator=(const ProfileManagerGuestTest&) = delete; ProfileManagerGuestTest& operator=(const ProfileManagerGuestTest&) = delete;
~ProfileManagerGuestTest() override = default; ~ProfileManagerGuestTest() override = default;
...@@ -591,6 +592,8 @@ class ProfileManagerGuestTest : public ProfileManagerTest { ...@@ -591,6 +592,8 @@ class ProfileManagerGuestTest : public ProfileManagerTest {
#endif #endif
} }
bool IsEphemeral() { return is_ephemeral; }
protected: protected:
ProfileManager* CreateProfileManagerForTest() override { ProfileManager* CreateProfileManagerForTest() override {
return new UnittestGuestProfileManager(temp_dir_.GetPath()); return new UnittestGuestProfileManager(temp_dir_.GetPath());
...@@ -602,9 +605,13 @@ class ProfileManagerGuestTest : public ProfileManagerTest { ...@@ -602,9 +605,13 @@ class ProfileManagerGuestTest : public ProfileManagerTest {
user_manager::UserManager::Get()); user_manager::UserManager::Get());
} }
#endif #endif
private:
base::test::ScopedFeatureList scoped_feature_list_;
bool is_ephemeral;
}; };
TEST_F(ProfileManagerGuestTest, GetLastUsedProfileAllowedByPolicy) { TEST_P(ProfileManagerGuestTest, GetLastUsedProfileAllowedByPolicy) {
ProfileManager* profile_manager = g_browser_process->profile_manager(); ProfileManager* profile_manager = g_browser_process->profile_manager();
ASSERT_TRUE(profile_manager); ASSERT_TRUE(profile_manager);
...@@ -614,7 +621,7 @@ TEST_F(ProfileManagerGuestTest, GetLastUsedProfileAllowedByPolicy) { ...@@ -614,7 +621,7 @@ TEST_F(ProfileManagerGuestTest, GetLastUsedProfileAllowedByPolicy) {
} }
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
TEST_F(ProfileManagerGuestTest, GuestProfileIngonito) { TEST_P(ProfileManagerGuestTest, GuestProfileIngonito) {
Profile* primary_profile = ProfileManager::GetPrimaryUserProfile(); Profile* primary_profile = ProfileManager::GetPrimaryUserProfile();
EXPECT_TRUE(primary_profile->IsOffTheRecord()); EXPECT_TRUE(primary_profile->IsOffTheRecord());
...@@ -630,6 +637,27 @@ TEST_F(ProfileManagerGuestTest, GuestProfileIngonito) { ...@@ -630,6 +637,27 @@ TEST_F(ProfileManagerGuestTest, GuestProfileIngonito) {
} }
#endif #endif
TEST_P(ProfileManagerGuestTest, GetGuestProfilePath) {
base::FilePath guest_path = ProfileManager::GetGuestProfilePath();
base::FilePath expected_path = temp_dir_.GetPath();
const std::string kExpectedGuestProfileName =
IsEphemeral() ? "Guest 1" : "Guest Profile";
#if defined(OS_WIN)
expected_path =
expected_path.Append(base::ASCIIToUTF16(kExpectedGuestProfileName));
#else
expected_path = expected_path.Append(kExpectedGuestProfileName);
#endif
EXPECT_EQ(expected_path, guest_path);
// TODO(https://crbug.com/1125474): Add browser test to ensure two ephemeral
// Guest profile do not share the path.
}
INSTANTIATE_TEST_SUITE_P(All,
ProfileManagerGuestTest,
/*is_ephemeral=*/testing::Bool());
TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) {
ProfileManager* profile_manager = g_browser_process->profile_manager(); ProfileManager* profile_manager = g_browser_process->profile_manager();
ProfileAttributesStorage& storage = ProfileAttributesStorage& storage =
...@@ -1330,7 +1358,7 @@ TEST_F(ProfileManagerTest, LastProfileDeleted) { ...@@ -1330,7 +1358,7 @@ TEST_F(ProfileManagerTest, LastProfileDeleted) {
EXPECT_EQ(dest_path2, storage.GetAllProfilesAttributes()[0]->GetPath()); EXPECT_EQ(dest_path2, storage.GetAllProfilesAttributes()[0]->GetPath());
} }
TEST_F(ProfileManagerTest, LastProfileDeletedWithGuestActiveProfile) { TEST_P(ProfileManagerGuestTest, LastProfileDeletedWithGuestActiveProfile) {
ProfileManager* profile_manager = g_browser_process->profile_manager(); ProfileManager* profile_manager = g_browser_process->profile_manager();
ASSERT_TRUE(profile_manager); ASSERT_TRUE(profile_manager);
ProfileAttributesStorage& storage = ProfileAttributesStorage& storage =
...@@ -1341,8 +1369,8 @@ TEST_F(ProfileManagerTest, LastProfileDeletedWithGuestActiveProfile) { ...@@ -1341,8 +1369,8 @@ TEST_F(ProfileManagerTest, LastProfileDeletedWithGuestActiveProfile) {
base::FilePath dest_path1 = temp_dir_.GetPath().AppendASCII(profile_name1); base::FilePath dest_path1 = temp_dir_.GetPath().AppendASCII(profile_name1);
MockObserver mock_observer; MockObserver mock_observer;
EXPECT_CALL(mock_observer, OnProfileCreated( EXPECT_CALL(mock_observer, OnProfileCreated(testing::NotNull(), NotFail()))
testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); .Times(testing::AtLeast(2));
CreateProfileAsync(profile_manager, profile_name1, &mock_observer); CreateProfileAsync(profile_manager, profile_name1, &mock_observer);
content::RunAllTasksUntilIdle(); content::RunAllTasksUntilIdle();
......
...@@ -65,6 +65,7 @@ void RegisterPrefs(PrefRegistrySimple* registry) { ...@@ -65,6 +65,7 @@ void RegisterPrefs(PrefRegistrySimple* registry) {
// Preferences about global profile information. // Preferences about global profile information.
registry->RegisterStringPref(prefs::kProfileLastUsed, std::string()); registry->RegisterStringPref(prefs::kProfileLastUsed, std::string());
registry->RegisterIntegerPref(prefs::kProfilesNumCreated, 1); registry->RegisterIntegerPref(prefs::kProfilesNumCreated, 1);
registry->RegisterIntegerPref(prefs::kGuestProfilesNumCreated, 1);
registry->RegisterListPref(prefs::kProfilesLastActive); registry->RegisterListPref(prefs::kProfilesLastActive);
registry->RegisterListPref(prefs::kProfilesDeleted); registry->RegisterListPref(prefs::kProfilesDeleted);
......
...@@ -130,6 +130,7 @@ const base::FilePath::CharType kStatusTrayWindowClass[] = ...@@ -130,6 +130,7 @@ const base::FilePath::CharType kStatusTrayWindowClass[] =
const char kInitialProfile[] = "Default"; const char kInitialProfile[] = "Default";
const char kMultiProfileDirPrefix[] = "Profile "; const char kMultiProfileDirPrefix[] = "Profile ";
const char kEphemeralGuestProfileDirPrefix[] = "Guest ";
const base::FilePath::CharType kGuestProfileDir[] = FPL("Guest Profile"); const base::FilePath::CharType kGuestProfileDir[] = FPL("Guest Profile");
const base::FilePath::CharType kSystemProfileDir[] = FPL("System Profile"); const base::FilePath::CharType kSystemProfileDir[] = FPL("System Profile");
......
...@@ -39,6 +39,7 @@ extern const base::FilePath::CharType kStatusTrayWindowClass[]; ...@@ -39,6 +39,7 @@ extern const base::FilePath::CharType kStatusTrayWindowClass[];
extern const char kInitialProfile[]; extern const char kInitialProfile[];
extern const char kMultiProfileDirPrefix[]; extern const char kMultiProfileDirPrefix[];
extern const char kEphemeralGuestProfileDirPrefix[];
extern const base::FilePath::CharType kGuestProfileDir[]; extern const base::FilePath::CharType kGuestProfileDir[];
extern const base::FilePath::CharType kSystemProfileDir[]; extern const base::FilePath::CharType kSystemProfileDir[];
......
...@@ -1610,6 +1610,10 @@ const char kProfilesLastActive[] = "profile.last_active_profiles"; ...@@ -1610,6 +1610,10 @@ const char kProfilesLastActive[] = "profile.last_active_profiles";
// directories. // directories.
const char kProfilesNumCreated[] = "profile.profiles_created"; const char kProfilesNumCreated[] = "profile.profiles_created";
// Total number of Guest profiles created for this Chrome build. Used to tag
// ephemeral Guest profile directories.
const char kGuestProfilesNumCreated[] = "profile.guest_profiles_created";
// String containing the version of Chrome that the profile was created by. // String containing the version of Chrome that the profile was created by.
// If profile was created before this feature was added, this pref will default // If profile was created before this feature was added, this pref will default
// to "1.0.0.0". // to "1.0.0.0".
......
...@@ -521,6 +521,7 @@ extern const char kHadThreeConsecutiveNotificationPermissionDenies[]; ...@@ -521,6 +521,7 @@ extern const char kHadThreeConsecutiveNotificationPermissionDenies[];
extern const char kProfileLastUsed[]; extern const char kProfileLastUsed[];
extern const char kProfilesLastActive[]; extern const char kProfilesLastActive[];
extern const char kProfilesNumCreated[]; extern const char kProfilesNumCreated[];
extern const char kGuestProfilesNumCreated[];
extern const char kProfileInfoCache[]; extern const char kProfileInfoCache[];
#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
extern const char kLegacyProfileNamesMigrated[]; extern const char kLegacyProfileNamesMigrated[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment