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

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

Issue 11817045: Move auth-error reporting code out of SyncGlobalError and into SigninGlobalError (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disabled ExtensionActionContextMenuTest.BrowserAction Created 7 years, 11 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/signin/signin_manager.h" 5 #include "chrome/browser/signin/signin_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 google_login_success_.ListenFor( 54 google_login_success_.ListenFor(
55 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, 55 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
56 content::Source<Profile>(profile_.get())); 56 content::Source<Profile>(profile_.get()));
57 google_login_failure_.ListenFor(chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, 57 google_login_failure_.ListenFor(chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED,
58 content::Source<Profile>(profile_.get())); 58 content::Source<Profile>(profile_.get()));
59 } 59 }
60 60
61 virtual void TearDown() OVERRIDE { 61 virtual void TearDown() OVERRIDE {
62 // Destroy the SigninManager here, because it relies on profile_ which is 62 // Destroy the SigninManager here, because it relies on profile_ which is
63 // freed in the base class. 63 // freed in the base class.
64 manager_->Shutdown();
64 manager_.reset(NULL); 65 manager_.reset(NULL);
65 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); 66 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL);
66 prefs_.reset(NULL); 67 prefs_.reset(NULL);
67 TokenServiceTestHarness::TearDown(); 68 TokenServiceTestHarness::TearDown();
68 } 69 }
69 70
70 void SetupFetcherAndComplete(const std::string& url, 71 void SetupFetcherAndComplete(const std::string& url,
71 int response_code, 72 int response_code,
72 const net::ResponseCookies& cookies, 73 const net::ResponseCookies& cookies,
73 const std::string& response_string) { 74 const std::string& response_string) {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 202
202 SimulateValidResponseClientLogin(true); 203 SimulateValidResponseClientLogin(true);
203 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty()); 204 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty());
204 EXPECT_TRUE(profile_->GetPrefs()->GetBoolean(prefs::kIsGooglePlusUser)); 205 EXPECT_TRUE(profile_->GetPrefs()->GetBoolean(prefs::kIsGooglePlusUser));
205 206
206 // Should go into token service and stop. 207 // Should go into token service and stop.
207 EXPECT_EQ(1U, google_login_success_.size()); 208 EXPECT_EQ(1U, google_login_success_.size());
208 EXPECT_EQ(0U, google_login_failure_.size()); 209 EXPECT_EQ(0U, google_login_failure_.size());
209 210
210 // Should persist across resets. 211 // Should persist across resets.
212 manager_->Shutdown();
211 manager_.reset(new SigninManager()); 213 manager_.reset(new SigninManager());
212 manager_->Initialize(profile_.get()); 214 manager_->Initialize(profile_.get());
213 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 215 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
214 } 216 }
215 217
216 TEST_F(SigninManagerTest, Prohibited) { 218 TEST_F(SigninManagerTest, Prohibited) {
217 g_browser_process->local_state()->SetString( 219 g_browser_process->local_state()->SetString(
218 prefs::kGoogleServicesUsernamePattern, ".*@google.com"); 220 prefs::kGoogleServicesUsernamePattern, ".*@google.com");
219 manager_->Initialize(profile_.get()); 221 manager_->Initialize(profile_.get());
220 EXPECT_TRUE(manager_->IsAllowedUsername("test@google.com")); 222 EXPECT_TRUE(manager_->IsAllowedUsername("test@google.com"));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 272
271 // This is flow, the oauth2 credentials should already be available in 273 // This is flow, the oauth2 credentials should already be available in
272 // the token service. 274 // the token service.
273 EXPECT_TRUE(service_->HasOAuthLoginToken()); 275 EXPECT_TRUE(service_->HasOAuthLoginToken());
274 276
275 // Should go into token service and stop. 277 // Should go into token service and stop.
276 EXPECT_EQ(1U, google_login_success_.size()); 278 EXPECT_EQ(1U, google_login_success_.size());
277 EXPECT_EQ(0U, google_login_failure_.size()); 279 EXPECT_EQ(0U, google_login_failure_.size());
278 280
279 // Should persist across resets. 281 // Should persist across resets.
282 manager_->Shutdown();
280 manager_.reset(new SigninManager()); 283 manager_.reset(new SigninManager());
281 manager_->Initialize(profile_.get()); 284 manager_->Initialize(profile_.get());
282 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 285 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
283 } 286 }
284 287
285 TEST_F(SigninManagerTest, SignInWithCredentialsWrongEmail) { 288 TEST_F(SigninManagerTest, SignInWithCredentialsWrongEmail) {
286 manager_->Initialize(profile_.get()); 289 manager_->Initialize(profile_.get());
287 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 290 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
288 291
289 // If the email address used to start the sign in does not match the 292 // If the email address used to start the sign in does not match the
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // Now clear the in memory data. 336 // Now clear the in memory data.
334 manager_->ClearTransientSigninData(); 337 manager_->ClearTransientSigninData();
335 EXPECT_TRUE(manager_->last_result_.data.empty()); 338 EXPECT_TRUE(manager_->last_result_.data.empty());
336 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty()); 339 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty());
337 340
338 // Ensure preferences are not modified. 341 // Ensure preferences are not modified.
339 EXPECT_FALSE( 342 EXPECT_FALSE(
340 profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername).empty()); 343 profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername).empty());
341 344
342 // On reset it should be regenerated. 345 // On reset it should be regenerated.
346 manager_->Shutdown();
343 manager_.reset(new SigninManager()); 347 manager_.reset(new SigninManager());
344 manager_->Initialize(profile_.get()); 348 manager_->Initialize(profile_.get());
345 349
346 // Now make sure we have the right user name. 350 // Now make sure we have the right user name.
347 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 351 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
348 } 352 }
349 353
350 TEST_F(SigninManagerTest, SignOutClientLogin) { 354 TEST_F(SigninManagerTest, SignOutClientLogin) {
351 manager_->Initialize(profile_.get()); 355 manager_->Initialize(profile_.get());
352 manager_->StartSignIn("username", "password", "", ""); 356 manager_->StartSignIn("username", "password", "", "");
353 SimulateValidResponseClientLogin(false); 357 SimulateValidResponseClientLogin(false);
354 manager_->OnClientLoginSuccess(credentials_); 358 manager_->OnClientLoginSuccess(credentials_);
355 359
356 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 360 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
357 manager_->SignOut(); 361 manager_->SignOut();
358 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 362 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
359 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kIsGooglePlusUser)); 363 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kIsGooglePlusUser));
360 // Should not be persisted anymore 364 // Should not be persisted anymore
365 manager_->Shutdown();
361 manager_.reset(new SigninManager()); 366 manager_.reset(new SigninManager());
362 manager_->Initialize(profile_.get()); 367 manager_->Initialize(profile_.get());
363 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 368 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
364 } 369 }
365 370
366 TEST_F(SigninManagerTest, SignInFailureClientLogin) { 371 TEST_F(SigninManagerTest, SignInFailureClientLogin) {
367 manager_->Initialize(profile_.get()); 372 manager_->Initialize(profile_.get());
368 manager_->StartSignIn("username", "password", "", ""); 373 manager_->StartSignIn("username", "password", "", "");
369 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); 374 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED);
370 manager_->OnClientLoginFailure(error); 375 manager_->OnClientLoginFailure(error);
371 376
372 EXPECT_EQ(0U, google_login_success_.size()); 377 EXPECT_EQ(0U, google_login_success_.size());
373 EXPECT_EQ(1U, google_login_failure_.size()); 378 EXPECT_EQ(1U, google_login_failure_.size());
374 379
375 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 380 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
376 381
377 // Should not be persisted 382 // Should not be persisted
383 manager_->Shutdown();
378 manager_.reset(new SigninManager()); 384 manager_.reset(new SigninManager());
379 manager_->Initialize(profile_.get()); 385 manager_->Initialize(profile_.get());
380 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 386 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
381 } 387 }
382 388
383 TEST_F(SigninManagerTest, ProvideSecondFactorSuccess) { 389 TEST_F(SigninManagerTest, ProvideSecondFactorSuccess) {
384 manager_->Initialize(profile_.get()); 390 manager_->Initialize(profile_.get());
385 manager_->StartSignIn("username", "password", "", ""); 391 manager_->StartSignIn("username", "password", "", "");
386 GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR); 392 GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR);
387 manager_->OnClientLoginFailure(error); 393 manager_->OnClientLoginFailure(error);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 490
485 manager_->ProvideOAuthChallengeResponse( 491 manager_->ProvideOAuthChallengeResponse(
486 GoogleServiceAuthError::CAPTCHA_REQUIRED, "token", "solution"); 492 GoogleServiceAuthError::CAPTCHA_REQUIRED, "token", "solution");
487 493
488 SimulateProvideOAuthChallengeResponseValid(); 494 SimulateProvideOAuthChallengeResponseValid();
489 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 495 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
490 496
491 EXPECT_EQ(1U, google_login_success_.size()); 497 EXPECT_EQ(1U, google_login_success_.size());
492 EXPECT_EQ(1U, google_login_failure_.size()); 498 EXPECT_EQ(1U, google_login_failure_.size());
493 } 499 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/signin_manager_fake.cc ('k') | chrome/browser/sync/profile_sync_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698