Commit 1e3550d5 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Migrate Arc unit tests to IdentityManager

identity::IdentityManager is the new API that replaces SigninManager[Base].

This includes ArcTermsOfServiceDefaultNegotiatorTest and ArcSupportHostTest.

Bug: 825190, 731023
Change-Id: I316c90c6d278e52d723468d63bc21cd288b2642b
Reviewed-on: https://chromium-review.googlesource.com/1025898Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553949}
parent 344eacf1
...@@ -10,14 +10,16 @@ ...@@ -10,14 +10,16 @@
#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/fake_signin_manager_builder.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/test/base/browser_with_test_window_test.h" #include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/consent_auditor/fake_consent_auditor.h" #include "components/consent_auditor/fake_consent_auditor.h"
#include "components/signin/core/browser/fake_signin_manager.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"
#include "services/identity/public/cpp/identity_manager.h"
#include "services/identity/public/cpp/identity_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -72,7 +74,10 @@ class ArcSupportHostTest : public BrowserWithTestWindowTest { ...@@ -72,7 +74,10 @@ class ArcSupportHostTest : public BrowserWithTestWindowTest {
BrowserWithTestWindowTest::SetUp(); BrowserWithTestWindowTest::SetUp();
user_manager_enabler_ = std::make_unique<user_manager::ScopedUserManager>( user_manager_enabler_ = std::make_unique<user_manager::ScopedUserManager>(
std::make_unique<chromeos::FakeChromeUserManager>()); std::make_unique<chromeos::FakeChromeUserManager>());
signin_manager()->SignIn("testing_account_id"); identity::MakePrimaryAccountAvailable(
SigninManagerFactory::GetForProfile(profile()),
ProfileOAuth2TokenServiceFactory::GetForProfile(profile()),
IdentityManagerFactory::GetForProfile(profile()), "test@account.com");
support_host_ = std::make_unique<ArcSupportHost>(profile()); support_host_ = std::make_unique<ArcSupportHost>(profile());
fake_arc_support_ = std::make_unique<FakeArcSupport>(support_host_.get()); fake_arc_support_ = std::make_unique<FakeArcSupport>(support_host_.get());
...@@ -123,15 +128,9 @@ class ArcSupportHostTest : public BrowserWithTestWindowTest { ...@@ -123,15 +128,9 @@ class ArcSupportHostTest : public BrowserWithTestWindowTest {
ConsentAuditorFactory::GetForProfile(profile())); ConsentAuditorFactory::GetForProfile(profile()));
} }
FakeSigninManagerBase* signin_manager() {
return static_cast<FakeSigninManagerBase*>(
SigninManagerFactory::GetForProfile(profile()));
}
// BrowserWithTestWindowTest: // BrowserWithTestWindowTest:
TestingProfile::TestingFactories GetTestingFactories() override { TestingProfile::TestingFactories GetTestingFactories() override {
return {{SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase}, return {{ConsentAuditorFactory::GetInstance(), BuildFakeConsentAuditor}};
{ConsentAuditorFactory::GetInstance(), BuildFakeConsentAuditor}};
} }
private: private:
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
#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/fake_signin_manager_builder.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.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/browser_with_test_window_test.h" #include "chrome/test/base/browser_with_test_window_test.h"
...@@ -25,10 +26,11 @@ ...@@ -25,10 +26,11 @@
#include "components/arc/arc_prefs.h" #include "components/arc/arc_prefs.h"
#include "components/consent_auditor/fake_consent_auditor.h" #include "components/consent_auditor/fake_consent_auditor.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/signin/core/browser/fake_signin_manager.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"
#include "services/identity/public/cpp/identity_manager.h"
#include "services/identity/public/cpp/identity_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace arc { namespace arc {
...@@ -43,7 +45,10 @@ class ArcTermsOfServiceDefaultNegotiatorTest ...@@ -43,7 +45,10 @@ class ArcTermsOfServiceDefaultNegotiatorTest
BrowserWithTestWindowTest::SetUp(); BrowserWithTestWindowTest::SetUp();
user_manager_enabler_ = std::make_unique<user_manager::ScopedUserManager>( user_manager_enabler_ = std::make_unique<user_manager::ScopedUserManager>(
std::make_unique<chromeos::FakeChromeUserManager>()); std::make_unique<chromeos::FakeChromeUserManager>());
signin_manager()->SignIn("testing_account_id"); identity::MakePrimaryAccountAvailable(
SigninManagerFactory::GetForProfile(profile()),
ProfileOAuth2TokenServiceFactory::GetForProfile(profile()),
IdentityManagerFactory::GetForProfile(profile()), "test@account.com");
support_host_ = std::make_unique<ArcSupportHost>(profile()); support_host_ = std::make_unique<ArcSupportHost>(profile());
fake_arc_support_ = std::make_unique<FakeArcSupport>(support_host_.get()); fake_arc_support_ = std::make_unique<FakeArcSupport>(support_host_.get());
...@@ -69,15 +74,15 @@ class ArcTermsOfServiceDefaultNegotiatorTest ...@@ -69,15 +74,15 @@ class ArcTermsOfServiceDefaultNegotiatorTest
ConsentAuditorFactory::GetForProfile(profile())); ConsentAuditorFactory::GetForProfile(profile()));
} }
FakeSigninManagerBase* signin_manager() { std::string GetAuthenticatedAccountId() {
return static_cast<FakeSigninManagerBase*>( return IdentityManagerFactory::GetForProfile(profile())
SigninManagerFactory::GetForProfile(profile())); ->GetPrimaryAccountInfo()
.account_id;
} }
// BrowserWithTestWindowTest: // BrowserWithTestWindowTest:
TestingProfile::TestingFactories GetTestingFactories() override { TestingProfile::TestingFactories GetTestingFactories() override {
return {{SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase}, return {{ConsentAuditorFactory::GetInstance(), BuildFakeConsentAuditor}};
{ConsentAuditorFactory::GetInstance(), BuildFakeConsentAuditor}};
} }
private: private:
...@@ -199,8 +204,7 @@ TEST_F(ArcTermsOfServiceDefaultNegotiatorTest, Accept) { ...@@ -199,8 +204,7 @@ TEST_F(ArcTermsOfServiceDefaultNegotiatorTest, Accept) {
consent_auditor::ConsentStatus::GIVEN, consent_auditor::ConsentStatus::GIVEN,
consent_auditor::ConsentStatus::GIVEN, consent_auditor::ConsentStatus::GIVEN,
consent_auditor::ConsentStatus::GIVEN}; consent_auditor::ConsentStatus::GIVEN};
EXPECT_EQ(consent_auditor()->account_id(), EXPECT_EQ(consent_auditor()->account_id(), GetAuthenticatedAccountId());
signin_manager()->GetAuthenticatedAccountId());
EXPECT_EQ(consent_auditor()->recorded_id_vectors(), consent_ids); EXPECT_EQ(consent_auditor()->recorded_id_vectors(), consent_ids);
EXPECT_EQ(consent_auditor()->recorded_features(), features); EXPECT_EQ(consent_auditor()->recorded_features(), features);
EXPECT_EQ(consent_auditor()->recorded_statuses(), statuses); EXPECT_EQ(consent_auditor()->recorded_statuses(), statuses);
...@@ -254,8 +258,7 @@ TEST_F(ArcTermsOfServiceDefaultNegotiatorTest, AcceptWithUnchecked) { ...@@ -254,8 +258,7 @@ TEST_F(ArcTermsOfServiceDefaultNegotiatorTest, AcceptWithUnchecked) {
consent_auditor::Feature::PLAY_STORE}; consent_auditor::Feature::PLAY_STORE};
const std::vector<consent_auditor::ConsentStatus> statuses = { const std::vector<consent_auditor::ConsentStatus> statuses = {
consent_auditor::ConsentStatus::GIVEN}; consent_auditor::ConsentStatus::GIVEN};
EXPECT_EQ(consent_auditor()->account_id(), EXPECT_EQ(consent_auditor()->account_id(), GetAuthenticatedAccountId());
signin_manager()->GetAuthenticatedAccountId());
EXPECT_EQ(consent_auditor()->recorded_id_vectors(), consent_ids); EXPECT_EQ(consent_auditor()->recorded_id_vectors(), consent_ids);
EXPECT_EQ(consent_auditor()->recorded_features(), features); EXPECT_EQ(consent_auditor()->recorded_features(), features);
EXPECT_EQ(consent_auditor()->recorded_statuses(), statuses); EXPECT_EQ(consent_auditor()->recorded_statuses(), statuses);
...@@ -302,8 +305,7 @@ TEST_F(ArcTermsOfServiceDefaultNegotiatorTest, AcceptWithManagedToS) { ...@@ -302,8 +305,7 @@ TEST_F(ArcTermsOfServiceDefaultNegotiatorTest, AcceptWithManagedToS) {
consent_auditor::Feature::GOOGLE_LOCATION_SERVICE}; consent_auditor::Feature::GOOGLE_LOCATION_SERVICE};
const std::vector<consent_auditor::ConsentStatus> statuses = { const std::vector<consent_auditor::ConsentStatus> statuses = {
consent_auditor::ConsentStatus::GIVEN}; consent_auditor::ConsentStatus::GIVEN};
EXPECT_EQ(consent_auditor()->account_id(), EXPECT_EQ(consent_auditor()->account_id(), GetAuthenticatedAccountId());
signin_manager()->GetAuthenticatedAccountId());
EXPECT_EQ(consent_auditor()->recorded_id_vectors(), consent_ids); EXPECT_EQ(consent_auditor()->recorded_id_vectors(), consent_ids);
EXPECT_EQ(consent_auditor()->recorded_features(), features); EXPECT_EQ(consent_auditor()->recorded_features(), features);
EXPECT_EQ(consent_auditor()->recorded_statuses(), statuses); EXPECT_EQ(consent_auditor()->recorded_statuses(), statuses);
......
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