diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-29 05:23:52 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-29 05:23:52 +0000 |
commit | 6730b1e747852448a0d905a27fb4d630cd0691b0 (patch) | |
tree | d7ec4bd1c2201794d37f3e166bee1c06fd8e4981 /chrome/browser/profiles | |
parent | 5ba4b8a98587c4acd7806d952cc087e4333d2429 (diff) | |
download | chromium_src-6730b1e747852448a0d905a27fb4d630cd0691b0.zip chromium_src-6730b1e747852448a0d905a27fb4d630cd0691b0.tar.gz chromium_src-6730b1e747852448a0d905a27fb4d630cd0691b0.tar.bz2 |
Fix ProfileInfoCacheUnittests
BUG=
TEST=
Review URL: http://codereview.chromium.org/8073010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103240 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/profiles')
-rw-r--r-- | chrome/browser/profiles/profile_info_cache_unittest.cc | 81 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_manager.h | 2 |
2 files changed, 47 insertions, 36 deletions
diff --git a/chrome/browser/profiles/profile_info_cache_unittest.cc b/chrome/browser/profiles/profile_info_cache_unittest.cc index 133970b..b7c172e 100644 --- a/chrome/browser/profiles/profile_info_cache_unittest.cc +++ b/chrome/browser/profiles/profile_info_cache_unittest.cc @@ -7,8 +7,10 @@ #include "base/stringprintf.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/profiles/profile_manager.h" #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_pref_service.h" +#include "chrome/test/base/testing_profile_manager.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/resource/resource_bundle.h" @@ -19,12 +21,20 @@ namespace { class ProfileInfoCacheUnittests : public testing::Test { protected: ProfileInfoCacheUnittests() - : local_state_(static_cast<TestingBrowserProcess*>(g_browser_process)) { - cache_.reset(new ProfileInfoCache(local_state_.Get(), GetUserDataDir())); + : testing_profile_manager_( + static_cast<TestingBrowserProcess*>(g_browser_process)) { } - FilePath GetUserDataDir() { - return StringToFilePath("usr").Append(StringToFilePath("profile")); + virtual void SetUp() OVERRIDE { + ASSERT_TRUE(testing_profile_manager_.SetUp()); + } + + ProfileInfoCache* GetCache() { + return testing_profile_manager_.profile_info_cache(); + } + + const FilePath& GetUserDataDir() { + return testing_profile_manager_.profile_manager()->user_data_dir(); } FilePath StringToFilePath(std::string string_path) { @@ -35,13 +45,12 @@ class ProfileInfoCacheUnittests : public testing::Test { #endif } - scoped_ptr<ProfileInfoCache> cache_; - ScopedTestingLocalState local_state_; + private: + TestingProfileManager testing_profile_manager_; }; -// TODO(sail): This fails on windows for some reason. -TEST_F(ProfileInfoCacheUnittests, DISABLED_AddProfiles) { - EXPECT_EQ(0u, cache_->GetNumberOfProfiles()); +TEST_F(ProfileInfoCacheUnittests, AddProfiles) { + EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); for (uint32 i = 0; i < 4; ++i) { std::string base_name = StringPrintf("path_%ud", i); @@ -51,53 +60,53 @@ TEST_F(ProfileInfoCacheUnittests, DISABLED_AddProfiles) { const SkBitmap& icon = ResourceBundle::GetSharedInstance().GetImageNamed( ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(i)); - cache_->AddProfileToCache(profile_path, profile_name, 0); + GetCache()->AddProfileToCache(profile_path, profile_name, 0); - EXPECT_EQ(i + 1, cache_->GetNumberOfProfiles()); - EXPECT_EQ(profile_name, cache_->GetNameOfProfileAtIndex(i)); - EXPECT_EQ(profile_path, cache_->GetPathOfProfileAtIndex(i)); - const SkBitmap& actual_icon = cache_->GetAvatarIconOfProfileAtIndex(i); + EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles()); + EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); + EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); + const SkBitmap& actual_icon = GetCache()->GetAvatarIconOfProfileAtIndex(i); EXPECT_EQ(icon.width(), actual_icon.width()); EXPECT_EQ(icon.height(), actual_icon.height()); } } -TEST_F(ProfileInfoCacheUnittests, DISABLED_DeleteProfile) { - EXPECT_EQ(0u, cache_->GetNumberOfProfiles()); +TEST_F(ProfileInfoCacheUnittests, DeleteProfile) { + EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); FilePath path_1 = GetUserDataDir().Append(StringToFilePath("path_1")); - cache_->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), + GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), 0); - EXPECT_EQ(1u, cache_->GetNumberOfProfiles()); + EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); FilePath path_2 = GetUserDataDir().Append(StringToFilePath("path_2")); string16 name_2 = ASCIIToUTF16("name_2"); - cache_->AddProfileToCache(path_2, name_2, 0); - EXPECT_EQ(2u, cache_->GetNumberOfProfiles()); + GetCache()->AddProfileToCache(path_2, name_2, 0); + EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles()); - cache_->DeleteProfileFromCache(path_1); - EXPECT_EQ(1u, cache_->GetNumberOfProfiles()); - EXPECT_EQ(name_2, cache_->GetNameOfProfileAtIndex(0)); + GetCache()->DeleteProfileFromCache(path_1); + EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); + EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex(0)); - cache_->DeleteProfileFromCache(path_2); - EXPECT_EQ(0u, cache_->GetNumberOfProfiles()); + GetCache()->DeleteProfileFromCache(path_2); + EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); } -TEST_F(ProfileInfoCacheUnittests, DISABLED_MutateProfile) { - cache_->AddProfileToCache(GetUserDataDir().Append(StringToFilePath("path_1")), - ASCIIToUTF16("name_1"), 0); - cache_->AddProfileToCache(GetUserDataDir().Append(StringToFilePath("path_2")), - ASCIIToUTF16("name_2"), 0); +TEST_F(ProfileInfoCacheUnittests, MutateProfile) { + GetCache()->AddProfileToCache(GetUserDataDir().Append( + StringToFilePath("path_1")), ASCIIToUTF16("name_1"), 0); + GetCache()->AddProfileToCache(GetUserDataDir().Append( + StringToFilePath("path_2")), ASCIIToUTF16("name_2"), 0); string16 new_name = ASCIIToUTF16("new_name"); - cache_->SetNameOfProfileAtIndex(1, new_name); - EXPECT_EQ(new_name, cache_->GetNameOfProfileAtIndex(1)); - EXPECT_NE(new_name, cache_->GetNameOfProfileAtIndex(0)); + GetCache()->SetNameOfProfileAtIndex(1, new_name); + EXPECT_EQ(new_name, GetCache()->GetNameOfProfileAtIndex(1)); + EXPECT_NE(new_name, GetCache()->GetNameOfProfileAtIndex(0)); size_t new_icon_index = 3; - cache_->SetAvatarIconOfProfileAtIndex(1, new_icon_index); + GetCache()->SetAvatarIconOfProfileAtIndex(1, new_icon_index); // Not much to test. - cache_->GetAvatarIconOfProfileAtIndex(1); + GetCache()->GetAvatarIconOfProfileAtIndex(1); } -} // namespace +} // namespace diff --git a/chrome/browser/profiles/profile_manager.h b/chrome/browser/profiles/profile_manager.h index 12bad66..eed68fa 100644 --- a/chrome/browser/profiles/profile_manager.h +++ b/chrome/browser/profiles/profile_manager.h @@ -178,6 +178,8 @@ class ProfileManager : public base::NonThreadSafe, // for testing. If |addToCache|, add to ProfileInfoCache as well. void RegisterTestingProfile(Profile* profile, bool addToCache); + const FilePath& user_data_dir() const { return user_data_dir_; } + protected: // Does final initial actions. virtual void DoFinalInit(Profile* profile, bool go_off_the_record); |