Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: chrome/browser/profiles/gaia_info_update_service_unittest.cc

Issue 1913373002: Revert "Refactor ProfileInfoCache in most of c/b/profiles" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/profiles/profile_attributes_entry.h"
15 #include "chrome/browser/profiles/profile_attributes_storage.h"
16 #include "chrome/browser/profiles/profile_downloader.h" 14 #include "chrome/browser/profiles/profile_downloader.h"
17 #include "chrome/browser/profiles/profile_info_cache.h" 15 #include "chrome/browser/profiles/profile_info_cache.h"
18 #include "chrome/browser/profiles/profile_info_cache_unittest.h" 16 #include "chrome/browser/profiles/profile_info_cache_unittest.h"
19 #include "chrome/browser/profiles/profiles_state.h" 17 #include "chrome/browser/profiles/profiles_state.h"
20 #include "chrome/browser/signin/account_tracker_service_factory.h" 18 #include "chrome/browser/signin/account_tracker_service_factory.h"
21 #include "chrome/browser/signin/chrome_signin_client_factory.h" 19 #include "chrome/browser/signin/chrome_signin_client_factory.h"
22 #include "chrome/browser/signin/signin_manager_factory.h" 20 #include "chrome/browser/signin/signin_manager_factory.h"
23 #include "chrome/browser/signin/test_signin_client_builder.h" 21 #include "chrome/browser/signin/test_signin_client_builder.h"
24 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
25 #include "chrome/test/base/testing_browser_process.h" 23 #include "chrome/test/base/testing_browser_process.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 explicit GAIAInfoUpdateServiceMock(Profile* profile) 59 explicit GAIAInfoUpdateServiceMock(Profile* profile)
62 : GAIAInfoUpdateService(profile) { 60 : GAIAInfoUpdateService(profile) {
63 } 61 }
64 62
65 virtual ~GAIAInfoUpdateServiceMock() { 63 virtual ~GAIAInfoUpdateServiceMock() {
66 } 64 }
67 65
68 MOCK_METHOD0(Update, void()); 66 MOCK_METHOD0(Update, void());
69 }; 67 };
70 68
71 // TODO(anthonyvd) : remove ProfileInfoCacheTest from the test fixture.
72 class GAIAInfoUpdateServiceTest : public ProfileInfoCacheTest { 69 class GAIAInfoUpdateServiceTest : public ProfileInfoCacheTest {
73 protected: 70 protected:
74 GAIAInfoUpdateServiceTest() : profile_(NULL) { 71 GAIAInfoUpdateServiceTest() : profile_(NULL) {
75 } 72 }
76 73
77 Profile* profile() { 74 Profile* profile() {
78 if (!profile_) 75 if (!profile_)
79 profile_ = CreateProfile("Person 1"); 76 profile_ = CreateProfile("Person 1");
80 return profile_; 77 return profile_;
81 } 78 }
82 79
83 ProfileAttributesStorage* storage() {
84 return testing_profile_manager_.profile_attributes_storage();
85 }
86
87 NiceMock<GAIAInfoUpdateServiceMock>* service() { return service_.get(); } 80 NiceMock<GAIAInfoUpdateServiceMock>* service() { return service_.get(); }
88 NiceMock<ProfileDownloaderMock>* downloader() { return downloader_.get(); } 81 NiceMock<ProfileDownloaderMock>* downloader() { return downloader_.get(); }
89 82
90 Profile* CreateProfile(const std::string& name) { 83 Profile* CreateProfile(const std::string& name) {
91 TestingProfile::TestingFactories testing_factories; 84 TestingProfile::TestingFactories testing_factories;
92 testing_factories.push_back(std::make_pair( 85 testing_factories.push_back(std::make_pair(
93 ChromeSigninClientFactory::GetInstance(), 86 ChromeSigninClientFactory::GetInstance(),
94 signin::BuildTestSigninClient)); 87 signin::BuildTestSigninClient));
95 Profile* profile = testing_profile_manager_.CreateTestingProfile( 88 Profile* profile = testing_profile_manager_.CreateTestingProfile(
96 name, std::unique_ptr<syncable_prefs::PrefServiceSyncable>(), 89 name, std::unique_ptr<syncable_prefs::PrefServiceSyncable>(),
97 base::UTF8ToUTF16(name), 0, std::string(), testing_factories); 90 base::UTF8ToUTF16(name), 0, std::string(), testing_factories);
98 // The testing manager sets the profile name manually, which counts as 91 // The testing manager sets the profile name manually, which counts as
99 // a user-customized profile name. Reset this to match the default name 92 // a user-customized profile name. Reset this to match the default name
100 // we are actually using. 93 // we are actually using.
101 ProfileAttributesEntry* entry = nullptr; 94 size_t index = GetCache()->GetIndexOfProfileWithPath(profile->GetPath());
102 // TODO(anthonyvd) : refactor the function so the following assertion can be 95 GetCache()->SetProfileIsUsingDefaultNameAtIndex(index, true);
103 // changed to ASSERT_TRUE.
104 DCHECK(storage()->GetProfileAttributesWithPath(profile->GetPath(), &entry));
105 entry->SetIsUsingDefaultName(true);
106 return profile; 96 return profile;
107 } 97 }
108 98
109 static std::string GivenName(const std::string& id) { 99 static std::string GivenName(const std::string& id) {
110 return id + "first"; 100 return id + "first";
111 } 101 }
112 static std::string FullName(const std::string& id) { 102 static std::string FullName(const std::string& id) {
113 return GivenName(id) + " " + id + "last"; 103 return GivenName(id) + " " + id + "last";
114 } 104 }
115 static base::string16 GivenName16(const std::string& id) { 105 static base::string16 GivenName16(const std::string& id) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 GetString(prefs::kGoogleServicesHostedDomain)); 173 GetString(prefs::kGoogleServicesHostedDomain));
184 174
185 base::string16 name = base::ASCIIToUTF16("Pat Smith"); 175 base::string16 name = base::ASCIIToUTF16("Pat Smith");
186 base::string16 given_name = base::ASCIIToUTF16("Pat"); 176 base::string16 given_name = base::ASCIIToUTF16("Pat");
187 gfx::Image image = gfx::test::CreateImage(256, 256); 177 gfx::Image image = gfx::test::CreateImage(256, 256);
188 std::string url("foo.com"); 178 std::string url("foo.com");
189 base::string16 hosted_domain(base::ASCIIToUTF16("")); 179 base::string16 hosted_domain(base::ASCIIToUTF16(""));
190 ProfileDownloadSuccess(name, given_name, image, url, hosted_domain); 180 ProfileDownloadSuccess(name, given_name, image, url, hosted_domain);
191 181
192 // On success the GAIA info should be updated. 182 // On success the GAIA info should be updated.
193 ProfileAttributesEntry* entry; 183 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath());
194 ASSERT_TRUE(storage()->GetProfileAttributesWithPath(profile()->GetPath(), 184 EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index));
195 &entry)); 185 EXPECT_EQ(given_name, GetCache()->GetGAIAGivenNameOfProfileAtIndex(index));
196 EXPECT_EQ(name, entry->GetGAIAName()); 186 EXPECT_TRUE(gfx::test::AreImagesEqual(
197 EXPECT_EQ(given_name, entry->GetGAIAGivenName()); 187 image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index)));
198 EXPECT_TRUE(gfx::test::AreImagesEqual(image, *entry->GetGAIAPicture()));
199 EXPECT_EQ(url, service()->GetCachedPictureURL()); 188 EXPECT_EQ(url, service()->GetCachedPictureURL());
200 EXPECT_EQ(Profile::kNoHostedDomainFound, profile()->GetPrefs()-> 189 EXPECT_EQ(Profile::kNoHostedDomainFound, profile()->GetPrefs()->
201 GetString(prefs::kGoogleServicesHostedDomain)); 190 GetString(prefs::kGoogleServicesHostedDomain));
202 } 191 }
203 192
204 TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) { 193 TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) {
205 ProfileAttributesEntry* entry; 194 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath());
206 ASSERT_TRUE(storage()->GetProfileAttributesWithPath(profile()->GetPath(), 195 base::string16 old_name = GetCache()->GetNameOfProfileAtIndex(index);
207 &entry)); 196 gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index);
208 base::string16 old_name = entry->GetName();
209 gfx::Image old_image = entry->GetAvatarIcon();
210 197
211 EXPECT_EQ(std::string(), service()->GetCachedPictureURL()); 198 EXPECT_EQ(std::string(), service()->GetCachedPictureURL());
212 199
213 service()->OnProfileDownloadFailure(downloader(), 200 service()->OnProfileDownloadFailure(downloader(),
214 ProfileDownloaderDelegate::SERVICE_ERROR); 201 ProfileDownloaderDelegate::SERVICE_ERROR);
215 202
216 // On failure nothing should be updated. 203 // On failure nothing should be updated.
217 EXPECT_EQ(old_name, entry->GetName()); 204 EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index));
218 EXPECT_EQ(base::string16(), entry->GetGAIAName()); 205 EXPECT_EQ(base::string16(), GetCache()->GetGAIANameOfProfileAtIndex(index));
219 EXPECT_EQ(base::string16(), entry->GetGAIAGivenName()); 206 EXPECT_EQ(base::string16(),
220 EXPECT_TRUE(gfx::test::AreImagesEqual(old_image, entry->GetAvatarIcon())); 207 GetCache()->GetGAIAGivenNameOfProfileAtIndex(index));
221 EXPECT_EQ(nullptr, entry->GetGAIAPicture()); 208 EXPECT_TRUE(gfx::test::AreImagesEqual(
209 old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index)));
210 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(index));
222 EXPECT_EQ(std::string(), service()->GetCachedPictureURL()); 211 EXPECT_EQ(std::string(), service()->GetCachedPictureURL());
223 EXPECT_EQ(std::string(), 212 EXPECT_EQ(std::string(),
224 profile()->GetPrefs()->GetString(prefs::kGoogleServicesHostedDomain)); 213 profile()->GetPrefs()->GetString(prefs::kGoogleServicesHostedDomain));
225 } 214 }
226 215
227 TEST_F(GAIAInfoUpdateServiceTest, ProfileLockEnabledForWhitelist) { 216 TEST_F(GAIAInfoUpdateServiceTest, ProfileLockEnabledForWhitelist) {
228 // No URL should be cached yet. 217 // No URL should be cached yet.
229 EXPECT_EQ(std::string(), service()->GetCachedPictureURL()); 218 EXPECT_EQ(std::string(), service()->GetCachedPictureURL());
230 219
231 base::string16 name = base::ASCIIToUTF16("Pat Smith"); 220 base::string16 name = base::ASCIIToUTF16("Pat Smith");
232 base::string16 given_name = base::ASCIIToUTF16("Pat"); 221 base::string16 given_name = base::ASCIIToUTF16("Pat");
233 gfx::Image image = gfx::test::CreateImage(256, 256); 222 gfx::Image image = gfx::test::CreateImage(256, 256);
234 std::string url("foo.com"); 223 std::string url("foo.com");
235 base::string16 hosted_domain(base::ASCIIToUTF16("google.com")); 224 base::string16 hosted_domain(base::ASCIIToUTF16("google.com"));
236 ProfileDownloadSuccess(name, given_name, image, url, hosted_domain); 225 ProfileDownloadSuccess(name, given_name, image, url, hosted_domain);
237 226
238 EXPECT_EQ("google.com", profile()->GetPrefs()-> 227 EXPECT_EQ("google.com", profile()->GetPrefs()->
239 GetString(prefs::kGoogleServicesHostedDomain)); 228 GetString(prefs::kGoogleServicesHostedDomain));
240 } 229 }
241 230
242 // TODO(anthonyvd) : remove or update test once the refactoring of the internals
243 // of ProfileInfoCache is complete.
244 TEST_F(GAIAInfoUpdateServiceTest, HandlesProfileReordering) { 231 TEST_F(GAIAInfoUpdateServiceTest, HandlesProfileReordering) {
245 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); 232 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath());
246 GetCache()->SetNameOfProfileAtIndex(index, FullName16("B")); 233 GetCache()->SetNameOfProfileAtIndex(index, FullName16("B"));
247 GetCache()->SetProfileIsUsingDefaultNameAtIndex(index, true); 234 GetCache()->SetProfileIsUsingDefaultNameAtIndex(index, true);
248 235
249 CreateProfile(FullName("A")); 236 CreateProfile(FullName("A"));
250 CreateProfile(FullName("C")); 237 CreateProfile(FullName("C"));
251 CreateProfile(FullName("E")); 238 CreateProfile(FullName("E"));
252 239
253 size_t index_before = 240 size_t index_before =
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 EXPECT_TRUE(service()->timer_.IsRunning()); 283 EXPECT_TRUE(service()->timer_.IsRunning());
297 } 284 }
298 285
299 #if !defined(OS_CHROMEOS) 286 #if !defined(OS_CHROMEOS)
300 287
301 TEST_F(GAIAInfoUpdateServiceTest, LogOut) { 288 TEST_F(GAIAInfoUpdateServiceTest, LogOut) {
302 SigninManager* signin_manager = 289 SigninManager* signin_manager =
303 SigninManagerFactory::GetForProfile(profile()); 290 SigninManagerFactory::GetForProfile(profile());
304 signin_manager->SetAuthenticatedAccountInfo("gaia_id", "pat@example.com"); 291 signin_manager->SetAuthenticatedAccountInfo("gaia_id", "pat@example.com");
305 base::string16 gaia_name = base::UTF8ToUTF16("Pat Foo"); 292 base::string16 gaia_name = base::UTF8ToUTF16("Pat Foo");
306 293 GetCache()->SetGAIANameOfProfileAtIndex(0, gaia_name);
307 ASSERT_EQ(1u, storage()->GetNumberOfProfiles());
308 ProfileAttributesEntry* entry = storage()->GetAllProfilesAttributes().front();
309 entry->SetGAIAName(gaia_name);
310 gfx::Image gaia_picture = gfx::test::CreateImage(256, 256); 294 gfx::Image gaia_picture = gfx::test::CreateImage(256, 256);
311 entry->SetGAIAPicture(&gaia_picture); 295 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_picture);
312 296
313 // Set a fake picture URL. 297 // Set a fake picture URL.
314 profile()->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL, 298 profile()->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL,
315 "example.com"); 299 "example.com");
316 300
317 EXPECT_FALSE(service()->GetCachedPictureURL().empty()); 301 EXPECT_FALSE(service()->GetCachedPictureURL().empty());
318 302
319 // Log out. 303 // Log out.
320 signin_manager->SignOut(signin_metrics::SIGNOUT_TEST, 304 signin_manager->SignOut(signin_metrics::SIGNOUT_TEST,
321 signin_metrics::SignoutDelete::IGNORE_METRIC); 305 signin_metrics::SignoutDelete::IGNORE_METRIC);
322 // Verify that the GAIA name and picture, and picture URL are unset. 306 // Verify that the GAIA name and picture, and picture URL are unset.
323 EXPECT_TRUE(entry->GetGAIAName().empty()); 307 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty());
324 EXPECT_EQ(nullptr, entry->GetGAIAPicture()); 308 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0));
325 EXPECT_TRUE(service()->GetCachedPictureURL().empty()); 309 EXPECT_TRUE(service()->GetCachedPictureURL().empty());
326 } 310 }
327 311
328 TEST_F(GAIAInfoUpdateServiceTest, LogIn) { 312 TEST_F(GAIAInfoUpdateServiceTest, LogIn) {
329 // Log in. 313 // Log in.
330 EXPECT_CALL(*service(), Update()); 314 EXPECT_CALL(*service(), Update());
331 AccountTrackerServiceFactory::GetForProfile(profile()) 315 AccountTrackerServiceFactory::GetForProfile(profile())
332 ->SeedAccountInfo("gaia_id", "pat@example.com"); 316 ->SeedAccountInfo("gaia_id", "pat@example.com");
333 SigninManager* signin_manager = 317 SigninManager* signin_manager =
334 SigninManagerFactory::GetForProfile(profile()); 318 SigninManagerFactory::GetForProfile(profile());
335 signin_manager->OnExternalSigninCompleted("pat@example.com"); 319 signin_manager->OnExternalSigninCompleted("pat@example.com");
336 } 320 }
337 321
338 #endif 322 #endif
OLDNEW
« no previous file with comments | « chrome/browser/profiles/gaia_info_update_service.cc ('k') | chrome/browser/profiles/profile_attributes_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698