| 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" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 EXPECT_CALL(*downloader(), GetProfilePicture()).WillOnce(Return(*bmp)); | 103 EXPECT_CALL(*downloader(), GetProfilePicture()).WillOnce(Return(*bmp)); |
| 104 EXPECT_CALL(*downloader(), GetProfilePictureStatus()). | 104 EXPECT_CALL(*downloader(), GetProfilePictureStatus()). |
| 105 WillOnce(Return(ProfileDownloader::PICTURE_SUCCESS)); | 105 WillOnce(Return(ProfileDownloader::PICTURE_SUCCESS)); |
| 106 EXPECT_CALL(*downloader(), GetProfilePictureURL()).WillOnce(Return(url)); | 106 EXPECT_CALL(*downloader(), GetProfilePictureURL()).WillOnce(Return(url)); |
| 107 | 107 |
| 108 service()->OnProfileDownloadSuccess(downloader()); | 108 service()->OnProfileDownloadSuccess(downloader()); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void RenameProfile(const base::string16& full_name, | 111 void RenameProfile(const base::string16& full_name, |
| 112 const base::string16& given_name) { | 112 const base::string16& given_name) { |
| 113 gfx::Image image = gfx::test::CreateImage(); | 113 gfx::Image image = gfx::test::CreateImage(256,256); |
| 114 std::string url("foo.com"); | 114 std::string url("foo.com"); |
| 115 ProfileDownloadSuccess(full_name, given_name, image, url); | 115 ProfileDownloadSuccess(full_name, given_name, image, url); |
| 116 | 116 |
| 117 // Make sure the right profile was updated correctly. | 117 // Make sure the right profile was updated correctly. |
| 118 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); | 118 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); |
| 119 EXPECT_EQ(full_name, GetCache()->GetGAIANameOfProfileAtIndex(index)); | 119 EXPECT_EQ(full_name, GetCache()->GetGAIANameOfProfileAtIndex(index)); |
| 120 EXPECT_EQ(given_name, GetCache()->GetGAIAGivenNameOfProfileAtIndex(index)); | 120 EXPECT_EQ(given_name, GetCache()->GetGAIAGivenNameOfProfileAtIndex(index)); |
| 121 } | 121 } |
| 122 | 122 |
| 123 private: | 123 private: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 143 } | 143 } |
| 144 | 144 |
| 145 } // namespace | 145 } // namespace |
| 146 | 146 |
| 147 TEST_F(GAIAInfoUpdateServiceTest, DownloadSuccess) { | 147 TEST_F(GAIAInfoUpdateServiceTest, DownloadSuccess) { |
| 148 // No URL should be cached yet. | 148 // No URL should be cached yet. |
| 149 EXPECT_EQ(std::string(), service()->GetCachedPictureURL()); | 149 EXPECT_EQ(std::string(), service()->GetCachedPictureURL()); |
| 150 | 150 |
| 151 base::string16 name = base::ASCIIToUTF16("Pat Smith"); | 151 base::string16 name = base::ASCIIToUTF16("Pat Smith"); |
| 152 base::string16 given_name = base::ASCIIToUTF16("Pat"); | 152 base::string16 given_name = base::ASCIIToUTF16("Pat"); |
| 153 gfx::Image image = gfx::test::CreateImage(); | 153 gfx::Image image = gfx::test::CreateImage(256, 256); |
| 154 std::string url("foo.com"); | 154 std::string url("foo.com"); |
| 155 ProfileDownloadSuccess(name, given_name, image, url); | 155 ProfileDownloadSuccess(name, given_name, image, url); |
| 156 | 156 |
| 157 // On success the GAIA info should be updated. | 157 // On success the GAIA info should be updated. |
| 158 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); | 158 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); |
| 159 EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index)); | 159 EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index)); |
| 160 EXPECT_EQ(given_name, GetCache()->GetGAIAGivenNameOfProfileAtIndex(index)); | 160 EXPECT_EQ(given_name, GetCache()->GetGAIAGivenNameOfProfileAtIndex(index)); |
| 161 EXPECT_TRUE(gfx::test::IsEqual( | 161 EXPECT_TRUE(gfx::test::IsEqual( |
| 162 image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index))); | 162 image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index))); |
| 163 EXPECT_EQ(url, service()->GetCachedPictureURL()); | 163 EXPECT_EQ(url, service()->GetCachedPictureURL()); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 240 } |
| 241 | 241 |
| 242 #if !defined(OS_CHROMEOS) | 242 #if !defined(OS_CHROMEOS) |
| 243 | 243 |
| 244 TEST_F(GAIAInfoUpdateServiceTest, LogOut) { | 244 TEST_F(GAIAInfoUpdateServiceTest, LogOut) { |
| 245 SigninManager* signin_manager = | 245 SigninManager* signin_manager = |
| 246 SigninManagerFactory::GetForProfile(profile()); | 246 SigninManagerFactory::GetForProfile(profile()); |
| 247 signin_manager->SetAuthenticatedUsername("pat@example.com"); | 247 signin_manager->SetAuthenticatedUsername("pat@example.com"); |
| 248 base::string16 gaia_name = base::UTF8ToUTF16("Pat Foo"); | 248 base::string16 gaia_name = base::UTF8ToUTF16("Pat Foo"); |
| 249 GetCache()->SetGAIANameOfProfileAtIndex(0, gaia_name); | 249 GetCache()->SetGAIANameOfProfileAtIndex(0, gaia_name); |
| 250 gfx::Image gaia_picture = gfx::test::CreateImage(); | 250 gfx::Image gaia_picture = gfx::test::CreateImage(256,256); |
| 251 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_picture); | 251 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_picture); |
| 252 | 252 |
| 253 // Set a fake picture URL. | 253 // Set a fake picture URL. |
| 254 profile()->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL, | 254 profile()->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL, |
| 255 "example.com"); | 255 "example.com"); |
| 256 | 256 |
| 257 EXPECT_FALSE(service()->GetCachedPictureURL().empty()); | 257 EXPECT_FALSE(service()->GetCachedPictureURL().empty()); |
| 258 | 258 |
| 259 // Log out. | 259 // Log out. |
| 260 signin_manager->SignOut(signin_metrics::SIGNOUT_TEST); | 260 signin_manager->SignOut(signin_metrics::SIGNOUT_TEST); |
| 261 // Verify that the GAIA name and picture, and picture URL are unset. | 261 // Verify that the GAIA name and picture, and picture URL are unset. |
| 262 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); | 262 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); |
| 263 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); | 263 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
| 264 EXPECT_TRUE(service()->GetCachedPictureURL().empty()); | 264 EXPECT_TRUE(service()->GetCachedPictureURL().empty()); |
| 265 } | 265 } |
| 266 | 266 |
| 267 TEST_F(GAIAInfoUpdateServiceTest, LogIn) { | 267 TEST_F(GAIAInfoUpdateServiceTest, LogIn) { |
| 268 // Log in. | 268 // Log in. |
| 269 EXPECT_CALL(*service(), Update()); | 269 EXPECT_CALL(*service(), Update()); |
| 270 SigninManager* signin_manager = | 270 SigninManager* signin_manager = |
| 271 SigninManagerFactory::GetForProfile(profile()); | 271 SigninManagerFactory::GetForProfile(profile()); |
| 272 signin_manager->OnExternalSigninCompleted("pat@example.com"); | 272 signin_manager->OnExternalSigninCompleted("pat@example.com"); |
| 273 } | 273 } |
| 274 | 274 |
| 275 #endif | 275 #endif |
| OLD | NEW |