Commit 947d8086 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

[s13n] Convert c/b/ui/webui/settings/people_handler_unittest.cc to IdentityManager

This CL converts the PeopleHandler unittests away from SignManager and
ProfileOAuth2TokenService, in favor of the new IdentityManager.

Production code has been converted in [1]. This is a follow up steps.

[1] https://crrev.com/c/1261637

BUG=890810

Change-Id: I405e46d2126180a2da61393bf32263ae43877b6b
Reviewed-on: https://chromium-review.googlesource.com/c/1311093Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#604377}
parent 60f250c8
...@@ -16,11 +16,9 @@ ...@@ -16,11 +16,9 @@
#include "base/values.h" #include "base/values.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/fake_signin_manager_builder.h" #include "chrome/browser/signin/identity_test_environment_profile_adaptor.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/scoped_account_consistency.h" #include "chrome/browser/signin/scoped_account_consistency.h"
#include "chrome/browser/signin/signin_error_controller_factory.h" #include "chrome/browser/signin/signin_error_controller_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/profile_sync_test_util.h" #include "chrome/browser/sync/profile_sync_test_util.h"
#include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/chrome_pages.h"
...@@ -37,8 +35,6 @@ ...@@ -37,8 +35,6 @@
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/fake_auth_status_provider.h" #include "components/signin/core/browser/fake_auth_status_provider.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/sync/base/sync_prefs.h" #include "components/sync/base/sync_prefs.h"
#include "components/sync_preferences/pref_service_syncable.h" #include "components/sync_preferences/pref_service_syncable.h"
#include "components/unified_consent/scoped_unified_consent.h" #include "components/unified_consent/scoped_unified_consent.h"
...@@ -50,6 +46,7 @@ ...@@ -50,6 +46,7 @@
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_web_ui.h" #include "content/public/test/test_web_ui.h"
#include "content/public/test/web_contents_tester.h" #include "content/public/test/web_contents_tester.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/layout.h" #include "ui/base/layout.h"
...@@ -206,10 +203,12 @@ class PeopleHandlerTest : public ChromeRenderViewHostTestHarness { ...@@ -206,10 +203,12 @@ class PeopleHandlerTest : public ChromeRenderViewHostTestHarness {
error_ = GoogleServiceAuthError::AuthErrorNone(); error_ = GoogleServiceAuthError::AuthErrorNone();
// Sign in the user. // Sign in the user.
mock_signin_ = SigninManagerFactory::GetForProfile(profile()); identity_test_env_adaptor_ =
std::make_unique<IdentityTestEnvironmentProfileAdaptor>(profile());
std::string username = GetTestUser(); std::string username = GetTestUser();
if (!username.empty()) if (!username.empty())
mock_signin_->SetAuthenticatedAccountInfo(username, username); identity_test_env()->SetPrimaryAccount(username);
mock_pss_ = static_cast<ProfileSyncServiceMock*>( mock_pss_ = static_cast<ProfileSyncServiceMock*>(
ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
...@@ -236,6 +235,7 @@ class PeopleHandlerTest : public ChromeRenderViewHostTestHarness { ...@@ -236,6 +235,7 @@ class PeopleHandlerTest : public ChromeRenderViewHostTestHarness {
handler_->set_web_ui(nullptr); handler_->set_web_ui(nullptr);
handler_->DisallowJavascript(); handler_->DisallowJavascript();
handler_->sync_startup_tracker_.reset(); handler_->sync_startup_tracker_.reset();
identity_test_env_adaptor_.reset();
ChromeRenderViewHostTestHarness::TearDown(); ChromeRenderViewHostTestHarness::TearDown();
} }
...@@ -258,7 +258,6 @@ class PeopleHandlerTest : public ChromeRenderViewHostTestHarness { ...@@ -258,7 +258,6 @@ class PeopleHandlerTest : public ChromeRenderViewHostTestHarness {
void SetupInitializedProfileSyncService() { void SetupInitializedProfileSyncService() {
// An initialized ProfileSyncService will have already completed sync setup // An initialized ProfileSyncService will have already completed sync setup
// and will have an initialized sync engine. // and will have an initialized sync engine.
ASSERT_TRUE(mock_signin_->IsInitialized());
ON_CALL(*mock_pss_, GetTransportState()) ON_CALL(*mock_pss_, GetTransportState())
.WillByDefault(Return(syncer::SyncService::TransportState::ACTIVE)); .WillByDefault(Return(syncer::SyncService::TransportState::ACTIVE));
} }
...@@ -325,9 +324,14 @@ class PeopleHandlerTest : public ChromeRenderViewHostTestHarness { ...@@ -325,9 +324,14 @@ class PeopleHandlerTest : public ChromeRenderViewHostTestHarness {
return std::string(kTestUser); return std::string(kTestUser);
} }
identity::IdentityTestEnvironment* identity_test_env() {
return identity_test_env_adaptor_->identity_test_env();
}
ProfileSyncServiceMock* mock_pss_; ProfileSyncServiceMock* mock_pss_;
GoogleServiceAuthError error_; GoogleServiceAuthError error_;
SigninManagerBase* mock_signin_; std::unique_ptr<IdentityTestEnvironmentProfileAdaptor>
identity_test_env_adaptor_;
content::TestWebUI web_ui_; content::TestWebUI web_ui_;
TestWebUIProvider test_provider_; TestWebUIProvider test_provider_;
std::unique_ptr<TestChromeWebUIControllerFactory> test_factory_; std::unique_ptr<TestChromeWebUIControllerFactory> test_factory_;
...@@ -347,9 +351,7 @@ TEST_F(PeopleHandlerFirstSigninTest, DisplayBasicLogin) { ...@@ -347,9 +351,7 @@ TEST_F(PeopleHandlerFirstSigninTest, DisplayBasicLogin) {
.WillByDefault(Return(syncer::SyncService::DISABLE_REASON_NOT_SIGNED_IN)); .WillByDefault(Return(syncer::SyncService::DISABLE_REASON_NOT_SIGNED_IN));
ON_CALL(*mock_pss_, IsFirstSetupComplete()).WillByDefault(Return(false)); ON_CALL(*mock_pss_, IsFirstSetupComplete()).WillByDefault(Return(false));
// Ensure that the user is not signed in before calling |HandleStartSignin()|. // Ensure that the user is not signed in before calling |HandleStartSignin()|.
SigninManager* manager = SigninManager::FromSigninManagerBase(mock_signin_); identity_test_env()->ClearPrimaryAccount();
manager->SignOut(signin_metrics::SIGNOUT_TEST,
signin_metrics::SignoutDelete::IGNORE_METRIC);
base::ListValue list_args; base::ListValue list_args;
handler_->HandleStartSignin(&list_args); handler_->HandleStartSignin(&list_args);
...@@ -818,7 +820,9 @@ TEST_F(PeopleHandlerTest, ShowSigninOnAuthError) { ...@@ -818,7 +820,9 @@ TEST_F(PeopleHandlerTest, ShowSigninOnAuthError) {
GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
SetupInitializedProfileSyncService(); SetupInitializedProfileSyncService();
mock_signin_->SetAuthenticatedAccountInfo(kTestUser, kTestUser); DCHECK_EQ(
identity_test_env()->identity_manager()->GetPrimaryAccountInfo().email,
kTestUser);
FakeAuthStatusProvider provider( FakeAuthStatusProvider provider(
SigninErrorControllerFactory::GetForProfile(profile())); SigninErrorControllerFactory::GetForProfile(profile()));
provider.SetAuthError(kTestUser, error_); provider.SetAuthError(kTestUser, error_);
...@@ -1027,21 +1031,25 @@ TEST_P(PeopleHandlerDiceUnifiedConsentTest, StoredAccountsList) { ...@@ -1027,21 +1031,25 @@ TEST_P(PeopleHandlerDiceUnifiedConsentTest, StoredAccountsList) {
: signin::AccountConsistencyMethod::kDiceFixAuthErrors); : signin::AccountConsistencyMethod::kDiceFixAuthErrors);
// Setup the profile. // Setup the profile.
TestingProfile profile; std::unique_ptr<TestingProfile> profile =
IdentityTestEnvironmentProfileAdaptor::
CreateProfileForIdentityTestEnvironment();
AccountTrackerService* account_tracker = AccountTrackerService* account_tracker =
AccountTrackerServiceFactory::GetForProfile(&profile); AccountTrackerServiceFactory::GetForProfile(profile.get());
SigninManager* signin_manager = SigninManagerFactory::GetForProfile(&profile);
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(&profile);
std::string account_1 = std::string account_1 =
account_tracker->SeedAccountInfo("1234", "a@gmail.com"); account_tracker->SeedAccountInfo("1234", "a@gmail.com");
std::string account_2 = std::string account_2 =
account_tracker->SeedAccountInfo("5678", "b@gmail.com"); account_tracker->SeedAccountInfo("5678", "b@gmail.com");
token_service->UpdateCredentials(account_1, "token");
token_service->UpdateCredentials(account_2, "token");
signin_manager->SetAuthenticatedAccountInfo("1234", "a@gmail.com");
PeopleHandler handler(&profile); auto identity_test_env_adaptor =
std::make_unique<IdentityTestEnvironmentProfileAdaptor>(profile.get());
auto* identity_test_env = identity_test_env_adaptor->identity_test_env();
identity_test_env->SetRefreshTokenForAccount(account_1);
identity_test_env->SetRefreshTokenForAccount(account_2);
identity_test_env->SetPrimaryAccount("a@gmail.com");
PeopleHandler handler(profile.get());
std::unique_ptr<base::ListValue> accounts_list = std::unique_ptr<base::ListValue> accounts_list =
handler.GetStoredAccountsList(); handler.GetStoredAccountsList();
......
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