Commit da87860c authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Convert arc_play_store_enabled_preference_handler_unittest.cc to use IdentityTestEnvironment

IdentityManager currently wraps other signin APIs including SigninManager
and PO2TS. This CL migrates ArcPlayStoreEnabledPreferenceHandlerTest
and IdentityManager's testing facility IdentityTestEnvironment, and
hides the test internals from SigninManager APIs.

This is part of the servicification effort.

BUG=907484

Change-Id: I85f764f3477ee8e974298c0b41e22ac6277f61c5
Reviewed-on: https://chromium-review.googlesource.com/c/1349589
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610843}
parent f16a2137
...@@ -16,8 +16,7 @@ ...@@ -16,8 +16,7 @@
#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/consent_auditor/consent_auditor_factory.h" #include "chrome/browser/consent_auditor/consent_auditor_factory.h"
#include "chrome/browser/consent_auditor/consent_auditor_test_utils.h" #include "chrome/browser/consent_auditor/consent_auditor_test_utils.h"
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_test_environment_profile_adaptor.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
...@@ -27,7 +26,6 @@ ...@@ -27,7 +26,6 @@
#include "components/arc/arc_util.h" #include "components/arc/arc_util.h"
#include "components/arc/test/fake_arc_session.h" #include "components/arc/test/fake_arc_session.h"
#include "components/consent_auditor/fake_consent_auditor.h" #include "components/consent_auditor/fake_consent_auditor.h"
#include "components/signin/core/browser/signin_manager_base.h"
#include "components/sync_preferences/testing_pref_service_syncable.h" #include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/user_manager/scoped_user_manager.h" #include "components/user_manager/scoped_user_manager.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
...@@ -43,7 +41,7 @@ using testing::_; ...@@ -43,7 +41,7 @@ using testing::_;
namespace arc { namespace arc {
namespace { namespace {
constexpr char kTestProfileName[] = "user@gmail.com"; constexpr char kTestEmail[] = "user@gmail.com";
constexpr char kTestGaiaId[] = "1234567890"; constexpr char kTestGaiaId[] = "1234567890";
class ArcPlayStoreEnabledPreferenceHandlerTest : public testing::Test { class ArcPlayStoreEnabledPreferenceHandlerTest : public testing::Test {
...@@ -63,12 +61,15 @@ class ArcPlayStoreEnabledPreferenceHandlerTest : public testing::Test { ...@@ -63,12 +61,15 @@ class ArcPlayStoreEnabledPreferenceHandlerTest : public testing::Test {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
TestingProfile::Builder profile_builder; TestingProfile::Builder profile_builder;
profile_builder.SetProfileName(kTestProfileName); profile_builder.SetProfileName(kTestEmail);
profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile")); profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile"));
profile_builder.AddTestingFactory( profile_builder.AddTestingFactory(
ConsentAuditorFactory::GetInstance(), ConsentAuditorFactory::GetInstance(),
base::BindRepeating(&BuildFakeConsentAuditor)); base::BindRepeating(&BuildFakeConsentAuditor));
profile_ = profile_builder.Build(); profile_ = IdentityTestEnvironmentProfileAdaptor::
CreateProfileForIdentityTestEnvironment(profile_builder);
identity_test_env_profile_adaptor_ =
std::make_unique<IdentityTestEnvironmentProfileAdaptor>(profile_.get());
arc_session_manager_ = std::make_unique<ArcSessionManager>( arc_session_manager_ = std::make_unique<ArcSessionManager>(
std::make_unique<ArcSessionRunner>(base::Bind(FakeArcSession::Create))); std::make_unique<ArcSessionRunner>(base::Bind(FakeArcSession::Create)));
...@@ -80,14 +81,14 @@ class ArcPlayStoreEnabledPreferenceHandlerTest : public testing::Test { ...@@ -80,14 +81,14 @@ class ArcPlayStoreEnabledPreferenceHandlerTest : public testing::Test {
GetFakeUserManager()->AddUser(account_id); GetFakeUserManager()->AddUser(account_id);
GetFakeUserManager()->LoginUser(account_id); GetFakeUserManager()->LoginUser(account_id);
SigninManagerBase* signin_manager = identity_test_env_profile_adaptor_->identity_test_env()->SetPrimaryAccount(
SigninManagerFactory::GetForProfile(profile()); kTestEmail);
signin_manager->SetAuthenticatedAccountInfo(kTestGaiaId, kTestProfileName);
} }
void TearDown() override { void TearDown() override {
preference_handler_.reset(); preference_handler_.reset();
arc_session_manager_.reset(); arc_session_manager_.reset();
identity_test_env_profile_adaptor_.reset();
profile_.reset(); profile_.reset();
chromeos::DBusThreadManager::Shutdown(); chromeos::DBusThreadManager::Shutdown();
} }
...@@ -110,15 +111,18 @@ class ArcPlayStoreEnabledPreferenceHandlerTest : public testing::Test { ...@@ -110,15 +111,18 @@ class ArcPlayStoreEnabledPreferenceHandlerTest : public testing::Test {
} }
std::string GetAuthenticatedAccountId() const { std::string GetAuthenticatedAccountId() const {
return IdentityManagerFactory::GetForProfile(profile()) auto* identity_manager =
->GetPrimaryAccountInfo() identity_test_env_profile_adaptor_->identity_test_env()
.account_id; ->identity_manager();
return identity_manager->GetPrimaryAccountInfo().account_id;
} }
private: private:
content::TestBrowserThreadBundle thread_bundle_; content::TestBrowserThreadBundle thread_bundle_;
user_manager::ScopedUserManager user_manager_enabler_; user_manager::ScopedUserManager user_manager_enabler_;
base::ScopedTempDir temp_dir_; base::ScopedTempDir temp_dir_;
std::unique_ptr<IdentityTestEnvironmentProfileAdaptor>
identity_test_env_profile_adaptor_;
std::unique_ptr<TestingProfile> profile_; std::unique_ptr<TestingProfile> profile_;
std::unique_ptr<ArcSessionManager> arc_session_manager_; std::unique_ptr<ArcSessionManager> arc_session_manager_;
std::unique_ptr<ArcPlayStoreEnabledPreferenceHandler> preference_handler_; std::unique_ptr<ArcPlayStoreEnabledPreferenceHandler> preference_handler_;
......
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