Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1161)

Unified Diff: chrome/browser/profiles/profile_manager_unittest.cc

Issue 1113333003: Don't create a new profile when cleaning up stale ephemeral profiles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: fix? Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profiles/profile_manager_unittest.cc
diff --git a/chrome/browser/profiles/profile_manager_unittest.cc b/chrome/browser/profiles/profile_manager_unittest.cc
index 76a2126745abd2bea3b17be1b2ea9aab44e08afa..1a8ea975f929de3bfa646eb414201ce65d10adae 100644
--- a/chrome/browser/profiles/profile_manager_unittest.cc
+++ b/chrome/browser/profiles/profile_manager_unittest.cc
@@ -65,6 +65,12 @@ namespace {
// observers is the same.
Profile* g_created_profile;
+#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
+void FailOnProfileCreation(Profile* profile, Profile::CreateStatus status) {
+ ADD_FAILURE();
+}
+#endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
+
class UnittestProfileManager : public ::ProfileManagerWithoutInit {
public:
explicit UnittestProfileManager(const base::FilePath& user_data_dir)
@@ -902,8 +908,9 @@ TEST_F(ProfileManagerTest, ActiveProfileDeleted) {
local_state->SetString(prefs::kProfileLastUsed, profile_name1);
// Delete the active profile.
- profile_manager->ScheduleProfileForDeletion(dest_path1,
- ProfileManager::CreateCallback());
+ profile_manager->ScheduleProfileForDeletion(
+ dest_path1, false /* suppress_profile_creation */,
+ ProfileManager::CreateCallback());
// Spin the message loop so that all the callbacks can finish running.
base::RunLoop().RunUntilIdle();
@@ -934,8 +941,9 @@ TEST_F(ProfileManagerTest, LastProfileDeleted) {
local_state->SetString(prefs::kProfileLastUsed, profile_name1);
// Delete the active profile.
- profile_manager->ScheduleProfileForDeletion(dest_path1,
- ProfileManager::CreateCallback());
+ profile_manager->ScheduleProfileForDeletion(
+ dest_path1, false /* suppress_profile_creation */,
+ ProfileManager::CreateCallback());
// Spin the message loop so that all the callbacks can finish running.
base::RunLoop().RunUntilIdle();
@@ -988,8 +996,9 @@ TEST_F(ProfileManagerTest, LastProfileDeletedWithGuestActiveProfile) {
local_state->SetString(prefs::kProfileLastUsed, guest_profile_name);
// Delete the other profile.
- profile_manager->ScheduleProfileForDeletion(dest_path1,
- ProfileManager::CreateCallback());
+ profile_manager->ScheduleProfileForDeletion(
+ dest_path1, false /* suppress_profile_creation */,
+ ProfileManager::CreateCallback());
// Spin the message loop so that all the callbacks can finish running.
base::RunLoop().RunUntilIdle();
@@ -998,11 +1007,46 @@ TEST_F(ProfileManagerTest, LastProfileDeletedWithGuestActiveProfile) {
base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2);
EXPECT_EQ(3u, profile_manager->GetLoadedProfiles().size());
- EXPECT_EQ(1u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles());
+ ASSERT_EQ(1u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles());
EXPECT_EQ(dest_path2,
profile_manager->GetProfileInfoCache().GetPathOfProfileAtIndex(0));
}
+TEST_F(ProfileManagerTest, DeleteStaleEphemeralProfile) {
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ ASSERT_TRUE(profile_manager);
+
+ // Create a profile, don't load it yet.
+ const std::string profile_name1 = "New Profile 1";
+ base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1);
+
+ ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
+ cache.AddProfileToCache(dest_path1, ASCIIToUTF16(profile_name1),
+ ASCIIToUTF16(profile_name1), 0, std::string());
+ EXPECT_EQ(1u, cache.GetNumberOfProfiles());
+ EXPECT_EQ(0u, profile_manager->GetLoadedProfiles().size());
+
+ // Set it as the active profile.
+ PrefService* local_state = g_browser_process->local_state();
+ local_state->SetString(prefs::kProfileLastUsed, profile_name1);
+
+ // Delete the active profile.
+ profile_manager->ScheduleProfileForDeletion(
+ dest_path1, true /* suppress_profile_creation */,
+ base::Bind(&FailOnProfileCreation));
+ // Spin the message loop so that all the callbacks can finish running.
+ base::RunLoop().RunUntilIdle();
+
+ // A new profile should have been set as the last used profile, but not loaded
+ // yet.
+ const std::string profile_name2 = "Profile 1";
Mike Lerman 2015/05/05 13:44:45 nit: variable is profile_name2, but the name is Pr
Bernhard Bauer 2015/05/05 14:33:22 Yes... except ProfileManager internally increases
+ base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2);
+
+ EXPECT_EQ(0u, profile_manager->GetLoadedProfiles().size());
+ EXPECT_EQ(0u, cache.GetNumberOfProfiles());
+ EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed));
+}
+
TEST_F(ProfileManagerTest, ProfileDisplayNameResetsDefaultName) {
if (!profiles::IsMultipleProfilesEnabled())
return;
@@ -1034,8 +1078,9 @@ TEST_F(ProfileManagerTest, ProfileDisplayNameResetsDefaultName) {
profiles::GetAvatarNameForProfile(profile2->GetPath()));
// Deleting a profile means returning to the default name.
- profile_manager->ScheduleProfileForDeletion(profile2->GetPath(),
- ProfileManager::CreateCallback());
+ profile_manager->ScheduleProfileForDeletion(
+ profile2->GetPath(), false /* suppress_profile_creation */,
+ ProfileManager::CreateCallback());
// Spin the message loop so that all the callbacks can finish running.
base::RunLoop().RunUntilIdle();
EXPECT_EQ(default_profile_name,
@@ -1081,8 +1126,9 @@ TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesCustomName) {
profiles::GetAvatarNameForProfile(profile2->GetPath()));
// Deleting a profile means returning to the original, custom name.
- profile_manager->ScheduleProfileForDeletion(profile2->GetPath(),
- ProfileManager::CreateCallback());
+ profile_manager->ScheduleProfileForDeletion(
+ profile2->GetPath(), false /* suppress_profile_creation */,
+ ProfileManager::CreateCallback());
// Spin the message loop so that all the callbacks can finish running.
base::RunLoop().RunUntilIdle();
EXPECT_EQ(custom_profile_name,
@@ -1136,8 +1182,9 @@ TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesSignedInName) {
profiles::GetAvatarNameForProfile(profile2->GetPath()));
// Deleting a profile means returning to the original, actual profile name.
- profile_manager->ScheduleProfileForDeletion(profile2->GetPath(),
- ProfileManager::CreateCallback());
+ profile_manager->ScheduleProfileForDeletion(
+ profile2->GetPath(), false /* suppress_profile_creation */,
+ ProfileManager::CreateCallback());
// Spin the message loop so that all the callbacks can finish running.
base::RunLoop().RunUntilIdle();
EXPECT_EQ(gaia_given_name,
@@ -1241,8 +1288,9 @@ TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) {
// Delete the active profile. This should switch and load the unloaded
// profile.
- profile_manager->ScheduleProfileForDeletion(dest_path1,
- ProfileManager::CreateCallback());
+ profile_manager->ScheduleProfileForDeletion(
+ dest_path1, false /* suppress_profile_creation */,
+ ProfileManager::CreateCallback());
// Spin the message loop so that all the callbacks can finish running.
base::RunLoop().RunUntilIdle();
@@ -1299,12 +1347,14 @@ TEST_F(ProfileManagerTest, ActiveProfileDeletedNextProfileDeletedToo) {
// Try to break this flow by setting the active profile to Profile2 in the
// middle (so after the first posted message), and trying to delete Profile2,
// so that the ProfileManager has to look for a different profile to load.
- profile_manager->ScheduleProfileForDeletion(dest_path1,
- ProfileManager::CreateCallback());
+ profile_manager->ScheduleProfileForDeletion(
+ dest_path1, false /* suppress_profile_creation */,
+ ProfileManager::CreateCallback());
local_state->SetString(prefs::kProfileLastUsed,
dest_path2.BaseName().MaybeAsASCII());
- profile_manager->ScheduleProfileForDeletion(dest_path2,
- ProfileManager::CreateCallback());
+ profile_manager->ScheduleProfileForDeletion(
+ dest_path2, false /* suppress_profile_creation */,
+ ProfileManager::CreateCallback());
// Spin the message loop so that all the callbacks can finish running.
base::RunLoop().RunUntilIdle();

Powered by Google App Engine
This is Rietveld 408576698