| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/api/identity/account_tracker.h" | 5 #include "google_apis/gaia/account_tracker.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 11 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 12 #include "google_apis/gaia/fake_identity_provider.h" |
| 12 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 13 #include "google_apis/gaia/fake_oauth2_token_service.h" |
| 13 #include "chrome/browser/signin/fake_signin_manager.h" | |
| 14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | |
| 15 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 16 #include "chrome/test/base/testing_profile.h" | |
| 17 #include "components/signin/core/browser/signin_manager_base.h" | |
| 18 #include "content/public/test/test_browser_thread_bundle.h" | |
| 19 #include "google_apis/gaia/gaia_oauth_client.h" | 14 #include "google_apis/gaia/gaia_oauth_client.h" |
| 20 #include "net/http/http_status_code.h" | 15 #include "net/http/http_status_code.h" |
| 21 #include "net/url_request/test_url_fetcher_factory.h" | 16 #include "net/url_request/test_url_fetcher_factory.h" |
| 22 #include "net/url_request/url_fetcher_delegate.h" | 17 #include "net/url_request/url_fetcher_delegate.h" |
| 23 #include "net/url_request/url_request_test_util.h" | 18 #include "net/url_request/url_request_test_util.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 20 |
| 26 // TODO(courage): Account removal really only applies to the primary account, | |
| 27 // because that's the only account tracked by the SigninManager. Many of the | |
| 28 // tests here remove non-primary accounts. They still properly test the account | |
| 29 // state machine, but it may be confusing to readers. Update these tests to | |
| 30 // avoid causing confusion. | |
| 31 | |
| 32 namespace { | 21 namespace { |
| 33 | 22 |
| 34 const char kPrimaryAccountKey[] = "primary_account@example.com"; | 23 const char kPrimaryAccountKey[] = "primary_account@example.com"; |
| 35 | 24 |
| 36 enum TrackingEventType { | 25 enum TrackingEventType { |
| 37 ADDED, | 26 ADDED, |
| 38 REMOVED, | 27 REMOVED, |
| 39 SIGN_IN, | 28 SIGN_IN, |
| 40 SIGN_OUT | 29 SIGN_OUT |
| 41 }; | 30 }; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 str += ",\n "; | 96 str += ",\n "; |
| 108 needs_comma = true; | 97 needs_comma = true; |
| 109 str += it->ToString(); | 98 str += it->ToString(); |
| 110 } | 99 } |
| 111 str += "]"; | 100 str += "]"; |
| 112 return str; | 101 return str; |
| 113 } | 102 } |
| 114 | 103 |
| 115 } // namespace | 104 } // namespace |
| 116 | 105 |
| 117 namespace extensions { | 106 namespace gaia { |
| 118 | 107 |
| 119 class AccountTrackerObserver : public AccountTracker::Observer { | 108 class AccountTrackerObserver : public AccountTracker::Observer { |
| 120 public: | 109 public: |
| 121 AccountTrackerObserver() {} | 110 AccountTrackerObserver() {} |
| 122 virtual ~AccountTrackerObserver() {} | 111 virtual ~AccountTrackerObserver() {} |
| 123 | 112 |
| 124 testing::AssertionResult CheckEvents(); | 113 testing::AssertionResult CheckEvents(); |
| 125 testing::AssertionResult CheckEvents(const TrackingEvent& e1); | 114 testing::AssertionResult CheckEvents(const TrackingEvent& e1); |
| 126 testing::AssertionResult CheckEvents(const TrackingEvent& e1, | 115 testing::AssertionResult CheckEvents(const TrackingEvent& e1, |
| 127 const TrackingEvent& e2); | 116 const TrackingEvent& e2); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 return result; | 260 return result; |
| 272 } | 261 } |
| 273 | 262 |
| 274 class IdentityAccountTrackerTest : public testing::Test { | 263 class IdentityAccountTrackerTest : public testing::Test { |
| 275 public: | 264 public: |
| 276 IdentityAccountTrackerTest() {} | 265 IdentityAccountTrackerTest() {} |
| 277 | 266 |
| 278 virtual ~IdentityAccountTrackerTest() {} | 267 virtual ~IdentityAccountTrackerTest() {} |
| 279 | 268 |
| 280 virtual void SetUp() OVERRIDE { | 269 virtual void SetUp() OVERRIDE { |
| 281 TestingProfile::Builder builder; | |
| 282 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), | |
| 283 BuildFakeProfileOAuth2TokenService); | |
| 284 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), | |
| 285 FakeSigninManagerBase::Build); | |
| 286 | 270 |
| 287 test_profile_ = builder.Build(); | 271 fake_oauth2_token_service_.reset(new FakeOAuth2TokenService()); |
| 288 | 272 |
| 289 fake_oauth2_token_service_ = static_cast<FakeProfileOAuth2TokenService*>( | 273 fake_identity_provider_.reset( |
| 290 ProfileOAuth2TokenServiceFactory::GetForProfile(test_profile_.get())); | 274 new FakeIdentityProvider(fake_oauth2_token_service_.get())); |
| 291 | 275 |
| 292 fake_signin_manager_ = static_cast<FakeSigninManagerForTesting*>( | 276 account_tracker_.reset( |
| 293 SigninManagerFactory::GetForProfile(test_profile_.get())); | 277 new AccountTracker(fake_identity_provider_.get(), |
| 294 #if defined(OS_CHROMEOS) | 278 new net::TestURLRequestContextGetter( |
| 295 // We don't sign the primary user in and out on ChromeOS, so set the | 279 message_loop_.message_loop_proxy()))); |
| 296 // username once in setup. | |
| 297 fake_signin_manager_->SetAuthenticatedUsername(kPrimaryAccountKey); | |
| 298 #endif | |
| 299 | |
| 300 account_tracker_.reset(new AccountTracker(test_profile_.get())); | |
| 301 account_tracker_->AddObserver(&observer_); | 280 account_tracker_->AddObserver(&observer_); |
| 302 | |
| 303 // Start off signed into the primary account, because most tests need the | |
| 304 // profile to be signed in. Remove the initial sign-in events that the | |
| 305 // tests don't care about. | |
| 306 NotifyTokenAvailable(kPrimaryAccountKey); | |
| 307 ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey); | |
| 308 observer()->Clear(); | |
| 309 } | 281 } |
| 310 | 282 |
| 311 virtual void TearDown() OVERRIDE { | 283 virtual void TearDown() OVERRIDE { |
| 312 account_tracker_->RemoveObserver(&observer_); | 284 account_tracker_->RemoveObserver(&observer_); |
| 313 account_tracker_->Shutdown(); | 285 account_tracker_->Shutdown(); |
| 314 } | 286 } |
| 315 | 287 |
| 316 Profile* profile() { | |
| 317 return test_profile_.get(); | |
| 318 } | |
| 319 | |
| 320 AccountTrackerObserver* observer() { | 288 AccountTrackerObserver* observer() { |
| 321 return &observer_; | 289 return &observer_; |
| 322 } | 290 } |
| 323 | 291 |
| 324 AccountTracker* account_tracker() { | 292 AccountTracker* account_tracker() { |
| 325 return account_tracker_.get(); | 293 return account_tracker_.get(); |
| 326 } | 294 } |
| 327 | 295 |
| 328 // Helpers to pass fake events to the tracker. | 296 // Helpers to pass fake events to the tracker. |
| 329 | 297 |
| 330 void NotifyRemoveAccount(const std::string& username) { | 298 void NotifyLogin(const std::string account_key) { |
| 331 #if !defined(OS_CHROMEOS) | 299 identity_provider()->LogIn(account_key); |
| 332 if (username == kPrimaryAccountKey) | |
| 333 fake_signin_manager_->SignOut(); | |
| 334 else | |
| 335 account_tracker()->GoogleSignedOut(username); | |
| 336 #else | |
| 337 account_tracker()->GoogleSignedOut(username); | |
| 338 #endif | |
| 339 } | 300 } |
| 340 | 301 |
| 302 void NotifyLogout() { identity_provider()->LogOut(); } |
| 303 |
| 341 void NotifyTokenAvailable(const std::string& username) { | 304 void NotifyTokenAvailable(const std::string& username) { |
| 342 fake_oauth2_token_service_->IssueRefreshTokenForUser(username, | 305 fake_oauth2_token_service_->AddAccount(username); |
| 343 "refresh_token"); | |
| 344 #if !defined(OS_CHROMEOS) | |
| 345 if (username == kPrimaryAccountKey) | |
| 346 fake_signin_manager_->OnExternalSigninCompleted(username); | |
| 347 #endif | |
| 348 } | 306 } |
| 349 | 307 |
| 350 void NotifyTokenRevoked(const std::string& username) { | 308 void NotifyTokenRevoked(const std::string& username) { |
| 351 fake_oauth2_token_service_->IssueRefreshTokenForUser(username, | 309 fake_oauth2_token_service_->RemoveAccount(username); |
| 352 std::string()); | |
| 353 } | 310 } |
| 354 | 311 |
| 355 // Helpers to fake access token and user info fetching | 312 // Helpers to fake access token and user info fetching |
| 356 void IssueAccessToken(const std::string& username) { | 313 void IssueAccessToken(const std::string& username) { |
| 357 fake_oauth2_token_service_->IssueAllTokensForAccount( | 314 fake_oauth2_token_service_->IssueAllTokensForAccount( |
| 358 username, "access_token-" + username, base::Time::Max()); | 315 username, "access_token-" + username, base::Time::Max()); |
| 359 } | 316 } |
| 360 | 317 |
| 361 std::string GetValidTokenInfoResponse(const std::string account_key) { | 318 std::string GetValidTokenInfoResponse(const std::string account_key) { |
| 362 return std::string("{ \"id\": \"") + AccountKeyToObfuscatedId(account_key) + | 319 return std::string("{ \"id\": \"") + AccountKeyToObfuscatedId(account_key) + |
| 363 "\" }"; | 320 "\" }"; |
| 364 } | 321 } |
| 365 | 322 |
| 366 void ReturnOAuthUrlFetchResults(int fetcher_id, | 323 void ReturnOAuthUrlFetchResults(int fetcher_id, |
| 367 net::HttpStatusCode response_code, | 324 net::HttpStatusCode response_code, |
| 368 const std::string& response_string); | 325 const std::string& response_string); |
| 369 | 326 |
| 370 void ReturnOAuthUrlFetchSuccess(const std::string& account_key); | 327 void ReturnOAuthUrlFetchSuccess(const std::string& account_key); |
| 371 void ReturnOAuthUrlFetchFailure(const std::string& account_key); | 328 void ReturnOAuthUrlFetchFailure(const std::string& account_key); |
| 372 | 329 |
| 330 void SetupPrimaryLogin() { |
| 331 // Initial setup for tests that start with a signed in profile. |
| 332 NotifyLogin(kPrimaryAccountKey); |
| 333 NotifyTokenAvailable(kPrimaryAccountKey); |
| 334 ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey); |
| 335 observer()->Clear(); |
| 336 } |
| 337 |
| 338 std::string active_account_id() { |
| 339 return identity_provider()->GetActiveAccountId(); |
| 340 } |
| 341 |
| 373 private: | 342 private: |
| 374 scoped_ptr<TestingProfile> test_profile_; | 343 FakeIdentityProvider* identity_provider() { |
| 344 return static_cast<FakeIdentityProvider*>( |
| 345 account_tracker_->identity_provider()); |
| 346 } |
| 347 |
| 348 base::MessageLoopForIO message_loop_; // net:: stuff needs IO message loop. |
| 375 net::TestURLFetcherFactory test_fetcher_factory_; | 349 net::TestURLFetcherFactory test_fetcher_factory_; |
| 376 FakeProfileOAuth2TokenService* fake_oauth2_token_service_; | 350 scoped_ptr<FakeOAuth2TokenService> fake_oauth2_token_service_; |
| 377 FakeSigninManagerForTesting* fake_signin_manager_; | 351 scoped_ptr<FakeIdentityProvider> fake_identity_provider_; |
| 378 content::TestBrowserThreadBundle thread_bundle_; | |
| 379 | 352 |
| 380 scoped_ptr<AccountTracker> account_tracker_; | 353 scoped_ptr<AccountTracker> account_tracker_; |
| 381 AccountTrackerObserver observer_; | 354 AccountTrackerObserver observer_; |
| 382 }; | 355 }; |
| 383 | 356 |
| 384 void IdentityAccountTrackerTest::ReturnOAuthUrlFetchResults( | 357 void IdentityAccountTrackerTest::ReturnOAuthUrlFetchResults( |
| 385 int fetcher_id, | 358 int fetcher_id, |
| 386 net::HttpStatusCode response_code, | 359 net::HttpStatusCode response_code, |
| 387 const std::string& response_string) { | 360 const std::string& response_string) { |
| 388 | 361 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 402 GetValidTokenInfoResponse(account_key)); | 375 GetValidTokenInfoResponse(account_key)); |
| 403 } | 376 } |
| 404 | 377 |
| 405 void IdentityAccountTrackerTest::ReturnOAuthUrlFetchFailure( | 378 void IdentityAccountTrackerTest::ReturnOAuthUrlFetchFailure( |
| 406 const std::string& account_key) { | 379 const std::string& account_key) { |
| 407 IssueAccessToken(account_key); | 380 IssueAccessToken(account_key); |
| 408 ReturnOAuthUrlFetchResults( | 381 ReturnOAuthUrlFetchResults( |
| 409 gaia::GaiaOAuthClient::kUrlFetcherId, net::HTTP_BAD_REQUEST, ""); | 382 gaia::GaiaOAuthClient::kUrlFetcherId, net::HTTP_BAD_REQUEST, ""); |
| 410 } | 383 } |
| 411 | 384 |
| 385 // Primary tests just involve the Active account |
| 386 |
| 387 TEST_F(IdentityAccountTrackerTest, PrimaryNoEventsBeforeLogin) { |
| 388 NotifyTokenAvailable(kPrimaryAccountKey); |
| 389 NotifyTokenRevoked(kPrimaryAccountKey); |
| 390 NotifyLogout(); |
| 391 EXPECT_TRUE(observer()->CheckEvents()); |
| 392 } |
| 393 |
| 394 TEST_F(IdentityAccountTrackerTest, PrimaryLoginThenTokenAvailable) { |
| 395 NotifyLogin(kPrimaryAccountKey); |
| 396 NotifyTokenAvailable(kPrimaryAccountKey); |
| 397 EXPECT_TRUE(observer()->CheckEvents()); |
| 398 |
| 399 ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey); |
| 400 EXPECT_TRUE( |
| 401 observer()->CheckEvents(TrackingEvent(ADDED, kPrimaryAccountKey), |
| 402 TrackingEvent(SIGN_IN, kPrimaryAccountKey))); |
| 403 } |
| 404 |
| 405 TEST_F(IdentityAccountTrackerTest, PrimaryTokenAvailableThenLogin) { |
| 406 NotifyTokenAvailable(kPrimaryAccountKey); |
| 407 EXPECT_TRUE(observer()->CheckEvents()); |
| 408 |
| 409 NotifyLogin(kPrimaryAccountKey); |
| 410 ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey); |
| 411 EXPECT_TRUE( |
| 412 observer()->CheckEvents(TrackingEvent(ADDED, kPrimaryAccountKey), |
| 413 TrackingEvent(SIGN_IN, kPrimaryAccountKey))); |
| 414 } |
| 415 |
| 416 TEST_F(IdentityAccountTrackerTest, PrimaryTokenAvailableAndRevokedThenLogin) { |
| 417 NotifyTokenAvailable(kPrimaryAccountKey); |
| 418 EXPECT_TRUE(observer()->CheckEvents()); |
| 419 |
| 420 NotifyLogin(kPrimaryAccountKey); |
| 421 ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey); |
| 422 EXPECT_TRUE( |
| 423 observer()->CheckEvents(TrackingEvent(ADDED, kPrimaryAccountKey), |
| 424 TrackingEvent(SIGN_IN, kPrimaryAccountKey))); |
| 425 } |
| 426 |
| 427 TEST_F(IdentityAccountTrackerTest, PrimaryRevokeThenLogout) { |
| 428 NotifyLogin(kPrimaryAccountKey); |
| 429 NotifyTokenAvailable(kPrimaryAccountKey); |
| 430 ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey); |
| 431 observer()->Clear(); |
| 432 |
| 433 NotifyTokenRevoked(kPrimaryAccountKey); |
| 434 EXPECT_TRUE( |
| 435 observer()->CheckEvents(TrackingEvent(SIGN_OUT, kPrimaryAccountKey))); |
| 436 |
| 437 NotifyLogout(); |
| 438 EXPECT_TRUE( |
| 439 observer()->CheckEvents(TrackingEvent(REMOVED, kPrimaryAccountKey))); |
| 440 } |
| 441 |
| 442 TEST_F(IdentityAccountTrackerTest, PrimaryRevokeThenLogin) { |
| 443 NotifyLogin(kPrimaryAccountKey); |
| 444 NotifyTokenAvailable(kPrimaryAccountKey); |
| 445 ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey); |
| 446 NotifyTokenRevoked(kPrimaryAccountKey); |
| 447 observer()->Clear(); |
| 448 |
| 449 NotifyLogin(kPrimaryAccountKey); |
| 450 EXPECT_TRUE(observer()->CheckEvents()); |
| 451 } |
| 452 |
| 453 TEST_F(IdentityAccountTrackerTest, PrimaryRevokeThenTokenAvailable) { |
| 454 NotifyLogin(kPrimaryAccountKey); |
| 455 NotifyTokenAvailable(kPrimaryAccountKey); |
| 456 ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey); |
| 457 NotifyTokenRevoked(kPrimaryAccountKey); |
| 458 observer()->Clear(); |
| 459 |
| 460 NotifyTokenAvailable(kPrimaryAccountKey); |
| 461 EXPECT_TRUE( |
| 462 observer()->CheckEvents(TrackingEvent(SIGN_IN, kPrimaryAccountKey))); |
| 463 } |
| 464 |
| 465 TEST_F(IdentityAccountTrackerTest, PrimaryLogoutThenRevoke) { |
| 466 NotifyLogin(kPrimaryAccountKey); |
| 467 NotifyTokenAvailable(kPrimaryAccountKey); |
| 468 ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey); |
| 469 observer()->Clear(); |
| 470 |
| 471 NotifyLogout(); |
| 472 EXPECT_TRUE( |
| 473 observer()->CheckEvents(TrackingEvent(SIGN_OUT, kPrimaryAccountKey), |
| 474 TrackingEvent(REMOVED, kPrimaryAccountKey))); |
| 475 |
| 476 NotifyTokenRevoked(kPrimaryAccountKey); |
| 477 EXPECT_TRUE(observer()->CheckEvents()); |
| 478 } |
| 479 |
| 480 TEST_F(IdentityAccountTrackerTest, PrimaryLogoutFetchCancelAvailable) { |
| 481 NotifyLogin(kPrimaryAccountKey); |
| 482 NotifyTokenAvailable(kPrimaryAccountKey); |
| 483 // TokenAvailable kicks off a fetch. Logout without satisfying it. |
| 484 NotifyLogout(); |
| 485 EXPECT_TRUE(observer()->CheckEvents()); |
| 486 |
| 487 NotifyLogin(kPrimaryAccountKey); |
| 488 NotifyTokenAvailable(kPrimaryAccountKey); |
| 489 ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey); |
| 490 EXPECT_TRUE(observer()->CheckEvents( |
| 491 TrackingEvent(ADDED, kPrimaryAccountKey), |
| 492 TrackingEvent(SIGN_IN, kPrimaryAccountKey))); |
| 493 } |
| 494 |
| 495 // Non-primary accounts |
| 496 |
| 412 TEST_F(IdentityAccountTrackerTest, Available) { | 497 TEST_F(IdentityAccountTrackerTest, Available) { |
| 498 SetupPrimaryLogin(); |
| 499 |
| 413 NotifyTokenAvailable("user@example.com"); | 500 NotifyTokenAvailable("user@example.com"); |
| 414 EXPECT_TRUE(observer()->CheckEvents()); | 501 EXPECT_TRUE(observer()->CheckEvents()); |
| 415 | 502 |
| 416 ReturnOAuthUrlFetchSuccess("user@example.com"); | 503 ReturnOAuthUrlFetchSuccess("user@example.com"); |
| 417 EXPECT_TRUE(observer()->CheckEvents( | 504 EXPECT_TRUE(observer()->CheckEvents( |
| 418 TrackingEvent(ADDED, "user@example.com"), | 505 TrackingEvent(ADDED, "user@example.com"), |
| 419 TrackingEvent(SIGN_IN, "user@example.com"))); | 506 TrackingEvent(SIGN_IN, "user@example.com"))); |
| 420 } | 507 } |
| 421 | 508 |
| 422 TEST_F(IdentityAccountTrackerTest, Revoke) { | 509 TEST_F(IdentityAccountTrackerTest, Revoke) { |
| 510 SetupPrimaryLogin(); |
| 511 |
| 423 account_tracker()->OnRefreshTokenRevoked("user@example.com"); | 512 account_tracker()->OnRefreshTokenRevoked("user@example.com"); |
| 424 EXPECT_TRUE(observer()->CheckEvents()); | 513 EXPECT_TRUE(observer()->CheckEvents()); |
| 425 } | 514 } |
| 426 | 515 |
| 427 TEST_F(IdentityAccountTrackerTest, Remove) { | 516 TEST_F(IdentityAccountTrackerTest, AvailableRevokeAvailable) { |
| 428 NotifyRemoveAccount("user@example.com"); | 517 SetupPrimaryLogin(); |
| 429 EXPECT_TRUE(observer()->CheckEvents()); | |
| 430 } | |
| 431 | |
| 432 TEST_F(IdentityAccountTrackerTest, AvailableRemoveFetchCancelAvailable) { | |
| 433 NotifyTokenAvailable("user@example.com"); | |
| 434 NotifyRemoveAccount("user@example.com"); | |
| 435 EXPECT_TRUE(observer()->CheckEvents()); | |
| 436 | 518 |
| 437 NotifyTokenAvailable("user@example.com"); | 519 NotifyTokenAvailable("user@example.com"); |
| 438 ReturnOAuthUrlFetchSuccess("user@example.com"); | 520 ReturnOAuthUrlFetchSuccess("user@example.com"); |
| 439 EXPECT_TRUE(observer()->CheckEvents( | |
| 440 TrackingEvent(ADDED, "user@example.com"), | |
| 441 TrackingEvent(SIGN_IN, "user@example.com"))); | |
| 442 } | |
| 443 | |
| 444 TEST_F(IdentityAccountTrackerTest, AvailableRemoveAvailable) { | |
| 445 NotifyTokenAvailable("user@example.com"); | |
| 446 ReturnOAuthUrlFetchSuccess("user@example.com"); | |
| 447 NotifyRemoveAccount("user@example.com"); | |
| 448 EXPECT_TRUE(observer()->CheckEvents( | |
| 449 TrackingEvent(ADDED, "user@example.com"), | |
| 450 TrackingEvent(SIGN_IN, "user@example.com"), | |
| 451 TrackingEvent(SIGN_OUT, "user@example.com"), | |
| 452 TrackingEvent(REMOVED, "user@example.com"))); | |
| 453 | |
| 454 NotifyTokenAvailable("user@example.com"); | |
| 455 ReturnOAuthUrlFetchSuccess("user@example.com"); | |
| 456 EXPECT_TRUE(observer()->CheckEvents( | |
| 457 TrackingEvent(ADDED, "user@example.com"), | |
| 458 TrackingEvent(SIGN_IN, "user@example.com"))); | |
| 459 } | |
| 460 | |
| 461 TEST_F(IdentityAccountTrackerTest, AvailableRevokeAvailable) { | |
| 462 NotifyTokenAvailable("user@example.com"); | |
| 463 ReturnOAuthUrlFetchSuccess("user@example.com"); | |
| 464 NotifyTokenRevoked("user@example.com"); | 521 NotifyTokenRevoked("user@example.com"); |
| 465 EXPECT_TRUE(observer()->CheckEvents( | 522 EXPECT_TRUE(observer()->CheckEvents( |
| 466 TrackingEvent(ADDED, "user@example.com"), | 523 TrackingEvent(ADDED, "user@example.com"), |
| 467 TrackingEvent(SIGN_IN, "user@example.com"), | 524 TrackingEvent(SIGN_IN, "user@example.com"), |
| 468 TrackingEvent(SIGN_OUT, "user@example.com"))); | 525 TrackingEvent(SIGN_OUT, "user@example.com"))); |
| 469 | 526 |
| 470 NotifyTokenAvailable("user@example.com"); | 527 NotifyTokenAvailable("user@example.com"); |
| 471 EXPECT_TRUE(observer()->CheckEvents( | 528 EXPECT_TRUE(observer()->CheckEvents( |
| 472 TrackingEvent(SIGN_IN, "user@example.com"))); | 529 TrackingEvent(SIGN_IN, "user@example.com"))); |
| 473 } | 530 } |
| 474 | 531 |
| 475 TEST_F(IdentityAccountTrackerTest, AvailableRevokeAvailableWithPendingFetch) { | 532 TEST_F(IdentityAccountTrackerTest, AvailableRevokeAvailableWithPendingFetch) { |
| 533 SetupPrimaryLogin(); |
| 534 |
| 476 NotifyTokenAvailable("user@example.com"); | 535 NotifyTokenAvailable("user@example.com"); |
| 477 NotifyTokenRevoked("user@example.com"); | 536 NotifyTokenRevoked("user@example.com"); |
| 478 EXPECT_TRUE(observer()->CheckEvents()); | 537 EXPECT_TRUE(observer()->CheckEvents()); |
| 479 | 538 |
| 480 NotifyTokenAvailable("user@example.com"); | 539 NotifyTokenAvailable("user@example.com"); |
| 481 ReturnOAuthUrlFetchSuccess("user@example.com"); | 540 ReturnOAuthUrlFetchSuccess("user@example.com"); |
| 482 EXPECT_TRUE(observer()->CheckEvents( | 541 EXPECT_TRUE(observer()->CheckEvents( |
| 483 TrackingEvent(ADDED, "user@example.com"), | 542 TrackingEvent(ADDED, "user@example.com"), |
| 484 TrackingEvent(SIGN_IN, "user@example.com"))); | 543 TrackingEvent(SIGN_IN, "user@example.com"))); |
| 485 } | 544 } |
| 486 | 545 |
| 487 TEST_F(IdentityAccountTrackerTest, AvailableRevokeRemove) { | 546 TEST_F(IdentityAccountTrackerTest, AvailableRevokeRevoke) { |
| 547 SetupPrimaryLogin(); |
| 548 |
| 488 NotifyTokenAvailable("user@example.com"); | 549 NotifyTokenAvailable("user@example.com"); |
| 489 ReturnOAuthUrlFetchSuccess("user@example.com"); | 550 ReturnOAuthUrlFetchSuccess("user@example.com"); |
| 490 NotifyTokenRevoked("user@example.com"); | 551 NotifyTokenRevoked("user@example.com"); |
| 491 EXPECT_TRUE(observer()->CheckEvents( | |
| 492 TrackingEvent(ADDED, "user@example.com"), | |
| 493 TrackingEvent(SIGN_IN, "user@example.com"), | |
| 494 TrackingEvent(SIGN_OUT, "user@example.com"))); | |
| 495 | |
| 496 NotifyRemoveAccount("user@example.com"); | |
| 497 EXPECT_TRUE(observer()->CheckEvents( | |
| 498 TrackingEvent(REMOVED, "user@example.com"))); | |
| 499 } | |
| 500 | |
| 501 TEST_F(IdentityAccountTrackerTest, AvailableRevokeRevoke) { | |
| 502 NotifyTokenAvailable("user@example.com"); | |
| 503 ReturnOAuthUrlFetchSuccess("user@example.com"); | |
| 504 NotifyTokenRevoked("user@example.com"); | |
| 505 EXPECT_TRUE(observer()->CheckEvents( | 552 EXPECT_TRUE(observer()->CheckEvents( |
| 506 TrackingEvent(ADDED, "user@example.com"), | 553 TrackingEvent(ADDED, "user@example.com"), |
| 507 TrackingEvent(SIGN_IN, "user@example.com"), | 554 TrackingEvent(SIGN_IN, "user@example.com"), |
| 508 TrackingEvent(SIGN_OUT, "user@example.com"))); | 555 TrackingEvent(SIGN_OUT, "user@example.com"))); |
| 509 | 556 |
| 510 NotifyTokenRevoked("user@example.com"); | 557 NotifyTokenRevoked("user@example.com"); |
| 511 EXPECT_TRUE(observer()->CheckEvents()); | 558 EXPECT_TRUE(observer()->CheckEvents()); |
| 512 } | 559 } |
| 513 | 560 |
| 514 TEST_F(IdentityAccountTrackerTest, AvailableAvailable) { | 561 TEST_F(IdentityAccountTrackerTest, AvailableAvailable) { |
| 562 SetupPrimaryLogin(); |
| 563 |
| 515 NotifyTokenAvailable("user@example.com"); | 564 NotifyTokenAvailable("user@example.com"); |
| 516 ReturnOAuthUrlFetchSuccess("user@example.com"); | 565 ReturnOAuthUrlFetchSuccess("user@example.com"); |
| 517 EXPECT_TRUE(observer()->CheckEvents( | 566 EXPECT_TRUE(observer()->CheckEvents( |
| 518 TrackingEvent(ADDED, "user@example.com"), | 567 TrackingEvent(ADDED, "user@example.com"), |
| 519 TrackingEvent(SIGN_IN, "user@example.com"))); | 568 TrackingEvent(SIGN_IN, "user@example.com"))); |
| 520 | 569 |
| 521 NotifyTokenAvailable("user@example.com"); | 570 NotifyTokenAvailable("user@example.com"); |
| 522 EXPECT_TRUE(observer()->CheckEvents()); | 571 EXPECT_TRUE(observer()->CheckEvents()); |
| 523 } | 572 } |
| 524 | 573 |
| 525 TEST_F(IdentityAccountTrackerTest, TwoAccounts) { | 574 TEST_F(IdentityAccountTrackerTest, TwoAccounts) { |
| 575 SetupPrimaryLogin(); |
| 576 |
| 526 NotifyTokenAvailable("alpha@example.com"); | 577 NotifyTokenAvailable("alpha@example.com"); |
| 527 ReturnOAuthUrlFetchSuccess("alpha@example.com"); | 578 ReturnOAuthUrlFetchSuccess("alpha@example.com"); |
| 528 EXPECT_TRUE(observer()->CheckEvents( | 579 EXPECT_TRUE(observer()->CheckEvents( |
| 529 TrackingEvent(ADDED, "alpha@example.com"), | 580 TrackingEvent(ADDED, "alpha@example.com"), |
| 530 TrackingEvent(SIGN_IN, "alpha@example.com"))); | 581 TrackingEvent(SIGN_IN, "alpha@example.com"))); |
| 531 | 582 |
| 532 NotifyTokenAvailable("beta@example.com"); | 583 NotifyTokenAvailable("beta@example.com"); |
| 533 ReturnOAuthUrlFetchSuccess("beta@example.com"); | 584 ReturnOAuthUrlFetchSuccess("beta@example.com"); |
| 534 EXPECT_TRUE(observer()->CheckEvents( | 585 EXPECT_TRUE(observer()->CheckEvents( |
| 535 TrackingEvent(ADDED, "beta@example.com"), | 586 TrackingEvent(ADDED, "beta@example.com"), |
| 536 TrackingEvent(SIGN_IN, "beta@example.com"))); | 587 TrackingEvent(SIGN_IN, "beta@example.com"))); |
| 537 | 588 |
| 538 NotifyRemoveAccount("alpha@example.com"); | 589 NotifyTokenRevoked("alpha@example.com"); |
| 539 EXPECT_TRUE(observer()->CheckEvents( | 590 EXPECT_TRUE( |
| 540 TrackingEvent(SIGN_OUT, "alpha@example.com"), | 591 observer()->CheckEvents(TrackingEvent(SIGN_OUT, "alpha@example.com"))); |
| 541 TrackingEvent(REMOVED, "alpha@example.com"))); | |
| 542 | 592 |
| 543 NotifyRemoveAccount("beta@example.com"); | 593 NotifyTokenRevoked("beta@example.com"); |
| 544 EXPECT_TRUE(observer()->CheckEvents( | |
| 545 TrackingEvent(SIGN_OUT, "beta@example.com"), | |
| 546 TrackingEvent(REMOVED, "beta@example.com"))); | |
| 547 } | |
| 548 | |
| 549 TEST_F(IdentityAccountTrackerTest, GlobalErrors) { | |
| 550 NotifyTokenAvailable("alpha@example.com"); | |
| 551 ReturnOAuthUrlFetchSuccess("alpha@example.com"); | |
| 552 EXPECT_TRUE(observer()->CheckEvents( | |
| 553 TrackingEvent(ADDED, "alpha@example.com"), | |
| 554 TrackingEvent(SIGN_IN, "alpha@example.com"))); | |
| 555 NotifyTokenAvailable("beta@example.com"); | |
| 556 ReturnOAuthUrlFetchSuccess("beta@example.com"); | |
| 557 EXPECT_TRUE(observer()->CheckEvents( | |
| 558 TrackingEvent(ADDED, "beta@example.com"), | |
| 559 TrackingEvent(SIGN_IN, "beta@example.com"))); | |
| 560 | |
| 561 EXPECT_EQ(GoogleServiceAuthError::AuthErrorNone(), | |
| 562 account_tracker()->GetAuthStatus()); | |
| 563 | |
| 564 account_tracker()->ReportAuthError( | |
| 565 "beta@example.com", | |
| 566 GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED)); | |
| 567 EXPECT_TRUE(observer()->CheckEvents( | 594 EXPECT_TRUE(observer()->CheckEvents( |
| 568 TrackingEvent(SIGN_OUT, "beta@example.com"))); | 595 TrackingEvent(SIGN_OUT, "beta@example.com"))); |
| 569 EXPECT_EQ(GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED), | |
| 570 account_tracker()->GetAuthStatus()); | |
| 571 | |
| 572 account_tracker()->ReportAuthError( | |
| 573 "alpha@example.com", | |
| 574 GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED)); | |
| 575 EXPECT_TRUE(observer()->CheckEvents( | |
| 576 TrackingEvent(SIGN_OUT, "alpha@example.com"))); | |
| 577 EXPECT_EQ(GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED), | |
| 578 account_tracker()->GetAuthStatus()); | |
| 579 | |
| 580 NotifyRemoveAccount("alpha@example.com"); | |
| 581 EXPECT_EQ(GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED), | |
| 582 account_tracker()->GetAuthStatus()); | |
| 583 | |
| 584 NotifyTokenAvailable("beta@example.com"); | |
| 585 EXPECT_EQ(GoogleServiceAuthError::AuthErrorNone(), | |
| 586 account_tracker()->GetAuthStatus()); | |
| 587 } | 596 } |
| 588 | 597 |
| 589 TEST_F(IdentityAccountTrackerTest, AvailableTokenFetchFailAvailable) { | 598 TEST_F(IdentityAccountTrackerTest, AvailableTokenFetchFailAvailable) { |
| 590 NotifyTokenAvailable("alpha@example.com"); | 599 SetupPrimaryLogin(); |
| 591 ReturnOAuthUrlFetchFailure("alpha@example.com"); | 600 |
| 601 NotifyTokenAvailable("user@example.com"); |
| 602 ReturnOAuthUrlFetchFailure("user@example.com"); |
| 592 EXPECT_TRUE(observer()->CheckEvents()); | 603 EXPECT_TRUE(observer()->CheckEvents()); |
| 593 | 604 |
| 594 NotifyTokenAvailable("user@example.com"); | 605 NotifyTokenAvailable("user@example.com"); |
| 595 ReturnOAuthUrlFetchSuccess("user@example.com"); | 606 ReturnOAuthUrlFetchSuccess("user@example.com"); |
| 596 EXPECT_TRUE(observer()->CheckEvents( | 607 EXPECT_TRUE(observer()->CheckEvents( |
| 597 TrackingEvent(ADDED, "user@example.com"), | 608 TrackingEvent(ADDED, "user@example.com"), |
| 598 TrackingEvent(SIGN_IN, "user@example.com"))); | 609 TrackingEvent(SIGN_IN, "user@example.com"))); |
| 599 } | 610 } |
| 600 | 611 |
| 601 // The Chrome OS fake sign-in manager doesn't do sign-in or sign-out. | 612 TEST_F(IdentityAccountTrackerTest, MultiSignOutSignIn) { |
| 602 #if !defined(OS_CHROMEOS) | 613 SetupPrimaryLogin(); |
| 603 | 614 |
| 604 TEST_F(IdentityAccountTrackerTest, PrimarySignOutSignIn) { | |
| 605 NotifyRemoveAccount(kPrimaryAccountKey); | |
| 606 EXPECT_TRUE(observer()->CheckEvents( | |
| 607 TrackingEvent(SIGN_OUT, kPrimaryAccountKey), | |
| 608 TrackingEvent(REMOVED, kPrimaryAccountKey))); | |
| 609 | |
| 610 NotifyTokenAvailable(kPrimaryAccountKey); | |
| 611 ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey); | |
| 612 EXPECT_TRUE(observer()->CheckEvents( | |
| 613 TrackingEvent(ADDED, kPrimaryAccountKey), | |
| 614 TrackingEvent(SIGN_IN, kPrimaryAccountKey))); | |
| 615 } | |
| 616 | |
| 617 TEST_F(IdentityAccountTrackerTest, PrimarySignOutSignInTwoAccounts) { | |
| 618 NotifyTokenAvailable("alpha@example.com"); | 615 NotifyTokenAvailable("alpha@example.com"); |
| 619 ReturnOAuthUrlFetchSuccess("alpha@example.com"); | 616 ReturnOAuthUrlFetchSuccess("alpha@example.com"); |
| 620 NotifyTokenAvailable("beta@example.com"); | 617 NotifyTokenAvailable("beta@example.com"); |
| 621 ReturnOAuthUrlFetchSuccess("beta@example.com"); | 618 ReturnOAuthUrlFetchSuccess("beta@example.com"); |
| 622 | 619 |
| 623 observer()->SortEventsByUser(); | 620 observer()->SortEventsByUser(); |
| 624 EXPECT_TRUE(observer()->CheckEvents( | 621 EXPECT_TRUE(observer()->CheckEvents( |
| 625 TrackingEvent(ADDED, "alpha@example.com"), | 622 TrackingEvent(ADDED, "alpha@example.com"), |
| 626 TrackingEvent(SIGN_IN, "alpha@example.com"), | 623 TrackingEvent(SIGN_IN, "alpha@example.com"), |
| 627 TrackingEvent(ADDED, "beta@example.com"), | 624 TrackingEvent(ADDED, "beta@example.com"), |
| 628 TrackingEvent(SIGN_IN, "beta@example.com"))); | 625 TrackingEvent(SIGN_IN, "beta@example.com"))); |
| 629 | 626 |
| 630 NotifyRemoveAccount(kPrimaryAccountKey); | 627 NotifyLogout(); |
| 631 observer()->SortEventsByUser(); | 628 observer()->SortEventsByUser(); |
| 632 EXPECT_TRUE(observer()->CheckEvents( | 629 EXPECT_TRUE(observer()->CheckEvents( |
| 633 TrackingEvent(SIGN_OUT, "alpha@example.com"), | 630 TrackingEvent(SIGN_OUT, "alpha@example.com"), |
| 634 TrackingEvent(REMOVED, "alpha@example.com"), | 631 TrackingEvent(REMOVED, "alpha@example.com"), |
| 635 TrackingEvent(SIGN_OUT, "beta@example.com"), | 632 TrackingEvent(SIGN_OUT, "beta@example.com"), |
| 636 TrackingEvent(REMOVED, "beta@example.com"), | 633 TrackingEvent(REMOVED, "beta@example.com"), |
| 637 TrackingEvent(SIGN_OUT, kPrimaryAccountKey), | 634 TrackingEvent(SIGN_OUT, kPrimaryAccountKey), |
| 638 TrackingEvent(REMOVED, kPrimaryAccountKey))); | 635 TrackingEvent(REMOVED, kPrimaryAccountKey))); |
| 639 | 636 |
| 640 // No events fire at all while profile is signed out. | 637 // No events fire at all while profile is signed out. |
| 641 NotifyTokenRevoked("alpha@example.com"); | 638 NotifyTokenRevoked("alpha@example.com"); |
| 642 NotifyTokenAvailable("gamma@example.com"); | 639 NotifyTokenAvailable("gamma@example.com"); |
| 643 EXPECT_TRUE(observer()->CheckEvents()); | 640 EXPECT_TRUE(observer()->CheckEvents()); |
| 644 | 641 |
| 645 // Signing the profile in again will resume tracking all accounts. | 642 // Signing the profile in again will resume tracking all accounts. |
| 643 NotifyLogin(kPrimaryAccountKey); |
| 646 NotifyTokenAvailable(kPrimaryAccountKey); | 644 NotifyTokenAvailable(kPrimaryAccountKey); |
| 647 ReturnOAuthUrlFetchSuccess("beta@example.com"); | 645 ReturnOAuthUrlFetchSuccess("beta@example.com"); |
| 648 ReturnOAuthUrlFetchSuccess("gamma@example.com"); | 646 ReturnOAuthUrlFetchSuccess("gamma@example.com"); |
| 649 ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey); | 647 ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey); |
| 650 observer()->SortEventsByUser(); | 648 observer()->SortEventsByUser(); |
| 651 EXPECT_TRUE(observer()->CheckEvents( | 649 EXPECT_TRUE(observer()->CheckEvents( |
| 652 TrackingEvent(ADDED, "beta@example.com"), | 650 TrackingEvent(ADDED, "beta@example.com"), |
| 653 TrackingEvent(SIGN_IN, "beta@example.com"), | 651 TrackingEvent(SIGN_IN, "beta@example.com"), |
| 654 TrackingEvent(ADDED, "gamma@example.com"), | 652 TrackingEvent(ADDED, "gamma@example.com"), |
| 655 TrackingEvent(SIGN_IN, "gamma@example.com"), | 653 TrackingEvent(SIGN_IN, "gamma@example.com"), |
| 656 TrackingEvent(ADDED, kPrimaryAccountKey), | 654 TrackingEvent(ADDED, kPrimaryAccountKey), |
| 657 TrackingEvent(SIGN_IN, kPrimaryAccountKey))); | 655 TrackingEvent(SIGN_IN, kPrimaryAccountKey))); |
| 658 | 656 |
| 659 // Revoking the primary token does not affect other accounts. | 657 // Revoking the primary token does not affect other accounts. |
| 660 NotifyTokenRevoked(kPrimaryAccountKey); | 658 NotifyTokenRevoked(kPrimaryAccountKey); |
| 661 EXPECT_TRUE(observer()->CheckEvents( | 659 EXPECT_TRUE(observer()->CheckEvents( |
| 662 TrackingEvent(SIGN_OUT, kPrimaryAccountKey))); | 660 TrackingEvent(SIGN_OUT, kPrimaryAccountKey))); |
| 663 | 661 |
| 664 NotifyTokenAvailable(kPrimaryAccountKey); | 662 NotifyTokenAvailable(kPrimaryAccountKey); |
| 665 EXPECT_TRUE(observer()->CheckEvents( | 663 EXPECT_TRUE(observer()->CheckEvents( |
| 666 TrackingEvent(SIGN_IN, kPrimaryAccountKey))); | 664 TrackingEvent(SIGN_IN, kPrimaryAccountKey))); |
| 667 } | 665 } |
| 668 | 666 |
| 669 #endif // !defined(OS_CHROMEOS) | 667 // Primary/non-primary interactions |
| 668 |
| 669 TEST_F(IdentityAccountTrackerTest, MultiNoEventsBeforeLogin) { |
| 670 NotifyTokenAvailable(kPrimaryAccountKey); |
| 671 NotifyTokenAvailable("user@example.com"); |
| 672 NotifyTokenRevoked("user@example.com"); |
| 673 NotifyTokenRevoked(kPrimaryAccountKey); |
| 674 NotifyLogout(); |
| 675 EXPECT_TRUE(observer()->CheckEvents()); |
| 676 } |
| 677 |
| 678 TEST_F(IdentityAccountTrackerTest, MultiLogoutRemovesAllAccounts) { |
| 679 NotifyLogin(kPrimaryAccountKey); |
| 680 NotifyTokenAvailable(kPrimaryAccountKey); |
| 681 ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey); |
| 682 NotifyTokenAvailable("user@example.com"); |
| 683 ReturnOAuthUrlFetchSuccess("user@example.com"); |
| 684 observer()->Clear(); |
| 685 |
| 686 NotifyLogout(); |
| 687 observer()->SortEventsByUser(); |
| 688 EXPECT_TRUE( |
| 689 observer()->CheckEvents(TrackingEvent(SIGN_OUT, kPrimaryAccountKey), |
| 690 TrackingEvent(REMOVED, kPrimaryAccountKey), |
| 691 TrackingEvent(SIGN_OUT, "user@example.com"), |
| 692 TrackingEvent(REMOVED, "user@example.com"))); |
| 693 } |
| 694 |
| 695 TEST_F(IdentityAccountTrackerTest, MultiRevokePrimaryDoesNotRemoveAllAccounts) { |
| 696 NotifyLogin(kPrimaryAccountKey); |
| 697 NotifyTokenAvailable(kPrimaryAccountKey); |
| 698 ReturnOAuthUrlFetchSuccess(kPrimaryAccountKey); |
| 699 NotifyTokenAvailable("user@example.com"); |
| 700 ReturnOAuthUrlFetchSuccess("user@example.com"); |
| 701 observer()->Clear(); |
| 702 |
| 703 NotifyTokenRevoked(kPrimaryAccountKey); |
| 704 observer()->SortEventsByUser(); |
| 705 EXPECT_TRUE( |
| 706 observer()->CheckEvents(TrackingEvent(SIGN_OUT, kPrimaryAccountKey))); |
| 707 } |
| 670 | 708 |
| 671 TEST_F(IdentityAccountTrackerTest, GetAccountsPrimary) { | 709 TEST_F(IdentityAccountTrackerTest, GetAccountsPrimary) { |
| 710 SetupPrimaryLogin(); |
| 711 |
| 672 std::vector<AccountIds> ids = account_tracker()->GetAccounts(); | 712 std::vector<AccountIds> ids = account_tracker()->GetAccounts(); |
| 673 EXPECT_EQ(1ul, ids.size()); | 713 EXPECT_EQ(1ul, ids.size()); |
| 674 EXPECT_EQ(kPrimaryAccountKey, ids[0].account_key); | 714 EXPECT_EQ(kPrimaryAccountKey, ids[0].account_key); |
| 675 EXPECT_EQ(AccountKeyToObfuscatedId(kPrimaryAccountKey), ids[0].gaia); | 715 EXPECT_EQ(AccountKeyToObfuscatedId(kPrimaryAccountKey), ids[0].gaia); |
| 676 } | 716 } |
| 677 | 717 |
| 678 TEST_F(IdentityAccountTrackerTest, GetAccountsSignedOut) { | 718 TEST_F(IdentityAccountTrackerTest, GetAccountsSignedOut) { |
| 679 NotifyTokenRevoked(kPrimaryAccountKey); | |
| 680 | |
| 681 std::vector<AccountIds> ids = account_tracker()->GetAccounts(); | 719 std::vector<AccountIds> ids = account_tracker()->GetAccounts(); |
| 682 EXPECT_EQ(0ul, ids.size()); | 720 EXPECT_EQ(0ul, ids.size()); |
| 683 } | 721 } |
| 684 | 722 |
| 685 TEST_F(IdentityAccountTrackerTest, GetAccountsOnlyReturnAccountsWithTokens) { | 723 TEST_F(IdentityAccountTrackerTest, GetAccountsOnlyReturnAccountsWithTokens) { |
| 724 SetupPrimaryLogin(); |
| 725 |
| 686 NotifyTokenAvailable("alpha@example.com"); | 726 NotifyTokenAvailable("alpha@example.com"); |
| 687 NotifyTokenAvailable("beta@example.com"); | 727 NotifyTokenAvailable("beta@example.com"); |
| 688 ReturnOAuthUrlFetchSuccess("beta@example.com"); | 728 ReturnOAuthUrlFetchSuccess("beta@example.com"); |
| 689 | 729 |
| 690 std::vector<AccountIds> ids = account_tracker()->GetAccounts(); | 730 std::vector<AccountIds> ids = account_tracker()->GetAccounts(); |
| 691 EXPECT_EQ(2ul, ids.size()); | 731 EXPECT_EQ(2ul, ids.size()); |
| 692 EXPECT_EQ(kPrimaryAccountKey, ids[0].account_key); | 732 EXPECT_EQ(kPrimaryAccountKey, ids[0].account_key); |
| 693 EXPECT_EQ(AccountKeyToObfuscatedId(kPrimaryAccountKey), ids[0].gaia); | 733 EXPECT_EQ(AccountKeyToObfuscatedId(kPrimaryAccountKey), ids[0].gaia); |
| 694 EXPECT_EQ("beta@example.com", ids[1].account_key); | 734 EXPECT_EQ("beta@example.com", ids[1].account_key); |
| 695 EXPECT_EQ(AccountKeyToObfuscatedId("beta@example.com"), ids[1].gaia); | 735 EXPECT_EQ(AccountKeyToObfuscatedId("beta@example.com"), ids[1].gaia); |
| 696 } | 736 } |
| 697 | 737 |
| 698 TEST_F(IdentityAccountTrackerTest, GetAccountsSortOrder) { | 738 TEST_F(IdentityAccountTrackerTest, GetAccountsSortOrder) { |
| 739 SetupPrimaryLogin(); |
| 740 |
| 699 NotifyTokenAvailable("zeta@example.com"); | 741 NotifyTokenAvailable("zeta@example.com"); |
| 700 ReturnOAuthUrlFetchSuccess("zeta@example.com"); | 742 ReturnOAuthUrlFetchSuccess("zeta@example.com"); |
| 701 NotifyTokenAvailable("alpha@example.com"); | 743 NotifyTokenAvailable("alpha@example.com"); |
| 702 ReturnOAuthUrlFetchSuccess("alpha@example.com"); | 744 ReturnOAuthUrlFetchSuccess("alpha@example.com"); |
| 703 | 745 |
| 704 // The primary account will be first in the vector. Remaining accounts | 746 // The primary account will be first in the vector. Remaining accounts |
| 705 // will be sorted by gaia ID. | 747 // will be sorted by gaia ID. |
| 706 std::vector<AccountIds> ids = account_tracker()->GetAccounts(); | 748 std::vector<AccountIds> ids = account_tracker()->GetAccounts(); |
| 707 EXPECT_EQ(3ul, ids.size()); | 749 EXPECT_EQ(3ul, ids.size()); |
| 708 EXPECT_EQ(kPrimaryAccountKey, ids[0].account_key); | 750 EXPECT_EQ(kPrimaryAccountKey, ids[0].account_key); |
| 709 EXPECT_EQ(AccountKeyToObfuscatedId(kPrimaryAccountKey), ids[0].gaia); | 751 EXPECT_EQ(AccountKeyToObfuscatedId(kPrimaryAccountKey), ids[0].gaia); |
| 710 EXPECT_EQ("alpha@example.com", ids[1].account_key); | 752 EXPECT_EQ("alpha@example.com", ids[1].account_key); |
| 711 EXPECT_EQ(AccountKeyToObfuscatedId("alpha@example.com"), ids[1].gaia); | 753 EXPECT_EQ(AccountKeyToObfuscatedId("alpha@example.com"), ids[1].gaia); |
| 712 EXPECT_EQ("zeta@example.com", ids[2].account_key); | 754 EXPECT_EQ("zeta@example.com", ids[2].account_key); |
| 713 EXPECT_EQ(AccountKeyToObfuscatedId("zeta@example.com"), ids[2].gaia); | 755 EXPECT_EQ(AccountKeyToObfuscatedId("zeta@example.com"), ids[2].gaia); |
| 714 } | 756 } |
| 715 | 757 |
| 716 TEST_F(IdentityAccountTrackerTest, | 758 TEST_F(IdentityAccountTrackerTest, |
| 717 GetAccountsReturnNothingWhenPrimarySignedOut) { | 759 GetAccountsReturnNothingWhenPrimarySignedOut) { |
| 760 SetupPrimaryLogin(); |
| 761 |
| 718 NotifyTokenAvailable("zeta@example.com"); | 762 NotifyTokenAvailable("zeta@example.com"); |
| 719 ReturnOAuthUrlFetchSuccess("zeta@example.com"); | 763 ReturnOAuthUrlFetchSuccess("zeta@example.com"); |
| 720 NotifyTokenAvailable("alpha@example.com"); | 764 NotifyTokenAvailable("alpha@example.com"); |
| 721 ReturnOAuthUrlFetchSuccess("alpha@example.com"); | 765 ReturnOAuthUrlFetchSuccess("alpha@example.com"); |
| 722 | 766 |
| 723 NotifyTokenRevoked(kPrimaryAccountKey); | 767 NotifyTokenRevoked(kPrimaryAccountKey); |
| 724 | 768 |
| 725 std::vector<AccountIds> ids = account_tracker()->GetAccounts(); | 769 std::vector<AccountIds> ids = account_tracker()->GetAccounts(); |
| 726 EXPECT_EQ(0ul, ids.size()); | 770 EXPECT_EQ(0ul, ids.size()); |
| 727 } | 771 } |
| 728 | 772 |
| 729 } // namespace extensions | 773 TEST_F(IdentityAccountTrackerTest, FindAccountIdsByGaiaIdPrimary) { |
| 774 SetupPrimaryLogin(); |
| 775 |
| 776 AccountIds ids = account_tracker()->FindAccountIdsByGaiaId( |
| 777 AccountKeyToObfuscatedId(kPrimaryAccountKey)); |
| 778 EXPECT_EQ(kPrimaryAccountKey, ids.account_key); |
| 779 EXPECT_EQ(kPrimaryAccountKey, ids.email); |
| 780 EXPECT_EQ(AccountKeyToObfuscatedId(kPrimaryAccountKey), ids.gaia); |
| 781 } |
| 782 |
| 783 TEST_F(IdentityAccountTrackerTest, FindAccountIdsByGaiaIdNotFound) { |
| 784 SetupPrimaryLogin(); |
| 785 |
| 786 AccountIds ids = account_tracker()->FindAccountIdsByGaiaId( |
| 787 AccountKeyToObfuscatedId("notfound@example.com")); |
| 788 EXPECT_TRUE(ids.account_key.empty()); |
| 789 EXPECT_TRUE(ids.email.empty()); |
| 790 EXPECT_TRUE(ids.gaia.empty()); |
| 791 } |
| 792 |
| 793 TEST_F(IdentityAccountTrackerTest, |
| 794 FindAccountIdsByGaiaIdReturnEmptyWhenPrimarySignedOut) { |
| 795 SetupPrimaryLogin(); |
| 796 |
| 797 NotifyTokenAvailable("zeta@example.com"); |
| 798 ReturnOAuthUrlFetchSuccess("zeta@example.com"); |
| 799 NotifyTokenAvailable("alpha@example.com"); |
| 800 ReturnOAuthUrlFetchSuccess("alpha@example.com"); |
| 801 |
| 802 NotifyTokenRevoked(kPrimaryAccountKey); |
| 803 |
| 804 AccountIds ids = |
| 805 account_tracker()->FindAccountIdsByGaiaId(kPrimaryAccountKey); |
| 806 EXPECT_TRUE(ids.account_key.empty()); |
| 807 EXPECT_TRUE(ids.email.empty()); |
| 808 EXPECT_TRUE(ids.gaia.empty()); |
| 809 |
| 810 ids = account_tracker()->FindAccountIdsByGaiaId("alpha@example.com"); |
| 811 EXPECT_TRUE(ids.account_key.empty()); |
| 812 EXPECT_TRUE(ids.email.empty()); |
| 813 EXPECT_TRUE(ids.gaia.empty()); |
| 814 } |
| 815 |
| 816 } // namespace gaia |
| OLD | NEW |