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

Side by Side Diff: chrome/browser/profiles/profile_manager_unittest.cc

Issue 17127002: Correctly integrate StoragePartition into TestingProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments. merge to ToT. Murder a DB thread and more TestBrowserThreads. Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/chromeos/settings/cros_settings.h" 17 #include "chrome/browser/chromeos/settings/cros_settings.h"
18 #include "chrome/browser/history/history_service.h" 18 #include "chrome/browser/history/history_service.h"
19 #include "chrome/browser/history/history_service_factory.h" 19 #include "chrome/browser/history/history_service_factory.h"
20 #include "chrome/browser/io_thread.h" 20 #include "chrome/browser/io_thread.h"
21 #include "chrome/browser/prefs/browser_prefs.h" 21 #include "chrome/browser/prefs/browser_prefs.h"
22 #include "chrome/browser/prefs/incognito_mode_prefs.h" 22 #include "chrome/browser/prefs/incognito_mode_prefs.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/profiles/profile_info_cache.h" 24 #include "chrome/browser/profiles/profile_info_cache.h"
25 #include "chrome/browser/profiles/profile_manager.h" 25 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/ui/browser.h" 26 #include "chrome/browser/ui/browser.h"
27 #include "chrome/common/chrome_constants.h" 27 #include "chrome/common/chrome_constants.h"
28 #include "chrome/common/chrome_notification_types.h" 28 #include "chrome/common/chrome_notification_types.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
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
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, AutoloadProfilesWithBackgroundApps) { 300 TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) {
306 ProfileManager* profile_manager = g_browser_process->profile_manager(); 301 ProfileManager* profile_manager = g_browser_process->profile_manager();
307 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 302 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
308 local_state_.Get()->SetUserPref(prefs::kBackgroundModeEnabled, 303 local_state_.Get()->SetUserPref(prefs::kBackgroundModeEnabled,
309 Value::CreateBooleanValue(true)); 304 Value::CreateBooleanValue(true));
310 305
311 // Setting a pref which is not applicable to a system (i.e., Android in this 306 // Setting a pref which is not applicable to a system (i.e., Android in this
312 // case) does not necessarily create it. Don't bother continuing with the 307 // case) does not necessarily create it. Don't bother continuing with the
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 temp_dir_.path().AppendASCII(profile_name1); 626 temp_dir_.path().AppendASCII(profile_name1);
632 base::FilePath dest_path2 = 627 base::FilePath dest_path2 =
633 temp_dir_.path().AppendASCII(profile_name2); 628 temp_dir_.path().AppendASCII(profile_name2);
634 629
635 MockObserver mock_observer; 630 MockObserver mock_observer;
636 EXPECT_CALL(mock_observer, OnProfileCreated( 631 EXPECT_CALL(mock_observer, OnProfileCreated(
637 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); 632 testing::NotNull(), NotFail())).Times(testing::AtLeast(3));
638 633
639 CreateProfileAsync(profile_manager, profile_name1, &mock_observer); 634 CreateProfileAsync(profile_manager, profile_name1, &mock_observer);
640 CreateProfileAsync(profile_manager, profile_name2, &mock_observer); 635 CreateProfileAsync(profile_manager, profile_name2, &mock_observer);
641 message_loop_.RunUntilIdle(); 636 base::RunLoop().RunUntilIdle();
642 637
643 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); 638 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size());
644 EXPECT_EQ(2u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); 639 EXPECT_EQ(2u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles());
645 640
646 // Set the active profile. 641 // Set the active profile.
647 PrefService* local_state = g_browser_process->local_state(); 642 PrefService* local_state = g_browser_process->local_state();
648 local_state->SetString(prefs::kProfileLastUsed, profile_name1); 643 local_state->SetString(prefs::kProfileLastUsed, profile_name1);
649 644
650 // Delete the active profile. 645 // Delete the active profile.
651 profile_manager->ScheduleProfileForDeletion(dest_path1, 646 profile_manager->ScheduleProfileForDeletion(dest_path1,
652 ProfileManager::CreateCallback()); 647 ProfileManager::CreateCallback());
653 // Spin the message loop so that all the callbacks can finish running. 648 // Spin the message loop so that all the callbacks can finish running.
654 message_loop_.RunUntilIdle(); 649 base::RunLoop().RunUntilIdle();
655 650
656 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); 651 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath());
657 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); 652 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed));
658 } 653 }
659 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 654 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
660 655
661 #if defined(OS_MACOSX) 656 #if defined(OS_MACOSX)
662 // These tests are for a Mac-only code path that assumes the browser 657 // These tests are for a Mac-only code path that assumes the browser
663 // process isn't killed when all browser windows are closed. 658 // process isn't killed when all browser windows are closed.
664 TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) { 659 TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) {
665 ProfileManager* profile_manager = g_browser_process->profile_manager(); 660 ProfileManager* profile_manager = g_browser_process->profile_manager();
666 ASSERT_TRUE(profile_manager); 661 ASSERT_TRUE(profile_manager);
667 662
668 // Create and load one profile, and just create a second profile. 663 // Create and load one profile, and just create a second profile.
669 const std::string profile_name1 = "New Profile 1"; 664 const std::string profile_name1 = "New Profile 1";
670 const std::string profile_name2 = "New Profile 2"; 665 const std::string profile_name2 = "New Profile 2";
671 base::FilePath dest_path1 = 666 base::FilePath dest_path1 =
672 temp_dir_.path().AppendASCII(profile_name1); 667 temp_dir_.path().AppendASCII(profile_name1);
673 base::FilePath dest_path2 = 668 base::FilePath dest_path2 =
674 temp_dir_.path().AppendASCII(profile_name2); 669 temp_dir_.path().AppendASCII(profile_name2);
675 670
676 MockObserver mock_observer; 671 MockObserver mock_observer;
677 EXPECT_CALL(mock_observer, OnProfileCreated( 672 EXPECT_CALL(mock_observer, OnProfileCreated(
678 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); 673 testing::NotNull(), NotFail())).Times(testing::AtLeast(2));
679 CreateProfileAsync(profile_manager, profile_name1, &mock_observer); 674 CreateProfileAsync(profile_manager, profile_name1, &mock_observer);
680 message_loop_.RunUntilIdle(); 675 base::RunLoop().RunUntilIdle();
681 676
682 // Track the profile, but don't load it. 677 // Track the profile, but don't load it.
683 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 678 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
684 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2), 679 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2),
685 string16(), 0, false); 680 string16(), 0, false);
686 message_loop_.RunUntilIdle(); 681 base::RunLoop().RunUntilIdle();
687 682
688 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); 683 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size());
689 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); 684 EXPECT_EQ(2u, cache.GetNumberOfProfiles());
690 685
691 // Set the active profile. 686 // Set the active profile.
692 PrefService* local_state = g_browser_process->local_state(); 687 PrefService* local_state = g_browser_process->local_state();
693 local_state->SetString(prefs::kProfileLastUsed, 688 local_state->SetString(prefs::kProfileLastUsed,
694 dest_path1.BaseName().MaybeAsASCII()); 689 dest_path1.BaseName().MaybeAsASCII());
695 690
696 // Delete the active profile. This should switch and load the unloaded 691 // Delete the active profile. This should switch and load the unloaded
697 // profile. 692 // profile.
698 profile_manager->ScheduleProfileForDeletion(dest_path1, 693 profile_manager->ScheduleProfileForDeletion(dest_path1,
699 ProfileManager::CreateCallback()); 694 ProfileManager::CreateCallback());
700 695
701 // Spin the message loop so that all the callbacks can finish running. 696 // Spin the message loop so that all the callbacks can finish running.
702 message_loop_.RunUntilIdle(); 697 base::RunLoop().RunUntilIdle();
703 698
704 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); 699 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath());
705 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); 700 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed));
706 } 701 }
707 702
708 // This tests the recursive call in ProfileManager::OnNewActiveProfileLoaded 703 // This tests the recursive call in ProfileManager::OnNewActiveProfileLoaded
709 // by simulating a scenario in which the profile that is being loaded as 704 // by simulating a scenario in which the profile that is being loaded as
710 // the next active profile has also been marked for deletion, so the 705 // the next active profile has also been marked for deletion, so the
711 // ProfileManager needs to recursively select a different next profile. 706 // ProfileManager needs to recursively select a different next profile.
712 TEST_F(ProfileManagerTest, ActiveProfileDeletedNextProfileDeletedToo) { 707 TEST_F(ProfileManagerTest, ActiveProfileDeletedNextProfileDeletedToo) {
713 ProfileManager* profile_manager = g_browser_process->profile_manager(); 708 ProfileManager* profile_manager = g_browser_process->profile_manager();
714 ASSERT_TRUE(profile_manager); 709 ASSERT_TRUE(profile_manager);
715 710
716 // Create and load one profile, and create two more profiles. 711 // Create and load one profile, and create two more profiles.
717 const std::string profile_name1 = "New Profile 1"; 712 const std::string profile_name1 = "New Profile 1";
718 const std::string profile_name2 = "New Profile 2"; 713 const std::string profile_name2 = "New Profile 2";
719 const std::string profile_name3 = "New Profile 3"; 714 const std::string profile_name3 = "New Profile 3";
720 base::FilePath dest_path1 = 715 base::FilePath dest_path1 =
721 temp_dir_.path().AppendASCII(profile_name1); 716 temp_dir_.path().AppendASCII(profile_name1);
722 base::FilePath dest_path2 = 717 base::FilePath dest_path2 =
723 temp_dir_.path().AppendASCII(profile_name2); 718 temp_dir_.path().AppendASCII(profile_name2);
724 base::FilePath dest_path3 = 719 base::FilePath dest_path3 =
725 temp_dir_.path().AppendASCII(profile_name3); 720 temp_dir_.path().AppendASCII(profile_name3);
726 721
727 MockObserver mock_observer; 722 MockObserver mock_observer;
728 EXPECT_CALL(mock_observer, OnProfileCreated( 723 EXPECT_CALL(mock_observer, OnProfileCreated(
729 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); 724 testing::NotNull(), NotFail())).Times(testing::AtLeast(2));
730 CreateProfileAsync(profile_manager, profile_name1, &mock_observer); 725 CreateProfileAsync(profile_manager, profile_name1, &mock_observer);
731 message_loop_.RunUntilIdle(); 726 base::RunLoop().RunUntilIdle();
732 727
733 // Create the other profiles, but don't load them. Assign a fake avatar icon 728 // Create the other profiles, but don't load them. Assign a fake avatar icon
734 // to ensure that profiles in the info cache are sorted by the profile name, 729 // to ensure that profiles in the info cache are sorted by the profile name,
735 // and not randomly by the avatar name. 730 // and not randomly by the avatar name.
736 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 731 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
737 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2), 732 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2),
738 ASCIIToUTF16(profile_name2), 1, false); 733 ASCIIToUTF16(profile_name2), 1, false);
739 cache.AddProfileToCache(dest_path3, ASCIIToUTF16(profile_name3), 734 cache.AddProfileToCache(dest_path3, ASCIIToUTF16(profile_name3),
740 ASCIIToUTF16(profile_name3), 2, false); 735 ASCIIToUTF16(profile_name3), 2, false);
741 736
742 message_loop_.RunUntilIdle(); 737 base::RunLoop().RunUntilIdle();
743 738
744 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); 739 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size());
745 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); 740 EXPECT_EQ(3u, cache.GetNumberOfProfiles());
746 741
747 // Set the active profile. 742 // Set the active profile.
748 PrefService* local_state = g_browser_process->local_state(); 743 PrefService* local_state = g_browser_process->local_state();
749 local_state->SetString(prefs::kProfileLastUsed, 744 local_state->SetString(prefs::kProfileLastUsed,
750 dest_path1.BaseName().MaybeAsASCII()); 745 dest_path1.BaseName().MaybeAsASCII());
751 746
752 // Delete the active profile, Profile1. 747 // Delete the active profile, Profile1.
753 // This will post a CreateProfileAsync message, that tries to load Profile2, 748 // This will post a CreateProfileAsync message, that tries to load Profile2,
754 // which checks that the profile is not being deleted, and then calls back 749 // which checks that the profile is not being deleted, and then calls back
755 // FinishDeletingProfile for Profile1. 750 // FinishDeletingProfile for Profile1.
756 // Try to break this flow by setting the active profile to Profile2 in the 751 // Try to break this flow by setting the active profile to Profile2 in the
757 // middle (so after the first posted message), and trying to delete Profile2, 752 // middle (so after the first posted message), and trying to delete Profile2,
758 // so that the ProfileManager has to look for a different profile to load. 753 // so that the ProfileManager has to look for a different profile to load.
759 profile_manager->ScheduleProfileForDeletion(dest_path1, 754 profile_manager->ScheduleProfileForDeletion(dest_path1,
760 ProfileManager::CreateCallback()); 755 ProfileManager::CreateCallback());
761 local_state->SetString(prefs::kProfileLastUsed, 756 local_state->SetString(prefs::kProfileLastUsed,
762 dest_path2.BaseName().MaybeAsASCII()); 757 dest_path2.BaseName().MaybeAsASCII());
763 profile_manager->ScheduleProfileForDeletion(dest_path2, 758 profile_manager->ScheduleProfileForDeletion(dest_path2,
764 ProfileManager::CreateCallback()); 759 ProfileManager::CreateCallback());
765 // Spin the message loop so that all the callbacks can finish running. 760 // Spin the message loop so that all the callbacks can finish running.
766 message_loop_.RunUntilIdle(); 761 base::RunLoop().RunUntilIdle();
767 762
768 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); 763 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath());
769 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); 764 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed));
770 } 765 }
771 #endif // !defined(OS_MACOSX) 766 #endif // !defined(OS_MACOSX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698