| Index: chrome/browser/profiles/profile_manager_unittest.cc
|
| ===================================================================
|
| --- chrome/browser/profiles/profile_manager_unittest.cc (revision 112723)
|
| +++ chrome/browser/profiles/profile_manager_unittest.cc (working copy)
|
| @@ -97,12 +97,14 @@
|
| virtual void SetUp() {
|
| // Create a new temporary directory, and store the path
|
| ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
|
| - profile_manager_.reset(new testing::ProfileManager(temp_dir_.path()));
|
| + static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager(
|
| + new testing::ProfileManager(temp_dir_.path()));
|
| #if defined(OS_WIN)
|
| // Force the ProfileInfoCache to be created immediately, so we can
|
| // remove the shortcut manager for testing.
|
| - profile_manager_->GetProfileInfoCache();
|
| - profile_manager_->RemoveProfileShortcutManagerForTesting();
|
| + ProfileManager* profile_manager = g_browser_process->profile_manager();
|
| + profile_manager->GetProfileInfoCache();
|
| + profile_manager->RemoveProfileShortcutManagerForTesting();
|
| #endif
|
| #if defined(OS_CHROMEOS)
|
| CommandLine *cl = CommandLine::ForCurrentProcess();
|
| @@ -111,7 +113,8 @@
|
| }
|
|
|
| virtual void TearDown() {
|
| - profile_manager_.reset();
|
| + static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager(
|
| + NULL);
|
| message_loop_.RunAllPending();
|
| }
|
|
|
| @@ -141,30 +144,30 @@
|
| IOThread io_thread_;
|
|
|
| scoped_ptr<base::SystemMonitor> system_monitor_dummy_;
|
| -
|
| - // Also will test profile deletion.
|
| - scoped_ptr<ProfileManager> profile_manager_;
|
| };
|
|
|
| TEST_F(ProfileManagerTest, GetProfile) {
|
| FilePath dest_path = temp_dir_.path();
|
| dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile"));
|
|
|
| + ProfileManager* profile_manager = g_browser_process->profile_manager();
|
| +
|
| Profile* profile;
|
|
|
| // Successfully create a profile.
|
| - profile = profile_manager_->GetProfile(dest_path);
|
| + profile = profile_manager->GetProfile(dest_path);
|
| EXPECT_TRUE(profile);
|
|
|
| // The profile already exists when we call GetProfile. Just load it.
|
| - EXPECT_EQ(profile, profile_manager_->GetProfile(dest_path));
|
| + EXPECT_EQ(profile, profile_manager->GetProfile(dest_path));
|
| }
|
|
|
| TEST_F(ProfileManagerTest, DefaultProfileDir) {
|
| FilePath expected_default =
|
| FilePath().AppendASCII(chrome::kInitialProfile);
|
| - EXPECT_EQ(expected_default.value(),
|
| - profile_manager_->GetInitialProfileDir().value());
|
| + EXPECT_EQ(
|
| + expected_default.value(),
|
| + g_browser_process->profile_manager()->GetInitialProfileDir().value());
|
| }
|
|
|
| #if defined(OS_CHROMEOS)
|
| @@ -177,17 +180,18 @@
|
|
|
| FilePath expected_default =
|
| FilePath().AppendASCII(chrome::kInitialProfile);
|
| + ProfileManager* profile_manager = g_browser_process->profile_manager();
|
| EXPECT_EQ(expected_default.value(),
|
| - profile_manager_->GetInitialProfileDir().value());
|
| + profile_manager->GetInitialProfileDir().value());
|
|
|
| - profile_manager_->Observe(chrome::NOTIFICATION_LOGIN_USER_CHANGED,
|
| + profile_manager->Observe(chrome::NOTIFICATION_LOGIN_USER_CHANGED,
|
| content::NotificationService::AllSources(),
|
| content::NotificationService::NoDetails());
|
| FilePath expected_logged_in(profile_dir);
|
| EXPECT_EQ(expected_logged_in.value(),
|
| - profile_manager_->GetInitialProfileDir().value());
|
| + profile_manager->GetInitialProfileDir().value());
|
| VLOG(1) << temp_dir_.path().Append(
|
| - profile_manager_->GetInitialProfileDir()).value();
|
| + profile_manager->GetInitialProfileDir()).value();
|
| }
|
|
|
| #endif
|
| @@ -199,13 +203,15 @@
|
| FilePath dest_path2 = temp_dir_.path();
|
| dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2"));
|
|
|
| + ProfileManager* profile_manager = g_browser_process->profile_manager();
|
| +
|
| // Successfully create the profiles.
|
| TestingProfile* profile1 =
|
| - static_cast<TestingProfile*>(profile_manager_->GetProfile(dest_path1));
|
| + static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1));
|
| ASSERT_TRUE(profile1);
|
|
|
| TestingProfile* profile2 =
|
| - static_cast<TestingProfile*>(profile_manager_->GetProfile(dest_path2));
|
| + static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path2));
|
| ASSERT_TRUE(profile2);
|
|
|
| // Force lazy-init of some profile services to simulate use.
|
| @@ -221,7 +227,8 @@
|
| // Make sure any pending tasks run before we destroy the profiles.
|
| message_loop_.RunAllPending();
|
|
|
| - profile_manager_.reset();
|
| + static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager(
|
| + NULL);
|
|
|
| // Make sure history cleans up correctly.
|
| message_loop_.RunAllPending();
|
| @@ -241,7 +248,8 @@
|
| EXPECT_CALL(mock_observer, OnProfileCreated(
|
| testing::NotNull(), NotFail())).Times(testing::AtLeast(1));
|
|
|
| - profile_manager_->CreateProfileAsync(dest_path, &mock_observer);
|
| + g_browser_process->profile_manager()->CreateProfileAsync(dest_path,
|
| + &mock_observer);
|
|
|
| message_loop_.RunAllPending();
|
| }
|
| @@ -268,10 +276,12 @@
|
| EXPECT_CALL(mock_observer3, OnProfileCreated(
|
| SameNotNull(), NotFail())).Times(testing::AtLeast(1));
|
|
|
| - profile_manager_->CreateProfileAsync(dest_path, &mock_observer1);
|
| - profile_manager_->CreateProfileAsync(dest_path, &mock_observer2);
|
| - profile_manager_->CreateProfileAsync(dest_path, &mock_observer3);
|
| + ProfileManager* profile_manager = g_browser_process->profile_manager();
|
|
|
| + profile_manager->CreateProfileAsync(dest_path, &mock_observer1);
|
| + profile_manager->CreateProfileAsync(dest_path, &mock_observer2);
|
| + profile_manager->CreateProfileAsync(dest_path, &mock_observer3);
|
| +
|
| message_loop_.RunAllPending();
|
| }
|
|
|
| @@ -285,14 +295,17 @@
|
| EXPECT_CALL(mock_observer, OnProfileCreated(
|
| testing::NotNull(), NotFail())).Times(testing::AtLeast(3));
|
|
|
| - profile_manager_->CreateProfileAsync(dest_path1, &mock_observer);
|
| - profile_manager_->CreateProfileAsync(dest_path2, &mock_observer);
|
| + ProfileManager* profile_manager = g_browser_process->profile_manager();
|
|
|
| + profile_manager->CreateProfileAsync(dest_path1, &mock_observer);
|
| + profile_manager->CreateProfileAsync(dest_path2, &mock_observer);
|
| +
|
| message_loop_.RunAllPending();
|
| }
|
|
|
| TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) {
|
| - ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache();
|
| + ProfileManager* profile_manager = g_browser_process->profile_manager();
|
| + ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
|
|
|
| EXPECT_EQ(0u, cache.GetNumberOfProfiles());
|
| cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_1"),
|
| @@ -305,7 +318,31 @@
|
| cache.SetBackgroundStatusOfProfileAtIndex(2, true);
|
| EXPECT_EQ(3u, cache.GetNumberOfProfiles());
|
|
|
| - profile_manager_->AutoloadProfiles();
|
| + profile_manager->AutoloadProfiles();
|
|
|
| - EXPECT_EQ(2u, profile_manager_->GetLoadedProfiles().size());
|
| + EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size());
|
| }
|
| +
|
| +TEST_F(ProfileManagerTest, InitProfileUserPrefs) {
|
| + FilePath dest_path = temp_dir_.path();
|
| + dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile"));
|
| +
|
| + ProfileManager* profile_manager = g_browser_process->profile_manager();
|
| +
|
| + Profile* profile;
|
| +
|
| + // Successfully create the profile
|
| + profile = profile_manager->GetProfile(dest_path);
|
| + ASSERT_TRUE(profile);
|
| +
|
| + // Check that the profile name is non empty
|
| + std::string profile_name =
|
| + profile->GetPrefs()->GetString(prefs::kProfileName);
|
| + EXPECT_FALSE(profile_name.empty());
|
| +
|
| + // Check that the profile avatar index is valid
|
| + size_t avatar_index = profile->GetPrefs()->GetInteger(
|
| + prefs::kProfileAvatarIndex);
|
| + EXPECT_TRUE(profile_manager->GetProfileInfoCache().IsDefaultAvatarIconIndex(
|
| + avatar_index));
|
| +}
|
|
|