15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind.h" 6a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/command_line.h" 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h" 8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 9116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "chrome/browser/password_manager/password_store_factory.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile_info_cache.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/profiles/profile_info_cache_observer.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile_manager.h" 13ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "chrome/browser/profiles/profile_window.h" 14ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "chrome/browser/profiles/profiles_state.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_finder.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_list.h" 174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/browser_window.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/host_desktop.h" 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/pref_names.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h" 21a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/test/base/test_switches.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/testing_browser_process.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/ui_test_utils.h" 24116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/autofill/core/common/password_form.h" 25116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/password_manager/core/browser/password_store.h" 26116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/password_manager/core/browser/password_store_consumer.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_CHROMEOS) 29a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/path_service.h" 30a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/common/chrome_constants.h" 31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/common/chrome_paths.h" 3223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "chromeos/chromeos_switches.h" 33a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 34a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif 35a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciconst ProfileManager::CreateCallback kOnProfileSwitchDoNothing; 390f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// An observer that returns back to test code after a new profile is 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// initialized. 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void OnUnblockOnProfileCreation(Profile* profile, 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile::CreateStatus status) { 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (status == Profile::CREATE_STATUS_INITIALIZED) 4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::MessageLoop::current()->Quit(); 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void ProfileCreationComplete(Profile* profile, Profile::CreateStatus status) { 49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ASSERT_NE(status, Profile::CREATE_STATUS_LOCAL_FAIL); 50868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ASSERT_NE(status, Profile::CREATE_STATUS_REMOTE_FAIL); 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // No browser should have been created for this profile yet. 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(chrome::GetTotalBrowserCountForProfile(profile), 0U); 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (status == Profile::CREATE_STATUS_INITIALIZED) 5590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::MessageLoop::current()->Quit(); 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void EphemeralProfileCreationComplete(Profile* profile, 594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) Profile::CreateStatus status) { 604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (status == Profile::CREATE_STATUS_INITIALIZED) 614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) profile->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, true); 624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ProfileCreationComplete(profile, status); 634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class ProfileRemovalObserver : public ProfileInfoCacheObserver { 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ProfileRemovalObserver() { 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver( 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) this); 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~ProfileRemovalObserver() { 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) g_browser_process->profile_manager()->GetProfileInfoCache().RemoveObserver( 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) this); 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string last_used_profile_name() { return last_used_profile_name_; } 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ProfileInfoCacheObserver overrides: 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void OnProfileWillBeRemoved( 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& profile_path) OVERRIDE { 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) last_used_profile_name_ = g_browser_process->local_state()->GetString( 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) prefs::kProfileLastUsed); 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string last_used_profile_name_; 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ProfileRemovalObserver); 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 92116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// The class serves to retrieve passwords from PasswordStore asynchronously. It 93116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// used by ProfileManagerBrowserTest.DeletePasswords on some platforms. 94116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass PasswordStoreConsumerVerifier : 95116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch public password_manager::PasswordStoreConsumer { 96116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch public: 97116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch PasswordStoreConsumerVerifier() : called_(false) {} 98116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 99116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void OnGetPasswordStoreResults( 100116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const std::vector<autofill::PasswordForm*>& results) OVERRIDE { 101116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch EXPECT_FALSE(called_); 102116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch called_ = true; 103116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch password_entries_.clear(); 104116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch password_entries_.assign(results.begin(), results.end()); 105116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 106116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 107116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool IsCalled() const { return called_; } 108116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 109116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const std::vector<autofill::PasswordForm*>& GetPasswords() const { 110116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return password_entries_.get(); 111116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 112116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch private: 113116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ScopedVector<autofill::PasswordForm> password_entries_; 114116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool called_; 115116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}; 116116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file contains tests for the ProfileManager that require a heavyweight 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// InProcessBrowserTest. These include tests involving profile deletion. 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TODO(jeremy): crbug.com/103355 - These tests should be enabled on all 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// platforms. 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ProfileManagerBrowserTest : public InProcessBrowserTest { 125cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) protected: 126cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 127cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#if defined(OS_CHROMEOS) 128cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) command_line->AppendSwitch( 129cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) chromeos::switches::kIgnoreUserProfileMappingForTests); 130cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#endif 131cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_MACOSX) 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Delete single profile and make sure a new one is created. 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeleteSingletonProfile) { 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ProfileManager* profile_manager = g_browser_process->profile_manager(); 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ProfileRemovalObserver observer; 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We should start out with 1 profile. 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(cache.GetNumberOfProfiles(), 1U); 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Delete singleton profile. 1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath singleton_profile_path = cache.GetPathOfProfileAtIndex(0); 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(singleton_profile_path.empty()); 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) profile_manager->ScheduleProfileForDeletion(singleton_profile_path, 149868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ProfileManager::CreateCallback()); 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Spin things till profile is actually deleted. 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::RunAllPendingInMessageLoop(); 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Make sure a new profile was created automatically. 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(cache.GetNumberOfProfiles(), 1U); 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath new_profile_path = cache.GetPathOfProfileAtIndex(0); 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_NE(new_profile_path, singleton_profile_path); 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Make sure that last used profile preference is set correctly. 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile* last_used = ProfileManager::GetLastUsedProfile(); 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(new_profile_path, last_used->GetPath()); 1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Make sure the last used profile was set correctly before the notification 1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // was sent. 1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string last_used_profile_name = 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) last_used->GetPath().BaseName().MaybeAsASCII(); 1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(last_used_profile_name, observer.last_used_profile_name()); 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Delete all profiles in a multi profile setup and make sure a new one is 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// created. 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Crashes/CHECKs. See crbug.com/104851 1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DISABLED_DeleteAllProfiles) { 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ProfileManager* profile_manager = g_browser_process->profile_manager(); 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Create an additional profile. 1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath(); 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) profile_manager->CreateProfileAsync(new_path, 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Bind(&OnUnblockOnProfileCreation), 181a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16(), base::string16(), 182a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::string()); 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Spin to allow profile creation to take place, loop is terminated 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // by OnUnblockOnProfileCreation when the profile is created. 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::RunMessageLoop(); 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(cache.GetNumberOfProfiles(), 2U); 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Delete all profiles. 1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath profile_path1 = cache.GetPathOfProfileAtIndex(0); 1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath profile_path2 = cache.GetPathOfProfileAtIndex(1); 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(profile_path1.empty()); 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(profile_path2.empty()); 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) profile_manager->ScheduleProfileForDeletion(profile_path1, 196868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ProfileManager::CreateCallback()); 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) profile_manager->ScheduleProfileForDeletion(profile_path2, 198868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) ProfileManager::CreateCallback()); 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Spin things so deletion can take place. 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::RunAllPendingInMessageLoop(); 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Make sure a new profile was created automatically. 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(cache.GetNumberOfProfiles(), 1U); 2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath new_profile_path = cache.GetPathOfProfileAtIndex(0); 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_NE(new_profile_path, profile_path1); 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_NE(new_profile_path, profile_path2); 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Make sure that last used profile preference is set correctly. 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile* last_used = ProfileManager::GetLastUsedProfile(); 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(new_profile_path, last_used->GetPath()); 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // OS_MACOSX 2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 215a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_CHROMEOS) 216a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 217cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class ProfileManagerCrOSBrowserTest : public ProfileManagerBrowserTest { 218a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) protected: 219a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 220cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Use a user hash other than the default chrome::kTestUserProfileDir 221cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // so that the prefix case is tested. 222cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, 223cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) "test-user-hash"); 224a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 225a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}; 226a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 227cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(ProfileManagerCrOSBrowserTest, GetLastUsedProfile) { 228a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Make sure that last used profile is correct. 229a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) Profile* last_used_profile = ProfileManager::GetLastUsedProfile(); 230a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(last_used_profile != NULL); 231a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 232a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::FilePath profile_path; 233a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) PathService::Get(chrome::DIR_USER_DATA, &profile_path); 234a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 235cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) profile_path = profile_path.AppendASCII( 236cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) std::string(chrome::kProfileDirPrefix) + "test-user-hash"); 237a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_EQ(profile_path.value(), last_used_profile->GetPath().value()); 238a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 239a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 240a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif // OS_CHROMEOS 241a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 2422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Times out (http://crbug.com/159002) 2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, 2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISABLED_CreateProfileWithCallback) { 2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ProfileManager* profile_manager = g_browser_process->profile_manager(); 2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(profile_manager->GetNumberOfProfiles(), 1U); 2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); 2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Create a profile, make sure callback is invoked before any callbacks are 2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // invoked (so they can do things like sign in the profile, etc). 2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ProfileManager::CreateMultiProfileAsync( 253a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16(), // name 254a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16(), // icon url 2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(ProfileCreationComplete), 2562385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch std::string()); 2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Wait for profile to finish loading. 2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::RunMessageLoop(); 2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(profile_manager->GetNumberOfProfiles(), 2U); 2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); 2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Now close all browser windows. 2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); 2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) for (std::vector<Profile*>::const_iterator it = profiles.begin(); 2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) it != profiles.end(); ++it) { 2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BrowserList::CloseAllBrowsersWithProfile(*it); 2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 269ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 270ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben MurdochIN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, 271ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch SwitchToProfile) { 272558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#if defined(OS_WIN) && defined(USE_ASH) 273558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // Disable this test in Metro+Ash for now (http://crbug.com/262796). 274a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 275558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch return; 276558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#endif 277558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 278ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // If multiprofile mode is not enabled, you can't switch between profiles. 279ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch if (!profiles::IsMultipleProfilesEnabled()) 280ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch return; 281ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 282ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch ProfileManager* profile_manager = g_browser_process->profile_manager(); 283ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 284ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch base::FilePath path_profile1 = cache.GetPathOfProfileAtIndex(0); 285ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 286ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch ASSERT_EQ(profile_manager->GetNumberOfProfiles(), 1U); 287ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); 288ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 289ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Create an additional profile. 290ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch base::FilePath path_profile2 = 291ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch profile_manager->GenerateNextProfileDirectoryPath(); 292ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch profile_manager->CreateProfileAsync(path_profile2, 293ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch base::Bind(&OnUnblockOnProfileCreation), 294a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16(), base::string16(), 295a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::string()); 296ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 297ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Spin to allow profile creation to take place, loop is terminated 298ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // by OnUnblockOnProfileCreation when the profile is created. 299ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch content::RunMessageLoop(); 300ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 301558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); 302ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch BrowserList* browser_list = BrowserList::GetInstance(desktop_type); 303ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch ASSERT_EQ(cache.GetNumberOfProfiles(), 2U); 304ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_EQ(1U, browser_list->size()); 305ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 306ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Open a browser window for the first profile. 3070f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) profiles::SwitchToProfile(path_profile1, desktop_type, false, 3085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) kOnProfileSwitchDoNothing, 3095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ProfileMetrics::SWITCH_PROFILE_ICON); 310ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); 311ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_EQ(1U, browser_list->size()); 312ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); 313ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 314ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Open a browser window for the second profile. 3150f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) profiles::SwitchToProfile(path_profile2, desktop_type, false, 3165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) kOnProfileSwitchDoNothing, 3175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ProfileMetrics::SWITCH_PROFILE_ICON); 318ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); 319ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_EQ(2U, browser_list->size()); 320ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); 321ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 322ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Switch to the first profile without opening a new window. 3230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) profiles::SwitchToProfile(path_profile1, desktop_type, false, 3245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) kOnProfileSwitchDoNothing, 3255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ProfileMetrics::SWITCH_PROFILE_ICON); 326ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); 327ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_EQ(2U, browser_list->size()); 328ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 329ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); 330ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); 331ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch} 3324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Flakes on Windows: http://crbug.com/314905 3345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#if defined(OS_WIN) 3355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#define MAYBE_EphemeralProfile DISABLED_EphemeralProfile 3365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#else 3375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#define MAYBE_EphemeralProfile EphemeralProfile 3385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif 3395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, MAYBE_EphemeralProfile) { 3404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#if defined(OS_WIN) && defined(USE_ASH) 3414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Disable this test in Metro+Ash for now (http://crbug.com/262796). 3424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 3434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return; 3444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#endif 3454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // If multiprofile mode is not enabled, you can't switch between profiles. 3474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (!profiles::IsMultipleProfilesEnabled()) 3484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return; 3494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ProfileManager* profile_manager = g_browser_process->profile_manager(); 3514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 3524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) base::FilePath path_profile1 = cache.GetPathOfProfileAtIndex(0); 3534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles()); 3554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); 3564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Create an ephemeral profile. 3584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) base::FilePath path_profile2 = 3594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) profile_manager->GenerateNextProfileDirectoryPath(); 3604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) profile_manager->CreateProfileAsync( 3614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) path_profile2, 3624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) base::Bind(&EphemeralProfileCreationComplete), 363a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16(), base::string16(), std::string()); 3644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Spin to allow profile creation to take place. 3664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::RunMessageLoop(); 3674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); 3694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) BrowserList* browser_list = BrowserList::GetInstance(desktop_type); 3704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_EQ(2U, cache.GetNumberOfProfiles()); 3714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(1U, browser_list->size()); 3724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Open a browser window for the second profile. 3740f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) profiles::SwitchToProfile(path_profile2, desktop_type, false, 3755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) kOnProfileSwitchDoNothing, 3765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ProfileMetrics::SWITCH_PROFILE_ICON); 3774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(2U, chrome::GetTotalBrowserCount()); 3784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(2U, browser_list->size()); 3794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); 3804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Create a second window for the ephemeral profile. 3820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) profiles::SwitchToProfile(path_profile2, desktop_type, true, 3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) kOnProfileSwitchDoNothing, 3845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ProfileMetrics::SWITCH_PROFILE_ICON); 3854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(3U, chrome::GetTotalBrowserCount()); 3864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(3U, browser_list->size()); 3874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); 3894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); 3904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(path_profile2, browser_list->get(2)->profile()->GetPath()); 3914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Closing the first window of the ephemeral profile should not delete it. 3934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) browser_list->get(2)->window()->Close(); 3944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::RunAllPendingInMessageLoop(); 3954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(2U, browser_list->size()); 3964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_EQ(2U, cache.GetNumberOfProfiles()); 3974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // The second should though. 3994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) browser_list->get(1)->window()->Close(); 4004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) content::RunAllPendingInMessageLoop(); 4014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(1U, browser_list->size()); 4024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ASSERT_EQ(1U, cache.GetNumberOfProfiles()); 4034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 40446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 405116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// The test makes sense on those platforms where the keychain exists. 406116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#if !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 407116680a4aac90f2aa7413d9095a592090648e557Ben MurdochIN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeletePasswords) { 408116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch Profile* profile = ProfileManager::GetActiveUserProfile(); 409116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ASSERT_TRUE(profile); 410116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 411116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch autofill::PasswordForm form; 412116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch form.scheme = autofill::PasswordForm::SCHEME_HTML; 413116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch form.origin = GURL("http://accounts.google.com/LoginAuth"); 414116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch form.signon_realm = "http://accounts.google.com/"; 415116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch form.username_value = base::ASCIIToUTF16("my_username"); 416116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch form.password_value = base::ASCIIToUTF16("my_password"); 417116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch form.ssl_valid = false; 418116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch form.preferred = true; 419116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch form.blacklisted_by_user = false; 420116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 421116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch scoped_refptr<password_manager::PasswordStore> password_store = 422116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS) 423116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch .get(); 4241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ASSERT_TRUE(password_store.get()); 425116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 426116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch password_store->AddLogin(form); 427116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch PasswordStoreConsumerVerifier verify_add; 428116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch password_store->GetAutofillableLogins(&verify_add); 429116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 430116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ProfileManager* profile_manager = g_browser_process->profile_manager(); 431116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch profile_manager->ScheduleProfileForDeletion(profile->GetPath(), 432116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ProfileManager::CreateCallback()); 433116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch content::RunAllPendingInMessageLoop(); 434116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch PasswordStoreConsumerVerifier verify_delete; 435116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch password_store->GetAutofillableLogins(&verify_delete); 436116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 437116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Run the password background thread. 438116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch base::RunLoop run_loop; 439116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch base::Closure task = base::Bind( 440116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch base::IgnoreResult(&content::BrowserThread::PostTask), 441116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch content::BrowserThread::UI, 442116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch FROM_HERE, 443116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch run_loop.QuitClosure()); 444116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch EXPECT_TRUE(password_store->ScheduleTask(task)); 445116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch run_loop.Run(); 446116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 447116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch EXPECT_TRUE(verify_add.IsCalled()); 448116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch EXPECT_EQ(1u, verify_add.GetPasswords().size()); 449116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch EXPECT_TRUE(verify_delete.IsCalled()); 450116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch EXPECT_EQ(0u, verify_delete.GetPasswords().size()); 451116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} 452116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#endif // !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 453