diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-29 20:31:48 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-29 20:31:48 +0000 |
commit | c828c6b23db1484d54b6777641df883daea61429 (patch) | |
tree | 0e1d1d2bf09d4cd05d01028438e5e333f348c9e1 /chrome/browser | |
parent | 55bdb501e79d634b23bdbba0c90dfe557e9c628b (diff) | |
download | chromium_src-c828c6b23db1484d54b6777641df883daea61429.zip chromium_src-c828c6b23db1484d54b6777641df883daea61429.tar.gz chromium_src-c828c6b23db1484d54b6777641df883daea61429.tar.bz2 |
Revert 112006 - Add service to update GAIA info
BUG=91241
TEST=
Review URL: http://codereview.chromium.org/8587024
TBR=sail@chromium.org
Review URL: http://codereview.chromium.org/8662039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112017 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/profiles/gaia_info_update_service.cc | 95 | ||||
-rw-r--r-- | chrome/browser/profiles/gaia_info_update_service.h | 43 | ||||
-rw-r--r-- | chrome/browser/profiles/gaia_info_update_service_unittest.cc | 129 | ||||
-rw-r--r-- | chrome/browser/profiles/off_the_record_profile_impl.cc | 4 | ||||
-rw-r--r-- | chrome/browser/profiles/off_the_record_profile_impl.h | 1 | ||||
-rw-r--r-- | chrome/browser/profiles/profile.h | 4 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_downloader.cc | 4 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_downloader.h | 6 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.cc | 10 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.h | 2 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_info_cache_unittest.cc | 207 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_info_cache_unittest.h | 36 |
12 files changed, 144 insertions, 397 deletions
diff --git a/chrome/browser/profiles/gaia_info_update_service.cc b/chrome/browser/profiles/gaia_info_update_service.cc deleted file mode 100644 index 038ea36..0000000 --- a/chrome/browser/profiles/gaia_info_update_service.cc +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/profiles/gaia_info_update_service.h" - -#include "base/command_line.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_info_cache.h" -#include "chrome/browser/profiles/profile_manager.h" -#include "chrome/browser/sync/profile_sync_service.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/pref_names.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/gfx/image/image.h" - -GAIAInfoUpdateService::GAIAInfoUpdateService(Profile* profile) - : profile_(profile) { -} - -GAIAInfoUpdateService::~GAIAInfoUpdateService() { -} - -void GAIAInfoUpdateService::Update() { - if (profile_image_downloader_.get()) - return; - profile_image_downloader_.reset(new ProfileDownloader(this)); - profile_image_downloader_->Start(); -} - -// static -bool GAIAInfoUpdateService::ShouldUseGAIAProfileInfo(Profile* profile) { -#if defined(OS_CHROMEOS) - return false; -#endif - - // Sync must be allowed. - if (!profile->GetOriginalProfile()->IsSyncAccessible()) - return false; - - // The user must be logged in. - ProfileSyncService* service = - profile->GetOriginalProfile()->GetProfileSyncService(); - if (!service || !service->HasSyncSetupCompleted()) - return false; - - // TODO(sail): For now put this feature behind a flag. - if (!CommandLine::ForCurrentProcess()->HasSwitch( - switches::kGaiaProfileInfo)) { - return false; - } - - return true; -} - -int GAIAInfoUpdateService::GetDesiredImageSideLength() { - return 256; -} - -Profile* GAIAInfoUpdateService::GetBrowserProfile() { - return profile_; -} - -void GAIAInfoUpdateService::OnDownloadComplete(ProfileDownloader* downloader, - bool success) { - if (!success) { - profile_image_downloader_.reset(); - return; - } - - string16 full_name = downloader->GetProfileFullName(); - SkBitmap bitmap = downloader->GetProfilePicture(); - profile_image_downloader_.reset(); - - ProfileInfoCache& cache = - g_browser_process->profile_manager()->GetProfileInfoCache(); - size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); - if (profile_index == std::string::npos) - return; - - cache.SetGAIANameOfProfileAtIndex(profile_index, full_name); - gfx::Image gfx_image(new SkBitmap(bitmap)); - cache.SetGAIAPictureOfProfileAtIndex(profile_index, gfx_image); - - // If this profile hasn't switched to using GAIA information for the profile - // name and picture then switch it now. Once the profile has switched this - // preference guards against clobbering the user's custom settings. - if (!cache.GetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index)) { - cache.SetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index, true); - cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true); - cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, true); - } -} diff --git a/chrome/browser/profiles/gaia_info_update_service.h b/chrome/browser/profiles/gaia_info_update_service.h deleted file mode 100644 index 7c680b6..0000000 --- a/chrome/browser/profiles/gaia_info_update_service.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_PROFILES_GAIA_INFO_UPDATE_SERVICE_H_ -#define CHROME_BROWSER_PROFILES_GAIA_INFO_UPDATE_SERVICE_H_ -#pragma once - -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "chrome/browser/profiles/profile_downloader_delegate.h" -#include "chrome/browser/profiles/profile_downloader.h" - -class Profile; -class ProfileDownloader; - -// This service kicks off a download of the user's name and profile picture. -// The results are saved in the profile info cache. -class GAIAInfoUpdateService : public ProfileDownloaderDelegate { - public: - explicit GAIAInfoUpdateService(Profile* profile); - virtual ~GAIAInfoUpdateService(); - - // Updates the GAIA info for the profile associated with this instance. - void Update(); - - // Checks if downloading GAIA info for the given profile is allowed. - static bool ShouldUseGAIAProfileInfo(Profile* profile); - - // ProfileDownloaderDelegate: - virtual int GetDesiredImageSideLength() OVERRIDE; - virtual Profile* GetBrowserProfile() OVERRIDE; - virtual void OnDownloadComplete(ProfileDownloader* downloader, - bool success) OVERRIDE; - - private: - Profile* profile_; - scoped_ptr<ProfileDownloader> profile_image_downloader_; - - DISALLOW_COPY_AND_ASSIGN(GAIAInfoUpdateService); -}; - -#endif // CHROME_BROWSER_PROFILES_GAIA_INFO_UPDATE_SERVICE_H_ diff --git a/chrome/browser/profiles/gaia_info_update_service_unittest.cc b/chrome/browser/profiles/gaia_info_update_service_unittest.cc deleted file mode 100644 index 07331b1..0000000 --- a/chrome/browser/profiles/gaia_info_update_service_unittest.cc +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/profiles/gaia_info_update_service.h" - -#include "base/utf_string_conversions.h" -#include "chrome/browser/browser_process.h" -#include "chrome/browser/profiles/profile_info_cache_unittest.h" -#include "chrome/test/base/testing_browser_process.h" -#include "chrome/test/base/testing_profile.h" -#include "chrome/test/base/testing_profile_manager.h" -#include "chrome/browser/profiles/profile_downloader.h" -#include "chrome/browser/profiles/profile_info_cache.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "ui/gfx/image/image.h" -#include "ui/gfx/image/image_unittest_util.h" - -using ::testing::Return; -using ::testing::NiceMock; - -namespace { - -class ProfileDownloaderMock : public ProfileDownloader { - public: - explicit ProfileDownloaderMock(ProfileDownloaderDelegate* delegate) - : ProfileDownloader(delegate) { - } - - virtual ~ProfileDownloaderMock() { - } - - MOCK_CONST_METHOD0(GetProfileFullName, string16()); - MOCK_CONST_METHOD0(GetProfilePicture, SkBitmap()); -}; - -class GAIAInfoUpdateServiceTest : public ProfileInfoCacheTest { - protected: - GAIAInfoUpdateServiceTest() : profile_(NULL) { - } - - Profile* profile() { - if (!profile_) - profile_ = testing_profile_manager_.CreateTestingProfile("profile_1"); - return profile_; - } - - private: - Profile* profile_; -}; - -TEST_F(GAIAInfoUpdateServiceTest, DownloadSuccess) { - GAIAInfoUpdateService service(profile()); - NiceMock<ProfileDownloaderMock> downloader(&service); - - string16 name = ASCIIToUTF16("Pat Smith"); - EXPECT_CALL(downloader, GetProfileFullName()).WillOnce(Return(name)); - gfx::Image image = gfx::test::CreateImage(); - SkBitmap bmp = image; - EXPECT_CALL(downloader, GetProfilePicture()).WillOnce(Return(bmp)); - - service.OnDownloadComplete(&downloader, true); - - // On success both the profile info and GAIA info should be updated. - size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); - EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(index)); - EXPECT_EQ(name, GetCache()->GetNameOfProfileAtIndex(index)); - EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index)); - EXPECT_TRUE(gfx::test::IsEqual( - image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); - EXPECT_TRUE(gfx::test::IsEqual( - image, GetCache()->GetGAIAPictureOfProfileAtIndex(index))); -} - -TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) { - size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); - string16 old_name = GetCache()->GetNameOfProfileAtIndex(index); - gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index); - - GAIAInfoUpdateService service(profile()); - NiceMock<ProfileDownloaderMock> downloader(&service); - - service.OnDownloadComplete(&downloader, false); - - // On failure nothing should be updated. - EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(index)); - EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); - EXPECT_EQ(string16(), GetCache()->GetGAIANameOfProfileAtIndex(index)); - EXPECT_TRUE(gfx::test::IsEqual( - old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); - EXPECT_TRUE(gfx::test::IsEmpty( - GetCache()->GetGAIAPictureOfProfileAtIndex(index))); -} - -TEST_F(GAIAInfoUpdateServiceTest, NoMigration) { - size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); - string16 old_name = GetCache()->GetNameOfProfileAtIndex(index); - gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index); - - // Mark the profile as migrated. - GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(index, true); - - GAIAInfoUpdateService service(profile()); - NiceMock<ProfileDownloaderMock> downloader(&service); - string16 new_name = ASCIIToUTF16("Pat Smith"); - EXPECT_CALL(downloader, GetProfileFullName()).WillOnce(Return(new_name)); - gfx::Image new_image = gfx::test::CreateImage(); - SkBitmap new_bmp = new_image; - EXPECT_CALL(downloader, GetProfilePicture()).WillOnce(Return(new_bmp)); - - service.OnDownloadComplete(&downloader, true); - - // On success with no migration the profile info should not be updated but - // the GAIA info should be updated. - EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(index)); - EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); - EXPECT_EQ(new_name, GetCache()->GetGAIANameOfProfileAtIndex(index)); - EXPECT_TRUE(gfx::test::IsEqual( - old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); - EXPECT_TRUE(gfx::test::IsEqual( - new_image, GetCache()->GetGAIAPictureOfProfileAtIndex(index))); -} - -TEST_F(GAIAInfoUpdateServiceTest, ShouldUseGAIAProfileInfo) { - // Currently this is disabled by default. - EXPECT_FALSE(GAIAInfoUpdateService::ShouldUseGAIAProfileInfo(profile())); -} - -} // namespace diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc index 619d835..0c11323 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.cc +++ b/chrome/browser/profiles/off_the_record_profile_impl.cc @@ -245,10 +245,6 @@ SSLHostState* OffTheRecordProfileImpl::GetSSLHostState() { return ssl_host_state_.get(); } -GAIAInfoUpdateService* OffTheRecordProfileImpl::GetGAIAInfoUpdateService() { - return NULL; -} - HistoryService* OffTheRecordProfileImpl::GetHistoryService( ServiceAccessType sat) { if (sat == EXPLICIT_ACCESS) diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h index ceb2fc2..b94fd86 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.h +++ b/chrome/browser/profiles/off_the_record_profile_impl.h @@ -53,7 +53,6 @@ class OffTheRecordProfileImpl : public Profile, virtual ExtensionSpecialStoragePolicy* GetExtensionSpecialStoragePolicy() OVERRIDE; virtual SSLHostState* GetSSLHostState() OVERRIDE; - virtual GAIAInfoUpdateService* GetGAIAInfoUpdateService() OVERRIDE; virtual HistoryService* GetHistoryService(ServiceAccessType sat) OVERRIDE; virtual HistoryService* GetHistoryServiceWithoutCreating() OVERRIDE; virtual FaviconService* GetFaviconService(ServiceAccessType sat) OVERRIDE; diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h index d1a52e6..2cf9b6d7 100644 --- a/chrome/browser/profiles/profile.h +++ b/chrome/browser/profiles/profile.h @@ -57,7 +57,6 @@ class ExtensionService; class ExtensionSpecialStoragePolicy; class FaviconService; class FindBarState; -class GAIAInfoUpdateService; class HistoryService; class HostContentSettingsMap; class NetworkActionPredictor; @@ -276,9 +275,6 @@ class Profile : public content::BrowserContext { // the ServiceAccessType definition above. virtual FaviconService* GetFaviconService(ServiceAccessType access) = 0; - // Accessor. The instance is created upon first access. - virtual GAIAInfoUpdateService* GetGAIAInfoUpdateService() = 0; - // Retrieves a pointer to the HistoryService associated with this // profile. The HistoryService is lazily created the first time // that this method is called. diff --git a/chrome/browser/profiles/profile_downloader.cc b/chrome/browser/profiles/profile_downloader.cc index da6eccb..468cc8c 100644 --- a/chrome/browser/profiles/profile_downloader.cc +++ b/chrome/browser/profiles/profile_downloader.cc @@ -201,11 +201,11 @@ void ProfileDownloader::Start() { } } -string16 ProfileDownloader::GetProfileFullName() const { +const string16& ProfileDownloader::GetProfileFullName() const { return profile_full_name_; } -SkBitmap ProfileDownloader::GetProfilePicture() const { +const SkBitmap& ProfileDownloader::GetProfilePicture() const { return profile_picture_; } diff --git a/chrome/browser/profiles/profile_downloader.h b/chrome/browser/profiles/profile_downloader.h index 6f4d1ec..2b9733e 100644 --- a/chrome/browser/profiles/profile_downloader.h +++ b/chrome/browser/profiles/profile_downloader.h @@ -32,16 +32,16 @@ class ProfileDownloader : public content::URLFetcherDelegate, // Starts downloading profile information if the necessary authorization token // is ready. If not, subscribes to token service and starts fetching if the // token is available. Should not be called more than once. - virtual void Start(); + void Start(); // On successful download this returns the full name of the user. For example // "Pat Smith". - virtual string16 GetProfileFullName() const; + const string16& GetProfileFullName() const; // On successful download this returns the profile picture of the user. // For users with no profile picture set (that is, they have the default // profile picture) this will return an Null bitmap. - virtual SkBitmap GetProfilePicture() const; + const SkBitmap& GetProfilePicture() const; private: // Overriden from content::URLFetcherDelegate: diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 8b88775b..ae99e83 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -63,7 +63,6 @@ #include "chrome/browser/prefs/pref_value_store.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/browser/prerender/prerender_manager_factory.h" -#include "chrome/browser/profiles/gaia_info_update_service.h" #include "chrome/browser/profiles/profile_dependency_manager.h" #include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_manager.h" @@ -899,12 +898,6 @@ FindBarState* ProfileImpl::GetFindBarState() { return find_bar_state_.get(); } -GAIAInfoUpdateService* ProfileImpl::GetGAIAInfoUpdateService() { - if (!gaia_info_update_service_.get()) - gaia_info_update_service_.reset(new GAIAInfoUpdateService(this)); - return gaia_info_update_service_.get(); -} - HistoryService* ProfileImpl::GetHistoryService(ServiceAccessType sat) { // If saving history is disabled, only allow explicit access. if (GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled) && @@ -1366,9 +1359,6 @@ void ProfileImpl::InitSyncService(const std::string& cros_user) { sync_service_->Initialize(); UpdateProfileUserNameCache(); - // Force the GAIA info update service to be initialized since it depends on - // the sync service. - GetGAIAInfoUpdateService(); } ChromeBlobStorageContext* ProfileImpl::GetBlobStorageContext() { diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index 7f143a6..293e820 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -87,7 +87,6 @@ class ProfileImpl : public Profile, virtual ExtensionSpecialStoragePolicy* GetExtensionSpecialStoragePolicy() OVERRIDE; virtual FaviconService* GetFaviconService(ServiceAccessType sat) OVERRIDE; - virtual GAIAInfoUpdateService* GetGAIAInfoUpdateService() OVERRIDE; virtual HistoryService* GetHistoryService(ServiceAccessType sat) OVERRIDE; virtual HistoryService* GetHistoryServiceWithoutCreating() OVERRIDE; virtual AutocompleteClassifier* GetAutocompleteClassifier() OVERRIDE; @@ -255,7 +254,6 @@ class ProfileImpl : public Profile, scoped_refptr<SpeechInputPreferences> speech_input_preferences_; scoped_refptr<UserStyleSheetWatcher> user_style_sheet_watcher_; scoped_ptr<FindBarState> find_bar_state_; - scoped_ptr<GAIAInfoUpdateService> gaia_info_update_service_; scoped_refptr<HistoryService> history_service_; scoped_ptr<FaviconService> favicon_service_; scoped_ptr<AutocompleteClassifier> autocomplete_classifier_; diff --git a/chrome/browser/profiles/profile_info_cache_unittest.cc b/chrome/browser/profiles/profile_info_cache_unittest.cc index 34e9918..a94155e 100644 --- a/chrome/browser/profiles/profile_info_cache_unittest.cc +++ b/chrome/browser/profiles/profile_info_cache_unittest.cc @@ -2,61 +2,120 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/profiles/profile_info_cache_unittest.h" +#include "chrome/browser/profiles/profile_info_cache.h" #include "base/stringprintf.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/chrome_notification_types.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 "chrome/test/base/ui_test_utils.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" +#include "content/test/test_browser_thread.h" +#include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/image/image.h" -#include "ui/gfx/image/image_unittest_util.h" using content::BrowserThread; -ProfileInfoCacheTest::ProfileInfoCacheTest() - : testing_profile_manager_( - static_cast<TestingBrowserProcess*>(g_browser_process)), - ui_thread_(BrowserThread::UI, &ui_loop_), - file_thread_(BrowserThread::FILE, &ui_loop_) { -} +namespace { -ProfileInfoCacheTest::~ProfileInfoCacheTest() { -} +bool IsEqual(const gfx::Image& image1, + const gfx::Image& image2) { + const SkBitmap& bmp1 = *image1.ToSkBitmap(); + const SkBitmap& bmp2 = *image2.ToSkBitmap(); -void ProfileInfoCacheTest::SetUp() { - ASSERT_TRUE(testing_profile_manager_.SetUp()); -} + if (bmp1.width() != bmp2.width() || + bmp1.height() != bmp2.height() || + bmp1.config() != SkBitmap::kARGB_8888_Config || + bmp2.config() != SkBitmap::kARGB_8888_Config) { + return false; + } -ProfileInfoCache* ProfileInfoCacheTest::GetCache() { - return testing_profile_manager_.profile_info_cache(); -} + SkAutoLockPixels lock1(bmp1); + SkAutoLockPixels lock2(bmp2); + if (!bmp1.getPixels() || !bmp2.getPixels()) + return false; -FilePath ProfileInfoCacheTest::GetProfilePath( - const std::string& base_name) { - return testing_profile_manager_.profile_manager()->user_data_dir(). - AppendASCII(base_name); + for (int y = 0; y < bmp1.height(); ++y) { + for (int x = 0; x < bmp1.width(); ++x) { + if (*bmp1.getAddr32(x,y) != *bmp2.getAddr32(x,y)) + return false; + } + } + + return true; } -void ProfileInfoCacheTest::ResetCache() { - testing_profile_manager_.DeleteProfileInfoCache(); +gfx::Image CreateTestImage() { + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 50); + bitmap.allocPixels(); + bitmap.eraseRGB(0xff, 0, 0); + return gfx::Image(new SkBitmap(bitmap)); } -namespace { +class ProfileInfoCacheUnittests : public testing::Test { + protected: + ProfileInfoCacheUnittests() + : testing_profile_manager_( + static_cast<TestingBrowserProcess*>(g_browser_process)), + ui_thread_(BrowserThread::UI, &ui_loop_), + file_thread_(BrowserThread::FILE) { + } + + virtual void SetUp() OVERRIDE { + ASSERT_TRUE(testing_profile_manager_.SetUp()); + file_thread_.Start(); + } + + virtual void TearDown() OVERRIDE { + // Process all tasks on the FILE thread. + file_thread_.Stop(); + // The FILE thread might post tasks back to the UI thread so drain the UI + // thread too. + ui_loop_.RunAllPending(); + } -TEST_F(ProfileInfoCacheTest, AddProfiles) { + 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) { +#if defined(OS_POSIX) + return FilePath(string_path); +#elif defined(OS_WIN) + return FilePath(ASCIIToWide(string_path)); +#endif + } + + void ResetCache() { + testing_profile_manager_.DeleteProfileInfoCache(); + } + + private: + MessageLoopForUI ui_loop_; + TestingProfileManager testing_profile_manager_; + content::TestBrowserThread ui_thread_; + content::TestBrowserThread file_thread_; +}; + +TEST_F(ProfileInfoCacheUnittests, AddProfiles) { EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); for (uint32 i = 0; i < 4; ++i) { - FilePath profile_path = GetProfilePath(StringPrintf("path_%ud", i)); + std::string base_name = StringPrintf("path_%ud", i); + FilePath profile_path = + GetUserDataDir().Append(StringToFilePath(base_name)); string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i)); const SkBitmap& icon = ResourceBundle::GetSharedInstance().GetImageNamed( ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(i)); @@ -79,7 +138,9 @@ TEST_F(ProfileInfoCacheTest, AddProfiles) { EXPECT_EQ(4u, GetCache()->GetNumberOfProfiles()); for (uint32 i = 0; i < 4; ++i) { - FilePath profile_path = GetProfilePath(StringPrintf("path_%ud", i)); + std::string base_name = StringPrintf("path_%ud", i); + FilePath profile_path = + GetUserDataDir().Append(StringToFilePath(base_name)); EXPECT_EQ(i, GetCache()->GetIndexOfProfileWithPath(profile_path)); string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i)); EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); @@ -90,15 +151,15 @@ TEST_F(ProfileInfoCacheTest, AddProfiles) { } } -TEST_F(ProfileInfoCacheTest, DeleteProfile) { +TEST_F(ProfileInfoCacheUnittests, DeleteProfile) { EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); - FilePath path_1 = GetProfilePath("path_1"); + FilePath path_1 = GetUserDataDir().Append(StringToFilePath("path_1")); GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), string16(), 0); EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); - FilePath path_2 = GetProfilePath("path_2"); + FilePath path_2 = GetUserDataDir().Append(StringToFilePath("path_2")); string16 name_2 = ASCIIToUTF16("name_2"); GetCache()->AddProfileToCache(path_2, name_2, string16(), 0); EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles()); @@ -111,11 +172,11 @@ TEST_F(ProfileInfoCacheTest, DeleteProfile) { EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); } -TEST_F(ProfileInfoCacheTest, MutateProfile) { - GetCache()->AddProfileToCache( - GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); - GetCache()->AddProfileToCache( - GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0); +TEST_F(ProfileInfoCacheUnittests, MutateProfile) { + GetCache()->AddProfileToCache(GetUserDataDir().Append( + StringToFilePath("path_1")), ASCIIToUTF16("name_1"), string16(), 0); + GetCache()->AddProfileToCache(GetUserDataDir().Append( + StringToFilePath("path_2")), ASCIIToUTF16("name_2"), string16(), 0); string16 new_name = ASCIIToUTF16("new_name"); GetCache()->SetNameOfProfileAtIndex(1, new_name); @@ -133,14 +194,14 @@ TEST_F(ProfileInfoCacheTest, MutateProfile) { GetCache()->GetAvatarIconOfProfileAtIndex(1); } -TEST_F(ProfileInfoCacheTest, Sort) { +TEST_F(ProfileInfoCacheUnittests, Sort) { string16 name_a = ASCIIToUTF16("apple"); - GetCache()->AddProfileToCache( - GetProfilePath("path_a"), name_a, string16(), 0); + GetCache()->AddProfileToCache(GetUserDataDir().Append( + StringToFilePath("path_a")), name_a, string16(), 0); string16 name_c = ASCIIToUTF16("cat"); - GetCache()->AddProfileToCache( - GetProfilePath("path_c"), name_c, string16(), 0); + GetCache()->AddProfileToCache(GetUserDataDir().Append( + StringToFilePath("path_c")), name_c, string16(), 0); // Sanity check the initial order. EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); @@ -148,8 +209,8 @@ TEST_F(ProfileInfoCacheTest, Sort) { // Add a new profile (start with a capital to test case insensitive sorting. string16 name_b = ASCIIToUTF16("Banana"); - GetCache()->AddProfileToCache( - GetProfilePath("path_b"), name_b, string16(), 0); + GetCache()->AddProfileToCache(GetUserDataDir().Append( + StringToFilePath("path_b")), name_b, string16(), 0); // Verify the new order. EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); @@ -166,18 +227,21 @@ TEST_F(ProfileInfoCacheTest, Sort) { EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(2)); // Delete a profile. - GetCache()->DeleteProfileFromCache(GetProfilePath("path_c")); + GetCache()->DeleteProfileFromCache(GetUserDataDir().Append( + StringToFilePath("path_c"))); // Verify the new order. EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0)); EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(1)); } -TEST_F(ProfileInfoCacheTest, BackgroundModeStatus) { +TEST_F(ProfileInfoCacheUnittests, BackgroundModeStatus) { GetCache()->AddProfileToCache( - GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); + GetUserDataDir().Append(StringToFilePath("path_1")), + ASCIIToUTF16("name_1"), string16(), 0); GetCache()->AddProfileToCache( - GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0); + GetUserDataDir().Append(StringToFilePath("path_2")), + ASCIIToUTF16("name_2"), string16(), 0); EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); @@ -198,11 +262,13 @@ TEST_F(ProfileInfoCacheTest, BackgroundModeStatus) { EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); } -TEST_F(ProfileInfoCacheTest, HasMigrated) { +TEST_F(ProfileInfoCacheUnittests, HasMigrated) { GetCache()->AddProfileToCache( - GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); + GetUserDataDir().Append(StringToFilePath("path_1")), + ASCIIToUTF16("name_1"), string16(), 0); GetCache()->AddProfileToCache( - GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0); + GetUserDataDir().Append(StringToFilePath("path_2")), + ASCIIToUTF16("name_2"), string16(), 0); // Sanity check. EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); @@ -224,12 +290,14 @@ TEST_F(ProfileInfoCacheTest, HasMigrated) { EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); } -TEST_F(ProfileInfoCacheTest, GAIAName) { +TEST_F(ProfileInfoCacheUnittests, GAIAName) { GetCache()->AddProfileToCache( - GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); + GetUserDataDir().Append(StringToFilePath("path_1")), + ASCIIToUTF16("name_1"), string16(), 0); string16 profile_name(ASCIIToUTF16("profile name 2")); GetCache()->AddProfileToCache( - GetProfilePath("path_2"), profile_name, string16(), 0); + GetUserDataDir().Append(StringToFilePath("path_2")), + profile_name, string16(), 0); // Sanity check. EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); @@ -256,11 +324,13 @@ TEST_F(ProfileInfoCacheTest, GAIAName) { EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); } -TEST_F(ProfileInfoCacheTest, GAIAPicture) { +TEST_F(ProfileInfoCacheUnittests, GAIAPicture) { GetCache()->AddProfileToCache( - GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); + GetUserDataDir().Append(StringToFilePath("path_1")), + ASCIIToUTF16("name_1"), string16(), 0); GetCache()->AddProfileToCache( - GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0); + GetUserDataDir().Append(StringToFilePath("path_2")), + ASCIIToUTF16("name_2"), string16(), 0); // Sanity check. EXPECT_TRUE( @@ -274,31 +344,31 @@ TEST_F(ProfileInfoCacheTest, GAIAPicture) { int id = ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(0); const gfx::Image& profile_image( ResourceBundle::GetSharedInstance().GetImageNamed(id)); - EXPECT_TRUE(gfx::test::IsEqual( + EXPECT_TRUE(IsEqual( profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); // Set GAIA picture. - gfx::Image gaia_image(gfx::test::CreateImage()); + gfx::Image gaia_image(CreateTestImage()); GetCache()->SetGAIAPictureOfProfileAtIndex(1, gaia_image); EXPECT_TRUE( GetCache()->GetGAIAPictureOfProfileAtIndex(0).ToSkBitmap()->isNull()); - EXPECT_TRUE(gfx::test::IsEqual( + EXPECT_TRUE(IsEqual( gaia_image, GetCache()->GetGAIAPictureOfProfileAtIndex(1))); - EXPECT_TRUE(gfx::test::IsEqual( + EXPECT_TRUE(IsEqual( profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); // Use GAIA picture as profile picture. GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, true); - EXPECT_TRUE(gfx::test::IsEqual( + EXPECT_TRUE(IsEqual( gaia_image, GetCache()->GetGAIAPictureOfProfileAtIndex(1))); - EXPECT_TRUE(gfx::test::IsEqual( + EXPECT_TRUE(IsEqual( gaia_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); // Don't use GAIA picture as profile picture. GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, false); - EXPECT_TRUE(gfx::test::IsEqual( + EXPECT_TRUE(IsEqual( gaia_image, GetCache()->GetGAIAPictureOfProfileAtIndex(1))); - EXPECT_TRUE(gfx::test::IsEqual( + EXPECT_TRUE(IsEqual( profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); } @@ -308,16 +378,17 @@ TEST_F(ProfileInfoCacheTest, GAIAPicture) { #define MAYBE_PersistGAIAPicture PersistGAIAPicture #endif -TEST_F(ProfileInfoCacheTest, MAYBE_PersistGAIAPicture) { +TEST_F(ProfileInfoCacheUnittests, MAYBE_PersistGAIAPicture) { GetCache()->AddProfileToCache( - GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); - gfx::Image gaia_image(gfx::test::CreateImage()); + GetUserDataDir().Append(StringToFilePath("path_1")), + ASCIIToUTF16("name_1"), string16(), 0); + gfx::Image gaia_image(CreateTestImage()); ui_test_utils::WindowedNotificationObserver save_observer( chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED, content::NotificationService::AllSources()); GetCache()->SetGAIAPictureOfProfileAtIndex(0, gaia_image); - EXPECT_TRUE(gfx::test::IsEqual( + EXPECT_TRUE(IsEqual( gaia_image, GetCache()->GetGAIAPictureOfProfileAtIndex(0))); // Wait for the file to be written to disk then reset the cache. @@ -332,7 +403,7 @@ TEST_F(ProfileInfoCacheTest, MAYBE_PersistGAIAPicture) { EXPECT_TRUE( GetCache()->GetGAIAPictureOfProfileAtIndex(0).ToSkBitmap()->isNull()); read_observer.Wait(); - EXPECT_TRUE(gfx::test::IsEqual( + EXPECT_TRUE(IsEqual( gaia_image, GetCache()->GetGAIAPictureOfProfileAtIndex(0))); } diff --git a/chrome/browser/profiles/profile_info_cache_unittest.h b/chrome/browser/profiles/profile_info_cache_unittest.h deleted file mode 100644 index a1d4485..0000000 --- a/chrome/browser/profiles/profile_info_cache_unittest.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_UNITTEST_H_ -#define CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_UNITTEST_H_ -#pragma once - -#include "chrome/test/base/testing_profile_manager.h" -#include "content/test/test_browser_thread.h" -#include "testing/gtest/include/gtest/gtest.h" - -class FilePath; -class ProfileInfoCache; - -class ProfileInfoCacheTest : public testing::Test { - protected: - ProfileInfoCacheTest(); - virtual ~ProfileInfoCacheTest(); - - virtual void SetUp() OVERRIDE; - - ProfileInfoCache* GetCache(); - FilePath GetProfilePath(const std::string& base_name); - void ResetCache(); - - protected: - TestingProfileManager testing_profile_manager_; - - private: - MessageLoopForUI ui_loop_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread file_thread_; -}; - -#endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_UNITTEST_H_ |