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::kGoogleServicesHostedDomain)); |
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::kGoogleServicesHostedDomain)); |
173 } | 183 } |
174 | 184 |
175 TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) { | 185 TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) { |
176 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); | 186 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); |
177 base::string16 old_name = GetCache()->GetNameOfProfileAtIndex(index); | 187 base::string16 old_name = GetCache()->GetNameOfProfileAtIndex(index); |
178 gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index); | 188 gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index); |
179 | 189 |
180 EXPECT_EQ(std::string(), service()->GetCachedPictureURL()); | 190 EXPECT_EQ(std::string(), service()->GetCachedPictureURL()); |
181 | 191 |
182 service()->OnProfileDownloadFailure(downloader(), | 192 service()->OnProfileDownloadFailure(downloader(), |
183 ProfileDownloaderDelegate::SERVICE_ERROR); | 193 ProfileDownloaderDelegate::SERVICE_ERROR); |
184 | 194 |
185 // On failure nothing should be updated. | 195 // On failure nothing should be updated. |
186 EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); | 196 EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); |
187 EXPECT_EQ(base::string16(), GetCache()->GetGAIANameOfProfileAtIndex(index)); | 197 EXPECT_EQ(base::string16(), GetCache()->GetGAIANameOfProfileAtIndex(index)); |
188 EXPECT_EQ(base::string16(), | 198 EXPECT_EQ(base::string16(), |
189 GetCache()->GetGAIAGivenNameOfProfileAtIndex(index)); | 199 GetCache()->GetGAIAGivenNameOfProfileAtIndex(index)); |
190 EXPECT_TRUE(gfx::test::IsEqual( | 200 EXPECT_TRUE(gfx::test::IsEqual( |
191 old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); | 201 old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); |
192 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(index)); | 202 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(index)); |
193 EXPECT_EQ(std::string(), service()->GetCachedPictureURL()); | 203 EXPECT_EQ(std::string(), service()->GetCachedPictureURL()); |
| 204 EXPECT_EQ(std::string(), |
| 205 profile()->GetPrefs()->GetString(prefs::kGoogleServicesHostedDomain)); |
| 206 } |
| 207 |
| 208 TEST_F(GAIAInfoUpdateServiceTest, ProfileLockEnabledForWhitelist) { |
| 209 // No URL should be cached yet. |
| 210 EXPECT_EQ(std::string(), service()->GetCachedPictureURL()); |
| 211 |
| 212 base::string16 name = base::ASCIIToUTF16("Pat Smith"); |
| 213 base::string16 given_name = base::ASCIIToUTF16("Pat"); |
| 214 gfx::Image image = gfx::test::CreateImage(256, 256); |
| 215 std::string url("foo.com"); |
| 216 base::string16 hosted_domain(base::ASCIIToUTF16("google.com")); |
| 217 ProfileDownloadSuccess(name, given_name, image, url, hosted_domain); |
| 218 |
| 219 EXPECT_EQ("google.com", profile()->GetPrefs()-> |
| 220 GetString(prefs::kGoogleServicesHostedDomain)); |
194 } | 221 } |
195 | 222 |
196 TEST_F(GAIAInfoUpdateServiceTest, HandlesProfileReordering) { | 223 TEST_F(GAIAInfoUpdateServiceTest, HandlesProfileReordering) { |
197 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); | 224 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); |
198 GetCache()->SetNameOfProfileAtIndex(index, FullName16("B")); | 225 GetCache()->SetNameOfProfileAtIndex(index, FullName16("B")); |
199 GetCache()->SetProfileIsUsingDefaultNameAtIndex(index, true); | 226 GetCache()->SetProfileIsUsingDefaultNameAtIndex(index, true); |
200 | 227 |
201 CreateProfile(FullName("A")); | 228 CreateProfile(FullName("A")); |
202 CreateProfile(FullName("C")); | 229 CreateProfile(FullName("C")); |
203 CreateProfile(FullName("E")); | 230 CreateProfile(FullName("E")); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 302 |
276 TEST_F(GAIAInfoUpdateServiceTest, LogIn) { | 303 TEST_F(GAIAInfoUpdateServiceTest, LogIn) { |
277 // Log in. | 304 // Log in. |
278 EXPECT_CALL(*service(), Update()); | 305 EXPECT_CALL(*service(), Update()); |
279 SigninManager* signin_manager = | 306 SigninManager* signin_manager = |
280 SigninManagerFactory::GetForProfile(profile()); | 307 SigninManagerFactory::GetForProfile(profile()); |
281 signin_manager->OnExternalSigninCompleted("pat@example.com"); | 308 signin_manager->OnExternalSigninCompleted("pat@example.com"); |
282 } | 309 } |
283 | 310 |
284 #endif | 311 #endif |
OLD | NEW |