| 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/prefs/pref_service_syncable.h" | 10 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 11 #include "chrome/browser/profiles/profile_downloader.h" | 11 #include "chrome/browser/profiles/profile_downloader.h" |
| 12 #include "chrome/browser/profiles/profile_info_cache.h" | 12 #include "chrome/browser/profiles/profile_info_cache.h" |
| 13 #include "chrome/browser/profiles/profile_info_cache_unittest.h" | 13 #include "chrome/browser/profiles/profile_info_cache_unittest.h" |
| 14 #include "chrome/browser/profiles/profiles_state.h" |
| 14 #include "chrome/browser/signin/chrome_signin_client_factory.h" | 15 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
| 15 #include "chrome/browser/signin/signin_manager_factory.h" | 16 #include "chrome/browser/signin/signin_manager_factory.h" |
| 16 #include "chrome/browser/signin/test_signin_client_builder.h" | 17 #include "chrome/browser/signin/test_signin_client_builder.h" |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/test/base/testing_browser_process.h" | 19 #include "chrome/test/base/testing_browser_process.h" |
| 19 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
| 20 #include "chrome/test/base/testing_profile_manager.h" | 21 #include "chrome/test/base/testing_profile_manager.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "ui/gfx/image/image.h" | 23 #include "ui/gfx/image/image.h" |
| 23 #include "ui/gfx/image/image_unittest_util.h" | 24 #include "ui/gfx/image/image_unittest_util.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 35 | 36 |
| 36 virtual ~ProfileDownloaderMock() { | 37 virtual ~ProfileDownloaderMock() { |
| 37 } | 38 } |
| 38 | 39 |
| 39 MOCK_CONST_METHOD0(GetProfileFullName, base::string16()); | 40 MOCK_CONST_METHOD0(GetProfileFullName, base::string16()); |
| 40 MOCK_CONST_METHOD0(GetProfileGivenName, base::string16()); | 41 MOCK_CONST_METHOD0(GetProfileGivenName, base::string16()); |
| 41 MOCK_CONST_METHOD0(GetProfilePicture, SkBitmap()); | 42 MOCK_CONST_METHOD0(GetProfilePicture, SkBitmap()); |
| 42 MOCK_CONST_METHOD0(GetProfilePictureStatus, | 43 MOCK_CONST_METHOD0(GetProfilePictureStatus, |
| 43 ProfileDownloader::PictureStatus()); | 44 ProfileDownloader::PictureStatus()); |
| 44 MOCK_CONST_METHOD0(GetProfilePictureURL, std::string()); | 45 MOCK_CONST_METHOD0(GetProfilePictureURL, std::string()); |
| 46 MOCK_CONST_METHOD0(GetProfileHostedDomain, base::string16()); |
| 45 }; | 47 }; |
| 46 | 48 |
| 47 class GAIAInfoUpdateServiceMock : public GAIAInfoUpdateService { | 49 class GAIAInfoUpdateServiceMock : public GAIAInfoUpdateService { |
| 48 public: | 50 public: |
| 49 explicit GAIAInfoUpdateServiceMock(Profile* profile) | 51 explicit GAIAInfoUpdateServiceMock(Profile* profile) |
| 50 : GAIAInfoUpdateService(profile) { | 52 : GAIAInfoUpdateService(profile) { |
| 51 } | 53 } |
| 52 | 54 |
| 53 virtual ~GAIAInfoUpdateServiceMock() { | 55 virtual ~GAIAInfoUpdateServiceMock() { |
| 54 } | 56 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 return base::UTF8ToUTF16(GivenName(id)); | 98 return base::UTF8ToUTF16(GivenName(id)); |
| 97 } | 99 } |
| 98 static base::string16 FullName16(const std::string& id) { | 100 static base::string16 FullName16(const std::string& id) { |
| 99 return base::UTF8ToUTF16(FullName(id)); | 101 return base::UTF8ToUTF16(FullName(id)); |
| 100 } | 102 } |
| 101 | 103 |
| 102 void ProfileDownloadSuccess( | 104 void ProfileDownloadSuccess( |
| 103 const base::string16& full_name, | 105 const base::string16& full_name, |
| 104 const base::string16& given_name, | 106 const base::string16& given_name, |
| 105 const gfx::Image& image, | 107 const gfx::Image& image, |
| 106 const std::string& url) { | 108 const std::string& url, |
| 109 const base::string16& hosted_domain) { |
| 107 EXPECT_CALL(*downloader(), GetProfileFullName()). | 110 EXPECT_CALL(*downloader(), GetProfileFullName()). |
| 108 WillOnce(Return(full_name)); | 111 WillOnce(Return(full_name)); |
| 109 EXPECT_CALL(*downloader(), GetProfileGivenName()). | 112 EXPECT_CALL(*downloader(), GetProfileGivenName()). |
| 110 WillOnce(Return(given_name)); | 113 WillOnce(Return(given_name)); |
| 111 const SkBitmap* bmp = image.ToSkBitmap(); | 114 const SkBitmap* bmp = image.ToSkBitmap(); |
| 112 EXPECT_CALL(*downloader(), GetProfilePicture()).WillOnce(Return(*bmp)); | 115 EXPECT_CALL(*downloader(), GetProfilePicture()).WillOnce(Return(*bmp)); |
| 113 EXPECT_CALL(*downloader(), GetProfilePictureStatus()). | 116 EXPECT_CALL(*downloader(), GetProfilePictureStatus()). |
| 114 WillOnce(Return(ProfileDownloader::PICTURE_SUCCESS)); | 117 WillOnce(Return(ProfileDownloader::PICTURE_SUCCESS)); |
| 115 EXPECT_CALL(*downloader(), GetProfilePictureURL()).WillOnce(Return(url)); | 118 EXPECT_CALL(*downloader(), GetProfilePictureURL()).WillOnce(Return(url)); |
| 119 EXPECT_CALL(*downloader(), GetProfileHostedDomain()). |
| 120 WillOnce(Return(hosted_domain)); |
| 116 | 121 |
| 117 service()->OnProfileDownloadSuccess(downloader()); | 122 service()->OnProfileDownloadSuccess(downloader()); |
| 118 } | 123 } |
| 119 | 124 |
| 120 void RenameProfile(const base::string16& full_name, | 125 void RenameProfile(const base::string16& full_name, |
| 121 const base::string16& given_name) { | 126 const base::string16& given_name) { |
| 122 gfx::Image image = gfx::test::CreateImage(256,256); | 127 gfx::Image image = gfx::test::CreateImage(256,256); |
| 123 std::string url("foo.com"); | 128 std::string url("foo.com"); |
| 124 ProfileDownloadSuccess(full_name, given_name, image, url); | 129 ProfileDownloadSuccess(full_name, given_name, image, url, base::string16()); |
| 125 | 130 |
| 126 // Make sure the right profile was updated correctly. | 131 // Make sure the right profile was updated correctly. |
| 127 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); | 132 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); |
| 128 EXPECT_EQ(full_name, GetCache()->GetGAIANameOfProfileAtIndex(index)); | 133 EXPECT_EQ(full_name, GetCache()->GetGAIANameOfProfileAtIndex(index)); |
| 129 EXPECT_EQ(given_name, GetCache()->GetGAIAGivenNameOfProfileAtIndex(index)); | 134 EXPECT_EQ(given_name, GetCache()->GetGAIAGivenNameOfProfileAtIndex(index)); |
| 130 } | 135 } |
| 131 | 136 |
| 132 private: | 137 private: |
| 133 virtual void SetUp() OVERRIDE; | 138 virtual void SetUp() OVERRIDE; |
| 134 virtual void TearDown() OVERRIDE; | 139 virtual void TearDown() OVERRIDE; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 149 service_->Shutdown(); | 154 service_->Shutdown(); |
| 150 service_.reset(); | 155 service_.reset(); |
| 151 ProfileInfoCacheTest::TearDown(); | 156 ProfileInfoCacheTest::TearDown(); |
| 152 } | 157 } |
| 153 | 158 |
| 154 } // namespace | 159 } // namespace |
| 155 | 160 |
| 156 TEST_F(GAIAInfoUpdateServiceTest, DownloadSuccess) { | 161 TEST_F(GAIAInfoUpdateServiceTest, DownloadSuccess) { |
| 157 // No URL should be cached yet. | 162 // No URL should be cached yet. |
| 158 EXPECT_EQ(std::string(), service()->GetCachedPictureURL()); | 163 EXPECT_EQ(std::string(), service()->GetCachedPictureURL()); |
| 164 EXPECT_EQ(std::string(), profile()->GetPrefs()-> |
| 165 GetString(prefs::kProfileHostedDomain)); |
| 159 | 166 |
| 160 base::string16 name = base::ASCIIToUTF16("Pat Smith"); | 167 base::string16 name = base::ASCIIToUTF16("Pat Smith"); |
| 161 base::string16 given_name = base::ASCIIToUTF16("Pat"); | 168 base::string16 given_name = base::ASCIIToUTF16("Pat"); |
| 162 gfx::Image image = gfx::test::CreateImage(256, 256); | 169 gfx::Image image = gfx::test::CreateImage(256, 256); |
| 163 std::string url("foo.com"); | 170 std::string url("foo.com"); |
| 164 ProfileDownloadSuccess(name, given_name, image, url); | 171 base::string16 hosted_domain(base::ASCIIToUTF16("")); |
| 172 ProfileDownloadSuccess(name, given_name, image, url, hosted_domain); |
| 165 | 173 |
| 166 // On success the GAIA info should be updated. | 174 // On success the GAIA info should be updated. |
| 167 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); | 175 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); |
| 168 EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index)); | 176 EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index)); |
| 169 EXPECT_EQ(given_name, GetCache()->GetGAIAGivenNameOfProfileAtIndex(index)); | 177 EXPECT_EQ(given_name, GetCache()->GetGAIAGivenNameOfProfileAtIndex(index)); |
| 170 EXPECT_TRUE(gfx::test::IsEqual( | 178 EXPECT_TRUE(gfx::test::IsEqual( |
| 171 image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index))); | 179 image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index))); |
| 172 EXPECT_EQ(url, service()->GetCachedPictureURL()); | 180 EXPECT_EQ(url, service()->GetCachedPictureURL()); |
| 181 EXPECT_EQ(Profile::kNoHostedDomainFound, profile()->GetPrefs()-> |
| 182 GetString(prefs::kProfileHostedDomain)); |
| 183 EXPECT_EQ(profiles::kCurrentLockAlgorithmVersion, |
| 184 profile()->GetPrefs()->GetInteger(prefs::kProfileIsLockableVersion)); |
| 173 } | 185 } |
| 174 | 186 |
| 175 TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) { | 187 TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) { |
| 176 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); | 188 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); |
| 177 base::string16 old_name = GetCache()->GetNameOfProfileAtIndex(index); | 189 base::string16 old_name = GetCache()->GetNameOfProfileAtIndex(index); |
| 178 gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index); | 190 gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index); |
| 179 | 191 |
| 180 EXPECT_EQ(std::string(), service()->GetCachedPictureURL()); | 192 EXPECT_EQ(std::string(), service()->GetCachedPictureURL()); |
| 181 | 193 |
| 182 service()->OnProfileDownloadFailure(downloader(), | 194 service()->OnProfileDownloadFailure(downloader(), |
| 183 ProfileDownloaderDelegate::SERVICE_ERROR); | 195 ProfileDownloaderDelegate::SERVICE_ERROR); |
| 184 | 196 |
| 185 // On failure nothing should be updated. | 197 // On failure nothing should be updated. |
| 186 EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); | 198 EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); |
| 187 EXPECT_EQ(base::string16(), GetCache()->GetGAIANameOfProfileAtIndex(index)); | 199 EXPECT_EQ(base::string16(), GetCache()->GetGAIANameOfProfileAtIndex(index)); |
| 188 EXPECT_EQ(base::string16(), | 200 EXPECT_EQ(base::string16(), |
| 189 GetCache()->GetGAIAGivenNameOfProfileAtIndex(index)); | 201 GetCache()->GetGAIAGivenNameOfProfileAtIndex(index)); |
| 190 EXPECT_TRUE(gfx::test::IsEqual( | 202 EXPECT_TRUE(gfx::test::IsEqual( |
| 191 old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); | 203 old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); |
| 192 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(index)); | 204 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(index)); |
| 193 EXPECT_EQ(std::string(), service()->GetCachedPictureURL()); | 205 EXPECT_EQ(std::string(), service()->GetCachedPictureURL()); |
| 206 EXPECT_EQ(std::string(), |
| 207 profile()->GetPrefs()->GetString(prefs::kProfileHostedDomain)); |
| 208 } |
| 209 |
| 210 TEST_F(GAIAInfoUpdateServiceTest, ProfileLockEnabledForWhitelist) { |
| 211 // No URL should be cached yet. |
| 212 EXPECT_EQ(std::string(), service()->GetCachedPictureURL()); |
| 213 |
| 214 base::string16 name = base::ASCIIToUTF16("Pat Smith"); |
| 215 base::string16 given_name = base::ASCIIToUTF16("Pat"); |
| 216 gfx::Image image = gfx::test::CreateImage(256, 256); |
| 217 std::string url("foo.com"); |
| 218 base::string16 hosted_domain(base::ASCIIToUTF16("google.com")); |
| 219 ProfileDownloadSuccess(name, given_name, image, url, hosted_domain); |
| 220 |
| 221 EXPECT_EQ("google.com", profile()->GetPrefs()-> |
| 222 GetString(prefs::kProfileHostedDomain)); |
| 223 EXPECT_EQ(profiles::kCurrentLockAlgorithmVersion, |
| 224 profile()->GetPrefs()->GetInteger(prefs::kProfileIsLockableVersion)); |
| 194 } | 225 } |
| 195 | 226 |
| 196 TEST_F(GAIAInfoUpdateServiceTest, HandlesProfileReordering) { | 227 TEST_F(GAIAInfoUpdateServiceTest, HandlesProfileReordering) { |
| 197 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); | 228 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); |
| 198 GetCache()->SetNameOfProfileAtIndex(index, FullName16("B")); | 229 GetCache()->SetNameOfProfileAtIndex(index, FullName16("B")); |
| 199 GetCache()->SetProfileIsUsingDefaultNameAtIndex(index, true); | 230 GetCache()->SetProfileIsUsingDefaultNameAtIndex(index, true); |
| 200 | 231 |
| 201 CreateProfile(FullName("A")); | 232 CreateProfile(FullName("A")); |
| 202 CreateProfile(FullName("C")); | 233 CreateProfile(FullName("C")); |
| 203 CreateProfile(FullName("E")); | 234 CreateProfile(FullName("E")); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 306 |
| 276 TEST_F(GAIAInfoUpdateServiceTest, LogIn) { | 307 TEST_F(GAIAInfoUpdateServiceTest, LogIn) { |
| 277 // Log in. | 308 // Log in. |
| 278 EXPECT_CALL(*service(), Update()); | 309 EXPECT_CALL(*service(), Update()); |
| 279 SigninManager* signin_manager = | 310 SigninManager* signin_manager = |
| 280 SigninManagerFactory::GetForProfile(profile()); | 311 SigninManagerFactory::GetForProfile(profile()); |
| 281 signin_manager->OnExternalSigninCompleted("pat@example.com"); | 312 signin_manager->OnExternalSigninCompleted("pat@example.com"); |
| 282 } | 313 } |
| 283 | 314 |
| 284 #endif | 315 #endif |
| OLD | NEW |