| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/browser/profiles/profile_info_cache_unittest.h" | 10 #include "chrome/browser/profiles/profile_info_cache_unittest.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 public: | 27 public: |
| 28 explicit ProfileDownloaderMock(ProfileDownloaderDelegate* delegate) | 28 explicit ProfileDownloaderMock(ProfileDownloaderDelegate* delegate) |
| 29 : ProfileDownloader(delegate) { | 29 : ProfileDownloader(delegate) { |
| 30 } | 30 } |
| 31 | 31 |
| 32 virtual ~ProfileDownloaderMock() { | 32 virtual ~ProfileDownloaderMock() { |
| 33 } | 33 } |
| 34 | 34 |
| 35 MOCK_CONST_METHOD0(GetProfileFullName, string16()); | 35 MOCK_CONST_METHOD0(GetProfileFullName, string16()); |
| 36 MOCK_CONST_METHOD0(GetProfilePicture, SkBitmap()); | 36 MOCK_CONST_METHOD0(GetProfilePicture, SkBitmap()); |
| 37 MOCK_CONST_METHOD0(GetProfilePictureResult, |
| 38 ProfileDownloader::PictureResult()); |
| 39 MOCK_CONST_METHOD0(GetProfilePictureURL, std::string()); |
| 37 }; | 40 }; |
| 38 | 41 |
| 39 class GAIAInfoUpdateServiceMock : public GAIAInfoUpdateService { | 42 class GAIAInfoUpdateServiceMock : public GAIAInfoUpdateService { |
| 40 public: | 43 public: |
| 41 explicit GAIAInfoUpdateServiceMock(Profile* profile) | 44 explicit GAIAInfoUpdateServiceMock(Profile* profile) |
| 42 : GAIAInfoUpdateService(profile) { | 45 : GAIAInfoUpdateService(profile) { |
| 43 } | 46 } |
| 44 | 47 |
| 45 virtual ~GAIAInfoUpdateServiceMock() { | 48 virtual ~GAIAInfoUpdateServiceMock() { |
| 46 } | 49 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 67 | 70 |
| 68 TEST_F(GAIAInfoUpdateServiceTest, DownloadSuccess) { | 71 TEST_F(GAIAInfoUpdateServiceTest, DownloadSuccess) { |
| 69 GAIAInfoUpdateService service(profile()); | 72 GAIAInfoUpdateService service(profile()); |
| 70 NiceMock<ProfileDownloaderMock> downloader(&service); | 73 NiceMock<ProfileDownloaderMock> downloader(&service); |
| 71 | 74 |
| 72 string16 name = ASCIIToUTF16("Pat Smith"); | 75 string16 name = ASCIIToUTF16("Pat Smith"); |
| 73 EXPECT_CALL(downloader, GetProfileFullName()).WillOnce(Return(name)); | 76 EXPECT_CALL(downloader, GetProfileFullName()).WillOnce(Return(name)); |
| 74 gfx::Image image = gfx::test::CreateImage(); | 77 gfx::Image image = gfx::test::CreateImage(); |
| 75 SkBitmap bmp = image; | 78 SkBitmap bmp = image; |
| 76 EXPECT_CALL(downloader, GetProfilePicture()).WillOnce(Return(bmp)); | 79 EXPECT_CALL(downloader, GetProfilePicture()).WillOnce(Return(bmp)); |
| 80 EXPECT_CALL(downloader, GetProfilePictureResult()). |
| 81 WillOnce(Return(ProfileDownloader::PICTURE_SUCCESS)); |
| 82 std::string url("foo.com"); |
| 83 EXPECT_CALL(downloader, GetProfilePictureURL()).WillOnce(Return(url)); |
| 84 |
| 85 // No URL should be cached yet. |
| 86 EXPECT_EQ(std::string(), service.GetCachedPictureURL()); |
| 77 | 87 |
| 78 service.OnDownloadComplete(&downloader, true); | 88 service.OnDownloadComplete(&downloader, true); |
| 79 | 89 |
| 80 // On success both the profile info and GAIA info should be updated. | 90 // On success both the profile info and GAIA info should be updated. |
| 81 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); | 91 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); |
| 82 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(index)); | 92 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(index)); |
| 83 EXPECT_EQ(name, GetCache()->GetNameOfProfileAtIndex(index)); | 93 EXPECT_EQ(name, GetCache()->GetNameOfProfileAtIndex(index)); |
| 84 EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index)); | 94 EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index)); |
| 85 EXPECT_TRUE(gfx::test::IsEqual( | 95 EXPECT_TRUE(gfx::test::IsEqual( |
| 86 image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); | 96 image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); |
| 87 EXPECT_TRUE(gfx::test::IsEqual( | 97 EXPECT_TRUE(gfx::test::IsEqual( |
| 88 image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index))); | 98 image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index))); |
| 99 EXPECT_EQ(url, service.GetCachedPictureURL()); |
| 89 } | 100 } |
| 90 | 101 |
| 91 TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) { | 102 TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) { |
| 92 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); | 103 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); |
| 93 string16 old_name = GetCache()->GetNameOfProfileAtIndex(index); | 104 string16 old_name = GetCache()->GetNameOfProfileAtIndex(index); |
| 94 gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index); | 105 gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index); |
| 95 | 106 |
| 96 GAIAInfoUpdateService service(profile()); | 107 GAIAInfoUpdateService service(profile()); |
| 108 EXPECT_EQ(std::string(), service.GetCachedPictureURL()); |
| 97 NiceMock<ProfileDownloaderMock> downloader(&service); | 109 NiceMock<ProfileDownloaderMock> downloader(&service); |
| 98 | 110 |
| 99 service.OnDownloadComplete(&downloader, false); | 111 service.OnDownloadComplete(&downloader, false); |
| 100 | 112 |
| 101 // On failure nothing should be updated. | 113 // On failure nothing should be updated. |
| 102 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(index)); | 114 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(index)); |
| 103 EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); | 115 EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); |
| 104 EXPECT_EQ(string16(), GetCache()->GetGAIANameOfProfileAtIndex(index)); | 116 EXPECT_EQ(string16(), GetCache()->GetGAIANameOfProfileAtIndex(index)); |
| 105 EXPECT_TRUE(gfx::test::IsEqual( | 117 EXPECT_TRUE(gfx::test::IsEqual( |
| 106 old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); | 118 old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); |
| 107 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(index)); | 119 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(index)); |
| 120 EXPECT_EQ(std::string(), service.GetCachedPictureURL()); |
| 108 } | 121 } |
| 109 | 122 |
| 110 TEST_F(GAIAInfoUpdateServiceTest, NoMigration) { | 123 TEST_F(GAIAInfoUpdateServiceTest, NoMigration) { |
| 111 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); | 124 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); |
| 112 string16 old_name = GetCache()->GetNameOfProfileAtIndex(index); | 125 string16 old_name = GetCache()->GetNameOfProfileAtIndex(index); |
| 113 gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index); | 126 gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index); |
| 114 | 127 |
| 115 // Mark the profile as migrated. | 128 // Mark the profile as migrated. |
| 116 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(index, true); | 129 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(index, true); |
| 117 | 130 |
| 118 GAIAInfoUpdateService service(profile()); | 131 GAIAInfoUpdateService service(profile()); |
| 119 NiceMock<ProfileDownloaderMock> downloader(&service); | 132 NiceMock<ProfileDownloaderMock> downloader(&service); |
| 120 string16 new_name = ASCIIToUTF16("Pat Smith"); | 133 string16 new_name = ASCIIToUTF16("Pat Smith"); |
| 121 EXPECT_CALL(downloader, GetProfileFullName()).WillOnce(Return(new_name)); | 134 EXPECT_CALL(downloader, GetProfileFullName()).WillOnce(Return(new_name)); |
| 122 gfx::Image new_image = gfx::test::CreateImage(); | 135 gfx::Image new_image = gfx::test::CreateImage(); |
| 123 SkBitmap new_bmp = new_image; | 136 SkBitmap new_bmp = new_image; |
| 124 EXPECT_CALL(downloader, GetProfilePicture()).WillOnce(Return(new_bmp)); | 137 EXPECT_CALL(downloader, GetProfilePicture()).WillOnce(Return(new_bmp)); |
| 138 EXPECT_CALL(downloader, GetProfilePictureResult()). |
| 139 WillOnce(Return(ProfileDownloader::PICTURE_SUCCESS)); |
| 140 EXPECT_CALL(downloader, GetProfilePictureURL()).WillOnce(Return("")); |
| 125 | 141 |
| 126 service.OnDownloadComplete(&downloader, true); | 142 service.OnDownloadComplete(&downloader, true); |
| 127 | 143 |
| 128 // On success with no migration the profile info should not be updated but | 144 // On success with no migration the profile info should not be updated but |
| 129 // the GAIA info should be updated. | 145 // the GAIA info should be updated. |
| 130 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(index)); | 146 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(index)); |
| 131 EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); | 147 EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); |
| 132 EXPECT_EQ(new_name, GetCache()->GetGAIANameOfProfileAtIndex(index)); | 148 EXPECT_EQ(new_name, GetCache()->GetGAIANameOfProfileAtIndex(index)); |
| 133 EXPECT_TRUE(gfx::test::IsEqual( | 149 EXPECT_TRUE(gfx::test::IsEqual( |
| 134 old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); | 150 old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 185 |
| 170 TEST_F(GAIAInfoUpdateServiceTest, LogIn) { | 186 TEST_F(GAIAInfoUpdateServiceTest, LogIn) { |
| 171 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, ""); | 187 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, ""); |
| 172 GAIAInfoUpdateServiceMock service(profile()); | 188 GAIAInfoUpdateServiceMock service(profile()); |
| 173 | 189 |
| 174 // Log in. | 190 // Log in. |
| 175 EXPECT_CALL(service, Update()); | 191 EXPECT_CALL(service, Update()); |
| 176 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 192 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
| 177 "pat@example.com"); | 193 "pat@example.com"); |
| 178 } | 194 } |
| OLD | NEW |