| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/message_loop.h" | |
| 11 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/run_loop.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
| 18 #include "chrome/browser/chromeos/settings/cros_settings.h" | 18 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 19 #include "chrome/browser/history/history_service.h" | 19 #include "chrome/browser/history/history_service.h" |
| 20 #include "chrome/browser/history/history_service_factory.h" | 20 #include "chrome/browser/history/history_service_factory.h" |
| 21 #include "chrome/browser/io_thread.h" | 21 #include "chrome/browser/io_thread.h" |
| 22 #include "chrome/browser/prefs/browser_prefs.h" | 22 #include "chrome/browser/prefs/browser_prefs.h" |
| 23 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 23 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/profiles/profile_info_cache.h" | 25 #include "chrome/browser/profiles/profile_info_cache.h" |
| 26 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
| 27 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
| 28 #include "chrome/common/chrome_constants.h" | 28 #include "chrome/common/chrome_constants.h" |
| 29 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
| 30 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 32 #include "chrome/test/base/scoped_testing_local_state.h" | 32 #include "chrome/test/base/scoped_testing_local_state.h" |
| 33 #include "chrome/test/base/test_browser_window.h" | 33 #include "chrome/test/base/test_browser_window.h" |
| 34 #include "chrome/test/base/testing_browser_process.h" | 34 #include "chrome/test/base/testing_browser_process.h" |
| 35 #include "chrome/test/base/testing_profile.h" | 35 #include "chrome/test/base/testing_profile.h" |
| 36 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
| 37 #include "content/public/test/test_browser_thread.h" | 37 #include "content/public/test/test_browser_thread_bundle.h" |
| 38 #include "testing/gmock/include/gmock/gmock.h" | 38 #include "testing/gmock/include/gmock/gmock.h" |
| 39 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
| 40 | 40 |
| 41 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
| 42 #include "chrome/browser/chromeos/login/mock_user_manager.h" | 42 #include "chrome/browser/chromeos/login/mock_user_manager.h" |
| 43 #include "chrome/browser/chromeos/login/user_manager.h" | 43 #include "chrome/browser/chromeos/login/user_manager.h" |
| 44 #include "chrome/browser/chromeos/settings/cros_settings.h" | 44 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 45 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 45 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 46 #include "chromeos/chromeos_switches.h" | 46 #include "chromeos/chromeos_switches.h" |
| 47 #endif | 47 #endif |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 class ProfileManagerTest : public testing::Test { | 89 class ProfileManagerTest : public testing::Test { |
| 90 protected: | 90 protected: |
| 91 class MockObserver { | 91 class MockObserver { |
| 92 public: | 92 public: |
| 93 MOCK_METHOD2(OnProfileCreated, | 93 MOCK_METHOD2(OnProfileCreated, |
| 94 void(Profile* profile, Profile::CreateStatus status)); | 94 void(Profile* profile, Profile::CreateStatus status)); |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 ProfileManagerTest() | 97 ProfileManagerTest() |
| 98 : local_state_(TestingBrowserProcess::GetGlobal()), | 98 : local_state_(TestingBrowserProcess::GetGlobal()) { |
| 99 ui_thread_(BrowserThread::UI, &message_loop_), | |
| 100 db_thread_(BrowserThread::DB, &message_loop_), | |
| 101 file_thread_(BrowserThread::FILE, &message_loop_) { | |
| 102 } | 99 } |
| 103 | 100 |
| 104 virtual void SetUp() { | 101 virtual void SetUp() { |
| 105 // Create a new temporary directory, and store the path | 102 // Create a new temporary directory, and store the path |
| 106 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 103 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 107 TestingBrowserProcess::GetGlobal()->SetProfileManager( | 104 TestingBrowserProcess::GetGlobal()->SetProfileManager( |
| 108 new testing::ProfileManager(temp_dir_.path())); | 105 new testing::ProfileManager(temp_dir_.path())); |
| 109 | 106 |
| 110 #if defined(OS_CHROMEOS) | 107 #if defined(OS_CHROMEOS) |
| 111 CommandLine* cl = CommandLine::ForCurrentProcess(); | 108 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 112 cl->AppendSwitch(switches::kTestType); | 109 cl->AppendSwitch(switches::kTestType); |
| 113 #endif | 110 #endif |
| 114 } | 111 } |
| 115 | 112 |
| 116 virtual void TearDown() { | 113 virtual void TearDown() { |
| 117 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); | 114 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); |
| 118 message_loop_.RunUntilIdle(); | 115 base::RunLoop().RunUntilIdle(); |
| 119 } | 116 } |
| 120 | 117 |
| 121 // Helper function to create a profile with |name| for a profile |manager|. | 118 // Helper function to create a profile with |name| for a profile |manager|. |
| 122 void CreateProfileAsync(ProfileManager* manager, | 119 void CreateProfileAsync(ProfileManager* manager, |
| 123 const std::string& name, | 120 const std::string& name, |
| 124 MockObserver* mock_observer) { | 121 MockObserver* mock_observer) { |
| 125 manager->CreateProfileAsync( | 122 manager->CreateProfileAsync( |
| 126 temp_dir_.path().AppendASCII(name), | 123 temp_dir_.path().AppendASCII(name), |
| 127 base::Bind(&MockObserver::OnProfileCreated, | 124 base::Bind(&MockObserver::OnProfileCreated, |
| 128 base::Unretained(mock_observer)), | 125 base::Unretained(mock_observer)), |
| 129 UTF8ToUTF16(name), | 126 UTF8ToUTF16(name), |
| 130 string16(), | 127 string16(), |
| 131 false); | 128 false); |
| 132 } | 129 } |
| 133 | 130 |
| 134 #if defined(OS_CHROMEOS) | 131 #if defined(OS_CHROMEOS) |
| 135 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 132 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 136 chromeos::ScopedTestCrosSettings test_cros_settings_; | 133 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 137 #endif | 134 #endif |
| 138 | 135 |
| 139 // The path to temporary directory used to contain the test operations. | 136 // The path to temporary directory used to contain the test operations. |
| 140 base::ScopedTempDir temp_dir_; | 137 base::ScopedTempDir temp_dir_; |
| 141 ScopedTestingLocalState local_state_; | 138 ScopedTestingLocalState local_state_; |
| 142 base::MessageLoopForUI message_loop_; | 139 |
| 143 content::TestBrowserThread ui_thread_; | 140 content::TestBrowserThreadBundle thread_bundle_; |
| 144 content::TestBrowserThread db_thread_; | |
| 145 content::TestBrowserThread file_thread_; | |
| 146 | 141 |
| 147 #if defined(OS_CHROMEOS) | 142 #if defined(OS_CHROMEOS) |
| 148 chromeos::ScopedTestUserManager test_user_manager_; | 143 chromeos::ScopedTestUserManager test_user_manager_; |
| 149 #endif | 144 #endif |
| 150 }; | 145 }; |
| 151 | 146 |
| 152 TEST_F(ProfileManagerTest, GetProfile) { | 147 TEST_F(ProfileManagerTest, GetProfile) { |
| 153 base::FilePath dest_path = temp_dir_.path(); | 148 base::FilePath dest_path = temp_dir_.path(); |
| 154 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); | 149 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); |
| 155 | 150 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 Profile::EXPLICIT_ACCESS)); | 220 Profile::EXPLICIT_ACCESS)); |
| 226 profile1->CreateBookmarkModel(true); | 221 profile1->CreateBookmarkModel(true); |
| 227 EXPECT_TRUE(BookmarkModelFactory::GetForProfile(profile1)); | 222 EXPECT_TRUE(BookmarkModelFactory::GetForProfile(profile1)); |
| 228 profile2->CreateBookmarkModel(true); | 223 profile2->CreateBookmarkModel(true); |
| 229 EXPECT_TRUE(BookmarkModelFactory::GetForProfile(profile2)); | 224 EXPECT_TRUE(BookmarkModelFactory::GetForProfile(profile2)); |
| 230 profile2->CreateHistoryService(true, false); | 225 profile2->CreateHistoryService(true, false); |
| 231 EXPECT_TRUE(HistoryServiceFactory::GetForProfile(profile2, | 226 EXPECT_TRUE(HistoryServiceFactory::GetForProfile(profile2, |
| 232 Profile::EXPLICIT_ACCESS)); | 227 Profile::EXPLICIT_ACCESS)); |
| 233 | 228 |
| 234 // Make sure any pending tasks run before we destroy the profiles. | 229 // Make sure any pending tasks run before we destroy the profiles. |
| 235 message_loop_.RunUntilIdle(); | 230 base::RunLoop().RunUntilIdle(); |
| 236 | 231 |
| 237 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); | 232 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); |
| 238 | 233 |
| 239 // Make sure history cleans up correctly. | 234 // Make sure history cleans up correctly. |
| 240 message_loop_.RunUntilIdle(); | 235 base::RunLoop().RunUntilIdle(); |
| 241 } | 236 } |
| 242 | 237 |
| 243 MATCHER(NotFail, "Profile creation failure status is not reported.") { | 238 MATCHER(NotFail, "Profile creation failure status is not reported.") { |
| 244 return arg == Profile::CREATE_STATUS_CREATED || | 239 return arg == Profile::CREATE_STATUS_CREATED || |
| 245 arg == Profile::CREATE_STATUS_INITIALIZED; | 240 arg == Profile::CREATE_STATUS_INITIALIZED; |
| 246 } | 241 } |
| 247 | 242 |
| 248 // Tests asynchronous profile creation mechanism. | 243 // Tests asynchronous profile creation mechanism. |
| 249 // Crashes: http://crbug.com/89421 | 244 // Crashes: http://crbug.com/89421 |
| 250 TEST_F(ProfileManagerTest, DISABLED_CreateProfileAsync) { | 245 TEST_F(ProfileManagerTest, DISABLED_CreateProfileAsync) { |
| 251 MockObserver mock_observer; | 246 MockObserver mock_observer; |
| 252 EXPECT_CALL(mock_observer, OnProfileCreated( | 247 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 253 testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); | 248 testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); |
| 254 | 249 |
| 255 CreateProfileAsync(g_browser_process->profile_manager(), | 250 CreateProfileAsync(g_browser_process->profile_manager(), |
| 256 "New Profile", &mock_observer); | 251 "New Profile", &mock_observer); |
| 257 | 252 |
| 258 message_loop_.RunUntilIdle(); | 253 base::RunLoop().RunUntilIdle(); |
| 259 } | 254 } |
| 260 | 255 |
| 261 MATCHER(SameNotNull, "The same non-NULL value for all calls.") { | 256 MATCHER(SameNotNull, "The same non-NULL value for all calls.") { |
| 262 if (!g_created_profile) | 257 if (!g_created_profile) |
| 263 g_created_profile = arg; | 258 g_created_profile = arg; |
| 264 return arg != NULL && arg == g_created_profile; | 259 return arg != NULL && arg == g_created_profile; |
| 265 } | 260 } |
| 266 | 261 |
| 267 TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) { | 262 TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) { |
| 268 g_created_profile = NULL; | 263 g_created_profile = NULL; |
| 269 | 264 |
| 270 MockObserver mock_observer1; | 265 MockObserver mock_observer1; |
| 271 EXPECT_CALL(mock_observer1, OnProfileCreated( | 266 EXPECT_CALL(mock_observer1, OnProfileCreated( |
| 272 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 267 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
| 273 MockObserver mock_observer2; | 268 MockObserver mock_observer2; |
| 274 EXPECT_CALL(mock_observer2, OnProfileCreated( | 269 EXPECT_CALL(mock_observer2, OnProfileCreated( |
| 275 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 270 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
| 276 MockObserver mock_observer3; | 271 MockObserver mock_observer3; |
| 277 EXPECT_CALL(mock_observer3, OnProfileCreated( | 272 EXPECT_CALL(mock_observer3, OnProfileCreated( |
| 278 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 273 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
| 279 | 274 |
| 280 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 275 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 281 const std::string profile_name = "New Profile"; | 276 const std::string profile_name = "New Profile"; |
| 282 CreateProfileAsync(profile_manager, profile_name, &mock_observer1); | 277 CreateProfileAsync(profile_manager, profile_name, &mock_observer1); |
| 283 CreateProfileAsync(profile_manager, profile_name, &mock_observer2); | 278 CreateProfileAsync(profile_manager, profile_name, &mock_observer2); |
| 284 CreateProfileAsync(profile_manager, profile_name, &mock_observer3); | 279 CreateProfileAsync(profile_manager, profile_name, &mock_observer3); |
| 285 | 280 |
| 286 message_loop_.RunUntilIdle(); | 281 base::RunLoop().RunUntilIdle(); |
| 287 } | 282 } |
| 288 | 283 |
| 289 TEST_F(ProfileManagerTest, CreateProfilesAsync) { | 284 TEST_F(ProfileManagerTest, CreateProfilesAsync) { |
| 290 const std::string profile_name1 = "New Profile 1"; | 285 const std::string profile_name1 = "New Profile 1"; |
| 291 const std::string profile_name2 = "New Profile 2"; | 286 const std::string profile_name2 = "New Profile 2"; |
| 292 | 287 |
| 293 MockObserver mock_observer; | 288 MockObserver mock_observer; |
| 294 EXPECT_CALL(mock_observer, OnProfileCreated( | 289 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 295 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); | 290 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); |
| 296 | 291 |
| 297 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 292 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 298 | 293 |
| 299 CreateProfileAsync(profile_manager, profile_name1, &mock_observer); | 294 CreateProfileAsync(profile_manager, profile_name1, &mock_observer); |
| 300 CreateProfileAsync(profile_manager, profile_name2, &mock_observer); | 295 CreateProfileAsync(profile_manager, profile_name2, &mock_observer); |
| 301 | 296 |
| 302 message_loop_.RunUntilIdle(); | 297 base::RunLoop().RunUntilIdle(); |
| 303 } | 298 } |
| 304 | 299 |
| 305 TEST_F(ProfileManagerTest, GetGuestProfilePath) { | 300 TEST_F(ProfileManagerTest, GetGuestProfilePath) { |
| 306 base::FilePath guest_path = ProfileManager::GetGuestProfilePath(); | 301 base::FilePath guest_path = ProfileManager::GetGuestProfilePath(); |
| 307 base::FilePath expected_path = temp_dir_.path(); | 302 base::FilePath expected_path = temp_dir_.path(); |
| 308 expected_path = expected_path.Append(chrome::kGuestProfileDir); | 303 expected_path = expected_path.Append(chrome::kGuestProfileDir); |
| 309 EXPECT_EQ(expected_path, guest_path); | 304 EXPECT_EQ(expected_path, guest_path); |
| 310 } | 305 } |
| 311 | 306 |
| 312 TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { | 307 TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 temp_dir_.path().AppendASCII(profile_name1); | 633 temp_dir_.path().AppendASCII(profile_name1); |
| 639 base::FilePath dest_path2 = | 634 base::FilePath dest_path2 = |
| 640 temp_dir_.path().AppendASCII(profile_name2); | 635 temp_dir_.path().AppendASCII(profile_name2); |
| 641 | 636 |
| 642 MockObserver mock_observer; | 637 MockObserver mock_observer; |
| 643 EXPECT_CALL(mock_observer, OnProfileCreated( | 638 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 644 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); | 639 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); |
| 645 | 640 |
| 646 CreateProfileAsync(profile_manager, profile_name1, &mock_observer); | 641 CreateProfileAsync(profile_manager, profile_name1, &mock_observer); |
| 647 CreateProfileAsync(profile_manager, profile_name2, &mock_observer); | 642 CreateProfileAsync(profile_manager, profile_name2, &mock_observer); |
| 648 message_loop_.RunUntilIdle(); | 643 base::RunLoop().RunUntilIdle(); |
| 649 | 644 |
| 650 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); | 645 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); |
| 651 EXPECT_EQ(2u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); | 646 EXPECT_EQ(2u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); |
| 652 | 647 |
| 653 // Set the active profile. | 648 // Set the active profile. |
| 654 PrefService* local_state = g_browser_process->local_state(); | 649 PrefService* local_state = g_browser_process->local_state(); |
| 655 local_state->SetString(prefs::kProfileLastUsed, profile_name1); | 650 local_state->SetString(prefs::kProfileLastUsed, profile_name1); |
| 656 | 651 |
| 657 // Delete the active profile. | 652 // Delete the active profile. |
| 658 profile_manager->ScheduleProfileForDeletion(dest_path1, | 653 profile_manager->ScheduleProfileForDeletion(dest_path1, |
| 659 ProfileManager::CreateCallback()); | 654 ProfileManager::CreateCallback()); |
| 660 // Spin the message loop so that all the callbacks can finish running. | 655 // Spin the message loop so that all the callbacks can finish running. |
| 661 message_loop_.RunUntilIdle(); | 656 base::RunLoop().RunUntilIdle(); |
| 662 | 657 |
| 663 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); | 658 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); |
| 664 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); | 659 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); |
| 665 } | 660 } |
| 666 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 661 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
| 667 | 662 |
| 668 #if defined(OS_MACOSX) | 663 #if defined(OS_MACOSX) |
| 669 // These tests are for a Mac-only code path that assumes the browser | 664 // These tests are for a Mac-only code path that assumes the browser |
| 670 // process isn't killed when all browser windows are closed. | 665 // process isn't killed when all browser windows are closed. |
| 671 TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) { | 666 TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) { |
| 672 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 667 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 673 ASSERT_TRUE(profile_manager); | 668 ASSERT_TRUE(profile_manager); |
| 674 | 669 |
| 675 // Create and load one profile, and just create a second profile. | 670 // Create and load one profile, and just create a second profile. |
| 676 const std::string profile_name1 = "New Profile 1"; | 671 const std::string profile_name1 = "New Profile 1"; |
| 677 const std::string profile_name2 = "New Profile 2"; | 672 const std::string profile_name2 = "New Profile 2"; |
| 678 base::FilePath dest_path1 = | 673 base::FilePath dest_path1 = |
| 679 temp_dir_.path().AppendASCII(profile_name1); | 674 temp_dir_.path().AppendASCII(profile_name1); |
| 680 base::FilePath dest_path2 = | 675 base::FilePath dest_path2 = |
| 681 temp_dir_.path().AppendASCII(profile_name2); | 676 temp_dir_.path().AppendASCII(profile_name2); |
| 682 | 677 |
| 683 MockObserver mock_observer; | 678 MockObserver mock_observer; |
| 684 EXPECT_CALL(mock_observer, OnProfileCreated( | 679 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 685 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | 680 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); |
| 686 CreateProfileAsync(profile_manager, profile_name1, &mock_observer); | 681 CreateProfileAsync(profile_manager, profile_name1, &mock_observer); |
| 687 message_loop_.RunUntilIdle(); | 682 base::RunLoop().RunUntilIdle(); |
| 688 | 683 |
| 689 // Track the profile, but don't load it. | 684 // Track the profile, but don't load it. |
| 690 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 685 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 691 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2), | 686 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2), |
| 692 string16(), 0, false); | 687 string16(), 0, false); |
| 693 message_loop_.RunUntilIdle(); | 688 base::RunLoop().RunUntilIdle(); |
| 694 | 689 |
| 695 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); | 690 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); |
| 696 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); | 691 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); |
| 697 | 692 |
| 698 // Set the active profile. | 693 // Set the active profile. |
| 699 PrefService* local_state = g_browser_process->local_state(); | 694 PrefService* local_state = g_browser_process->local_state(); |
| 700 local_state->SetString(prefs::kProfileLastUsed, | 695 local_state->SetString(prefs::kProfileLastUsed, |
| 701 dest_path1.BaseName().MaybeAsASCII()); | 696 dest_path1.BaseName().MaybeAsASCII()); |
| 702 | 697 |
| 703 // Delete the active profile. This should switch and load the unloaded | 698 // Delete the active profile. This should switch and load the unloaded |
| 704 // profile. | 699 // profile. |
| 705 profile_manager->ScheduleProfileForDeletion(dest_path1, | 700 profile_manager->ScheduleProfileForDeletion(dest_path1, |
| 706 ProfileManager::CreateCallback()); | 701 ProfileManager::CreateCallback()); |
| 707 | 702 |
| 708 // Spin the message loop so that all the callbacks can finish running. | 703 // Spin the message loop so that all the callbacks can finish running. |
| 709 message_loop_.RunUntilIdle(); | 704 base::RunLoop().RunUntilIdle(); |
| 710 | 705 |
| 711 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); | 706 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); |
| 712 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); | 707 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); |
| 713 } | 708 } |
| 714 | 709 |
| 715 // This tests the recursive call in ProfileManager::OnNewActiveProfileLoaded | 710 // This tests the recursive call in ProfileManager::OnNewActiveProfileLoaded |
| 716 // by simulating a scenario in which the profile that is being loaded as | 711 // by simulating a scenario in which the profile that is being loaded as |
| 717 // the next active profile has also been marked for deletion, so the | 712 // the next active profile has also been marked for deletion, so the |
| 718 // ProfileManager needs to recursively select a different next profile. | 713 // ProfileManager needs to recursively select a different next profile. |
| 719 TEST_F(ProfileManagerTest, ActiveProfileDeletedNextProfileDeletedToo) { | 714 TEST_F(ProfileManagerTest, ActiveProfileDeletedNextProfileDeletedToo) { |
| 720 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 715 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 721 ASSERT_TRUE(profile_manager); | 716 ASSERT_TRUE(profile_manager); |
| 722 | 717 |
| 723 // Create and load one profile, and create two more profiles. | 718 // Create and load one profile, and create two more profiles. |
| 724 const std::string profile_name1 = "New Profile 1"; | 719 const std::string profile_name1 = "New Profile 1"; |
| 725 const std::string profile_name2 = "New Profile 2"; | 720 const std::string profile_name2 = "New Profile 2"; |
| 726 const std::string profile_name3 = "New Profile 3"; | 721 const std::string profile_name3 = "New Profile 3"; |
| 727 base::FilePath dest_path1 = | 722 base::FilePath dest_path1 = |
| 728 temp_dir_.path().AppendASCII(profile_name1); | 723 temp_dir_.path().AppendASCII(profile_name1); |
| 729 base::FilePath dest_path2 = | 724 base::FilePath dest_path2 = |
| 730 temp_dir_.path().AppendASCII(profile_name2); | 725 temp_dir_.path().AppendASCII(profile_name2); |
| 731 base::FilePath dest_path3 = | 726 base::FilePath dest_path3 = |
| 732 temp_dir_.path().AppendASCII(profile_name3); | 727 temp_dir_.path().AppendASCII(profile_name3); |
| 733 | 728 |
| 734 MockObserver mock_observer; | 729 MockObserver mock_observer; |
| 735 EXPECT_CALL(mock_observer, OnProfileCreated( | 730 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 736 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | 731 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); |
| 737 CreateProfileAsync(profile_manager, profile_name1, &mock_observer); | 732 CreateProfileAsync(profile_manager, profile_name1, &mock_observer); |
| 738 message_loop_.RunUntilIdle(); | 733 base::RunLoop().RunUntilIdle(); |
| 739 | 734 |
| 740 // Create the other profiles, but don't load them. Assign a fake avatar icon | 735 // Create the other profiles, but don't load them. Assign a fake avatar icon |
| 741 // to ensure that profiles in the info cache are sorted by the profile name, | 736 // to ensure that profiles in the info cache are sorted by the profile name, |
| 742 // and not randomly by the avatar name. | 737 // and not randomly by the avatar name. |
| 743 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 738 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 744 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2), | 739 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2), |
| 745 ASCIIToUTF16(profile_name2), 1, false); | 740 ASCIIToUTF16(profile_name2), 1, false); |
| 746 cache.AddProfileToCache(dest_path3, ASCIIToUTF16(profile_name3), | 741 cache.AddProfileToCache(dest_path3, ASCIIToUTF16(profile_name3), |
| 747 ASCIIToUTF16(profile_name3), 2, false); | 742 ASCIIToUTF16(profile_name3), 2, false); |
| 748 | 743 |
| 749 message_loop_.RunUntilIdle(); | 744 base::RunLoop().RunUntilIdle(); |
| 750 | 745 |
| 751 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); | 746 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); |
| 752 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); | 747 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); |
| 753 | 748 |
| 754 // Set the active profile. | 749 // Set the active profile. |
| 755 PrefService* local_state = g_browser_process->local_state(); | 750 PrefService* local_state = g_browser_process->local_state(); |
| 756 local_state->SetString(prefs::kProfileLastUsed, | 751 local_state->SetString(prefs::kProfileLastUsed, |
| 757 dest_path1.BaseName().MaybeAsASCII()); | 752 dest_path1.BaseName().MaybeAsASCII()); |
| 758 | 753 |
| 759 // Delete the active profile, Profile1. | 754 // Delete the active profile, Profile1. |
| 760 // This will post a CreateProfileAsync message, that tries to load Profile2, | 755 // This will post a CreateProfileAsync message, that tries to load Profile2, |
| 761 // which checks that the profile is not being deleted, and then calls back | 756 // which checks that the profile is not being deleted, and then calls back |
| 762 // FinishDeletingProfile for Profile1. | 757 // FinishDeletingProfile for Profile1. |
| 763 // Try to break this flow by setting the active profile to Profile2 in the | 758 // Try to break this flow by setting the active profile to Profile2 in the |
| 764 // middle (so after the first posted message), and trying to delete Profile2, | 759 // middle (so after the first posted message), and trying to delete Profile2, |
| 765 // so that the ProfileManager has to look for a different profile to load. | 760 // so that the ProfileManager has to look for a different profile to load. |
| 766 profile_manager->ScheduleProfileForDeletion(dest_path1, | 761 profile_manager->ScheduleProfileForDeletion(dest_path1, |
| 767 ProfileManager::CreateCallback()); | 762 ProfileManager::CreateCallback()); |
| 768 local_state->SetString(prefs::kProfileLastUsed, | 763 local_state->SetString(prefs::kProfileLastUsed, |
| 769 dest_path2.BaseName().MaybeAsASCII()); | 764 dest_path2.BaseName().MaybeAsASCII()); |
| 770 profile_manager->ScheduleProfileForDeletion(dest_path2, | 765 profile_manager->ScheduleProfileForDeletion(dest_path2, |
| 771 ProfileManager::CreateCallback()); | 766 ProfileManager::CreateCallback()); |
| 772 // Spin the message loop so that all the callbacks can finish running. | 767 // Spin the message loop so that all the callbacks can finish running. |
| 773 message_loop_.RunUntilIdle(); | 768 base::RunLoop().RunUntilIdle(); |
| 774 | 769 |
| 775 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); | 770 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); |
| 776 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); | 771 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); |
| 777 } | 772 } |
| 778 #endif // !defined(OS_MACOSX) | 773 #endif // !defined(OS_MACOSX) |
| OLD | NEW |