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

Side by Side Diff: chrome/browser/signin/signin_manager_unittest.cc

Issue 479353003: Add IsAuthenticated() method to SigninManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/signin/signin_global_error.cc ('k') | chrome/browser/signin/signin_promo.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/signin/core/browser/signin_manager.h" 5 #include "components/signin/core/browser/signin_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 void ShutDownManager() { 158 void ShutDownManager() {
159 DCHECK(manager_); 159 DCHECK(manager_);
160 manager_->RemoveObserver(&test_observer_); 160 manager_->RemoveObserver(&test_observer_);
161 manager_->Shutdown(); 161 manager_->Shutdown();
162 if (naked_manager_) 162 if (naked_manager_)
163 naked_manager_.reset(NULL); 163 naked_manager_.reset(NULL);
164 manager_ = NULL; 164 manager_ = NULL;
165 } 165 }
166 166
167 void ExpectSignInWithRefreshTokenSuccess() { 167 void ExpectSignInWithRefreshTokenSuccess() {
168 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty()); 168 EXPECT_TRUE(manager_->IsAuthenticated());
169 169
170 ProfileOAuth2TokenService* token_service = 170 ProfileOAuth2TokenService* token_service =
171 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()); 171 ProfileOAuth2TokenServiceFactory::GetForProfile(profile());
172 EXPECT_TRUE(token_service->RefreshTokenIsAvailable( 172 EXPECT_TRUE(token_service->RefreshTokenIsAvailable(
173 manager_->GetAuthenticatedUsername())); 173 manager_->GetAuthenticatedUsername()));
174 174
175 // Should go into token service and stop. 175 // Should go into token service and stop.
176 EXPECT_EQ(1, test_observer_.num_successful_signins_); 176 EXPECT_EQ(1, test_observer_.num_successful_signins_);
177 EXPECT_EQ(0, test_observer_.num_failed_signins_); 177 EXPECT_EQ(0, test_observer_.num_failed_signins_);
178 } 178 }
179 179
180 void CompleteSigninCallback(const std::string& oauth_token) { 180 void CompleteSigninCallback(const std::string& oauth_token) {
181 oauth_tokens_fetched_.push_back(oauth_token); 181 oauth_tokens_fetched_.push_back(oauth_token);
182 manager_->CompletePendingSignin(); 182 manager_->CompletePendingSignin();
183 } 183 }
184 184
185 content::TestBrowserThreadBundle thread_bundle_; 185 content::TestBrowserThreadBundle thread_bundle_;
186 net::TestURLFetcherFactory factory_; 186 net::TestURLFetcherFactory factory_;
187 scoped_ptr<SigninManager> naked_manager_; 187 scoped_ptr<SigninManager> naked_manager_;
188 SigninManager* manager_; 188 SigninManager* manager_;
189 TestSigninManagerObserver test_observer_; 189 TestSigninManagerObserver test_observer_;
190 scoped_ptr<TestingProfile> profile_; 190 scoped_ptr<TestingProfile> profile_;
191 std::vector<std::string> oauth_tokens_fetched_; 191 std::vector<std::string> oauth_tokens_fetched_;
192 scoped_ptr<TestingPrefServiceSimple> prefs_; 192 scoped_ptr<TestingPrefServiceSimple> prefs_;
193 std::vector<std::string> cookies_; 193 std::vector<std::string> cookies_;
194 }; 194 };
195 195
196 TEST_F(SigninManagerTest, SignInWithRefreshToken) { 196 TEST_F(SigninManagerTest, SignInWithRefreshToken) {
197 SetUpSigninManagerAsService(); 197 SetUpSigninManagerAsService();
198 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 198 EXPECT_FALSE(manager_->IsAuthenticated());
199 199
200 manager_->StartSignInWithRefreshToken( 200 manager_->StartSignInWithRefreshToken(
201 "rt1", 201 "rt1",
202 "user@gmail.com", 202 "user@gmail.com",
203 "password", 203 "password",
204 SigninManager::OAuthTokenFetchedCallback()); 204 SigninManager::OAuthTokenFetchedCallback());
205 205
206 ExpectSignInWithRefreshTokenSuccess(); 206 ExpectSignInWithRefreshTokenSuccess();
207 207
208 // Should persist across resets. 208 // Should persist across resets.
209 ShutDownManager(); 209 ShutDownManager();
210 CreateNakedSigninManager(); 210 CreateNakedSigninManager();
211 manager_->Initialize(NULL); 211 manager_->Initialize(NULL);
212 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 212 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
213 } 213 }
214 214
215 TEST_F(SigninManagerTest, SignInWithRefreshTokenCallbackComplete) { 215 TEST_F(SigninManagerTest, SignInWithRefreshTokenCallbackComplete) {
216 SetUpSigninManagerAsService(); 216 SetUpSigninManagerAsService();
217 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 217 EXPECT_FALSE(manager_->IsAuthenticated());
218 218
219 // Since the password is empty, must verify the gaia cookies first. 219 // Since the password is empty, must verify the gaia cookies first.
220 SigninManager::OAuthTokenFetchedCallback callback = 220 SigninManager::OAuthTokenFetchedCallback callback =
221 base::Bind(&SigninManagerTest::CompleteSigninCallback, 221 base::Bind(&SigninManagerTest::CompleteSigninCallback,
222 base::Unretained(this)); 222 base::Unretained(this));
223 manager_->StartSignInWithRefreshToken( 223 manager_->StartSignInWithRefreshToken(
224 "rt1", 224 "rt1",
225 "user@gmail.com", 225 "user@gmail.com",
226 "password", 226 "password",
227 callback); 227 callback);
228 228
229 ExpectSignInWithRefreshTokenSuccess(); 229 ExpectSignInWithRefreshTokenSuccess();
230 ASSERT_EQ(1U, oauth_tokens_fetched_.size()); 230 ASSERT_EQ(1U, oauth_tokens_fetched_.size());
231 EXPECT_EQ(oauth_tokens_fetched_[0], "rt1"); 231 EXPECT_EQ(oauth_tokens_fetched_[0], "rt1");
232 } 232 }
233 233
234 TEST_F(SigninManagerTest, SignOut) { 234 TEST_F(SigninManagerTest, SignOut) {
235 SetUpSigninManagerAsService(); 235 SetUpSigninManagerAsService();
236 manager_->StartSignInWithRefreshToken( 236 manager_->StartSignInWithRefreshToken(
237 "rt1", 237 "rt1",
238 "user@gmail.com", 238 "user@gmail.com",
239 "password", 239 "password",
240 SigninManager::OAuthTokenFetchedCallback()); 240 SigninManager::OAuthTokenFetchedCallback());
241 manager_->SignOut(signin_metrics::SIGNOUT_TEST); 241 manager_->SignOut(signin_metrics::SIGNOUT_TEST);
242 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 242 EXPECT_FALSE(manager_->IsAuthenticated());
243 // Should not be persisted anymore 243 // Should not be persisted anymore
244 ShutDownManager(); 244 ShutDownManager();
245 CreateNakedSigninManager(); 245 CreateNakedSigninManager();
246 manager_->Initialize(NULL); 246 manager_->Initialize(NULL);
247 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 247 EXPECT_FALSE(manager_->IsAuthenticated());
248 } 248 }
249 249
250 TEST_F(SigninManagerTest, SignOutWhileProhibited) { 250 TEST_F(SigninManagerTest, SignOutWhileProhibited) {
251 SetUpSigninManagerAsService(); 251 SetUpSigninManagerAsService();
252 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 252 EXPECT_FALSE(manager_->IsAuthenticated());
253 253
254 manager_->SetAuthenticatedUsername("user@gmail.com"); 254 manager_->SetAuthenticatedUsername("user@gmail.com");
255 manager_->ProhibitSignout(true); 255 manager_->ProhibitSignout(true);
256 manager_->SignOut(signin_metrics::SIGNOUT_TEST); 256 manager_->SignOut(signin_metrics::SIGNOUT_TEST);
257 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty()); 257 EXPECT_TRUE(manager_->IsAuthenticated());
258 manager_->ProhibitSignout(false); 258 manager_->ProhibitSignout(false);
259 manager_->SignOut(signin_metrics::SIGNOUT_TEST); 259 manager_->SignOut(signin_metrics::SIGNOUT_TEST);
260 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 260 EXPECT_FALSE(manager_->IsAuthenticated());
261 } 261 }
262 262
263 TEST_F(SigninManagerTest, TestIsWebBasedSigninFlowURL) { 263 TEST_F(SigninManagerTest, TestIsWebBasedSigninFlowURL) {
264 EXPECT_FALSE(SigninManager::IsWebBasedSigninFlowURL( 264 EXPECT_FALSE(SigninManager::IsWebBasedSigninFlowURL(
265 GURL("http://www.google.com"))); 265 GURL("http://www.google.com")));
266 EXPECT_TRUE(SigninManager::IsWebBasedSigninFlowURL( 266 EXPECT_TRUE(SigninManager::IsWebBasedSigninFlowURL(
267 GURL("https://accounts.google.com/ServiceLogin?service=chromiumsync"))); 267 GURL("https://accounts.google.com/ServiceLogin?service=chromiumsync")));
268 EXPECT_FALSE(SigninManager::IsWebBasedSigninFlowURL( 268 EXPECT_FALSE(SigninManager::IsWebBasedSigninFlowURL(
269 GURL("http://accounts.google.com/ServiceLogin?service=chromiumsync"))); 269 GURL("http://accounts.google.com/ServiceLogin?service=chromiumsync")));
270 // http, not https, should not be treated as web based signin. 270 // http, not https, should not be treated as web based signin.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername)); 341 profile()->GetPrefs()->GetString(prefs::kGoogleServicesUsername));
342 EXPECT_EQ("external@example.com", manager_->GetAuthenticatedUsername()); 342 EXPECT_EQ("external@example.com", manager_->GetAuthenticatedUsername());
343 } 343 }
344 344
345 TEST_F(SigninManagerTest, SigninNotAllowed) { 345 TEST_F(SigninManagerTest, SigninNotAllowed) {
346 std::string user("user@google.com"); 346 std::string user("user@google.com");
347 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user); 347 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user);
348 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); 348 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false);
349 SetUpSigninManagerAsService(); 349 SetUpSigninManagerAsService();
350 } 350 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/signin_global_error.cc ('k') | chrome/browser/signin/signin_promo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698