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

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

Issue 11886079: Revert 177136 due to memory error on Mac ASAN (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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();
65 manager_.reset(NULL); 64 manager_.reset(NULL);
66 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); 65 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL);
67 prefs_.reset(NULL); 66 prefs_.reset(NULL);
68 TokenServiceTestHarness::TearDown(); 67 TokenServiceTestHarness::TearDown();
69 } 68 }
70 69
71 void SetupFetcherAndComplete(const std::string& url, 70 void SetupFetcherAndComplete(const std::string& url,
72 int response_code, 71 int response_code,
73 const net::ResponseCookies& cookies, 72 const net::ResponseCookies& cookies,
74 const std::string& response_string) { 73 const std::string& response_string) {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 201
203 SimulateValidResponseClientLogin(true); 202 SimulateValidResponseClientLogin(true);
204 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty()); 203 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty());
205 EXPECT_TRUE(profile_->GetPrefs()->GetBoolean(prefs::kIsGooglePlusUser)); 204 EXPECT_TRUE(profile_->GetPrefs()->GetBoolean(prefs::kIsGooglePlusUser));
206 205
207 // Should go into token service and stop. 206 // Should go into token service and stop.
208 EXPECT_EQ(1U, google_login_success_.size()); 207 EXPECT_EQ(1U, google_login_success_.size());
209 EXPECT_EQ(0U, google_login_failure_.size()); 208 EXPECT_EQ(0U, google_login_failure_.size());
210 209
211 // Should persist across resets. 210 // Should persist across resets.
212 manager_->Shutdown();
213 manager_.reset(new SigninManager()); 211 manager_.reset(new SigninManager());
214 manager_->Initialize(profile_.get()); 212 manager_->Initialize(profile_.get());
215 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 213 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
216 } 214 }
217 215
218 TEST_F(SigninManagerTest, Prohibited) { 216 TEST_F(SigninManagerTest, Prohibited) {
219 g_browser_process->local_state()->SetString( 217 g_browser_process->local_state()->SetString(
220 prefs::kGoogleServicesUsernamePattern, ".*@google.com"); 218 prefs::kGoogleServicesUsernamePattern, ".*@google.com");
221 manager_->Initialize(profile_.get()); 219 manager_->Initialize(profile_.get());
222 EXPECT_TRUE(manager_->IsAllowedUsername("test@google.com")); 220 EXPECT_TRUE(manager_->IsAllowedUsername("test@google.com"));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 270
273 // This is flow, the oauth2 credentials should already be available in 271 // This is flow, the oauth2 credentials should already be available in
274 // the token service. 272 // the token service.
275 EXPECT_TRUE(service_->HasOAuthLoginToken()); 273 EXPECT_TRUE(service_->HasOAuthLoginToken());
276 274
277 // Should go into token service and stop. 275 // Should go into token service and stop.
278 EXPECT_EQ(1U, google_login_success_.size()); 276 EXPECT_EQ(1U, google_login_success_.size());
279 EXPECT_EQ(0U, google_login_failure_.size()); 277 EXPECT_EQ(0U, google_login_failure_.size());
280 278
281 // Should persist across resets. 279 // Should persist across resets.
282 manager_->Shutdown();
283 manager_.reset(new SigninManager()); 280 manager_.reset(new SigninManager());
284 manager_->Initialize(profile_.get()); 281 manager_->Initialize(profile_.get());
285 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 282 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
286 } 283 }
287 284
288 TEST_F(SigninManagerTest, SignInWithCredentialsWrongEmail) { 285 TEST_F(SigninManagerTest, SignInWithCredentialsWrongEmail) {
289 manager_->Initialize(profile_.get()); 286 manager_->Initialize(profile_.get());
290 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 287 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
291 288
292 // If the email address used to start the sign in does not match the 289 // 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
336 // Now clear the in memory data. 333 // Now clear the in memory data.
337 manager_->ClearTransientSigninData(); 334 manager_->ClearTransientSigninData();
338 EXPECT_TRUE(manager_->last_result_.data.empty()); 335 EXPECT_TRUE(manager_->last_result_.data.empty());
339 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty()); 336 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty());
340 337
341 // Ensure preferences are not modified. 338 // Ensure preferences are not modified.
342 EXPECT_FALSE( 339 EXPECT_FALSE(
343 profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername).empty()); 340 profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername).empty());
344 341
345 // On reset it should be regenerated. 342 // On reset it should be regenerated.
346 manager_->Shutdown();
347 manager_.reset(new SigninManager()); 343 manager_.reset(new SigninManager());
348 manager_->Initialize(profile_.get()); 344 manager_->Initialize(profile_.get());
349 345
350 // Now make sure we have the right user name. 346 // Now make sure we have the right user name.
351 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 347 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
352 } 348 }
353 349
354 TEST_F(SigninManagerTest, SignOutClientLogin) { 350 TEST_F(SigninManagerTest, SignOutClientLogin) {
355 manager_->Initialize(profile_.get()); 351 manager_->Initialize(profile_.get());
356 manager_->StartSignIn("username", "password", "", ""); 352 manager_->StartSignIn("username", "password", "", "");
357 SimulateValidResponseClientLogin(false); 353 SimulateValidResponseClientLogin(false);
358 manager_->OnClientLoginSuccess(credentials_); 354 manager_->OnClientLoginSuccess(credentials_);
359 355
360 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 356 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
361 manager_->SignOut(); 357 manager_->SignOut();
362 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 358 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
363 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kIsGooglePlusUser)); 359 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kIsGooglePlusUser));
364 // Should not be persisted anymore 360 // Should not be persisted anymore
365 manager_->Shutdown();
366 manager_.reset(new SigninManager()); 361 manager_.reset(new SigninManager());
367 manager_->Initialize(profile_.get()); 362 manager_->Initialize(profile_.get());
368 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 363 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
369 } 364 }
370 365
371 TEST_F(SigninManagerTest, SignInFailureClientLogin) { 366 TEST_F(SigninManagerTest, SignInFailureClientLogin) {
372 manager_->Initialize(profile_.get()); 367 manager_->Initialize(profile_.get());
373 manager_->StartSignIn("username", "password", "", ""); 368 manager_->StartSignIn("username", "password", "", "");
374 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); 369 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED);
375 manager_->OnClientLoginFailure(error); 370 manager_->OnClientLoginFailure(error);
376 371
377 EXPECT_EQ(0U, google_login_success_.size()); 372 EXPECT_EQ(0U, google_login_success_.size());
378 EXPECT_EQ(1U, google_login_failure_.size()); 373 EXPECT_EQ(1U, google_login_failure_.size());
379 374
380 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 375 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
381 376
382 // Should not be persisted 377 // Should not be persisted
383 manager_->Shutdown();
384 manager_.reset(new SigninManager()); 378 manager_.reset(new SigninManager());
385 manager_->Initialize(profile_.get()); 379 manager_->Initialize(profile_.get());
386 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 380 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
387 } 381 }
388 382
389 TEST_F(SigninManagerTest, ProvideSecondFactorSuccess) { 383 TEST_F(SigninManagerTest, ProvideSecondFactorSuccess) {
390 manager_->Initialize(profile_.get()); 384 manager_->Initialize(profile_.get());
391 manager_->StartSignIn("username", "password", "", ""); 385 manager_->StartSignIn("username", "password", "", "");
392 GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR); 386 GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR);
393 manager_->OnClientLoginFailure(error); 387 manager_->OnClientLoginFailure(error);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 484
491 manager_->ProvideOAuthChallengeResponse( 485 manager_->ProvideOAuthChallengeResponse(
492 GoogleServiceAuthError::CAPTCHA_REQUIRED, "token", "solution"); 486 GoogleServiceAuthError::CAPTCHA_REQUIRED, "token", "solution");
493 487
494 SimulateProvideOAuthChallengeResponseValid(); 488 SimulateProvideOAuthChallengeResponseValid();
495 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 489 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
496 490
497 EXPECT_EQ(1U, google_login_success_.size()); 491 EXPECT_EQ(1U, google_login_success_.size());
498 EXPECT_EQ(1U, google_login_failure_.size()); 492 EXPECT_EQ(1U, google_login_failure_.size());
499 } 493 }
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