Index: chrome/browser/profiles/profile_manager_browsertest.cc |
diff --git a/chrome/browser/profiles/profile_manager_browsertest.cc b/chrome/browser/profiles/profile_manager_browsertest.cc |
index cd9d8e8ad1e06baf60ae9d31238750061ad6d0c0..00a88d3f617dd78a5609650b17570cccb7ab0aca 100644 |
--- a/chrome/browser/profiles/profile_manager_browsertest.cc |
+++ b/chrome/browser/profiles/profile_manager_browsertest.cc |
@@ -13,6 +13,7 @@ |
#include "chrome/browser/profiles/profiles_state.h" |
#include "chrome/browser/ui/browser_finder.h" |
#include "chrome/browser/ui/browser_list.h" |
+#include "chrome/browser/ui/browser_window.h" |
#include "chrome/browser/ui/host_desktop.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/test/base/in_process_browser_test.h" |
@@ -40,6 +41,13 @@ void ProfileCreationComplete(Profile* profile, Profile::CreateStatus status) { |
base::MessageLoop::current()->Quit(); |
} |
+void EphemeralProfileCreationComplete(Profile* profile, |
+ Profile::CreateStatus status) { |
+ if (status == Profile::CREATE_STATUS_INITIALIZED) |
+ profile->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, true); |
+ ProfileCreationComplete(profile, status); |
+} |
+ |
class ProfileRemovalObserver : public ProfileInfoCacheObserver { |
public: |
ProfileRemovalObserver() { |
@@ -240,3 +248,72 @@ IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, |
EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); |
EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); |
} |
+ |
+IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, EphemeralProfile) { |
+#if defined(OS_WIN) && defined(USE_ASH) |
+ // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
+ return; |
+#endif |
+ |
+ // If multiprofile mode is not enabled, you can't switch between profiles. |
+ if (!profiles::IsMultipleProfilesEnabled()) |
+ return; |
+ |
+ ProfileManager* profile_manager = g_browser_process->profile_manager(); |
+ ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
+ base::FilePath path_profile1 = cache.GetPathOfProfileAtIndex(0); |
+ |
+ ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles()); |
+ EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); |
+ |
+ // Create an ephemeral profile. |
+ base::FilePath path_profile2 = |
+ profile_manager->GenerateNextProfileDirectoryPath(); |
+ profile_manager->CreateProfileAsync( |
+ path_profile2, |
+ base::Bind(&EphemeralProfileCreationComplete), |
+ string16(), string16(), std::string()); |
+ |
+ // Spin to allow profile creation to take place. |
+ content::RunMessageLoop(); |
+ |
+ chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); |
+ BrowserList* browser_list = BrowserList::GetInstance(desktop_type); |
+ ASSERT_EQ(2U, cache.GetNumberOfProfiles()); |
+ EXPECT_EQ(1U, browser_list->size()); |
+ |
+ // Open a browser window for the second profile. |
+ profiles::SwitchToProfile(path_profile2, desktop_type, false); |
+ EXPECT_EQ(2U, chrome::GetTotalBrowserCount()); |
+ EXPECT_EQ(2U, browser_list->size()); |
+ EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); |
+ |
+ // Create a second window for the ephemeral profile. |
+ profiles::SwitchToProfile(path_profile2, desktop_type, true); |
+ EXPECT_EQ(3U, chrome::GetTotalBrowserCount()); |
+ EXPECT_EQ(3U, browser_list->size()); |
+ |
+ EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); |
+ EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); |
+ EXPECT_EQ(path_profile2, browser_list->get(2)->profile()->GetPath()); |
+ |
+ // Closing the first window of the ephemeral profile should not delete it. |
+ browser_list->get(2)->window()->Close(); |
+ content::RunAllPendingInMessageLoop(); |
+ EXPECT_EQ(2U, browser_list->size()); |
+ ASSERT_EQ(2U, cache.GetNumberOfProfiles()); |
+ |
+ // The second should though. |
+ browser_list->get(1)->window()->Close(); |
+ content::RunAllPendingInMessageLoop(); |
+ content::RunAllPendingInMessageLoop(); |
+ EXPECT_EQ(1U, browser_list->size()); |
+ ASSERT_EQ(1U, cache.GetNumberOfProfiles()); |
+ |
+ // Closing the last window should not reduce the number of profiles. |
+ browser_list->get(0)->window()->Close(); |
+ content::RunAllPendingInMessageLoop(); |
+ EXPECT_EQ(0U, browser_list->size()); |
+ ASSERT_EQ(1U, cache.GetNumberOfProfiles()); |
+} |