diff options
author | Tim Song <tengs@chromium.org> | 2016-02-29 11:38:27 -0800 |
---|---|---|
committer | Tim Song <tengs@chromium.org> | 2016-02-29 19:40:52 +0000 |
commit | 601d5f3bedad31bca5661aced7ecbf8d32293291 (patch) | |
tree | f41b31b7ab1b69032035719733a38ec1ae662ea7 | |
parent | 5d31c64708b5209a4aa7fcf975d77ec060342e8d (diff) | |
download | chromium_src-601d5f3bedad31bca5661aced7ecbf8d32293291.zip chromium_src-601d5f3bedad31bca5661aced7ecbf8d32293291.tar.gz chromium_src-601d5f3bedad31bca5661aced7ecbf8d32293291.tar.bz2 |
Fix Smart Lock bugs introduced by change from raw email to AccountId.
BUG=585672
TEST=verified on link
Review URL: https://codereview.chromium.org/1734243003
Cr-Commit-Position: refs/heads/master@{#378002}
(cherry picked from commit b2b328b08f644cc4e6557aa36502b25558997b44)
Review URL: https://codereview.chromium.org/1749893002 .
Cr-Commit-Position: refs/branch-heads/2623@{#539}
Cr-Branched-From: 92d77538a86529ca35f9220bd3cd512cbea1f086-refs/heads/master@{#369907}
3 files changed, 26 insertions, 11 deletions
diff --git a/chrome/browser/signin/easy_unlock_service_regular.cc b/chrome/browser/signin/easy_unlock_service_regular.cc index cbee08b..3228338 100644 --- a/chrome/browser/signin/easy_unlock_service_regular.cc +++ b/chrome/browser/signin/easy_unlock_service_regular.cc @@ -163,11 +163,13 @@ AccountId EasyUnlockServiceRegular::GetAccountId() const { // |profile| has to be a signed-in profile with SigninManager already // created. Otherwise, just crash to collect stack. DCHECK(signin_manager); - const std::string user_email = - signin_manager->GetAuthenticatedAccountInfo().email; - return user_email.empty() + const AccountInfo account_info = + signin_manager->GetAuthenticatedAccountInfo(); + return account_info.email.empty() ? EmptyAccountId() - : AccountId::FromUserEmail(gaia::CanonicalizeEmail(user_email)); + : AccountId::FromUserEmailGaiaId( + gaia::CanonicalizeEmail(account_info.email), + account_info.gaia); } void EasyUnlockServiceRegular::LaunchSetup() { diff --git a/chrome/browser/signin/easy_unlock_service_signin_chromeos.cc b/chrome/browser/signin/easy_unlock_service_signin_chromeos.cc index 7868b69..3b93ac2 100644 --- a/chrome/browser/signin/easy_unlock_service_signin_chromeos.cc +++ b/chrome/browser/signin/easy_unlock_service_signin_chromeos.cc @@ -338,8 +338,7 @@ void EasyUnlockServiceSignin::OnFocusedUserChanged( // these // cases update the app state. Otherwise, it's enough to notify the app the // user data has been updated. - const bool should_update_app_state = - account_id_.is_valid() != account_id.is_valid(); + const bool should_update_app_state = (account_id_ != account_id); account_id_ = account_id; user_pod_last_focused_timestamp_ = base::TimeTicks::Now(); @@ -375,7 +374,7 @@ void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() { if (!base::SysInfo::IsRunningOnChromeOS()) return; - if (account_id_.is_valid() || !service_active_) + if (!account_id_.is_valid() || !service_active_) return; const auto it = user_data_.find(account_id_); @@ -467,7 +466,7 @@ void EasyUnlockServiceSignin::OnUserDataLoaded( const EasyUnlockServiceSignin::UserData* EasyUnlockServiceSignin::FindLoadedDataForCurrentUser() const { - if (account_id_.is_valid()) + if (!account_id_.is_valid()) return nullptr; const auto it = user_data_.find(account_id_); diff --git a/chrome/browser/signin/easy_unlock_service_unittest_chromeos.cc b/chrome/browser/signin/easy_unlock_service_unittest_chromeos.cc index 118c2b2..7305084 100644 --- a/chrome/browser/signin/easy_unlock_service_unittest_chromeos.cc +++ b/chrome/browser/signin/easy_unlock_service_unittest_chromeos.cc @@ -45,7 +45,9 @@ namespace { // IDs for fake users used in tests. const char kTestUserPrimary[] = "primary_user@nowhere.com"; +const char kPrimaryGaiaId[] = "1111111111"; const char kTestUserSecondary[] = "secondary_user@nowhere.com"; +const char kSecondaryGaiaId[] = "2222222222"; // App manager to be used in EasyUnlockService tests. // This effectivelly abstracts the extension system from the tests. @@ -222,7 +224,8 @@ class EasyUnlockServiceTest : public testing::Test { ON_CALL(*mock_user_manager_, IsCurrentUserNonCryptohomeDataEphemeral()) .WillByDefault(Return(false)); - SetUpProfile(&profile_, AccountId::FromUserEmail(kTestUserPrimary)); + SetUpProfile(&profile_, AccountId::FromUserEmailGaiaId( + kTestUserPrimary, kPrimaryGaiaId)); } void TearDown() override { @@ -267,7 +270,8 @@ class EasyUnlockServiceTest : public testing::Test { void SetUpSecondaryProfile() { SetUpProfile(&secondary_profile_, - AccountId::FromUserEmail(kTestUserSecondary)); + AccountId::FromUserEmailGaiaId(kTestUserSecondary, + kSecondaryGaiaId)); } private: @@ -287,7 +291,7 @@ class EasyUnlockServiceTest : public testing::Test { SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile(profile->get()); - signin_manager->SetAuthenticatedAccountInfo(account_id.GetUserEmail(), + signin_manager->SetAuthenticatedAccountInfo(account_id.GetGaiaId(), account_id.GetUserEmail()); } @@ -375,4 +379,14 @@ TEST_F(EasyUnlockServiceTest, NotAllowedForEphemeralAccounts) { EasyUnlockAppInState(profile_.get(), TestAppManager::STATE_NOT_LOADED)); } +TEST_F(EasyUnlockServiceTest, GetAccountId) { + EXPECT_EQ(AccountId::FromUserEmailGaiaId(kTestUserPrimary, kPrimaryGaiaId), + EasyUnlockService::Get(profile_.get())->GetAccountId()); + + SetUpSecondaryProfile(); + EXPECT_EQ(AccountId::FromUserEmailGaiaId(kTestUserSecondary, + kSecondaryGaiaId), + EasyUnlockService::Get(secondary_profile_.get())->GetAccountId()); +} + } // namespace |