Commit 244bea03 authored by Abhijeet Kandalkar's avatar Abhijeet Kandalkar Committed by Commit Bot

Eliminate use of SigninManager in password_store_signin_notifier_impl_unittest.cc

This CL replace the use of SigninManager by IdentityManager and removes
unused headers.

It also replace LegacyXXX() methods by IdentityTestEnvironment class
methods.

Bug: 926949
Change-Id: Ie776be3de99e1e544fbe5c17330c923114fff594
Reviewed-on: https://chromium-review.googlesource.com/c/1447992Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Commit-Queue: Abhijeet Kandalkar <abhijeet@igalia.com>
Cr-Commit-Position: refs/heads/master@{#629557}
parent b0a798fa
...@@ -6,9 +6,7 @@ ...@@ -6,9 +6,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "chrome/browser/signin/account_fetcher_service_factory.h" #include "chrome/browser/signin/account_fetcher_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/identity_manager_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/password_manager/core/browser/mock_password_store.h" #include "components/password_manager/core/browser/mock_password_store.h"
#include "components/signin/core/browser/account_fetcher_service.h" #include "components/signin/core/browser/account_fetcher_service.h"
...@@ -25,13 +23,12 @@ namespace { ...@@ -25,13 +23,12 @@ namespace {
class PasswordStoreSigninNotifierImplTest : public testing::Test { class PasswordStoreSigninNotifierImplTest : public testing::Test {
public: public:
PasswordStoreSigninNotifierImplTest() { PasswordStoreSigninNotifierImplTest() {
TestingProfile::Builder builder; testing_profile_ = IdentityTestEnvironmentProfileAdaptor::
builder.AddTestingFactory( CreateProfileForIdentityTestEnvironment();
SigninManagerFactory::GetInstance(),
base::BindRepeating(&BuildFakeSigninManagerForTesting)); identity_test_env_adaptor_ =
testing_profile_.reset(builder.Build().release()); std::make_unique<IdentityTestEnvironmentProfileAdaptor>(
fake_signin_manager_ = static_cast<FakeSigninManagerForTesting*>( testing_profile_.get());
SigninManagerFactory::GetForProfile(testing_profile_.get()));
store_ = new MockPasswordStore(); store_ = new MockPasswordStore();
} }
...@@ -39,10 +36,15 @@ class PasswordStoreSigninNotifierImplTest : public testing::Test { ...@@ -39,10 +36,15 @@ class PasswordStoreSigninNotifierImplTest : public testing::Test {
store_->ShutdownOnUIThread(); store_->ShutdownOnUIThread();
} }
identity::IdentityTestEnvironment* identity_test_env() {
return identity_test_env_adaptor_->identity_test_env();
}
protected: protected:
content::TestBrowserThreadBundle thread_bundle; content::TestBrowserThreadBundle thread_bundle;
std::unique_ptr<TestingProfile> testing_profile_; std::unique_ptr<TestingProfile> testing_profile_;
FakeSigninManagerForTesting* fake_signin_manager_; // Weak std::unique_ptr<IdentityTestEnvironmentProfileAdaptor>
identity_test_env_adaptor_;
scoped_refptr<MockPasswordStore> store_; scoped_refptr<MockPasswordStore> store_;
}; };
...@@ -51,10 +53,10 @@ class PasswordStoreSigninNotifierImplTest : public testing::Test { ...@@ -51,10 +53,10 @@ class PasswordStoreSigninNotifierImplTest : public testing::Test {
TEST_F(PasswordStoreSigninNotifierImplTest, Subscribed) { TEST_F(PasswordStoreSigninNotifierImplTest, Subscribed) {
PasswordStoreSigninNotifierImpl notifier(testing_profile_.get()); PasswordStoreSigninNotifierImpl notifier(testing_profile_.get());
notifier.SubscribeToSigninEvents(store_.get()); notifier.SubscribeToSigninEvents(store_.get());
fake_signin_manager_->SignIn("accountid", "username"); identity_test_env()->MakePrimaryAccountAvailable("test@example.com");
testing::Mock::VerifyAndClearExpectations(store_.get()); testing::Mock::VerifyAndClearExpectations(store_.get());
EXPECT_CALL(*store_, ClearAllGaiaPasswordHash()); EXPECT_CALL(*store_, ClearAllGaiaPasswordHash());
fake_signin_manager_->ForceSignOut(); identity_test_env()->ClearPrimaryAccount();
notifier.UnsubscribeFromSigninEvents(); notifier.UnsubscribeFromSigninEvents();
} }
...@@ -65,8 +67,8 @@ TEST_F(PasswordStoreSigninNotifierImplTest, Unsubscribed) { ...@@ -65,8 +67,8 @@ TEST_F(PasswordStoreSigninNotifierImplTest, Unsubscribed) {
notifier.SubscribeToSigninEvents(store_.get()); notifier.SubscribeToSigninEvents(store_.get());
notifier.UnsubscribeFromSigninEvents(); notifier.UnsubscribeFromSigninEvents();
EXPECT_CALL(*store_, ClearAllGaiaPasswordHash()).Times(0); EXPECT_CALL(*store_, ClearAllGaiaPasswordHash()).Times(0);
fake_signin_manager_->SignIn("accountid", "username"); identity_test_env()->MakePrimaryAccountAvailable("test@example.com");
fake_signin_manager_->ForceSignOut(); identity_test_env()->ClearPrimaryAccount();
} }
// Checks that if a notifier is unsubscribed on sign-in events, then // Checks that if a notifier is unsubscribed on sign-in events, then
...@@ -75,42 +77,28 @@ TEST_F(PasswordStoreSigninNotifierImplTest, SignOutContentArea) { ...@@ -75,42 +77,28 @@ TEST_F(PasswordStoreSigninNotifierImplTest, SignOutContentArea) {
PasswordStoreSigninNotifierImpl notifier(testing_profile_.get()); PasswordStoreSigninNotifierImpl notifier(testing_profile_.get());
notifier.SubscribeToSigninEvents(store_.get()); notifier.SubscribeToSigninEvents(store_.get());
identity::IdentityManager* identity_manager = identity_test_env()->MakePrimaryAccountAvailable("username");
IdentityManagerFactory::GetForProfileIfExists(testing_profile_.get());
identity::PrimaryAccountMutator* primary_account_mutator =
identity_manager->GetPrimaryAccountMutator();
DCHECK(primary_account_mutator);
primary_account_mutator->LegacyStartSigninWithRefreshTokenForPrimaryAccount(
/*refresh_token=*/"refresh_token",
/*gaia_id=*/"primary_account_id",
/*username=*/"username", base::OnceCallback<void(const std::string&)>());
primary_account_mutator->LegacyCompletePendingPrimaryAccountSignin();
testing::Mock::VerifyAndClearExpectations(store_.get()); testing::Mock::VerifyAndClearExpectations(store_.get());
EXPECT_CALL(*store_, ClearGaiaPasswordHash("username2")); EXPECT_CALL(*store_, ClearGaiaPasswordHash("username2"));
auto* identity_manager = identity_test_env()->identity_manager();
AccountFetcherService* account_fetcher_service = AccountFetcherService* account_fetcher_service =
AccountFetcherServiceFactory::GetForProfile(testing_profile_.get()); AccountFetcherServiceFactory::GetForProfile(testing_profile_.get());
// This call is necessary to ensure that the account removal is fully
// processed in this testing context.
account_fetcher_service->EnableNetworkFetchesForTest();
identity_manager->GetAccountsMutator()->AddOrUpdateAccount( identity_manager->GetAccountsMutator()->AddOrUpdateAccount(
/*gaia_id=*/"secondary_account_id", /*gaia_id=*/"secondary_account_id",
/*email=*/"username2", /*email=*/"username2",
/*refresh_token=*/"refresh_token", /*refresh_token=*/"refresh_token",
/*is_under_advanced_protection=*/false, /*is_under_advanced_protection=*/false,
signin_metrics::SourceForRefreshTokenOperation::kUnknown); signin_metrics::SourceForRefreshTokenOperation::kUnknown);
// This call is necessary to ensure that the account removal is fully
// processed in this testing context.
account_fetcher_service->EnableNetworkFetchesForTest();
identity_manager->GetAccountsMutator()->RemoveAccount( identity_manager->GetAccountsMutator()->RemoveAccount(
"secondary_account_id", "secondary_account_id",
signin_metrics::SourceForRefreshTokenOperation::kUserMenu_RemoveAccount); signin_metrics::SourceForRefreshTokenOperation::kUserMenu_RemoveAccount);
testing::Mock::VerifyAndClearExpectations(store_.get()); testing::Mock::VerifyAndClearExpectations(store_.get());
EXPECT_CALL(*store_, ClearAllGaiaPasswordHash()); EXPECT_CALL(*store_, ClearAllGaiaPasswordHash());
primary_account_mutator->ClearPrimaryAccount( identity_test_env()->ClearPrimaryAccount();
identity::PrimaryAccountMutator::ClearAccountsAction::kRemoveAll,
signin_metrics::FORCE_SIGNOUT_ALWAYS_ALLOWED_FOR_TEST,
signin_metrics::SignoutDelete::IGNORE_METRIC);
notifier.UnsubscribeFromSigninEvents(); notifier.UnsubscribeFromSigninEvents();
} }
......
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