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

Unified Diff: chrome/browser/profiles/profile_manager_unittest.cc

Issue 8883030: Making profile avatars and names sync. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding a Profile Manager unittest Created 9 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/profiles/profile_manager.cc ('k') | chrome/browser/sync/test/integration/sync_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/profiles/profile_manager_unittest.cc
diff --git a/chrome/browser/profiles/profile_manager_unittest.cc b/chrome/browser/profiles/profile_manager_unittest.cc
index 0182d90e70fa6cfbd944429155f4f3cd50e8a697..5f240119c9c32c339427cc8a85ccd2c6b3d19b5f 100644
--- a/chrome/browser/profiles/profile_manager_unittest.cc
+++ b/chrome/browser/profiles/profile_manager_unittest.cc
@@ -97,12 +97,14 @@ class ProfileManagerTest : public testing::Test {
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 @@ class ProfileManagerTest : public testing::Test {
}
virtual void TearDown() {
- profile_manager_.reset();
+ static_cast<TestingBrowserProcess*>(g_browser_process)->SetProfileManager(
+ NULL);
message_loop_.RunAllPending();
}
@@ -142,30 +145,30 @@ class ProfileManagerTest : public testing::Test {
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)
@@ -178,17 +181,18 @@ TEST_F(ProfileManagerTest, LoggedInProfileDir) {
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
@@ -200,13 +204,15 @@ TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) {
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.
@@ -222,7 +228,8 @@ TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) {
// 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();
@@ -242,7 +249,7 @@ TEST_F(ProfileManagerTest, DISABLED_CreateProfileAsync) {
EXPECT_CALL(mock_observer, OnProfileCreated(
testing::NotNull(), NotFail())).Times(testing::AtLeast(1));
- profile_manager_->CreateProfileAsync(dest_path,
+ g_browser_process->profile_manager()->CreateProfileAsync(dest_path,
base::Bind(&MockObserver::OnProfileCreated,
base::Unretained(&mock_observer)));
@@ -271,13 +278,15 @@ TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) {
EXPECT_CALL(mock_observer3, OnProfileCreated(
SameNotNull(), NotFail())).Times(testing::AtLeast(1));
- profile_manager_->CreateProfileAsync(dest_path,
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+
+ profile_manager->CreateProfileAsync(dest_path,
base::Bind(&MockObserver::OnProfileCreated,
base::Unretained(&mock_observer1)));
- profile_manager_->CreateProfileAsync(dest_path,
+ profile_manager->CreateProfileAsync(dest_path,
base::Bind(&MockObserver::OnProfileCreated,
base::Unretained(&mock_observer2)));
- profile_manager_->CreateProfileAsync(dest_path,
+ profile_manager->CreateProfileAsync(dest_path,
base::Bind(&MockObserver::OnProfileCreated,
base::Unretained(&mock_observer3)));
@@ -294,10 +303,12 @@ TEST_F(ProfileManagerTest, CreateProfilesAsync) {
EXPECT_CALL(mock_observer, OnProfileCreated(
testing::NotNull(), NotFail())).Times(testing::AtLeast(3));
- profile_manager_->CreateProfileAsync(dest_path1,
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+
+ profile_manager->CreateProfileAsync(dest_path1,
base::Bind(&MockObserver::OnProfileCreated,
base::Unretained(&mock_observer)));
- profile_manager_->CreateProfileAsync(dest_path2,
+ profile_manager->CreateProfileAsync(dest_path2,
base::Bind(&MockObserver::OnProfileCreated,
base::Unretained(&mock_observer)));
@@ -305,7 +316,8 @@ TEST_F(ProfileManagerTest, CreateProfilesAsync) {
}
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"),
@@ -318,7 +330,58 @@ TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) {
cache.SetBackgroundStatusOfProfileAtIndex(2, true);
EXPECT_EQ(3u, cache.GetNumberOfProfiles());
- profile_manager_->AutoloadProfiles();
+ profile_manager->AutoloadProfiles();
+
+ 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));
+}
+
+// Tests that a new profile's entry in the profile info cache is setup with the
+// same values that are in the profile prefs.
+TEST_F(ProfileManagerTest, InitProfileInfoCacheForAProfile) {
+ FilePath dest_path = temp_dir_.path();
+ dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile"));
+
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
+
+ // Successfully create the profile
+ Profile* profile = profile_manager->GetProfile(dest_path);
+ ASSERT_TRUE(profile);
+
+ std::string profile_name =
+ profile->GetPrefs()->GetString(prefs::kProfileName);
+ size_t avatar_index =
+ profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex);
+
+ size_t profile_index = cache.GetIndexOfProfileWithPath(dest_path);
- EXPECT_EQ(2u, profile_manager_->GetLoadedProfiles().size());
+ // Check if the profile prefs are the same as the cache prefs
+ EXPECT_EQ(profile_name,
+ UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index)));
+ EXPECT_EQ(avatar_index,
+ cache.GetAvatarIconIndexOfProfileAtIndex(profile_index));
}
« no previous file with comments | « chrome/browser/profiles/profile_manager.cc ('k') | chrome/browser/sync/test/integration/sync_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698