Chromium Code Reviews| 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..1cc34dfb808abce31a0dc9f3237dbbe8d60945c1 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,12 @@ void ProfileCreationComplete(Profile* profile, Profile::CreateStatus status) { |
| base::MessageLoop::current()->Quit(); |
| } |
| +void EphemeralProfileCreationComplete(Profile* profile, |
| + Profile::CreateStatus status) { |
| + ProfileCreationComplete(profile, status); |
| + profile->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, true); |
| +} |
| + |
| class ProfileRemovalObserver : public ProfileInfoCacheObserver { |
| public: |
| ProfileRemovalObserver() { |
| @@ -240,3 +247,70 @@ 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()) |
|
rpetterson
2013/10/04 19:42:20
When would you not have multi profiles enabled? I
pastarmovj
2013/10/10 11:46:32
TBH I just copied this check from the other tests
rpetterson
2013/10/10 17:40:19
Got it. That makes sense.
|
| + return; |
| + |
| + ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| + ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| + base::FilePath path_profile1 = cache.GetPathOfProfileAtIndex(0); |
| + |
| + ASSERT_EQ(profile_manager->GetNumberOfProfiles(), 1U); |
| + EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); |
| + |
| + // 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(cache.GetNumberOfProfiles(), 2U); |
| + EXPECT_EQ(1U, browser_list->size()); |
| + |
| + // Open a browser window for the second profile. |
| + profiles::SwitchToProfile(path_profile2, desktop_type, false); |
| + EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); |
| + 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(chrome::GetTotalBrowserCount(), 3U); |
| + 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()); |
|
rpetterson
2013/10/04 19:42:20
You did this check earlier. Did you mean to check
pastarmovj
2013/10/10 11:46:32
Done.
|
| + |
| + // Closing the first window of the ephemeral profile should not delete it. |
| + browser_list->GetLastActive()->window()->Close(); |
| + content::RunAllPendingInMessageLoop(); |
| + EXPECT_EQ(2U, browser_list->size()); |
| + ASSERT_EQ(cache.GetNumberOfProfiles(), 2U); |
| + |
| + // The second should though. |
| + browser_list->GetLastActive()->window()->Close(); |
| + content::RunAllPendingInMessageLoop(); |
| + EXPECT_EQ(1U, browser_list->size()); |
| + ASSERT_EQ(cache.GetNumberOfProfiles(), 1U); |
| + |
| + // Closing the last window should not reduce the number of profiles. |
| + browser_list->GetLastActive()->window()->Close(); |
| + content::RunAllPendingInMessageLoop(); |
| + EXPECT_EQ(0U, browser_list->size()); |
| + ASSERT_EQ(cache.GetNumberOfProfiles(), 1U); |
| +} |