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 <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/memory/ptr_util.h" |
12 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
13 #include "build/build_config.h" | 15 #include "build/build_config.h" |
14 #include "components/os_crypt/os_crypt_mocker.h" | 16 #include "components/os_crypt/os_crypt_mocker.h" |
15 #include "components/prefs/pref_registry_simple.h" | 17 #include "components/prefs/pref_registry_simple.h" |
16 #include "components/prefs/scoped_user_pref_update.h" | 18 #include "components/prefs/scoped_user_pref_update.h" |
17 #include "components/prefs/testing_pref_service.h" | 19 #include "components/prefs/testing_pref_service.h" |
18 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 20 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
19 #include "components/signin/core/browser/signin_error_controller.h" | 21 #include "components/signin/core/browser/signin_error_controller.h" |
20 #include "components/signin/core/browser/test_signin_client.h" | 22 #include "components/signin/core/browser/test_signin_client.h" |
21 #include "components/signin/core/browser/webdata/token_web_data.h" | 23 #include "components/signin/core/browser/webdata/token_web_data.h" |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 std::string gaia_id = "foo's gaia id"; | 535 std::string gaia_id = "foo's gaia id"; |
534 | 536 |
535 switches::EnableAccountConsistencyForTesting( | 537 switches::EnableAccountConsistencyForTesting( |
536 base::CommandLine::ForCurrentProcess()); | 538 base::CommandLine::ForCurrentProcess()); |
537 pref_service_.SetInteger(prefs::kAccountIdMigrationState, | 539 pref_service_.SetInteger(prefs::kAccountIdMigrationState, |
538 AccountTrackerService::MIGRATION_NOT_STARTED); | 540 AccountTrackerService::MIGRATION_NOT_STARTED); |
539 | 541 |
540 ListPrefUpdate update(&pref_service_, | 542 ListPrefUpdate update(&pref_service_, |
541 AccountTrackerService::kAccountInfoPref); | 543 AccountTrackerService::kAccountInfoPref); |
542 update->Clear(); | 544 update->Clear(); |
543 base::DictionaryValue* dict = new base::DictionaryValue(); | 545 auto dict = base::MakeUnique<base::DictionaryValue>(); |
544 update->Append(dict); | |
545 dict->SetString("account_id", base::UTF8ToUTF16(email)); | 546 dict->SetString("account_id", base::UTF8ToUTF16(email)); |
546 dict->SetString("email", base::UTF8ToUTF16(email)); | 547 dict->SetString("email", base::UTF8ToUTF16(email)); |
547 dict->SetString("gaia", base::UTF8ToUTF16(gaia_id)); | 548 dict->SetString("gaia", base::UTF8ToUTF16(gaia_id)); |
| 549 update->Append(std::move(dict)); |
548 account_tracker_service_.Shutdown(); | 550 account_tracker_service_.Shutdown(); |
549 account_tracker_service_.Initialize(client_.get()); | 551 account_tracker_service_.Initialize(client_.get()); |
550 | 552 |
551 AddAuthTokenManually("AccountId-" + email, "refresh_token"); | 553 AddAuthTokenManually("AccountId-" + email, "refresh_token"); |
552 oauth2_service_delegate_->LoadCredentials(gaia_id); | 554 oauth2_service_delegate_->LoadCredentials(gaia_id); |
553 base::RunLoop().RunUntilIdle(); | 555 base::RunLoop().RunUntilIdle(); |
554 | 556 |
555 EXPECT_EQ(1, tokens_loaded_count_); | 557 EXPECT_EQ(1, tokens_loaded_count_); |
556 EXPECT_EQ(1, token_available_count_); | 558 EXPECT_EQ(1, token_available_count_); |
557 EXPECT_EQ(1, start_batch_changes_); | 559 EXPECT_EQ(1, start_batch_changes_); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 std::string gaia_id2 = "bar's gaia id"; | 594 std::string gaia_id2 = "bar's gaia id"; |
593 | 595 |
594 switches::EnableAccountConsistencyForTesting( | 596 switches::EnableAccountConsistencyForTesting( |
595 base::CommandLine::ForCurrentProcess()); | 597 base::CommandLine::ForCurrentProcess()); |
596 pref_service_.SetInteger(prefs::kAccountIdMigrationState, | 598 pref_service_.SetInteger(prefs::kAccountIdMigrationState, |
597 AccountTrackerService::MIGRATION_NOT_STARTED); | 599 AccountTrackerService::MIGRATION_NOT_STARTED); |
598 | 600 |
599 ListPrefUpdate update(&pref_service_, | 601 ListPrefUpdate update(&pref_service_, |
600 AccountTrackerService::kAccountInfoPref); | 602 AccountTrackerService::kAccountInfoPref); |
601 update->Clear(); | 603 update->Clear(); |
602 base::DictionaryValue* dict = new base::DictionaryValue(); | 604 auto dict = base::MakeUnique<base::DictionaryValue>(); |
603 update->Append(dict); | |
604 dict->SetString("account_id", base::UTF8ToUTF16(email1)); | 605 dict->SetString("account_id", base::UTF8ToUTF16(email1)); |
605 dict->SetString("email", base::UTF8ToUTF16(email1)); | 606 dict->SetString("email", base::UTF8ToUTF16(email1)); |
606 dict->SetString("gaia", base::UTF8ToUTF16(gaia_id1)); | 607 dict->SetString("gaia", base::UTF8ToUTF16(gaia_id1)); |
607 dict = new base::DictionaryValue(); | 608 update->Append(std::move(dict)); |
608 update->Append(dict); | 609 dict = base::MakeUnique<base::DictionaryValue>(); |
609 dict->SetString("account_id", base::UTF8ToUTF16(email2)); | 610 dict->SetString("account_id", base::UTF8ToUTF16(email2)); |
610 dict->SetString("email", base::UTF8ToUTF16(email2)); | 611 dict->SetString("email", base::UTF8ToUTF16(email2)); |
611 dict->SetString("gaia", base::UTF8ToUTF16(gaia_id2)); | 612 dict->SetString("gaia", base::UTF8ToUTF16(gaia_id2)); |
| 613 update->Append(std::move(dict)); |
612 account_tracker_service_.Shutdown(); | 614 account_tracker_service_.Shutdown(); |
613 account_tracker_service_.Initialize(client_.get()); | 615 account_tracker_service_.Initialize(client_.get()); |
614 | 616 |
615 AddAuthTokenManually("AccountId-" + email1, "refresh_token"); | 617 AddAuthTokenManually("AccountId-" + email1, "refresh_token"); |
616 AddAuthTokenManually("AccountId-" + email2, "refresh_token"); | 618 AddAuthTokenManually("AccountId-" + email2, "refresh_token"); |
617 AddAuthTokenManually("AccountId-" + gaia_id1, "refresh_token"); | 619 AddAuthTokenManually("AccountId-" + gaia_id1, "refresh_token"); |
618 oauth2_service_delegate_->LoadCredentials(gaia_id1); | 620 oauth2_service_delegate_->LoadCredentials(gaia_id1); |
619 base::RunLoop().RunUntilIdle(); | 621 base::RunLoop().RunUntilIdle(); |
620 | 622 |
621 EXPECT_EQ(1, tokens_loaded_count_); | 623 EXPECT_EQ(1, tokens_loaded_count_); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 EXPECT_EQ(1, tokens_loaded_count_); | 688 EXPECT_EQ(1, tokens_loaded_count_); |
687 EXPECT_EQ(2, token_available_count_); | 689 EXPECT_EQ(2, token_available_count_); |
688 EXPECT_EQ(0, token_revoked_count_); | 690 EXPECT_EQ(0, token_revoked_count_); |
689 EXPECT_EQ(1, start_batch_changes_); | 691 EXPECT_EQ(1, start_batch_changes_); |
690 EXPECT_EQ(1, end_batch_changes_); | 692 EXPECT_EQ(1, end_batch_changes_); |
691 EXPECT_TRUE( | 693 EXPECT_TRUE( |
692 oauth2_service_delegate_->RefreshTokenIsAvailable(primary_account)); | 694 oauth2_service_delegate_->RefreshTokenIsAvailable(primary_account)); |
693 EXPECT_TRUE( | 695 EXPECT_TRUE( |
694 oauth2_service_delegate_->RefreshTokenIsAvailable(secondary_account)); | 696 oauth2_service_delegate_->RefreshTokenIsAvailable(secondary_account)); |
695 } | 697 } |
OLD | NEW |