Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/profiles/gaia_info_update_service.h" | 5 #include "chrome/browser/profiles/gaia_info_update_service.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/profiles/profile_downloader.h" | 10 #include "chrome/browser/profiles/profile_downloader.h" |
| 11 #include "chrome/browser/profiles/profile_info_cache.h" | 11 #include "chrome/browser/profiles/profile_info_cache.h" |
| 12 #include "chrome/browser/profiles/profile_info_cache_unittest.h" | 12 #include "chrome/browser/profiles/profile_info_cache_unittest.h" |
| 13 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
| 15 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 16 #include "chrome/test/base/testing_profile_manager.h" | 17 #include "chrome/test/base/testing_profile_manager.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
| 19 #include "ui/gfx/image/image_unittest_util.h" | 20 #include "ui/gfx/image/image_unittest_util.h" |
| 20 | 21 |
| 21 using ::testing::Return; | 22 using ::testing::Return; |
| 22 using ::testing::NiceMock; | 23 using ::testing::NiceMock; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 } | 70 } |
| 70 | 71 |
| 71 private: | 72 private: |
| 72 Profile* profile_; | 73 Profile* profile_; |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 } // namespace | 76 } // namespace |
| 76 | 77 |
| 77 TEST_F(GAIAInfoUpdateServiceTest, DownloadSuccess) { | 78 TEST_F(GAIAInfoUpdateServiceTest, DownloadSuccess) { |
| 78 GAIAInfoUpdateService service(profile()); | 79 GAIAInfoUpdateService service(profile()); |
| 79 NiceMock<ProfileDownloaderMock> downloader(&service); | |
| 80 | 80 |
| 81 base::string16 name = base::ASCIIToUTF16("Pat Smith"); | 81 { |
|
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.
| |
| 82 EXPECT_CALL(downloader, GetProfileFullName()).WillOnce(Return(name)); | 82 NiceMock<ProfileDownloaderMock> downloader(&service); |
| 83 gfx::Image image = gfx::test::CreateImage(); | |
| 84 const SkBitmap* bmp = image.ToSkBitmap(); | |
| 85 EXPECT_CALL(downloader, GetProfilePicture()).WillOnce(Return(*bmp)); | |
| 86 EXPECT_CALL(downloader, GetProfilePictureStatus()). | |
| 87 WillOnce(Return(ProfileDownloader::PICTURE_SUCCESS)); | |
| 88 std::string url("foo.com"); | |
| 89 EXPECT_CALL(downloader, GetProfilePictureURL()).WillOnce(Return(url)); | |
| 90 | 83 |
| 91 // No URL should be cached yet. | 84 base::string16 name = base::ASCIIToUTF16("Pat Smith"); |
| 92 EXPECT_EQ(std::string(), service.GetCachedPictureURL()); | 85 EXPECT_CALL(downloader, GetProfileFullName()).WillOnce(Return(name)); |
| 86 gfx::Image image = gfx::test::CreateImage(); | |
| 87 const SkBitmap* bmp = image.ToSkBitmap(); | |
| 88 EXPECT_CALL(downloader, GetProfilePicture()).WillOnce(Return(*bmp)); | |
| 89 EXPECT_CALL(downloader, GetProfilePictureStatus()). | |
| 90 WillOnce(Return(ProfileDownloader::PICTURE_SUCCESS)); | |
| 91 std::string url("foo.com"); | |
| 92 EXPECT_CALL(downloader, GetProfilePictureURL()).WillOnce(Return(url)); | |
| 93 | 93 |
| 94 service.OnProfileDownloadSuccess(&downloader); | 94 // No URL should be cached yet. |
| 95 EXPECT_EQ(std::string(), service.GetCachedPictureURL()); | |
| 95 | 96 |
| 96 // On success both the profile info and GAIA info should be updated. | 97 service.OnProfileDownloadSuccess(&downloader); |
| 97 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); | 98 |
| 98 EXPECT_EQ(name, GetCache()->GetNameOfProfileAtIndex(index)); | 99 // On success both the profile info and GAIA info should be updated. |
| 99 EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index)); | 100 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); |
| 100 EXPECT_TRUE(gfx::test::IsEqual( | 101 EXPECT_EQ(name, GetCache()->GetNameOfProfileAtIndex(index)); |
| 101 image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); | 102 EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index)); |
| 102 EXPECT_TRUE(gfx::test::IsEqual( | 103 EXPECT_TRUE(gfx::test::IsEqual( |
| 103 image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index))); | 104 image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); |
| 104 EXPECT_EQ(url, service.GetCachedPictureURL()); | 105 EXPECT_TRUE(gfx::test::IsEqual( |
| 106 image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index))); | |
| 107 EXPECT_EQ(url, service.GetCachedPictureURL()); | |
| 108 } | |
| 109 | |
| 110 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
| |
| 105 } | 111 } |
| 106 | 112 |
| 107 TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) { | 113 TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) { |
| 108 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); | 114 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); |
| 109 base::string16 old_name = GetCache()->GetNameOfProfileAtIndex(index); | 115 base::string16 old_name = GetCache()->GetNameOfProfileAtIndex(index); |
| 110 gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index); | 116 gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index); |
| 111 | 117 |
| 112 GAIAInfoUpdateService service(profile()); | 118 GAIAInfoUpdateService service(profile()); |
| 113 EXPECT_EQ(std::string(), service.GetCachedPictureURL()); | 119 EXPECT_EQ(std::string(), service.GetCachedPictureURL()); |
| 114 NiceMock<ProfileDownloaderMock> downloader(&service); | |
| 115 | 120 |
| 116 service.OnProfileDownloadFailure(&downloader, | 121 { |
| 117 ProfileDownloaderDelegate::SERVICE_ERROR); | 122 NiceMock<ProfileDownloaderMock> downloader(&service); |
| 118 | 123 |
| 119 // On failure nothing should be updated. | 124 service.OnProfileDownloadFailure(&downloader, |
| 120 EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); | 125 ProfileDownloaderDelegate::SERVICE_ERROR); |
| 121 EXPECT_EQ(base::string16(), GetCache()->GetGAIANameOfProfileAtIndex(index)); | 126 |
| 122 EXPECT_TRUE(gfx::test::IsEqual( | 127 // On failure nothing should be updated. |
| 123 old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); | 128 EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); |
| 124 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(index)); | 129 EXPECT_EQ(base::string16(), GetCache()->GetGAIANameOfProfileAtIndex(index)); |
| 125 EXPECT_EQ(std::string(), service.GetCachedPictureURL()); | 130 EXPECT_TRUE(gfx::test::IsEqual( |
| 131 old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); | |
| 132 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(index)); | |
| 133 EXPECT_EQ(std::string(), service.GetCachedPictureURL()); | |
| 134 } | |
| 135 | |
| 136 service.Shutdown(); | |
| 126 } | 137 } |
| 127 | 138 |
| 128 TEST_F(GAIAInfoUpdateServiceTest, ShouldUseGAIAProfileInfo) { | 139 TEST_F(GAIAInfoUpdateServiceTest, ShouldUseGAIAProfileInfo) { |
| 129 #if defined(OS_CHROMEOS) | 140 #if defined(OS_CHROMEOS) |
| 130 // This feature should never be enabled on ChromeOS. | 141 // This feature should never be enabled on ChromeOS. |
| 131 EXPECT_FALSE(GAIAInfoUpdateService::ShouldUseGAIAProfileInfo(profile())); | 142 EXPECT_FALSE(GAIAInfoUpdateService::ShouldUseGAIAProfileInfo(profile())); |
| 132 #endif | 143 #endif |
| 133 } | 144 } |
| 134 | 145 |
| 135 TEST_F(GAIAInfoUpdateServiceTest, ScheduleUpdate) { | 146 TEST_F(GAIAInfoUpdateServiceTest, ScheduleUpdate) { |
| 136 GAIAInfoUpdateService service(profile()); | 147 GAIAInfoUpdateService service(profile()); |
| 137 EXPECT_TRUE(service.timer_.IsRunning()); | 148 EXPECT_TRUE(service.timer_.IsRunning()); |
| 138 service.timer_.Stop(); | 149 service.timer_.Stop(); |
| 139 EXPECT_FALSE(service.timer_.IsRunning()); | 150 EXPECT_FALSE(service.timer_.IsRunning()); |
| 140 service.ScheduleNextUpdate(); | 151 service.ScheduleNextUpdate(); |
| 141 EXPECT_TRUE(service.timer_.IsRunning()); | 152 EXPECT_TRUE(service.timer_.IsRunning()); |
| 153 | |
| 154 service.Shutdown(); | |
| 142 } | 155 } |
| 143 | 156 |
| 157 #if !defined(OS_CHROMEOS) | |
| 158 | |
| 144 TEST_F(GAIAInfoUpdateServiceTest, LogOut) { | 159 TEST_F(GAIAInfoUpdateServiceTest, LogOut) { |
| 145 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 160 SigninManager* signin_manager = |
| 146 "pat@example.com"); | 161 SigninManagerFactory::GetForProfile(profile()); |
| 162 signin_manager->SetAuthenticatedUsername("pat@example.com"); | |
| 147 base::string16 gaia_name = base::UTF8ToUTF16("Pat Foo"); | 163 base::string16 gaia_name = base::UTF8ToUTF16("Pat Foo"); |
| 148 GetCache()->SetGAIANameOfProfileAtIndex(0, gaia_name); | 164 GetCache()->SetGAIANameOfProfileAtIndex(0, gaia_name); |
| 149 gfx::Image gaia_picture = gfx::test::CreateImage(); | 165 gfx::Image gaia_picture = gfx::test::CreateImage(); |
| 150 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_picture); | 166 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_picture); |
| 151 | 167 |
| 152 // Set a fake picture URL. | 168 // Set a fake picture URL. |
| 153 profile()->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL, | 169 profile()->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL, |
| 154 "example.com"); | 170 "example.com"); |
| 155 | 171 |
| 156 GAIAInfoUpdateService service(profile()); | 172 GAIAInfoUpdateService service(profile()); |
| 157 EXPECT_FALSE(service.GetCachedPictureURL().empty()); | 173 EXPECT_FALSE(service.GetCachedPictureURL().empty()); |
| 174 | |
| 158 // Log out. | 175 // Log out. |
| 159 profile()->GetPrefs() | 176 signin_manager->SignOut(); |
| 160 ->SetString(prefs::kGoogleServicesUsername, std::string()); | |
| 161 | |
| 162 // Verify that the GAIA name and picture, and picture URL are unset. | 177 // Verify that the GAIA name and picture, and picture URL are unset. |
| 163 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); | 178 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); |
| 164 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); | 179 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
| 165 EXPECT_TRUE(service.GetCachedPictureURL().empty()); | 180 EXPECT_TRUE(service.GetCachedPictureURL().empty()); |
| 181 | |
| 182 service.Shutdown(); | |
| 166 } | 183 } |
| 167 | 184 |
| 168 TEST_F(GAIAInfoUpdateServiceTest, LogIn) { | 185 TEST_F(GAIAInfoUpdateServiceTest, LogIn) { |
| 169 profile()->GetPrefs() | |
| 170 ->SetString(prefs::kGoogleServicesUsername, std::string()); | |
| 171 GAIAInfoUpdateServiceMock service(profile()); | 186 GAIAInfoUpdateServiceMock service(profile()); |
| 172 | 187 |
| 173 // Log in. | 188 // Log in. |
| 174 EXPECT_CALL(service, Update()); | 189 EXPECT_CALL(service, Update()); |
| 175 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 190 SigninManager* signin_manager = |
| 176 "pat@example.com"); | 191 SigninManagerFactory::GetForProfile(profile()); |
| 192 signin_manager->OnExternalSigninCompleted("pat@example.com"); | |
| 193 | |
| 194 service.Shutdown(); | |
| 177 } | 195 } |
| 196 | |
| 197 #endif | |
| OLD | NEW |