Commit 376a7724 authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

s13n: Replace use of AccountTrackerService in authentication_service_unittest.mm

As a step to make to use IdentityManager,this CL replaces all uses of ATS
with IdentityManager's ones in authentication_service_unittest.mm.

Bug: 922796
Change-Id: I74dd7a7b8d640da88c2f999a43fb1439b79e5c97
Reviewed-on: https://chromium-review.googlesource.com/c/1438734Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Gyuyoung Kim <gyuyoung@igalia.com>
Cr-Commit-Position: refs/heads/master@{#628315}
parent dd43c86a
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include "ios/chrome/browser/experimental_flags.h" #include "ios/chrome/browser/experimental_flags.h"
#include "ios/chrome/browser/pref_names.h" #include "ios/chrome/browser/pref_names.h"
#include "ios/chrome/browser/prefs/browser_prefs.h" #include "ios/chrome/browser/prefs/browser_prefs.h"
#include "ios/chrome/browser/signin/account_tracker_service_factory.h"
#import "ios/chrome/browser/signin/authentication_service.h" #import "ios/chrome/browser/signin/authentication_service.h"
#import "ios/chrome/browser/signin/authentication_service_delegate_fake.h" #import "ios/chrome/browser/signin/authentication_service_delegate_fake.h"
#import "ios/chrome/browser/signin/authentication_service_factory.h" #import "ios/chrome/browser/signin/authentication_service_factory.h"
...@@ -40,6 +39,7 @@ ...@@ -40,6 +39,7 @@
#import "ios/public/provider/chrome/browser/signin/chrome_identity.h" #import "ios/public/provider/chrome/browser/signin/chrome_identity.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.h" #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.h"
#include "ios/web/public/test/test_web_thread_bundle.h" #include "ios/web/public/test/test_web_thread_bundle.h"
#include "services/identity/public/cpp/identity_manager.h"
#import "services/identity/public/cpp/identity_test_environment.h" #import "services/identity/public/cpp/identity_test_environment.h"
#include "base/bind.h" #include "base/bind.h"
...@@ -263,13 +263,12 @@ TEST_F(AuthenticationServiceTest, TestSignInAndGetAuthenticatedIdentity) { ...@@ -263,13 +263,12 @@ TEST_F(AuthenticationServiceTest, TestSignInAndGetAuthenticatedIdentity) {
ProfileOAuth2TokenService* token_service = ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForBrowserState( ProfileOAuth2TokenServiceFactory::GetForBrowserState(
browser_state_.get()); browser_state_.get());
AccountTrackerService* account_tracker =
ios::AccountTrackerServiceFactory::GetForBrowserState(
browser_state_.get());
std::string user_email = base::SysNSStringToUTF8([identity_ userEmail]); std::string user_email = base::SysNSStringToUTF8([identity_ userEmail]);
AccountInfo account_info = AccountInfo account_info =
account_tracker->FindAccountInfoByEmail(user_email); identity_manager()
->FindAccountInfoForAccountWithRefreshTokenByEmailAddress(user_email)
.value();
EXPECT_EQ(user_email, account_info.email); EXPECT_EQ(user_email, account_info.email);
EXPECT_EQ(base::SysNSStringToUTF8([identity_ gaiaID]), account_info.gaia); EXPECT_EQ(base::SysNSStringToUTF8([identity_ gaiaID]), account_info.gaia);
EXPECT_TRUE(token_service->RefreshTokenIsAvailable(account_info.account_id)); EXPECT_TRUE(token_service->RefreshTokenIsAvailable(account_info.account_id));
...@@ -392,20 +391,18 @@ TEST_F(AuthenticationServiceTest, StoreAndGetAccountsInPrefs) { ...@@ -392,20 +391,18 @@ TEST_F(AuthenticationServiceTest, StoreAndGetAccountsInPrefs) {
StoreAccountsInPrefs(); StoreAccountsInPrefs();
accounts = GetAccountsInPrefs(); accounts = GetAccountsInPrefs();
ASSERT_EQ(2u, accounts.size()); ASSERT_EQ(2u, accounts.size());
AccountTrackerService* account_tracker =
ios::AccountTrackerServiceFactory::GetForBrowserState( switch (identity_manager()->GetAccountIdMigrationState()) {
browser_state_.get()); case identity::IdentityManager::MIGRATION_NOT_STARTED:
switch (account_tracker->GetMigrationState()) {
case AccountTrackerService::MIGRATION_NOT_STARTED:
EXPECT_EQ("foo2@foo.com", accounts[0]); EXPECT_EQ("foo2@foo.com", accounts[0]);
EXPECT_EQ("foo@foo.com", accounts[1]); EXPECT_EQ("foo@foo.com", accounts[1]);
break; break;
case AccountTrackerService::MIGRATION_IN_PROGRESS: case identity::IdentityManager::MIGRATION_IN_PROGRESS:
case AccountTrackerService::MIGRATION_DONE: case identity::IdentityManager::MIGRATION_DONE:
EXPECT_EQ("foo2ID", accounts[0]); EXPECT_EQ("foo2ID", accounts[0]);
EXPECT_EQ("fooID", accounts[1]); EXPECT_EQ("fooID", accounts[1]);
break; break;
case AccountTrackerService::NUM_MIGRATION_STATES: case identity::IdentityManager::NUM_MIGRATION_STATES:
FAIL() << "NUM_MIGRATION_STATES is not a real migration state."; FAIL() << "NUM_MIGRATION_STATES is not a real migration state.";
break; break;
} }
...@@ -427,20 +424,18 @@ TEST_F(AuthenticationServiceTest, ...@@ -427,20 +424,18 @@ TEST_F(AuthenticationServiceTest,
identity_manager()->GetAccountsWithRefreshTokens(); identity_manager()->GetAccountsWithRefreshTokens();
std::sort(accounts.begin(), accounts.end(), account_compare_func); std::sort(accounts.begin(), accounts.end(), account_compare_func);
ASSERT_EQ(2u, accounts.size()); ASSERT_EQ(2u, accounts.size());
AccountTrackerService* account_tracker =
ios::AccountTrackerServiceFactory::GetForBrowserState( switch (identity_manager()->GetAccountIdMigrationState()) {
browser_state_.get()); case identity::IdentityManager::MIGRATION_NOT_STARTED:
switch (account_tracker->GetMigrationState()) {
case AccountTrackerService::MIGRATION_NOT_STARTED:
EXPECT_EQ("foo2@foo.com", accounts[0].account_id); EXPECT_EQ("foo2@foo.com", accounts[0].account_id);
EXPECT_EQ("foo@foo.com", accounts[1].account_id); EXPECT_EQ("foo@foo.com", accounts[1].account_id);
break; break;
case AccountTrackerService::MIGRATION_IN_PROGRESS: case identity::IdentityManager::MIGRATION_IN_PROGRESS:
case AccountTrackerService::MIGRATION_DONE: case identity::IdentityManager::MIGRATION_DONE:
EXPECT_EQ("foo2ID", accounts[0].account_id); EXPECT_EQ("foo2ID", accounts[0].account_id);
EXPECT_EQ("fooID", accounts[1].account_id); EXPECT_EQ("fooID", accounts[1].account_id);
break; break;
case AccountTrackerService::NUM_MIGRATION_STATES: case identity::IdentityManager::NUM_MIGRATION_STATES:
FAIL() << "NUM_MIGRATION_STATES is not a real migration state."; FAIL() << "NUM_MIGRATION_STATES is not a real migration state.";
break; break;
} }
...@@ -455,19 +450,19 @@ TEST_F(AuthenticationServiceTest, ...@@ -455,19 +450,19 @@ TEST_F(AuthenticationServiceTest,
accounts = identity_manager()->GetAccountsWithRefreshTokens(); accounts = identity_manager()->GetAccountsWithRefreshTokens();
std::sort(accounts.begin(), accounts.end(), account_compare_func); std::sort(accounts.begin(), accounts.end(), account_compare_func);
ASSERT_EQ(3u, accounts.size()); ASSERT_EQ(3u, accounts.size());
switch (account_tracker->GetMigrationState()) { switch (identity_manager()->GetAccountIdMigrationState()) {
case AccountTrackerService::MIGRATION_NOT_STARTED: case identity::IdentityManager::MIGRATION_NOT_STARTED:
EXPECT_EQ("foo2@foo.com", accounts[0].account_id); EXPECT_EQ("foo2@foo.com", accounts[0].account_id);
EXPECT_EQ("foo3@foo.com", accounts[1].account_id); EXPECT_EQ("foo3@foo.com", accounts[1].account_id);
EXPECT_EQ("foo@foo.com", accounts[2].account_id); EXPECT_EQ("foo@foo.com", accounts[2].account_id);
break; break;
case AccountTrackerService::MIGRATION_IN_PROGRESS: case identity::IdentityManager::MIGRATION_IN_PROGRESS:
case AccountTrackerService::MIGRATION_DONE: case identity::IdentityManager::MIGRATION_DONE:
EXPECT_EQ("foo2ID", accounts[0].account_id); EXPECT_EQ("foo2ID", accounts[0].account_id);
EXPECT_EQ("foo3ID", accounts[1].account_id); EXPECT_EQ("foo3ID", accounts[1].account_id);
EXPECT_EQ("fooID", accounts[2].account_id); EXPECT_EQ("fooID", accounts[2].account_id);
break; break;
case AccountTrackerService::NUM_MIGRATION_STATES: case identity::IdentityManager::NUM_MIGRATION_STATES:
FAIL() << "NUM_MIGRATION_STATES is not a real migration state."; FAIL() << "NUM_MIGRATION_STATES is not a real migration state.";
break; break;
} }
...@@ -541,11 +536,8 @@ TEST_F(AuthenticationServiceTest, IsAuthenticatedBackground) { ...@@ -541,11 +536,8 @@ TEST_F(AuthenticationServiceTest, IsAuthenticatedBackground) {
} }
TEST_F(AuthenticationServiceTest, MigrateAccountsStoredInPref) { TEST_F(AuthenticationServiceTest, MigrateAccountsStoredInPref) {
AccountTrackerService* account_tracker = if (identity_manager()->GetAccountIdMigrationState() ==
ios::AccountTrackerServiceFactory::GetForBrowserState( identity::IdentityManager::MIGRATION_NOT_STARTED) {
browser_state_.get());
if (account_tracker->GetMigrationState() ==
AccountTrackerService::MIGRATION_NOT_STARTED) {
// The account tracker is not migratable. Skip the test as the accounts // The account tracker is not migratable. Skip the test as the accounts
// cannot be migrated. // cannot be migrated.
return; return;
...@@ -554,7 +546,7 @@ TEST_F(AuthenticationServiceTest, MigrateAccountsStoredInPref) { ...@@ -554,7 +546,7 @@ TEST_F(AuthenticationServiceTest, MigrateAccountsStoredInPref) {
// Force the migration state to MIGRATION_NOT_STARTED before signing in. // Force the migration state to MIGRATION_NOT_STARTED before signing in.
browser_state_->GetPrefs()->SetInteger( browser_state_->GetPrefs()->SetInteger(
prefs::kAccountIdMigrationState, prefs::kAccountIdMigrationState,
AccountTrackerService::MIGRATION_NOT_STARTED); identity::IdentityManager::MIGRATION_NOT_STARTED);
browser_state_->GetPrefs()->SetBoolean(prefs::kSigninLastAccountsMigrated, browser_state_->GetPrefs()->SetBoolean(prefs::kSigninLastAccountsMigrated,
false); false);
...@@ -566,11 +558,10 @@ TEST_F(AuthenticationServiceTest, MigrateAccountsStoredInPref) { ...@@ -566,11 +558,10 @@ TEST_F(AuthenticationServiceTest, MigrateAccountsStoredInPref) {
EXPECT_EQ("foo2@foo.com", accounts_in_prefs[0]); EXPECT_EQ("foo2@foo.com", accounts_in_prefs[0]);
EXPECT_EQ("foo@foo.com", accounts_in_prefs[1]); EXPECT_EQ("foo@foo.com", accounts_in_prefs[1]);
// Migrate the accounts (this actually requires a shutdown and re-initialize // Migrate the accounts.
// of the account tracker). browser_state_->GetPrefs()->SetInteger(
account_tracker->Shutdown(); prefs::kAccountIdMigrationState,
account_tracker->Initialize(browser_state_->GetPrefs(), base::FilePath()); identity::IdentityManager::MIGRATION_DONE);
account_tracker->SetMigrationDone();
// Reload all credentials to find account info with the refresh token. // Reload all credentials to find account info with the refresh token.
// If it tries to find refresh token with gaia ID after // If it tries to find refresh token with gaia ID after
......
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