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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 std::string url("foo.com"); | 88 std::string url("foo.com"); |
89 EXPECT_CALL(downloader, GetProfilePictureURL()).WillOnce(Return(url)); | 89 EXPECT_CALL(downloader, GetProfilePictureURL()).WillOnce(Return(url)); |
90 | 90 |
91 // No URL should be cached yet. | 91 // No URL should be cached yet. |
92 EXPECT_EQ(std::string(), service.GetCachedPictureURL()); | 92 EXPECT_EQ(std::string(), service.GetCachedPictureURL()); |
93 | 93 |
94 service.OnProfileDownloadSuccess(&downloader); | 94 service.OnProfileDownloadSuccess(&downloader); |
95 | 95 |
96 // On success both the profile info and GAIA info should be updated. | 96 // On success both the profile info and GAIA info should be updated. |
97 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); | 97 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); |
98 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(index)); | |
99 EXPECT_TRUE(GetCache()->IsUsingGAIANameOfProfileAtIndex(index)); | |
100 EXPECT_EQ(name, GetCache()->GetNameOfProfileAtIndex(index)); | 98 EXPECT_EQ(name, GetCache()->GetNameOfProfileAtIndex(index)); |
101 EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index)); | 99 EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index)); |
102 EXPECT_TRUE(gfx::test::IsEqual( | 100 EXPECT_TRUE(gfx::test::IsEqual( |
103 image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); | 101 image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); |
104 EXPECT_TRUE(gfx::test::IsEqual( | 102 EXPECT_TRUE(gfx::test::IsEqual( |
105 image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index))); | 103 image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index))); |
106 EXPECT_EQ(url, service.GetCachedPictureURL()); | 104 EXPECT_EQ(url, service.GetCachedPictureURL()); |
107 } | 105 } |
108 | 106 |
109 TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) { | 107 TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) { |
110 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); | 108 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); |
111 base::string16 old_name = GetCache()->GetNameOfProfileAtIndex(index); | 109 base::string16 old_name = GetCache()->GetNameOfProfileAtIndex(index); |
112 gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index); | 110 gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index); |
113 | 111 |
114 GAIAInfoUpdateService service(profile()); | 112 GAIAInfoUpdateService service(profile()); |
115 EXPECT_EQ(std::string(), service.GetCachedPictureURL()); | 113 EXPECT_EQ(std::string(), service.GetCachedPictureURL()); |
116 NiceMock<ProfileDownloaderMock> downloader(&service); | 114 NiceMock<ProfileDownloaderMock> downloader(&service); |
117 | 115 |
118 service.OnProfileDownloadFailure(&downloader, | 116 service.OnProfileDownloadFailure(&downloader, |
119 ProfileDownloaderDelegate::SERVICE_ERROR); | 117 ProfileDownloaderDelegate::SERVICE_ERROR); |
120 | 118 |
121 // On failure nothing should be updated. | 119 // On failure nothing should be updated. |
122 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(index)); | |
123 EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); | 120 EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); |
124 EXPECT_EQ(base::string16(), GetCache()->GetGAIANameOfProfileAtIndex(index)); | 121 EXPECT_EQ(base::string16(), GetCache()->GetGAIANameOfProfileAtIndex(index)); |
125 EXPECT_TRUE(gfx::test::IsEqual( | 122 EXPECT_TRUE(gfx::test::IsEqual( |
126 old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); | 123 old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); |
127 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(index)); | 124 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(index)); |
128 EXPECT_EQ(std::string(), service.GetCachedPictureURL()); | 125 EXPECT_EQ(std::string(), service.GetCachedPictureURL()); |
129 } | 126 } |
130 | 127 |
131 TEST_F(GAIAInfoUpdateServiceTest, NoMigration) { | |
132 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); | |
133 base::string16 old_name = GetCache()->GetNameOfProfileAtIndex(index); | |
134 gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index); | |
135 | |
136 // Mark the profile as migrated. | |
137 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(index, true); | |
138 | |
139 GAIAInfoUpdateService service(profile()); | |
140 NiceMock<ProfileDownloaderMock> downloader(&service); | |
141 base::string16 new_name = base::ASCIIToUTF16("Pat Smith"); | |
142 EXPECT_CALL(downloader, GetProfileFullName()).WillOnce(Return(new_name)); | |
143 gfx::Image new_image = gfx::test::CreateImage(); | |
144 const SkBitmap* new_bmp = new_image.ToSkBitmap(); | |
145 EXPECT_CALL(downloader, GetProfilePicture()).WillOnce(Return(*new_bmp)); | |
146 EXPECT_CALL(downloader, GetProfilePictureStatus()). | |
147 WillOnce(Return(ProfileDownloader::PICTURE_SUCCESS)); | |
148 EXPECT_CALL(downloader, GetProfilePictureURL()).WillOnce(Return("")); | |
149 | |
150 service.OnProfileDownloadSuccess(&downloader); | |
151 | |
152 // On success with no migration the profile info should not be updated but | |
153 // the GAIA info should be updated. | |
154 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(index)); | |
155 EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); | |
156 EXPECT_EQ(new_name, GetCache()->GetGAIANameOfProfileAtIndex(index)); | |
157 EXPECT_TRUE(gfx::test::IsEqual( | |
158 old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); | |
159 EXPECT_TRUE(gfx::test::IsEqual( | |
160 new_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index))); | |
161 } | |
162 | |
163 TEST_F(GAIAInfoUpdateServiceTest, ShouldUseGAIAProfileInfo) { | 128 TEST_F(GAIAInfoUpdateServiceTest, ShouldUseGAIAProfileInfo) { |
164 #if defined(OS_CHROMEOS) | 129 #if defined(OS_CHROMEOS) |
165 // This feature should never be enabled on ChromeOS. | 130 // This feature should never be enabled on ChromeOS. |
166 EXPECT_FALSE(GAIAInfoUpdateService::ShouldUseGAIAProfileInfo(profile())); | 131 EXPECT_FALSE(GAIAInfoUpdateService::ShouldUseGAIAProfileInfo(profile())); |
167 #endif | 132 #endif |
168 } | 133 } |
169 | 134 |
170 TEST_F(GAIAInfoUpdateServiceTest, ScheduleUpdate) { | 135 TEST_F(GAIAInfoUpdateServiceTest, ScheduleUpdate) { |
171 GAIAInfoUpdateService service(profile()); | 136 GAIAInfoUpdateService service(profile()); |
172 EXPECT_TRUE(service.timer_.IsRunning()); | 137 EXPECT_TRUE(service.timer_.IsRunning()); |
(...skipping 30 matching lines...) Expand all Loading... |
203 TEST_F(GAIAInfoUpdateServiceTest, LogIn) { | 168 TEST_F(GAIAInfoUpdateServiceTest, LogIn) { |
204 profile()->GetPrefs() | 169 profile()->GetPrefs() |
205 ->SetString(prefs::kGoogleServicesUsername, std::string()); | 170 ->SetString(prefs::kGoogleServicesUsername, std::string()); |
206 GAIAInfoUpdateServiceMock service(profile()); | 171 GAIAInfoUpdateServiceMock service(profile()); |
207 | 172 |
208 // Log in. | 173 // Log in. |
209 EXPECT_CALL(service, Update()); | 174 EXPECT_CALL(service, Update()); |
210 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 175 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
211 "pat@example.com"); | 176 "pat@example.com"); |
212 } | 177 } |
OLD | NEW |