Chromium Code Reviews| 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 adaf53ac3db1cebc22dfab1971847e42cf02cdcf..6764c79d67946cec051b2c63b4a3e5cc157818ad 100644 |
| --- a/chrome/browser/profiles/profile_manager_unittest.cc |
| +++ b/chrome/browser/profiles/profile_manager_unittest.cc |
| @@ -120,6 +120,17 @@ class ProfileManagerTest : public testing::Test { |
| message_loop_.RunUntilIdle(); |
| } |
| + virtual void CreateProfileAsync(ProfileManager* manager, |
| + const base::FilePath& path, |
| + MockObserver* mock_observer) { |
| + manager->CreateProfileAsync( |
| + path, base::Bind(&MockObserver::OnProfileCreated, |
| + base::Unretained(mock_observer)), |
| + string16(), |
| + string16(), |
| + false); |
| + } |
| + |
| #if defined(OS_CHROMEOS) |
| chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| chromeos::ScopedTestCrosSettings test_cros_settings_; |
| @@ -247,10 +258,9 @@ TEST_F(ProfileManagerTest, DISABLED_CreateProfileAsync) { |
| EXPECT_CALL(mock_observer, OnProfileCreated( |
| testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); |
| - g_browser_process->profile_manager()->CreateProfileAsync(dest_path, |
| - base::Bind(&MockObserver::OnProfileCreated, |
| - base::Unretained(&mock_observer)), |
| - string16(), string16(), false); |
| + CreateProfileAsync(g_browser_process->profile_manager(), |
| + dest_path, |
| + &mock_observer); |
| message_loop_.RunUntilIdle(); |
| } |
| @@ -279,18 +289,9 @@ TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) { |
| ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| - profile_manager->CreateProfileAsync(dest_path, |
| - base::Bind(&MockObserver::OnProfileCreated, |
| - base::Unretained(&mock_observer1)), |
| - string16(), string16(), false); |
| - profile_manager->CreateProfileAsync(dest_path, |
| - base::Bind(&MockObserver::OnProfileCreated, |
| - base::Unretained(&mock_observer2)), |
| - string16(), string16(), false); |
| - profile_manager->CreateProfileAsync(dest_path, |
| - base::Bind(&MockObserver::OnProfileCreated, |
| - base::Unretained(&mock_observer3)), |
| - string16(), string16(), false); |
| + CreateProfileAsync(profile_manager, dest_path, &mock_observer1); |
| + CreateProfileAsync(profile_manager, dest_path, &mock_observer2); |
| + CreateProfileAsync(profile_manager, dest_path, &mock_observer3); |
| message_loop_.RunUntilIdle(); |
| } |
| @@ -307,14 +308,8 @@ TEST_F(ProfileManagerTest, CreateProfilesAsync) { |
| ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| - profile_manager->CreateProfileAsync(dest_path1, |
| - base::Bind(&MockObserver::OnProfileCreated, |
| - base::Unretained(&mock_observer)), |
| - string16(), string16(), false); |
| - profile_manager->CreateProfileAsync(dest_path2, |
| - base::Bind(&MockObserver::OnProfileCreated, |
| - base::Unretained(&mock_observer)), |
| - string16(), string16(), false); |
| + CreateProfileAsync(profile_manager, dest_path1, &mock_observer); |
| + CreateProfileAsync(profile_manager, dest_path2, &mock_observer); |
| message_loop_.RunUntilIdle(); |
| } |
| @@ -450,6 +445,93 @@ TEST_F(ProfileManagerTest, GetLastUsedProfileAllowedByPolicy) { |
| profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord()); |
| } |
| +TEST_F(ProfileManagerTest, ActiveProfileDeleted) { |
| + ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| + ASSERT_TRUE(profile_manager); |
| + |
| + // Create and load two profiles. |
| + base::FilePath dest_path1 = |
| + temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 1")); |
| + base::FilePath dest_path2 = |
| + temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); |
| + |
| + MockObserver mock_observer; |
| + EXPECT_CALL(mock_observer, OnProfileCreated( |
| + testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); |
| + |
| + CreateProfileAsync(profile_manager, dest_path1, &mock_observer); |
| + CreateProfileAsync(profile_manager, dest_path2, &mock_observer); |
| + message_loop_.RunUntilIdle(); |
| + |
| + EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); |
| + EXPECT_EQ(2u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); |
| + |
| + // Set the active profile. |
| + PrefService* local_state = g_browser_process->local_state(); |
| + local_state->SetString(prefs::kProfileLastUsed, |
| + dest_path1.BaseName().MaybeAsASCII()); |
| + |
| + // Delete the active profile. |
| + profile_manager->ScheduleProfileForDeletion(dest_path1, |
| + ProfileManager::CreateCallback()); |
| + // Spin the message loop so that all the callbacks can finish running. |
| + message_loop_.RunUntilIdle(); |
| + |
| + EXPECT_EQ( |
| + g_browser_process->profile_manager()->GetLastUsedProfile()->GetPath(), |
| + dest_path2); |
| + EXPECT_EQ( |
| + g_browser_process->local_state()->GetString(prefs::kProfileLastUsed), |
| + "New Profile 2"); |
|
Alexei Svitkine (slow)
2013/06/14 22:04:58
Same comments here as for the test below.
|
| +} |
| + |
| +TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) { |
| + ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| + ASSERT_TRUE(profile_manager); |
| + |
| + // Create and load one profile, and just create a second profile. |
| + base::FilePath dest_path1 = |
| + temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 1")); |
| + base::FilePath dest_path2 = |
| + temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); |
| + |
| + MockObserver mock_observer; |
| + EXPECT_CALL(mock_observer, OnProfileCreated( |
| + testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); |
| + CreateProfileAsync(profile_manager, dest_path1, &mock_observer); |
| + message_loop_.RunUntilIdle(); |
| + |
| + // Track the profile, but don't load it. |
| + ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| + cache.AddProfileToCache(dest_path2, ASCIIToUTF16("New Profile 2"), |
| + string16(), 0, false); |
| + |
| + message_loop_.RunUntilIdle(); |
| + |
| + EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); |
| + EXPECT_EQ(2u, cache.GetNumberOfProfiles()); |
| + |
| + // Set the active profile. |
| + PrefService* local_state = g_browser_process->local_state(); |
| + local_state->SetString(prefs::kProfileLastUsed, |
| + dest_path1.BaseName().MaybeAsASCII()); |
| + |
| + // Delete the active profile. This should switch and load the unloaded |
| + // profile. |
| + profile_manager->ScheduleProfileForDeletion(dest_path1, |
| + ProfileManager::CreateCallback()); |
| + |
| + // Spin the message loop so that all the callbacks can finish running. |
| + message_loop_.RunUntilIdle(); |
| + |
| + EXPECT_EQ( |
| + g_browser_process->profile_manager()->GetLastUsedProfile()->GetPath(), |
|
Alexei Svitkine (slow)
2013/06/14 22:04:58
Nit: you already have a local pointer to profile_m
noms (inactive)
2013/06/18 21:38:11
Done.
|
| + dest_path2); |
| + EXPECT_EQ( |
| + g_browser_process->local_state()->GetString(prefs::kProfileLastUsed), |
|
Alexei Svitkine (slow)
2013/06/14 22:04:58
Ditto for local_state
noms (inactive)
2013/06/18 21:38:11
Done.
|
| + "New Profile 2"); |
|
Alexei Svitkine (slow)
2013/06/14 22:04:58
Usually, we put the expected value as the first pa
noms (inactive)
2013/06/18 21:38:11
Done.
|
| +} |
| + |
| #if !defined(OS_ANDROID) |
| // There's no Browser object on Android. |
| TEST_F(ProfileManagerTest, LastOpenedProfiles) { |