| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/mutable_profile_oauth2_token_service_delegate.h" | 5 #include "chrome/browser/signin/mutable_profile_oauth2_token_service_delegate.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 oauth2_service_delegate_->RevokeAllCredentials(); | 275 oauth2_service_delegate_->RevokeAllCredentials(); |
| 276 EXPECT_EQ(0, token_available_count_); | 276 EXPECT_EQ(0, token_available_count_); |
| 277 EXPECT_EQ(1, token_revoked_count_); | 277 EXPECT_EQ(1, token_revoked_count_); |
| 278 EXPECT_EQ(0, tokens_loaded_count_); | 278 EXPECT_EQ(0, tokens_loaded_count_); |
| 279 EXPECT_EQ(1, start_batch_changes_); | 279 EXPECT_EQ(1, start_batch_changes_); |
| 280 EXPECT_EQ(1, end_batch_changes_); | 280 EXPECT_EQ(1, end_batch_changes_); |
| 281 ResetObserverCounts(); | 281 ResetObserverCounts(); |
| 282 } | 282 } |
| 283 | 283 |
| 284 TEST_F(MutableProfileOAuth2TokenServiceDelegateTest, | 284 TEST_F(MutableProfileOAuth2TokenServiceDelegateTest, |
| 285 LoadCredentialsStateEmptyPrimaryAccountId) { |
| 286 // Ensure DB is clean. |
| 287 oauth2_service_delegate_->RevokeAllCredentials(); |
| 288 |
| 289 EXPECT_EQ(OAuth2TokenServiceDelegate::LOAD_CREDENTIALS_NOT_STARTED, |
| 290 oauth2_service_delegate_->GetLoadCredentialsState()); |
| 291 oauth2_service_delegate_->LoadCredentials(""); |
| 292 EXPECT_EQ(OAuth2TokenServiceDelegate::LOAD_CREDENTIALS_FINISHED_WITH_SUCCESS, |
| 293 oauth2_service_delegate_->GetLoadCredentialsState()); |
| 294 } |
| 295 |
| 296 TEST_F(MutableProfileOAuth2TokenServiceDelegateTest, |
| 285 PersistenceLoadCredentials) { | 297 PersistenceLoadCredentials) { |
| 286 switches::EnableAccountConsistencyForTesting( | 298 switches::EnableAccountConsistencyForTesting( |
| 287 base::CommandLine::ForCurrentProcess()); | 299 base::CommandLine::ForCurrentProcess()); |
| 288 | 300 |
| 289 // Ensure DB is clean. | 301 // Ensure DB is clean. |
| 290 oauth2_service_delegate_->RevokeAllCredentials(); | 302 oauth2_service_delegate_->RevokeAllCredentials(); |
| 291 ResetObserverCounts(); | 303 ResetObserverCounts(); |
| 292 // Perform a load from an empty DB. | 304 // Perform a load from an empty DB. |
| 305 EXPECT_EQ(OAuth2TokenServiceDelegate::LOAD_CREDENTIALS_NOT_STARTED, |
| 306 oauth2_service_delegate_->GetLoadCredentialsState()); |
| 293 oauth2_service_delegate_->LoadCredentials("account_id"); | 307 oauth2_service_delegate_->LoadCredentials("account_id"); |
| 308 EXPECT_EQ(OAuth2TokenServiceDelegate::LOAD_CREDENTIALS_IN_PROGRESS, |
| 309 oauth2_service_delegate_->GetLoadCredentialsState()); |
| 294 base::RunLoop().RunUntilIdle(); | 310 base::RunLoop().RunUntilIdle(); |
| 311 EXPECT_EQ(OAuth2TokenServiceDelegate::LOAD_CREDENTIALS_FINISHED_WITH_SUCCESS, |
| 312 oauth2_service_delegate_->GetLoadCredentialsState()); |
| 295 EXPECT_EQ(1, start_batch_changes_); | 313 EXPECT_EQ(1, start_batch_changes_); |
| 296 EXPECT_EQ(1, end_batch_changes_); | 314 EXPECT_EQ(1, end_batch_changes_); |
| 297 ExpectOneTokensLoadedNotification(); | 315 ExpectOneTokensLoadedNotification(); |
| 298 // LoadCredentials() guarantees that the account given to it as argument | 316 // LoadCredentials() guarantees that the account given to it as argument |
| 299 // is in the refresh_token map. | 317 // is in the refresh_token map. |
| 300 EXPECT_EQ(1U, oauth2_service_delegate_->refresh_tokens_.size()); | 318 EXPECT_EQ(1U, oauth2_service_delegate_->refresh_tokens_.size()); |
| 301 EXPECT_TRUE(oauth2_service_delegate_->refresh_tokens_["account_id"] | 319 EXPECT_TRUE(oauth2_service_delegate_->refresh_tokens_["account_id"] |
| 302 ->refresh_token() | 320 ->refresh_token() |
| 303 .empty()); | 321 .empty()); |
| 304 // Setup a DB with tokens that don't require upgrade and clear memory. | 322 // Setup a DB with tokens that don't require upgrade and clear memory. |
| 305 oauth2_service_delegate_->UpdateCredentials("account_id", "refresh_token"); | 323 oauth2_service_delegate_->UpdateCredentials("account_id", "refresh_token"); |
| 306 oauth2_service_delegate_->UpdateCredentials("account_id2", "refresh_token2"); | 324 oauth2_service_delegate_->UpdateCredentials("account_id2", "refresh_token2"); |
| 307 oauth2_service_delegate_->refresh_tokens_.clear(); | 325 oauth2_service_delegate_->refresh_tokens_.clear(); |
| 308 EXPECT_EQ(2, start_batch_changes_); | 326 EXPECT_EQ(2, start_batch_changes_); |
| 309 EXPECT_EQ(2, end_batch_changes_); | 327 EXPECT_EQ(2, end_batch_changes_); |
| 310 ResetObserverCounts(); | 328 ResetObserverCounts(); |
| 311 | 329 |
| 312 oauth2_service_delegate_->LoadCredentials("account_id"); | 330 oauth2_service_delegate_->LoadCredentials("account_id"); |
| 331 EXPECT_EQ(OAuth2TokenServiceDelegate::LOAD_CREDENTIALS_IN_PROGRESS, |
| 332 oauth2_service_delegate_->GetLoadCredentialsState()); |
| 313 base::RunLoop().RunUntilIdle(); | 333 base::RunLoop().RunUntilIdle(); |
| 334 EXPECT_EQ(OAuth2TokenServiceDelegate::LOAD_CREDENTIALS_FINISHED_WITH_SUCCESS, |
| 335 oauth2_service_delegate_->GetLoadCredentialsState()); |
| 314 EXPECT_EQ(2, token_available_count_); | 336 EXPECT_EQ(2, token_available_count_); |
| 315 EXPECT_EQ(0, token_revoked_count_); | 337 EXPECT_EQ(0, token_revoked_count_); |
| 316 EXPECT_EQ(1, tokens_loaded_count_); | 338 EXPECT_EQ(1, tokens_loaded_count_); |
| 317 EXPECT_EQ(1, start_batch_changes_); | 339 EXPECT_EQ(1, start_batch_changes_); |
| 318 EXPECT_EQ(1, end_batch_changes_); | 340 EXPECT_EQ(1, end_batch_changes_); |
| 319 ResetObserverCounts(); | 341 ResetObserverCounts(); |
| 320 | 342 |
| 321 // TODO(fgorski): Enable below when implemented: | 343 // TODO(fgorski): Enable below when implemented: |
| 322 // EXPECT_TRUE(oauth2_servive_->RefreshTokenIsAvailable("account_id")); | 344 // EXPECT_TRUE(oauth2_servive_->RefreshTokenIsAvailable("account_id")); |
| 323 EXPECT_TRUE(oauth2_service_delegate_->RefreshTokenIsAvailable("account_id2")); | 345 EXPECT_TRUE(oauth2_service_delegate_->RefreshTokenIsAvailable("account_id2")); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 EXPECT_EQ(1, tokens_loaded_count_); | 711 EXPECT_EQ(1, tokens_loaded_count_); |
| 690 EXPECT_EQ(2, token_available_count_); | 712 EXPECT_EQ(2, token_available_count_); |
| 691 EXPECT_EQ(0, token_revoked_count_); | 713 EXPECT_EQ(0, token_revoked_count_); |
| 692 EXPECT_EQ(1, start_batch_changes_); | 714 EXPECT_EQ(1, start_batch_changes_); |
| 693 EXPECT_EQ(1, end_batch_changes_); | 715 EXPECT_EQ(1, end_batch_changes_); |
| 694 EXPECT_TRUE( | 716 EXPECT_TRUE( |
| 695 oauth2_service_delegate_->RefreshTokenIsAvailable(primary_account)); | 717 oauth2_service_delegate_->RefreshTokenIsAvailable(primary_account)); |
| 696 EXPECT_TRUE( | 718 EXPECT_TRUE( |
| 697 oauth2_service_delegate_->RefreshTokenIsAvailable(secondary_account)); | 719 oauth2_service_delegate_->RefreshTokenIsAvailable(secondary_account)); |
| 698 } | 720 } |
| OLD | NEW |