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

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: Code review. 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
« no previous file with comments | « chrome/browser/profiles/profile_manager.cc ('k') | chrome/browser/ui/browser_init.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7d598c3cb3cea0b0c2c219d811904aca3b1f7290..e10633d98644ffce99ca94441fb7a4e1b395da48 100644
--- a/chrome/browser/profiles/profile_manager_unittest.cc
+++ b/chrome/browser/profiles/profile_manager_unittest.cc
@@ -384,3 +384,111 @@ TEST_F(ProfileManagerTest, InitProfileInfoCacheForAProfile) {
EXPECT_EQ(avatar_index,
cache.GetAvatarIconIndexOfProfileAtIndex(profile_index));
}
+
+TEST_F(ProfileManagerTest, LastOpenedProfiles) {
+ 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_opened_profiles =
+ profile_manager->GetLastOpenedProfiles();
+ ASSERT_EQ(0U, last_opened_profiles.size());
+
+ // Create a browser for profile1.
+ scoped_ptr<Browser> browser1a(new Browser(Browser::TYPE_TABBED, profile1));
+
+ last_opened_profiles = profile_manager->GetLastOpenedProfiles();
+ ASSERT_EQ(1U, last_opened_profiles.size());
+ EXPECT_EQ(profile1, last_opened_profiles[0]);
+
+ // And for profile2.
+ scoped_ptr<Browser> browser2(new Browser(Browser::TYPE_TABBED, profile2));
+
+ last_opened_profiles = profile_manager->GetLastOpenedProfiles();
+ ASSERT_EQ(2U, last_opened_profiles.size());
+ EXPECT_EQ(profile1, last_opened_profiles[0]);
+ EXPECT_EQ(profile2, last_opened_profiles[1]);
+
+ // Adding more browsers doesn't change anything.
+ scoped_ptr<Browser> browser1b(new Browser(Browser::TYPE_TABBED, profile1));
+ last_opened_profiles = profile_manager->GetLastOpenedProfiles();
+ ASSERT_EQ(2U, last_opened_profiles.size());
+ EXPECT_EQ(profile1, last_opened_profiles[0]);
+ EXPECT_EQ(profile2, last_opened_profiles[1]);
+
+ // Close the browsers.
+ browser1a.reset();
+ last_opened_profiles = profile_manager->GetLastOpenedProfiles();
+ ASSERT_EQ(2U, last_opened_profiles.size());
+ EXPECT_EQ(profile1, last_opened_profiles[0]);
+ EXPECT_EQ(profile2, last_opened_profiles[1]);
+
+ browser1b.reset();
+ last_opened_profiles = profile_manager->GetLastOpenedProfiles();
+ ASSERT_EQ(1U, last_opened_profiles.size());
+ EXPECT_EQ(profile2, last_opened_profiles[0]);
+
+ browser2.reset();
+ last_opened_profiles = profile_manager->GetLastOpenedProfiles();
+ ASSERT_EQ(0U, last_opened_profiles.size());
+}
+
+TEST_F(ProfileManagerTest, LastOpenedProfilesAtShutdown) {
+ 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_opened_profiles =
+ profile_manager->GetLastOpenedProfiles();
+ ASSERT_EQ(2U, last_opened_profiles.size());
+ EXPECT_EQ(profile1, last_opened_profiles[0]);
+ EXPECT_EQ(profile2, last_opened_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
+ // open.
+ browser1.reset();
+ browser2.reset();
+
+ last_opened_profiles = profile_manager->GetLastOpenedProfiles();
+ ASSERT_EQ(2U, last_opened_profiles.size());
+ EXPECT_EQ(profile1, last_opened_profiles[0]);
+ EXPECT_EQ(profile2, last_opened_profiles[1]);
+}
« no previous file with comments | « chrome/browser/profiles/profile_manager.cc ('k') | chrome/browser/ui/browser_init.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698