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

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

Issue 566933005: Do not display lock for hosted domains (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improved tests, more comments Created 6 years, 3 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 "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
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
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 19 matching lines...) Expand all
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());
159 164
160 base::string16 name = base::ASCIIToUTF16("Pat Smith"); 165 base::string16 name = base::ASCIIToUTF16("Pat Smith");
161 base::string16 given_name = base::ASCIIToUTF16("Pat"); 166 base::string16 given_name = base::ASCIIToUTF16("Pat");
162 gfx::Image image = gfx::test::CreateImage(256, 256); 167 gfx::Image image = gfx::test::CreateImage(256, 256);
163 std::string url("foo.com"); 168 std::string url("foo.com");
164 ProfileDownloadSuccess(name, given_name, image, url); 169 base::string16 hosted_domain(base::ASCIIToUTF16(""));
170 ProfileDownloadSuccess(name, given_name, image, url, hosted_domain);
165 171
166 // On success the GAIA info should be updated. 172 // On success the GAIA info should be updated.
167 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); 173 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath());
168 EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index)); 174 EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index));
169 EXPECT_EQ(given_name, GetCache()->GetGAIAGivenNameOfProfileAtIndex(index)); 175 EXPECT_EQ(given_name, GetCache()->GetGAIAGivenNameOfProfileAtIndex(index));
170 EXPECT_TRUE(gfx::test::IsEqual( 176 EXPECT_TRUE(gfx::test::IsEqual(
171 image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index))); 177 image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index)));
172 EXPECT_EQ(url, service()->GetCachedPictureURL()); 178 EXPECT_EQ(url, service()->GetCachedPictureURL());
179 EXPECT_EQ(true, profile()->GetPrefs()->GetBoolean(prefs::kProfileIsLockable));
180 EXPECT_EQ(profiles::kCurrentLockAlgorithmVersion,
181 profile()->GetPrefs()->GetInteger(
182 prefs::kProfileIsLockableVersion));
noms (inactive) 2014/09/15 20:24:39 nit: can this also be made to fit on one line, lik
Mike Lerman 2014/09/15 20:41:09 Ah, missed one.
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(false,
205 profile()->GetPrefs()->GetBoolean(prefs::kProfileIsLockable));
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(true, profile()->GetPrefs()->GetBoolean(prefs::kProfileIsLockable));
220 EXPECT_EQ(profiles::kCurrentLockAlgorithmVersion,
221 profile()->GetPrefs()->GetInteger(prefs::kProfileIsLockableVersion));
222 }
223
224 TEST_F(GAIAInfoUpdateServiceTest, ProfileLockDisabledByDefault) {
225 // No URL should be cached yet.
226 EXPECT_EQ(std::string(), service()->GetCachedPictureURL());
227
228 base::string16 name = base::ASCIIToUTF16("Pat Smith");
229 base::string16 given_name = base::ASCIIToUTF16("Pat");
230 gfx::Image image = gfx::test::CreateImage(256, 256);
231 std::string url("foo.com");
232 base::string16 hosted_domain(base::ASCIIToUTF16("other.com"));
233 ProfileDownloadSuccess(name, given_name, image, url, hosted_domain);
234
235 EXPECT_EQ(false,
236 profile()->GetPrefs()->GetBoolean(prefs::kProfileIsLockable));
237 EXPECT_EQ(profiles::kCurrentLockAlgorithmVersion,
238 profile()->GetPrefs()->GetInteger(prefs::kProfileIsLockableVersion));
194 } 239 }
195 240
196 TEST_F(GAIAInfoUpdateServiceTest, HandlesProfileReordering) { 241 TEST_F(GAIAInfoUpdateServiceTest, HandlesProfileReordering) {
197 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); 242 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath());
198 GetCache()->SetNameOfProfileAtIndex(index, FullName16("B")); 243 GetCache()->SetNameOfProfileAtIndex(index, FullName16("B"));
199 GetCache()->SetProfileIsUsingDefaultNameAtIndex(index, true); 244 GetCache()->SetProfileIsUsingDefaultNameAtIndex(index, true);
200 245
201 CreateProfile(FullName("A")); 246 CreateProfile(FullName("A"));
202 CreateProfile(FullName("C")); 247 CreateProfile(FullName("C"));
203 CreateProfile(FullName("E")); 248 CreateProfile(FullName("E"));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 320
276 TEST_F(GAIAInfoUpdateServiceTest, LogIn) { 321 TEST_F(GAIAInfoUpdateServiceTest, LogIn) {
277 // Log in. 322 // Log in.
278 EXPECT_CALL(*service(), Update()); 323 EXPECT_CALL(*service(), Update());
279 SigninManager* signin_manager = 324 SigninManager* signin_manager =
280 SigninManagerFactory::GetForProfile(profile()); 325 SigninManagerFactory::GetForProfile(profile());
281 signin_manager->OnExternalSigninCompleted("pat@example.com"); 326 signin_manager->OnExternalSigninCompleted("pat@example.com");
282 } 327 }
283 328
284 #endif 329 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698