| OLD | NEW |
| 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 "components/signin/core/browser/signin_manager.h" | 5 #include "components/signin/core/browser/signin_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
| 18 #include "chrome/browser/prefs/browser_prefs.h" | 19 #include "chrome/browser/prefs/browser_prefs.h" |
| 19 #include "chrome/browser/signin/account_fetcher_service_factory.h" | 20 #include "chrome/browser/signin/account_fetcher_service_factory.h" |
| 20 #include "chrome/browser/signin/account_tracker_service_factory.h" | 21 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 21 #include "chrome/browser/signin/chrome_signin_client_factory.h" | 22 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
| 22 #include "chrome/browser/signin/fake_account_fetcher_service_builder.h" | 23 #include "chrome/browser/signin/fake_account_fetcher_service_builder.h" |
| 23 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 24 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 std::string gaia_id = "account_gaia_id"; | 499 std::string gaia_id = "account_gaia_id"; |
| 499 | 500 |
| 500 CreateNakedSigninManager(); | 501 CreateNakedSigninManager(); |
| 501 | 502 |
| 502 PrefService* client_prefs = signin_client()->GetPrefs(); | 503 PrefService* client_prefs = signin_client()->GetPrefs(); |
| 503 client_prefs->SetInteger(prefs::kAccountIdMigrationState, | 504 client_prefs->SetInteger(prefs::kAccountIdMigrationState, |
| 504 AccountTrackerService::MIGRATION_NOT_STARTED); | 505 AccountTrackerService::MIGRATION_NOT_STARTED); |
| 505 ListPrefUpdate update(client_prefs, | 506 ListPrefUpdate update(client_prefs, |
| 506 AccountTrackerService::kAccountInfoPref); | 507 AccountTrackerService::kAccountInfoPref); |
| 507 update->Clear(); | 508 update->Clear(); |
| 508 base::DictionaryValue* dict = new base::DictionaryValue(); | 509 auto dict = base::MakeUnique<base::DictionaryValue>(); |
| 509 update->Append(dict); | |
| 510 dict->SetString("account_id", base::UTF8ToUTF16(email)); | 510 dict->SetString("account_id", base::UTF8ToUTF16(email)); |
| 511 dict->SetString("email", base::UTF8ToUTF16(email)); | 511 dict->SetString("email", base::UTF8ToUTF16(email)); |
| 512 dict->SetString("gaia", base::UTF8ToUTF16(gaia_id)); | 512 dict->SetString("gaia", base::UTF8ToUTF16(gaia_id)); |
| 513 update->Append(std::move(dict)); |
| 513 | 514 |
| 514 tracker->Shutdown(); | 515 tracker->Shutdown(); |
| 515 tracker->Initialize(signin_client()); | 516 tracker->Initialize(signin_client()); |
| 516 | 517 |
| 517 client_prefs->SetString(prefs::kGoogleServicesAccountId, email); | 518 client_prefs->SetString(prefs::kGoogleServicesAccountId, email); |
| 518 manager_->Initialize(g_browser_process->local_state()); | 519 manager_->Initialize(g_browser_process->local_state()); |
| 519 | 520 |
| 520 EXPECT_EQ(gaia_id, manager_->GetAuthenticatedAccountId()); | 521 EXPECT_EQ(gaia_id, manager_->GetAuthenticatedAccountId()); |
| 521 EXPECT_EQ(gaia_id, profile()->GetPrefs()->GetString( | 522 EXPECT_EQ(gaia_id, profile()->GetPrefs()->GetString( |
| 522 prefs::kGoogleServicesAccountId)); | 523 prefs::kGoogleServicesAccountId)); |
| 523 } | 524 } |
| 524 } | 525 } |
| 525 | 526 |
| 526 TEST_F(SigninManagerTest, VeryOldProfileGaiaIdMigration) { | 527 TEST_F(SigninManagerTest, VeryOldProfileGaiaIdMigration) { |
| 527 AccountTrackerService* tracker = | 528 AccountTrackerService* tracker = |
| 528 AccountTrackerServiceFactory::GetForProfile(profile()); | 529 AccountTrackerServiceFactory::GetForProfile(profile()); |
| 529 if (tracker->GetMigrationState() != | 530 if (tracker->GetMigrationState() != |
| 530 AccountTrackerService::MIGRATION_NOT_STARTED) { | 531 AccountTrackerService::MIGRATION_NOT_STARTED) { |
| 531 std::string email = "user@gmail.com"; | 532 std::string email = "user@gmail.com"; |
| 532 std::string gaia_id = "account_gaia_id"; | 533 std::string gaia_id = "account_gaia_id"; |
| 533 | 534 |
| 534 CreateNakedSigninManager(); | 535 CreateNakedSigninManager(); |
| 535 | 536 |
| 536 PrefService* client_prefs = signin_client()->GetPrefs(); | 537 PrefService* client_prefs = signin_client()->GetPrefs(); |
| 537 client_prefs->SetInteger(prefs::kAccountIdMigrationState, | 538 client_prefs->SetInteger(prefs::kAccountIdMigrationState, |
| 538 AccountTrackerService::MIGRATION_NOT_STARTED); | 539 AccountTrackerService::MIGRATION_NOT_STARTED); |
| 539 ListPrefUpdate update(client_prefs, | 540 ListPrefUpdate update(client_prefs, |
| 540 AccountTrackerService::kAccountInfoPref); | 541 AccountTrackerService::kAccountInfoPref); |
| 541 update->Clear(); | 542 update->Clear(); |
| 542 base::DictionaryValue* dict = new base::DictionaryValue(); | 543 auto dict = base::MakeUnique<base::DictionaryValue>(); |
| 543 update->Append(dict); | |
| 544 dict->SetString("account_id", base::UTF8ToUTF16(email)); | 544 dict->SetString("account_id", base::UTF8ToUTF16(email)); |
| 545 dict->SetString("email", base::UTF8ToUTF16(email)); | 545 dict->SetString("email", base::UTF8ToUTF16(email)); |
| 546 dict->SetString("gaia", base::UTF8ToUTF16(gaia_id)); | 546 dict->SetString("gaia", base::UTF8ToUTF16(gaia_id)); |
| 547 update->Append(std::move(dict)); |
| 547 | 548 |
| 548 tracker->Shutdown(); | 549 tracker->Shutdown(); |
| 549 tracker->Initialize(signin_client()); | 550 tracker->Initialize(signin_client()); |
| 550 | 551 |
| 551 client_prefs->ClearPref(prefs::kGoogleServicesAccountId); | 552 client_prefs->ClearPref(prefs::kGoogleServicesAccountId); |
| 552 client_prefs->SetString(prefs::kGoogleServicesUsername, email); | 553 client_prefs->SetString(prefs::kGoogleServicesUsername, email); |
| 553 manager_->Initialize(g_browser_process->local_state()); | 554 manager_->Initialize(g_browser_process->local_state()); |
| 554 | 555 |
| 555 EXPECT_EQ(gaia_id, manager_->GetAuthenticatedAccountId()); | 556 EXPECT_EQ(gaia_id, manager_->GetAuthenticatedAccountId()); |
| 556 EXPECT_EQ(gaia_id, profile()->GetPrefs()->GetString( | 557 EXPECT_EQ(gaia_id, profile()->GetPrefs()->GetString( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 567 std::string gaia_id = "account_gaia_id"; | 568 std::string gaia_id = "account_gaia_id"; |
| 568 | 569 |
| 569 CreateNakedSigninManager(); | 570 CreateNakedSigninManager(); |
| 570 | 571 |
| 571 PrefService* client_prefs = signin_client()->GetPrefs(); | 572 PrefService* client_prefs = signin_client()->GetPrefs(); |
| 572 client_prefs->SetInteger(prefs::kAccountIdMigrationState, | 573 client_prefs->SetInteger(prefs::kAccountIdMigrationState, |
| 573 AccountTrackerService::MIGRATION_NOT_STARTED); | 574 AccountTrackerService::MIGRATION_NOT_STARTED); |
| 574 ListPrefUpdate update(client_prefs, | 575 ListPrefUpdate update(client_prefs, |
| 575 AccountTrackerService::kAccountInfoPref); | 576 AccountTrackerService::kAccountInfoPref); |
| 576 update->Clear(); | 577 update->Clear(); |
| 577 base::DictionaryValue* dict = new base::DictionaryValue(); | 578 auto dict = base::MakeUnique<base::DictionaryValue>(); |
| 578 update->Append(dict); | |
| 579 dict->SetString("account_id", base::UTF8ToUTF16(email)); | 579 dict->SetString("account_id", base::UTF8ToUTF16(email)); |
| 580 dict->SetString("email", base::UTF8ToUTF16(email)); | 580 dict->SetString("email", base::UTF8ToUTF16(email)); |
| 581 dict->SetString("gaia", base::UTF8ToUTF16(gaia_id)); | 581 dict->SetString("gaia", base::UTF8ToUTF16(gaia_id)); |
| 582 update->Append(std::move(dict)); |
| 582 | 583 |
| 583 tracker->Shutdown(); | 584 tracker->Shutdown(); |
| 584 tracker->Initialize(signin_client()); | 585 tracker->Initialize(signin_client()); |
| 585 | 586 |
| 586 client_prefs->SetString(prefs::kGoogleServicesAccountId, gaia_id); | 587 client_prefs->SetString(prefs::kGoogleServicesAccountId, gaia_id); |
| 587 manager_->Initialize(g_browser_process->local_state()); | 588 manager_->Initialize(g_browser_process->local_state()); |
| 588 | 589 |
| 589 EXPECT_EQ(gaia_id, manager_->GetAuthenticatedAccountId()); | 590 EXPECT_EQ(gaia_id, manager_->GetAuthenticatedAccountId()); |
| 590 EXPECT_EQ(gaia_id, profile()->GetPrefs()->GetString( | 591 EXPECT_EQ(gaia_id, profile()->GetPrefs()->GetString( |
| 591 prefs::kGoogleServicesAccountId)); | 592 prefs::kGoogleServicesAccountId)); |
| 592 | 593 |
| 593 base::RunLoop().RunUntilIdle(); | 594 base::RunLoop().RunUntilIdle(); |
| 594 EXPECT_EQ(AccountTrackerService::MIGRATION_DONE, | 595 EXPECT_EQ(AccountTrackerService::MIGRATION_DONE, |
| 595 tracker->GetMigrationState()); | 596 tracker->GetMigrationState()); |
| 596 } | 597 } |
| 597 } | 598 } |
| OLD | NEW |