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

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

Issue 9087009: Restore all profiles which were active when restoring the last open pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix. Created 8 years, 11 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 5f240119c9c32c339427cc8a85ccd2c6b3d19b5f..bcb19d1f7b199c361e41c7ac30fb882d45c67fc3 100644
--- a/chrome/browser/profiles/profile_manager_unittest.cc
+++ b/chrome/browser/profiles/profile_manager_unittest.cc
@@ -385,3 +385,111 @@ TEST_F(ProfileManagerTest, InitProfileInfoCacheForAProfile) {
EXPECT_EQ(avatar_index,
cache.GetAvatarIconIndexOfProfileAtIndex(profile_index));
}
+
+TEST_F(ProfileManagerTest, LastActiveProfiles) {
+ FilePath dest_path1 = temp_dir_.path();
+ dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1"));
+
+ FilePath dest_path2 = temp_dir_.path();
+ dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2"));
+
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+
+ // Successfully create the profiles.
+ TestingProfile* profile1 =
+ static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1));
+ ASSERT_TRUE(profile1);
+
+ TestingProfile* profile2 =
+ static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path2));
+ ASSERT_TRUE(profile2);
+
+ std::vector<Profile*> last_active_profiles =
+ profile_manager->GetLastActiveProfiles();
+ ASSERT_EQ(0U, last_active_profiles.size());
+
+ // Create a browser for profile1.
+ scoped_ptr<Browser> browser1a(new Browser(Browser::TYPE_TABBED, profile1));
+
+ last_active_profiles = profile_manager->GetLastActiveProfiles();
+ ASSERT_EQ(1U, last_active_profiles.size());
+ EXPECT_EQ(profile1, last_active_profiles[0]);
+
+ // And for profile2.
+ scoped_ptr<Browser> browser2(new Browser(Browser::TYPE_TABBED, profile2));
+
+ last_active_profiles = profile_manager->GetLastActiveProfiles();
+ ASSERT_EQ(2U, last_active_profiles.size());
+ EXPECT_EQ(profile1, last_active_profiles[0]);
+ EXPECT_EQ(profile2, last_active_profiles[1]);
+
+ // Adding more browsers doesn't change anything.
+ scoped_ptr<Browser> browser1b(new Browser(Browser::TYPE_TABBED, profile1));
+ last_active_profiles = profile_manager->GetLastActiveProfiles();
+ ASSERT_EQ(2U, last_active_profiles.size());
+ EXPECT_EQ(profile1, last_active_profiles[0]);
+ EXPECT_EQ(profile2, last_active_profiles[1]);
+
+ // Close the browsers.
+ browser1a.reset();
+ last_active_profiles = profile_manager->GetLastActiveProfiles();
+ ASSERT_EQ(2U, last_active_profiles.size());
+ EXPECT_EQ(profile1, last_active_profiles[0]);
+ EXPECT_EQ(profile2, last_active_profiles[1]);
+
+ browser1b.reset();
+ last_active_profiles = profile_manager->GetLastActiveProfiles();
+ ASSERT_EQ(1U, last_active_profiles.size());
+ EXPECT_EQ(profile2, last_active_profiles[0]);
+
+ browser2.reset();
+ last_active_profiles = profile_manager->GetLastActiveProfiles();
+ ASSERT_EQ(0U, last_active_profiles.size());
+}
+
+TEST_F(ProfileManagerTest, LastActiveProfilesAtShutdown) {
+ FilePath dest_path1 = temp_dir_.path();
+ dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1"));
+
+ FilePath dest_path2 = temp_dir_.path();
+ dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2"));
+
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+
+ // Successfully create the profiles.
+ TestingProfile* profile1 =
+ static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1));
+ ASSERT_TRUE(profile1);
+
+ TestingProfile* profile2 =
+ static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path2));
+ ASSERT_TRUE(profile2);
+
+ // Create a browser for profile1.
+ scoped_ptr<Browser> browser1(new Browser(Browser::TYPE_TABBED, profile1));
+
+ // And for profile2.
+ scoped_ptr<Browser> browser2(new Browser(Browser::TYPE_TABBED, profile2));
+
+ std::vector<Profile*> last_active_profiles =
+ profile_manager->GetLastActiveProfiles();
+ ASSERT_EQ(2U, last_active_profiles.size());
+ EXPECT_EQ(profile1, last_active_profiles[0]);
+ EXPECT_EQ(profile2, last_active_profiles[1]);
+
+ // Simulate a shutdown.
+ content::NotificationService::current()->Notify(
+ content::NOTIFICATION_APP_EXITING,
+ content::NotificationService::AllSources(),
+ content::NotificationService::NoDetails());
+
+ // Even if the browsers are destructed during shutdown, the profiles stay
+ // active.
+ browser1.reset();
+ browser2.reset();
+
+ last_active_profiles = profile_manager->GetLastActiveProfiles();
+ ASSERT_EQ(2U, last_active_profiles.size());
+ EXPECT_EQ(profile1, last_active_profiles[0]);
+ EXPECT_EQ(profile2, last_active_profiles[1]);
+}

Powered by Google App Engine
This is Rietveld 408576698