Chromium Code Reviews| Index: chrome/browser/profiles/gaia_info_update_service_unittest.cc |
| diff --git a/chrome/browser/profiles/gaia_info_update_service_unittest.cc b/chrome/browser/profiles/gaia_info_update_service_unittest.cc |
| index 1eacf5b3e089bc3be8a1ea55048b8b790e50048f..fc002e2eff9640f9b0b11f639d8e78d63aa8d199 100644 |
| --- a/chrome/browser/profiles/gaia_info_update_service_unittest.cc |
| +++ b/chrome/browser/profiles/gaia_info_update_service_unittest.cc |
| @@ -10,6 +10,7 @@ |
| #include "chrome/browser/profiles/profile_downloader.h" |
| #include "chrome/browser/profiles/profile_info_cache.h" |
| #include "chrome/browser/profiles/profile_info_cache_unittest.h" |
| +#include "chrome/browser/signin/signin_manager_factory.h" |
| #include "chrome/common/pref_names.h" |
| #include "chrome/test/base/testing_browser_process.h" |
| #include "chrome/test/base/testing_profile.h" |
| @@ -76,32 +77,37 @@ class GAIAInfoUpdateServiceTest : public ProfileInfoCacheTest { |
| TEST_F(GAIAInfoUpdateServiceTest, DownloadSuccess) { |
| GAIAInfoUpdateService service(profile()); |
| - NiceMock<ProfileDownloaderMock> downloader(&service); |
| - |
| - base::string16 name = base::ASCIIToUTF16("Pat Smith"); |
| - EXPECT_CALL(downloader, GetProfileFullName()).WillOnce(Return(name)); |
| - gfx::Image image = gfx::test::CreateImage(); |
| - const SkBitmap* bmp = image.ToSkBitmap(); |
| - EXPECT_CALL(downloader, GetProfilePicture()).WillOnce(Return(*bmp)); |
| - EXPECT_CALL(downloader, GetProfilePictureStatus()). |
| - WillOnce(Return(ProfileDownloader::PICTURE_SUCCESS)); |
| - std::string url("foo.com"); |
| - EXPECT_CALL(downloader, GetProfilePictureURL()).WillOnce(Return(url)); |
| - |
| - // No URL should be cached yet. |
| - EXPECT_EQ(std::string(), service.GetCachedPictureURL()); |
| - service.OnProfileDownloadSuccess(&downloader); |
| + { |
|
noms (inactive)
2014/03/24 13:35:25
Can you add a comment as to why we need to put th
Roger Tawa OOO till Jul 10th
2014/03/24 17:49:30
Removed with change below.
|
| + NiceMock<ProfileDownloaderMock> downloader(&service); |
| + |
| + base::string16 name = base::ASCIIToUTF16("Pat Smith"); |
| + EXPECT_CALL(downloader, GetProfileFullName()).WillOnce(Return(name)); |
| + gfx::Image image = gfx::test::CreateImage(); |
| + const SkBitmap* bmp = image.ToSkBitmap(); |
| + EXPECT_CALL(downloader, GetProfilePicture()).WillOnce(Return(*bmp)); |
| + EXPECT_CALL(downloader, GetProfilePictureStatus()). |
| + WillOnce(Return(ProfileDownloader::PICTURE_SUCCESS)); |
| + std::string url("foo.com"); |
| + EXPECT_CALL(downloader, GetProfilePictureURL()).WillOnce(Return(url)); |
| + |
| + // No URL should be cached yet. |
| + EXPECT_EQ(std::string(), service.GetCachedPictureURL()); |
| + |
| + service.OnProfileDownloadSuccess(&downloader); |
| + |
| + // On success both the profile info and GAIA info should be updated. |
| + size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); |
| + 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))); |
| + EXPECT_EQ(url, service.GetCachedPictureURL()); |
| + } |
| - // On success both the profile info and GAIA info should be updated. |
| - size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); |
| - 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))); |
| - EXPECT_EQ(url, service.GetCachedPictureURL()); |
| + service.Shutdown(); |
|
noms (inactive)
2014/03/24 13:35:25
Do all the tests have to call GAIAInfoUpdateServic
Roger Tawa OOO till Jul 10th
2014/03/24 17:49:30
Not all tests use a GAIAInfoUpdateService, so its
|
| } |
| TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) { |
| @@ -111,18 +117,23 @@ TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) { |
| GAIAInfoUpdateService service(profile()); |
| EXPECT_EQ(std::string(), service.GetCachedPictureURL()); |
| - NiceMock<ProfileDownloaderMock> downloader(&service); |
| - service.OnProfileDownloadFailure(&downloader, |
| - ProfileDownloaderDelegate::SERVICE_ERROR); |
| + { |
| + NiceMock<ProfileDownloaderMock> downloader(&service); |
| - // On failure nothing should be updated. |
| - EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); |
| - EXPECT_EQ(base::string16(), GetCache()->GetGAIANameOfProfileAtIndex(index)); |
| - EXPECT_TRUE(gfx::test::IsEqual( |
| - old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); |
| - EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(index)); |
| - EXPECT_EQ(std::string(), service.GetCachedPictureURL()); |
| + service.OnProfileDownloadFailure(&downloader, |
| + ProfileDownloaderDelegate::SERVICE_ERROR); |
| + |
| + // On failure nothing should be updated. |
| + EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); |
| + EXPECT_EQ(base::string16(), GetCache()->GetGAIANameOfProfileAtIndex(index)); |
| + EXPECT_TRUE(gfx::test::IsEqual( |
| + old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); |
| + EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(index)); |
| + EXPECT_EQ(std::string(), service.GetCachedPictureURL()); |
| + } |
| + |
| + service.Shutdown(); |
| } |
| TEST_F(GAIAInfoUpdateServiceTest, ShouldUseGAIAProfileInfo) { |
| @@ -139,11 +150,16 @@ TEST_F(GAIAInfoUpdateServiceTest, ScheduleUpdate) { |
| EXPECT_FALSE(service.timer_.IsRunning()); |
| service.ScheduleNextUpdate(); |
| EXPECT_TRUE(service.timer_.IsRunning()); |
| + |
| + service.Shutdown(); |
| } |
| +#if !defined(OS_CHROMEOS) |
| + |
| TEST_F(GAIAInfoUpdateServiceTest, LogOut) { |
| - profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
| - "pat@example.com"); |
| + SigninManager* signin_manager = |
| + SigninManagerFactory::GetForProfile(profile()); |
| + signin_manager->SetAuthenticatedUsername("pat@example.com"); |
| base::string16 gaia_name = base::UTF8ToUTF16("Pat Foo"); |
| GetCache()->SetGAIANameOfProfileAtIndex(0, gaia_name); |
| gfx::Image gaia_picture = gfx::test::CreateImage(); |
| @@ -155,23 +171,27 @@ TEST_F(GAIAInfoUpdateServiceTest, LogOut) { |
| GAIAInfoUpdateService service(profile()); |
| EXPECT_FALSE(service.GetCachedPictureURL().empty()); |
| - // Log out. |
| - profile()->GetPrefs() |
| - ->SetString(prefs::kGoogleServicesUsername, std::string()); |
| + // Log out. |
| + signin_manager->SignOut(); |
| // Verify that the GAIA name and picture, and picture URL are unset. |
| EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); |
| EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
| EXPECT_TRUE(service.GetCachedPictureURL().empty()); |
| + |
| + service.Shutdown(); |
| } |
| TEST_F(GAIAInfoUpdateServiceTest, LogIn) { |
| - profile()->GetPrefs() |
| - ->SetString(prefs::kGoogleServicesUsername, std::string()); |
| GAIAInfoUpdateServiceMock service(profile()); |
| // Log in. |
| EXPECT_CALL(service, Update()); |
| - profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
| - "pat@example.com"); |
| + SigninManager* signin_manager = |
| + SigninManagerFactory::GetForProfile(profile()); |
| + signin_manager->OnExternalSigninCompleted("pat@example.com"); |
| + |
| + service.Shutdown(); |
| } |
| + |
| +#endif |