Commit 8decfc99 authored by Mihai Sardarescu's avatar Mihai Sardarescu Committed by Commit Bot

Start using Gaia ID as the account ID on ChromeOS

This CL enables the usage of the Gaia ID as the account ID for the
account manager for profiles that have no accounts on start-up. This
allows us to start using Gaia ID as the account ID on ChromeOS as well.

Using this strategy has very little risk as there should not be any
data that needs to be migrated from email to Gaia ID.

Bug: 1028182

Change-Id: I90cbcf4a9bb8be848276b64d8802e090de428a0b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2491365Reviewed-by: default avatarKush Sinha <sinhak@chromium.org>
Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Auto-Submit: Mihai Sardarescu <msarda@chromium.org>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828215}
parent a6ee3f4e
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
#include "extensions/browser/process_manager.h" #include "extensions/browser/process_manager.h"
#include "extensions/test/extension_test_message_listener.h" #include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/result_catcher.h" #include "extensions/test/result_catcher.h"
#include "google_apis/gaia/gaia_auth_util.h"
#include "net/cookies/canonical_cookie.h" #include "net/cookies/canonical_cookie.h"
#include "net/test/embedded_test_server/http_request.h" #include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h" #include "net/test/embedded_test_server/http_response.h"
...@@ -302,29 +303,30 @@ class OAuth2Test : public OobeBaseTest { ...@@ -302,29 +303,30 @@ class OAuth2Test : public OobeBaseTest {
void LoginAsExistingUser() { void LoginAsExistingUser() {
// PickAccountId does not work at this point as the primary user profile has // PickAccountId does not work at this point as the primary user profile has
// not yet been created. // not yet been created.
const std::string email = kTestEmail; EXPECT_EQ(GetOAuthStatusFromLocalState(kTestEmail),
EXPECT_EQ(GetOAuthStatusFromLocalState(email),
user_manager::User::OAUTH2_TOKEN_STATUS_VALID); user_manager::User::OAUTH2_TOKEN_STATUS_VALID);
// Try login. Primary profile has changed. // Try login. Primary profile has changed.
ash::LoginScreenTestApi::SubmitPassword( AccountId account_id =
AccountId::FromUserEmailGaiaId(kTestEmail, kTestGaiaId), AccountId::FromUserEmailGaiaId(kTestEmail, kTestGaiaId);
kTestAccountPassword, true /*check_if_submittable */); ash::LoginScreenTestApi::SubmitPassword(account_id, kTestAccountPassword,
true /*check_if_submittable */);
test::WaitForPrimaryUserSessionStart(); test::WaitForPrimaryUserSessionStart();
Profile* profile = ProfileManager::GetPrimaryUserProfile(); Profile* profile = ProfileManager::GetPrimaryUserProfile();
CoreAccountId account_id = PickAccountId(profile, kTestGaiaId, kTestEmail);
ASSERT_EQ(email, account_id.ToString());
// Wait for the session merge to finish. // Wait for the session merge to finish.
WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE); WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE);
EXPECT_EQ(GetOAuthStatusFromLocalState(kTestEmail),
user_manager::User::OAUTH2_TOKEN_STATUS_VALID);
// Check for existence of refresh token. // Check for existence of the primary account and its refresh token.
signin::IdentityManager* identity_manager = signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile); IdentityManagerFactory::GetForProfile(profile);
EXPECT_TRUE(identity_manager->HasAccountWithRefreshToken(account_id)); CoreAccountInfo primary_account = identity_manager->GetPrimaryAccountInfo();
EXPECT_TRUE(gaia::AreEmailsSame(kTestEmail, primary_account.email));
EXPECT_EQ(GetOAuthStatusFromLocalState(account_id.ToString()), EXPECT_EQ(kTestGaiaId, primary_account.gaia);
user_manager::User::OAUTH2_TOKEN_STATUS_VALID); EXPECT_TRUE(identity_manager->HasAccountWithRefreshToken(
primary_account.account_id));
} }
bool TryToLogin(const AccountId& account_id, const std::string& password) { bool TryToLogin(const AccountId& account_id, const std::string& password) {
...@@ -340,14 +342,14 @@ class OAuth2Test : public OobeBaseTest { ...@@ -340,14 +342,14 @@ class OAuth2Test : public OobeBaseTest {
} }
user_manager::User::OAuthTokenStatus GetOAuthStatusFromLocalState( user_manager::User::OAuthTokenStatus GetOAuthStatusFromLocalState(
const std::string& account_id) const { const std::string& email) const {
PrefService* local_state = g_browser_process->local_state(); PrefService* local_state = g_browser_process->local_state();
const base::DictionaryValue* prefs_oauth_status = const base::DictionaryValue* prefs_oauth_status =
local_state->GetDictionary("OAuthTokenStatus"); local_state->GetDictionary("OAuthTokenStatus");
int oauth_token_status = user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN; int oauth_token_status = user_manager::User::OAUTH_TOKEN_STATUS_UNKNOWN;
if (prefs_oauth_status && if (prefs_oauth_status &&
prefs_oauth_status->GetIntegerWithoutPathExpansion( prefs_oauth_status->GetIntegerWithoutPathExpansion(
account_id, &oauth_token_status)) { email, &oauth_token_status)) {
user_manager::User::OAuthTokenStatus result = user_manager::User::OAuthTokenStatus result =
static_cast<user_manager::User::OAuthTokenStatus>(oauth_token_status); static_cast<user_manager::User::OAuthTokenStatus>(oauth_token_status);
return result; return result;
...@@ -517,7 +519,7 @@ IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_PRE_PRE_MergeSession) { ...@@ -517,7 +519,7 @@ IN_PROC_BROWSER_TEST_F(OAuth2Test, PRE_PRE_PRE_MergeSession) {
IdentityManagerFactory::GetForProfile(GetProfile()); IdentityManagerFactory::GetForProfile(GetProfile());
EXPECT_TRUE(identity_manager->HasAccountWithRefreshToken(account_id)); EXPECT_TRUE(identity_manager->HasAccountWithRefreshToken(account_id));
EXPECT_EQ(GetOAuthStatusFromLocalState(account_id.ToString()), EXPECT_EQ(GetOAuthStatusFromLocalState(kTestEmail),
user_manager::User::OAUTH2_TOKEN_STATUS_VALID); user_manager::User::OAUTH2_TOKEN_STATUS_VALID);
CookieReader cookie_reader; CookieReader cookie_reader;
cookie_reader.ReadCookies(GetProfile()); cookie_reader.ReadCookies(GetProfile());
...@@ -566,21 +568,20 @@ IN_PROC_BROWSER_TEST_F(OAuth2Test, MergeSession) { ...@@ -566,21 +568,20 @@ IN_PROC_BROWSER_TEST_F(OAuth2Test, MergeSession) {
// PickAccountId does not work at this point as the primary user profile has // PickAccountId does not work at this point as the primary user profile has
// not yet been created. // not yet been created.
const std::string account_id = kTestEmail; EXPECT_EQ(GetOAuthStatusFromLocalState(kTestEmail),
EXPECT_EQ(GetOAuthStatusFromLocalState(account_id),
user_manager::User::OAUTH2_TOKEN_STATUS_VALID); user_manager::User::OAUTH2_TOKEN_STATUS_VALID);
EXPECT_TRUE( EXPECT_TRUE(
TryToLogin(AccountId::FromUserEmailGaiaId(kTestEmail, kTestGaiaId), TryToLogin(AccountId::FromUserEmailGaiaId(kTestEmail, kTestGaiaId),
kTestAccountPassword)); kTestAccountPassword));
ASSERT_EQ(account_id, ASSERT_EQ(kTestGaiaId,
PickAccountId(GetProfile(), kTestGaiaId, kTestEmail).ToString()); PickAccountId(GetProfile(), kTestGaiaId, kTestEmail).ToString());
// Wait for the session merge to finish. // Wait for the session merge to finish.
WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_FAILED); WaitForMergeSessionCompletion(OAuth2LoginManager::SESSION_RESTORE_DONE);
EXPECT_EQ(GetOAuthStatusFromLocalState(account_id), EXPECT_EQ(GetOAuthStatusFromLocalState(kTestEmail),
user_manager::User::OAUTH2_TOKEN_STATUS_INVALID); user_manager::User::OAUTH2_TOKEN_STATUS_INVALID);
} }
......
...@@ -51,9 +51,12 @@ class AndroidManagementClientTest : public testing::Test { ...@@ -51,9 +51,12 @@ class AndroidManagementClientTest : public testing::Test {
shared_url_loader_factory_ = shared_url_loader_factory_ =
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>( base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&url_loader_factory_); &url_loader_factory_);
signin::IdentityManager* identity_manager =
identity_test_environment_.identity_manager();
CoreAccountId account_id = identity_manager->PickAccountIdForAccount(
signin::GetTestGaiaIdForEmail(kAccountEmail), kAccountEmail);
client_.reset(new AndroidManagementClient( client_.reset(new AndroidManagementClient(
&service_, shared_url_loader_factory_, CoreAccountId(kAccountEmail), &service_, shared_url_loader_factory_, account_id, identity_manager));
identity_test_environment_.identity_manager()));
service_.ScheduleInitialization(0); service_.ScheduleInitialization(0);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -83,12 +86,9 @@ TEST_F(AndroidManagementClientTest, CheckAndroidManagementCall) { ...@@ -83,12 +86,9 @@ TEST_F(AndroidManagementClientTest, CheckAndroidManagementCall) {
Run(AndroidManagementClient::Result::UNMANAGED)) Run(AndroidManagementClient::Result::UNMANAGED))
.Times(1); .Times(1);
// On ChromeOS platform, account_id and email are same.
AccountInfo account_info = AccountInfo account_info =
identity_test_environment_.MakeAccountAvailable(kAccountEmail); identity_test_environment_.MakeAccountAvailable(kAccountEmail);
client_->StartCheckAndroidManagement(callback_observer_.Get()); client_->StartCheckAndroidManagement(callback_observer_.Get());
identity_test_environment_ identity_test_environment_
.WaitForAccessTokenRequestIfNecessaryAndRespondWithToken( .WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
account_info.account_id, kOAuthToken, base::Time::Max()); account_info.account_id, kOAuthToken, base::Time::Max());
......
...@@ -32,7 +32,7 @@ namespace policy { ...@@ -32,7 +32,7 @@ namespace policy {
namespace { namespace {
constexpr char kAffiliatedUserEmail[] = "affiliated-user@example.com"; constexpr char kAffiliatedUserEmail[] = "affiliated-user@example.com";
constexpr char kAffiliatedUserGaiaId[] = "affiliated-user@example.com"; constexpr char kAffiliatedUserGaiaId[] = "affiliated-user_example.com";
constexpr char kAffiliationID[] = "some-affiliation-id"; constexpr char kAffiliationID[] = "some-affiliation-id";
constexpr char kAnotherAffiliationID[] = "another-affiliation-id"; constexpr char kAnotherAffiliationID[] = "another-affiliation-id";
......
...@@ -27,13 +27,7 @@ using SyncConsent = sync_pb::UserConsentTypes::SyncConsent; ...@@ -27,13 +27,7 @@ using SyncConsent = sync_pb::UserConsentTypes::SyncConsent;
namespace { namespace {
CoreAccountId GetAccountId() { CoreAccountId GetAccountId() {
#if defined(OS_CHROMEOS)
// TODO(vitaliii): Unify the two, because it takes ages to debug and
// impossible to discover otherwise.
return CoreAccountId("user@gmail.com");
#else
return CoreAccountId("gaia_id_for_user_gmail.com"); return CoreAccountId("gaia_id_for_user_gmail.com");
#endif
} }
class UserConsentEqualityChecker : public SingleClientStatusChangeChecker { class UserConsentEqualityChecker : public SingleClientStatusChangeChecker {
......
...@@ -186,15 +186,6 @@ AccountInfo AccountTrackerService::FindAccountInfoByEmail( ...@@ -186,15 +186,6 @@ AccountInfo AccountTrackerService::FindAccountInfoByEmail(
return AccountInfo(); return AccountInfo();
} }
// static
bool AccountTrackerService::IsMigrationSupported() {
#if defined(OS_CHROMEOS)
return base::FeatureList::IsEnabled(switches::kAccountIdMigration);
#else
return true;
#endif
}
AccountTrackerService::AccountIdMigrationState AccountTrackerService::AccountIdMigrationState
AccountTrackerService::GetMigrationState() const { AccountTrackerService::GetMigrationState() const {
return GetMigrationState(pref_service_); return GetMigrationState(pref_service_);
...@@ -366,10 +357,7 @@ void AccountTrackerService::MigrateToGaiaId() { ...@@ -366,10 +357,7 @@ void AccountTrackerService::MigrateToGaiaId() {
} }
} }
bool AccountTrackerService::IsMigrationDone() const { bool AccountTrackerService::AreAllAccountsMigrated() const {
if (!IsMigrationSupported())
return false;
for (const auto& pair : accounts_) { for (const auto& pair : accounts_) {
if (pair.first.ToString() != pair.second.gaia) if (pair.first.ToString() != pair.second.gaia)
return false; return false;
...@@ -380,9 +368,21 @@ bool AccountTrackerService::IsMigrationDone() const { ...@@ -380,9 +368,21 @@ bool AccountTrackerService::IsMigrationDone() const {
AccountTrackerService::AccountIdMigrationState AccountTrackerService::AccountIdMigrationState
AccountTrackerService::ComputeNewMigrationState() const { AccountTrackerService::ComputeNewMigrationState() const {
// If migration is not supported, skip migration. if (accounts_.empty()) {
if (!IsMigrationSupported()) // If there are no accounts in the account tracker service, then we expect
// that this is profile that was never signed in to Chrome. Consider the
// migration done as there are no accounts to migrate..
return MIGRATION_DONE;
}
#if defined(OS_CHROMEOS)
// Migration on ChromeOS is not started by default due to the following risks:
// * a lot more data than on desktop is keyed by the account id
// * bugs in the migration flow can lead to user not being able to sign in
// to their device which makes the device unusable.
if (!base::FeatureList::IsEnabled(switches::kAccountIdMigration))
return MIGRATION_NOT_STARTED; return MIGRATION_NOT_STARTED;
#endif
bool migration_required = false; bool migration_required = false;
for (const auto& pair : accounts_) { for (const auto& pair : accounts_) {
...@@ -399,7 +399,7 @@ AccountTrackerService::ComputeNewMigrationState() const { ...@@ -399,7 +399,7 @@ AccountTrackerService::ComputeNewMigrationState() const {
} }
void AccountTrackerService::SetMigrationState(AccountIdMigrationState state) { void AccountTrackerService::SetMigrationState(AccountIdMigrationState state) {
DCHECK(state != MIGRATION_DONE || IsMigrationDone()); DCHECK(state != MIGRATION_DONE || AreAllAccountsMigrated());
pref_service_->SetInteger(prefs::kAccountIdMigrationState, state); pref_service_->SetInteger(prefs::kAccountIdMigrationState, state);
} }
...@@ -554,24 +554,16 @@ void AccountTrackerService::LoadFromPrefs() { ...@@ -554,24 +554,16 @@ void AccountTrackerService::LoadFromPrefs() {
RemoveAccountImageFromDisk(account_id); RemoveAccountImageFromDisk(account_id);
} }
if (IsMigrationSupported()) { if (GetMigrationState() != MIGRATION_DONE) {
if (GetMigrationState() != MIGRATION_DONE) { const AccountIdMigrationState new_state = ComputeNewMigrationState();
const AccountIdMigrationState new_state = ComputeNewMigrationState(); SetMigrationState(new_state);
SetMigrationState(new_state);
if (new_state == MIGRATION_IN_PROGRESS) { if (new_state == MIGRATION_IN_PROGRESS) {
MigrateToGaiaId(); MigrateToGaiaId();
}
} }
} else {
// ChromeOS running on Linux and Linux share the preferences, so the
// migration may have been performed on Linux. Reset the migration
// state to ensure that the same code path is used whether ChromeOS
// is running on Linux on a dev build or on real ChromeOS device.
SetMigrationState(MIGRATION_NOT_STARTED);
} }
DCHECK(GetMigrationState() != MIGRATION_DONE || IsMigrationDone()); DCHECK(GetMigrationState() != MIGRATION_DONE || AreAllAccountsMigrated());
UMA_HISTOGRAM_ENUMERATION("Signin.AccountTracker.GaiaIdMigrationState", UMA_HISTOGRAM_ENUMERATION("Signin.AccountTracker.GaiaIdMigrationState",
GetMigrationState(), NUM_MIGRATION_STATES); GetMigrationState(), NUM_MIGRATION_STATES);
......
...@@ -121,10 +121,6 @@ class AccountTrackerService { ...@@ -121,10 +121,6 @@ class AccountTrackerService {
void RemoveAccount(const CoreAccountId& account_id); void RemoveAccount(const CoreAccountId& account_id);
// Is migration of the account id from normalized email to gaia id supported
// on the current platform?
static bool IsMigrationSupported();
AccountIdMigrationState GetMigrationState() const; AccountIdMigrationState GetMigrationState() const;
void SetMigrationDone(); void SetMigrationDone();
...@@ -213,7 +209,7 @@ class AccountTrackerService { ...@@ -213,7 +209,7 @@ class AccountTrackerService {
// Returns whether the accounts are all keyed by gaia id. This should // Returns whether the accounts are all keyed by gaia id. This should
// be the case when the migration state is set to MIGRATION_DONE. // be the case when the migration state is set to MIGRATION_DONE.
bool IsMigrationDone() const; bool AreAllAccountsMigrated() const;
// Computes the new migration state. The state is saved to preference // Computes the new migration state. The state is saved to preference
// before performing the migration in order to support resuming the // before performing the migration in order to support resuming the
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/image_fetcher/core/fake_image_decoder.h" #include "components/image_fetcher/core/fake_image_decoder.h"
...@@ -23,6 +24,7 @@ ...@@ -23,6 +24,7 @@
#include "components/signin/internal/identity_manager/fake_profile_oauth2_token_service.h" #include "components/signin/internal/identity_manager/fake_profile_oauth2_token_service.h"
#include "components/signin/public/base/avatar_icon_util.h" #include "components/signin/public/base/avatar_icon_util.h"
#include "components/signin/public/base/signin_pref_names.h" #include "components/signin/public/base/signin_pref_names.h"
#include "components/signin/public/base/signin_switches.h"
#include "components/signin/public/base/test_signin_client.h" #include "components/signin/public/base/test_signin_client.h"
#include "components/signin/public/identity_manager/account_info.h" #include "components/signin/public/identity_manager/account_info.h"
#include "google_apis/gaia/gaia_oauth_client.h" #include "google_apis/gaia/gaia_oauth_client.h"
...@@ -698,6 +700,11 @@ TEST_F(AccountTrackerServiceTest, FindAccountInfoByEmail) { ...@@ -698,6 +700,11 @@ TEST_F(AccountTrackerServiceTest, FindAccountInfoByEmail) {
} }
TEST_F(AccountTrackerServiceTest, Persistence) { TEST_F(AccountTrackerServiceTest, Persistence) {
#if defined(OS_CHROMEOS)
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(switches::kAccountIdMigration);
#endif
// Define a user data directory for the account image storage. // Define a user data directory for the account image storage.
base::ScopedTempDir scoped_user_data_dir; base::ScopedTempDir scoped_user_data_dir;
ASSERT_TRUE(scoped_user_data_dir.CreateUniqueTempDir()); ASSERT_TRUE(scoped_user_data_dir.CreateUniqueTempDir());
...@@ -854,6 +861,11 @@ TEST_F(AccountTrackerServiceTest, SeedAccountInfoFull) { ...@@ -854,6 +861,11 @@ TEST_F(AccountTrackerServiceTest, SeedAccountInfoFull) {
} }
TEST_F(AccountTrackerServiceTest, UpgradeToFullAccountInfo) { TEST_F(AccountTrackerServiceTest, UpgradeToFullAccountInfo) {
#if defined(OS_CHROMEOS)
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(switches::kAccountIdMigration);
#endif
// Start by simulating an incomplete account info and let it be saved to // Start by simulating an incomplete account info and let it be saved to
// prefs. // prefs.
ResetAccountTracker(); ResetAccountTracker();
...@@ -981,8 +993,10 @@ TEST_F(AccountTrackerServiceTest, LegacyDottedAccountIds) { ...@@ -981,8 +993,10 @@ TEST_F(AccountTrackerServiceTest, LegacyDottedAccountIds) {
} }
TEST_F(AccountTrackerServiceTest, MigrateAccountIdToGaiaId) { TEST_F(AccountTrackerServiceTest, MigrateAccountIdToGaiaId) {
if (!AccountTrackerService::IsMigrationSupported()) #if defined(OS_CHROMEOS)
return; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(switches::kAccountIdMigration);
#endif
const std::string email_alpha = AccountKeyToEmail(kAccountKeyAlpha); const std::string email_alpha = AccountKeyToEmail(kAccountKeyAlpha);
const std::string gaia_alpha = AccountKeyToGaiaId(kAccountKeyAlpha); const std::string gaia_alpha = AccountKeyToGaiaId(kAccountKeyAlpha);
...@@ -1028,8 +1042,10 @@ TEST_F(AccountTrackerServiceTest, MigrateAccountIdToGaiaId) { ...@@ -1028,8 +1042,10 @@ TEST_F(AccountTrackerServiceTest, MigrateAccountIdToGaiaId) {
} }
TEST_F(AccountTrackerServiceTest, CanNotMigrateAccountIdToGaiaId) { TEST_F(AccountTrackerServiceTest, CanNotMigrateAccountIdToGaiaId) {
if (!AccountTrackerService::IsMigrationSupported()) #if defined(OS_CHROMEOS)
return; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(switches::kAccountIdMigration);
#endif
const std::string email_alpha = AccountKeyToEmail(kAccountKeyAlpha); const std::string email_alpha = AccountKeyToEmail(kAccountKeyAlpha);
const std::string gaia_alpha = AccountKeyToGaiaId(kAccountKeyAlpha); const std::string gaia_alpha = AccountKeyToGaiaId(kAccountKeyAlpha);
...@@ -1074,8 +1090,10 @@ TEST_F(AccountTrackerServiceTest, CanNotMigrateAccountIdToGaiaId) { ...@@ -1074,8 +1090,10 @@ TEST_F(AccountTrackerServiceTest, CanNotMigrateAccountIdToGaiaId) {
} }
TEST_F(AccountTrackerServiceTest, GaiaIdMigrationCrashInTheMiddle) { TEST_F(AccountTrackerServiceTest, GaiaIdMigrationCrashInTheMiddle) {
if (!AccountTrackerService::IsMigrationSupported()) #if defined(OS_CHROMEOS)
return; base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(switches::kAccountIdMigration);
#endif
const std::string email_alpha = AccountKeyToEmail(kAccountKeyAlpha); const std::string email_alpha = AccountKeyToEmail(kAccountKeyAlpha);
const std::string gaia_alpha = AccountKeyToGaiaId(kAccountKeyAlpha); const std::string gaia_alpha = AccountKeyToGaiaId(kAccountKeyAlpha);
......
...@@ -391,7 +391,6 @@ void PrimaryAccountManager::OnSignoutDecisionReached( ...@@ -391,7 +391,6 @@ void PrimaryAccountManager::OnSignoutDecisionReached(
observer.GoogleSignedOut(account_info); observer.GoogleSignedOut(account_info);
} }
#if !defined(OS_CHROMEOS)
void PrimaryAccountManager::OnRefreshTokensLoaded() { void PrimaryAccountManager::OnRefreshTokensLoaded() {
token_service_->RemoveObserver(this); token_service_->RemoveObserver(this);
...@@ -415,4 +414,3 @@ void PrimaryAccountManager::OnRefreshTokensLoaded() { ...@@ -415,4 +414,3 @@ void PrimaryAccountManager::OnRefreshTokensLoaded() {
} }
} }
} }
#endif // !defined(OS_CHROMEOS)
...@@ -193,10 +193,8 @@ class PrimaryAccountManager : public ProfileOAuth2TokenServiceObserver { ...@@ -193,10 +193,8 @@ class PrimaryAccountManager : public ProfileOAuth2TokenServiceObserver {
bool assert_signout_allowed, bool assert_signout_allowed,
SigninClient::SignoutDecision signout_decision); SigninClient::SignoutDecision signout_decision);
#if !defined(OS_CHROMEOS)
// ProfileOAuth2TokenServiceObserver: // ProfileOAuth2TokenServiceObserver:
void OnRefreshTokensLoaded() override; void OnRefreshTokensLoaded() override;
#endif
const CoreAccountInfo& primary_account_info() const { const CoreAccountInfo& primary_account_info() const {
return primary_account_info_; return primary_account_info_;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/image_fetcher/core/fake_image_decoder.h" #include "components/image_fetcher/core/fake_image_decoder.h"
...@@ -24,6 +25,7 @@ ...@@ -24,6 +25,7 @@
#include "components/signin/internal/identity_manager/profile_oauth2_token_service.h" #include "components/signin/internal/identity_manager/profile_oauth2_token_service.h"
#include "components/signin/public/base/account_consistency_method.h" #include "components/signin/public/base/account_consistency_method.h"
#include "components/signin/public/base/signin_pref_names.h" #include "components/signin/public/base/signin_pref_names.h"
#include "components/signin/public/base/signin_switches.h"
#include "components/signin/public/base/test_signin_client.h" #include "components/signin/public/base/test_signin_client.h"
#include "components/sync_preferences/testing_pref_service_syncable.h" #include "components/sync_preferences/testing_pref_service_syncable.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -359,64 +361,72 @@ TEST_F(PrimaryAccountManagerTest, SigninNotAllowed) { ...@@ -359,64 +361,72 @@ TEST_F(PrimaryAccountManagerTest, SigninNotAllowed) {
#endif #endif
TEST_F(PrimaryAccountManagerTest, GaiaIdMigration) { TEST_F(PrimaryAccountManagerTest, GaiaIdMigration) {
if (account_tracker()->GetMigrationState() != #if defined(OS_CHROMEOS)
AccountTrackerService::MIGRATION_NOT_STARTED) { base::test::ScopedFeatureList scoped_feature_list;
std::string email = "user@gmail.com"; scoped_feature_list.InitAndEnableFeature(switches::kAccountIdMigration);
std::string gaia_id = "account_gaia_id"; #endif
PrefService* client_prefs = signin_client()->GetPrefs(); ASSERT_EQ(AccountTrackerService::MIGRATION_DONE,
client_prefs->SetInteger(prefs::kAccountIdMigrationState, account_tracker()->GetMigrationState());
AccountTrackerService::MIGRATION_NOT_STARTED); std::string email = "user@gmail.com";
ListPrefUpdate update(client_prefs, prefs::kAccountInfo); std::string gaia_id = "account_gaia_id";
update->Clear();
auto dict = std::make_unique<base::DictionaryValue>(); PrefService* client_prefs = signin_client()->GetPrefs();
dict->SetString("account_id", email); client_prefs->SetInteger(prefs::kAccountIdMigrationState,
dict->SetString("email", email); AccountTrackerService::MIGRATION_NOT_STARTED);
dict->SetString("gaia", gaia_id); ListPrefUpdate update(client_prefs, prefs::kAccountInfo);
update->Append(std::move(dict)); update->Clear();
auto dict = std::make_unique<base::DictionaryValue>();
account_tracker()->Shutdown(); dict->SetString("account_id", email);
account_tracker()->Initialize(prefs(), base::FilePath()); dict->SetString("email", email);
dict->SetString("gaia", gaia_id);
client_prefs->SetString(prefs::kGoogleServicesAccountId, email); update->Append(std::move(dict));
CreatePrimaryAccountManager(); account_tracker()->Shutdown();
account_tracker()->Initialize(prefs(), base::FilePath());
EXPECT_EQ(CoreAccountId(gaia_id), manager_->GetAuthenticatedAccountId());
EXPECT_EQ(gaia_id, user_prefs_.GetString(prefs::kGoogleServicesAccountId)); client_prefs->SetString(prefs::kGoogleServicesAccountId, email);
}
CreatePrimaryAccountManager();
EXPECT_EQ(CoreAccountId(gaia_id), manager_->GetAuthenticatedAccountId());
EXPECT_EQ(gaia_id, user_prefs_.GetString(prefs::kGoogleServicesAccountId));
} }
TEST_F(PrimaryAccountManagerTest, GaiaIdMigrationCrashInTheMiddle) { TEST_F(PrimaryAccountManagerTest, GaiaIdMigrationCrashInTheMiddle) {
if (account_tracker()->GetMigrationState() != #if defined(OS_CHROMEOS)
AccountTrackerService::MIGRATION_NOT_STARTED) { base::test::ScopedFeatureList scoped_feature_list;
std::string email = "user@gmail.com"; scoped_feature_list.InitAndEnableFeature(switches::kAccountIdMigration);
std::string gaia_id = "account_gaia_id"; #endif
PrefService* client_prefs = signin_client()->GetPrefs(); ASSERT_EQ(AccountTrackerService::MIGRATION_DONE,
client_prefs->SetInteger(prefs::kAccountIdMigrationState, account_tracker()->GetMigrationState());
AccountTrackerService::MIGRATION_NOT_STARTED); std::string email = "user@gmail.com";
ListPrefUpdate update(client_prefs, prefs::kAccountInfo); std::string gaia_id = "account_gaia_id";
update->Clear();
auto dict = std::make_unique<base::DictionaryValue>(); PrefService* client_prefs = signin_client()->GetPrefs();
dict->SetString("account_id", email); client_prefs->SetInteger(prefs::kAccountIdMigrationState,
dict->SetString("email", email); AccountTrackerService::MIGRATION_NOT_STARTED);
dict->SetString("gaia", gaia_id); ListPrefUpdate update(client_prefs, prefs::kAccountInfo);
update->Append(std::move(dict)); update->Clear();
auto dict = std::make_unique<base::DictionaryValue>();
account_tracker()->Shutdown(); dict->SetString("account_id", email);
account_tracker()->Initialize(prefs(), base::FilePath()); dict->SetString("email", email);
dict->SetString("gaia", gaia_id);
client_prefs->SetString(prefs::kGoogleServicesAccountId, gaia_id); update->Append(std::move(dict));
CreatePrimaryAccountManager(); account_tracker()->Shutdown();
EXPECT_EQ(CoreAccountId(gaia_id), manager_->GetAuthenticatedAccountId()); account_tracker()->Initialize(prefs(), base::FilePath());
EXPECT_EQ(gaia_id, user_prefs_.GetString(prefs::kGoogleServicesAccountId));
client_prefs->SetString(prefs::kGoogleServicesAccountId, gaia_id);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(AccountTrackerService::MIGRATION_DONE, CreatePrimaryAccountManager();
account_tracker()->GetMigrationState()); EXPECT_EQ(CoreAccountId(gaia_id), manager_->GetAuthenticatedAccountId());
} EXPECT_EQ(gaia_id, user_prefs_.GetString(prefs::kGoogleServicesAccountId));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(AccountTrackerService::MIGRATION_DONE,
account_tracker()->GetMigrationState());
} }
TEST_F(PrimaryAccountManagerTest, RestoreFromPrefsConsented) { TEST_F(PrimaryAccountManagerTest, RestoreFromPrefsConsented) {
......
...@@ -2206,15 +2206,8 @@ TEST_F(IdentityManagerTest, AreRefreshTokensLoaded) { ...@@ -2206,15 +2206,8 @@ TEST_F(IdentityManagerTest, AreRefreshTokensLoaded) {
} }
TEST_F(IdentityManagerTest, AccountIdMigration_DoneOnInitialization) { TEST_F(IdentityManagerTest, AccountIdMigration_DoneOnInitialization) {
// Migration gets marked as DONE while initializing the AccountTrackerService EXPECT_EQ(IdentityManager::AccountIdMigrationState::MIGRATION_DONE,
// on platforms supporting account ID migration only. identity_manager()->GetAccountIdMigrationState());
if (account_tracker()->IsMigrationSupported()) {
EXPECT_EQ(identity_manager()->GetAccountIdMigrationState(),
IdentityManager::AccountIdMigrationState::MIGRATION_DONE);
} else {
EXPECT_EQ(identity_manager()->GetAccountIdMigrationState(),
IdentityManager::AccountIdMigrationState::MIGRATION_NOT_STARTED);
}
} }
// Checks that IdentityManager::Observer gets OnAccountUpdated when account info // Checks that IdentityManager::Observer gets OnAccountUpdated when account info
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment