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

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

Issue 196243009: Just some cleanup before I start on the profile name fix. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 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 | Annotate | Revision Log
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/profiles/profile_downloader.h" 10 #include "chrome/browser/profiles/profile_downloader.h"
11 #include "chrome/browser/profiles/profile_info_cache.h" 11 #include "chrome/browser/profiles/profile_info_cache.h"
12 #include "chrome/browser/profiles/profile_info_cache_unittest.h" 12 #include "chrome/browser/profiles/profile_info_cache_unittest.h"
13 #include "chrome/browser/signin/signin_manager_factory.h"
13 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
14 #include "chrome/test/base/testing_browser_process.h" 15 #include "chrome/test/base/testing_browser_process.h"
15 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
16 #include "chrome/test/base/testing_profile_manager.h" 17 #include "chrome/test/base/testing_profile_manager.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 #include "ui/gfx/image/image.h" 19 #include "ui/gfx/image/image.h"
19 #include "ui/gfx/image/image_unittest_util.h" 20 #include "ui/gfx/image/image_unittest_util.h"
20 21
21 using ::testing::Return; 22 using ::testing::Return;
22 using ::testing::NiceMock; 23 using ::testing::NiceMock;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 profile_ = testing_profile_manager_.CreateTestingProfile("Person 1"); 62 profile_ = testing_profile_manager_.CreateTestingProfile("Person 1");
62 // The testing manager sets the profile name manually, which counts as 63 // The testing manager sets the profile name manually, which counts as
63 // a user-customized profile name. Reset this to match the default name 64 // a user-customized profile name. Reset this to match the default name
64 // we are actually using. 65 // we are actually using.
65 size_t index = GetCache()->GetIndexOfProfileWithPath(profile_->GetPath()); 66 size_t index = GetCache()->GetIndexOfProfileWithPath(profile_->GetPath());
66 GetCache()->SetProfileIsUsingDefaultNameAtIndex(index, true); 67 GetCache()->SetProfileIsUsingDefaultNameAtIndex(index, true);
67 } 68 }
68 return profile_; 69 return profile_;
69 } 70 }
70 71
72 NiceMock<GAIAInfoUpdateServiceMock>* service() { return service_.get(); }
73 NiceMock<ProfileDownloaderMock>* downloader() { return downloader_.get(); }
74
71 private: 75 private:
76 virtual void SetUp() OVERRIDE;
77 virtual void TearDown() OVERRIDE;
78
72 Profile* profile_; 79 Profile* profile_;
80 scoped_ptr<NiceMock<GAIAInfoUpdateServiceMock> > service_;
81 scoped_ptr<NiceMock<ProfileDownloaderMock> > downloader_;
73 }; 82 };
74 83
84 void GAIAInfoUpdateServiceTest::SetUp() {
85 ProfileInfoCacheTest::SetUp();
86 service_.reset(new NiceMock<GAIAInfoUpdateServiceMock>(profile()));
87 downloader_.reset(new NiceMock<ProfileDownloaderMock>(service()));
88 }
89
90 void GAIAInfoUpdateServiceTest::TearDown() {
91 downloader_.reset();
92 service_->Shutdown();
93 service_.reset();
94 ProfileInfoCacheTest::TearDown();
95 }
96
75 } // namespace 97 } // namespace
76 98
77 TEST_F(GAIAInfoUpdateServiceTest, DownloadSuccess) { 99 TEST_F(GAIAInfoUpdateServiceTest, DownloadSuccess) {
78 GAIAInfoUpdateService service(profile());
79 NiceMock<ProfileDownloaderMock> downloader(&service);
80
81 base::string16 name = base::ASCIIToUTF16("Pat Smith"); 100 base::string16 name = base::ASCIIToUTF16("Pat Smith");
82 EXPECT_CALL(downloader, GetProfileFullName()).WillOnce(Return(name)); 101 EXPECT_CALL(*downloader(), GetProfileFullName()).WillOnce(Return(name));
83 gfx::Image image = gfx::test::CreateImage(); 102 gfx::Image image = gfx::test::CreateImage();
84 const SkBitmap* bmp = image.ToSkBitmap(); 103 const SkBitmap* bmp = image.ToSkBitmap();
85 EXPECT_CALL(downloader, GetProfilePicture()).WillOnce(Return(*bmp)); 104 EXPECT_CALL(*downloader(), GetProfilePicture()).WillOnce(Return(*bmp));
86 EXPECT_CALL(downloader, GetProfilePictureStatus()). 105 EXPECT_CALL(*downloader(), GetProfilePictureStatus()).
87 WillOnce(Return(ProfileDownloader::PICTURE_SUCCESS)); 106 WillOnce(Return(ProfileDownloader::PICTURE_SUCCESS));
88 std::string url("foo.com"); 107 std::string url("foo.com");
89 EXPECT_CALL(downloader, GetProfilePictureURL()).WillOnce(Return(url)); 108 EXPECT_CALL(*downloader(), GetProfilePictureURL()).WillOnce(Return(url));
90 109
91 // No URL should be cached yet. 110 // No URL should be cached yet.
92 EXPECT_EQ(std::string(), service.GetCachedPictureURL()); 111 EXPECT_EQ(std::string(), service()->GetCachedPictureURL());
93 112
94 service.OnProfileDownloadSuccess(&downloader); 113 service()->OnProfileDownloadSuccess(downloader());
95 114
96 // On success both the profile info and GAIA info should be updated. 115 // On success both the profile info and GAIA info should be updated.
97 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); 116 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath());
98 EXPECT_EQ(name, GetCache()->GetNameOfProfileAtIndex(index)); 117 EXPECT_EQ(name, GetCache()->GetNameOfProfileAtIndex(index));
99 EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index)); 118 EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index));
100 EXPECT_TRUE(gfx::test::IsEqual( 119 EXPECT_TRUE(gfx::test::IsEqual(
101 image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); 120 image, GetCache()->GetAvatarIconOfProfileAtIndex(index)));
102 EXPECT_TRUE(gfx::test::IsEqual( 121 EXPECT_TRUE(gfx::test::IsEqual(
103 image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index))); 122 image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index)));
104 EXPECT_EQ(url, service.GetCachedPictureURL()); 123 EXPECT_EQ(url, service()->GetCachedPictureURL());
105 } 124 }
106 125
107 TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) { 126 TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) {
108 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()); 127 size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath());
109 base::string16 old_name = GetCache()->GetNameOfProfileAtIndex(index); 128 base::string16 old_name = GetCache()->GetNameOfProfileAtIndex(index);
110 gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index); 129 gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index);
111 130
112 GAIAInfoUpdateService service(profile()); 131 EXPECT_EQ(std::string(), service()->GetCachedPictureURL());
113 EXPECT_EQ(std::string(), service.GetCachedPictureURL());
114 NiceMock<ProfileDownloaderMock> downloader(&service);
115 132
116 service.OnProfileDownloadFailure(&downloader, 133 service()->OnProfileDownloadFailure(downloader(),
117 ProfileDownloaderDelegate::SERVICE_ERROR); 134 ProfileDownloaderDelegate::SERVICE_ERROR);
118 135
119 // On failure nothing should be updated. 136 // On failure nothing should be updated.
120 EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index)); 137 EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index));
121 EXPECT_EQ(base::string16(), GetCache()->GetGAIANameOfProfileAtIndex(index)); 138 EXPECT_EQ(base::string16(), GetCache()->GetGAIANameOfProfileAtIndex(index));
122 EXPECT_TRUE(gfx::test::IsEqual( 139 EXPECT_TRUE(gfx::test::IsEqual(
123 old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index))); 140 old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index)));
124 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(index)); 141 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(index));
125 EXPECT_EQ(std::string(), service.GetCachedPictureURL()); 142 EXPECT_EQ(std::string(), service()->GetCachedPictureURL());
126 } 143 }
127 144
128 TEST_F(GAIAInfoUpdateServiceTest, ShouldUseGAIAProfileInfo) { 145 TEST_F(GAIAInfoUpdateServiceTest, ShouldUseGAIAProfileInfo) {
129 #if defined(OS_CHROMEOS) 146 #if defined(OS_CHROMEOS)
130 // This feature should never be enabled on ChromeOS. 147 // This feature should never be enabled on ChromeOS.
131 EXPECT_FALSE(GAIAInfoUpdateService::ShouldUseGAIAProfileInfo(profile())); 148 EXPECT_FALSE(GAIAInfoUpdateService::ShouldUseGAIAProfileInfo(profile()));
132 #endif 149 #endif
133 } 150 }
134 151
135 TEST_F(GAIAInfoUpdateServiceTest, ScheduleUpdate) { 152 TEST_F(GAIAInfoUpdateServiceTest, ScheduleUpdate) {
136 GAIAInfoUpdateService service(profile()); 153 EXPECT_TRUE(service()->timer_.IsRunning());
137 EXPECT_TRUE(service.timer_.IsRunning()); 154 service()->timer_.Stop();
138 service.timer_.Stop(); 155 EXPECT_FALSE(service()->timer_.IsRunning());
139 EXPECT_FALSE(service.timer_.IsRunning()); 156 service()->ScheduleNextUpdate();
140 service.ScheduleNextUpdate(); 157 EXPECT_TRUE(service()->timer_.IsRunning());
141 EXPECT_TRUE(service.timer_.IsRunning());
142 } 158 }
143 159
160 #if !defined(OS_CHROMEOS)
161
144 TEST_F(GAIAInfoUpdateServiceTest, LogOut) { 162 TEST_F(GAIAInfoUpdateServiceTest, LogOut) {
145 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, 163 SigninManager* signin_manager =
146 "pat@example.com"); 164 SigninManagerFactory::GetForProfile(profile());
165 signin_manager->SetAuthenticatedUsername("pat@example.com");
147 base::string16 gaia_name = base::UTF8ToUTF16("Pat Foo"); 166 base::string16 gaia_name = base::UTF8ToUTF16("Pat Foo");
148 GetCache()->SetGAIANameOfProfileAtIndex(0, gaia_name); 167 GetCache()->SetGAIANameOfProfileAtIndex(0, gaia_name);
149 gfx::Image gaia_picture = gfx::test::CreateImage(); 168 gfx::Image gaia_picture = gfx::test::CreateImage();
150 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_picture); 169 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_picture);
151 170
152 // Set a fake picture URL. 171 // Set a fake picture URL.
153 profile()->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL, 172 profile()->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL,
154 "example.com"); 173 "example.com");
155 174
156 GAIAInfoUpdateService service(profile()); 175 EXPECT_FALSE(service()->GetCachedPictureURL().empty());
157 EXPECT_FALSE(service.GetCachedPictureURL().empty()); 176
158 // Log out. 177 // Log out.
159 profile()->GetPrefs() 178 signin_manager->SignOut();
160 ->SetString(prefs::kGoogleServicesUsername, std::string());
161
162 // Verify that the GAIA name and picture, and picture URL are unset. 179 // Verify that the GAIA name and picture, and picture URL are unset.
163 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); 180 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty());
164 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); 181 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0));
165 EXPECT_TRUE(service.GetCachedPictureURL().empty()); 182 EXPECT_TRUE(service()->GetCachedPictureURL().empty());
166 } 183 }
167 184
168 TEST_F(GAIAInfoUpdateServiceTest, LogIn) { 185 TEST_F(GAIAInfoUpdateServiceTest, LogIn) {
169 profile()->GetPrefs() 186 // Log in.
170 ->SetString(prefs::kGoogleServicesUsername, std::string()); 187 EXPECT_CALL(*service(), Update());
171 GAIAInfoUpdateServiceMock service(profile()); 188 SigninManager* signin_manager =
189 SigninManagerFactory::GetForProfile(profile());
190 signin_manager->OnExternalSigninCompleted("pat@example.com");
191 }
172 192
173 // Log in. 193 #endif
174 EXPECT_CALL(service, Update());
175 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
176 "pat@example.com");
177 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/gaia_info_update_service_factory.cc ('k') | components/signin/core/browser/signin_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698