Commit ba5ecfd4 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Convert PasswordStoreSigninNotifierImplTest to IdentityTestEnvironment

Change PasswordStoreSigninNotifierImpl to receive IdentityManager
instead of the Profile in its constructor.

Convert the test class to use IdentityTestEnvironment instead of
IdentityTestEnvironmentProfileAdaptor, thus allowing to remove the
need for creating a TestingProfile.

Bug: 984487
Change-Id: Ic840579d42a91080c4b611903eddb4634a79a028
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1706509Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#679031}
parent 0158de38
...@@ -303,7 +303,7 @@ PasswordStoreFactory::BuildServiceInstanceFor( ...@@ -303,7 +303,7 @@ PasswordStoreFactory::BuildServiceInstanceFor(
(defined(OS_LINUX) && !defined(OS_CHROMEOS)) (defined(OS_LINUX) && !defined(OS_CHROMEOS))
std::unique_ptr<password_manager::PasswordStoreSigninNotifier> notifier = std::unique_ptr<password_manager::PasswordStoreSigninNotifier> notifier =
std::make_unique<password_manager::PasswordStoreSigninNotifierImpl>( std::make_unique<password_manager::PasswordStoreSigninNotifierImpl>(
profile); IdentityManagerFactory::GetForProfile(profile));
ps->SetPasswordStoreSigninNotifier(std::move(notifier)); ps->SetPasswordStoreSigninNotifier(std::move(notifier));
#endif #endif
......
...@@ -4,16 +4,14 @@ ...@@ -4,16 +4,14 @@
#include "chrome/browser/password_manager/password_store_signin_notifier_impl.h" #include "chrome/browser/password_manager/password_store_signin_notifier_impl.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "components/signin/public/identity_manager/identity_manager.h" #include "components/signin/public/identity_manager/identity_manager.h"
namespace password_manager { namespace password_manager {
PasswordStoreSigninNotifierImpl::PasswordStoreSigninNotifierImpl( PasswordStoreSigninNotifierImpl::PasswordStoreSigninNotifierImpl(
Profile* profile) identity::IdentityManager* identity_manager)
: profile_(profile) { : identity_manager_(identity_manager) {
DCHECK(profile); DCHECK(identity_manager_);
} }
PasswordStoreSigninNotifierImpl::~PasswordStoreSigninNotifierImpl() {} PasswordStoreSigninNotifierImpl::~PasswordStoreSigninNotifierImpl() {}
...@@ -21,11 +19,11 @@ PasswordStoreSigninNotifierImpl::~PasswordStoreSigninNotifierImpl() {} ...@@ -21,11 +19,11 @@ PasswordStoreSigninNotifierImpl::~PasswordStoreSigninNotifierImpl() {}
void PasswordStoreSigninNotifierImpl::SubscribeToSigninEvents( void PasswordStoreSigninNotifierImpl::SubscribeToSigninEvents(
PasswordStore* store) { PasswordStore* store) {
set_store(store); set_store(store);
IdentityManagerFactory::GetForProfile(profile_)->AddObserver(this); identity_manager_->AddObserver(this);
} }
void PasswordStoreSigninNotifierImpl::UnsubscribeFromSigninEvents() { void PasswordStoreSigninNotifierImpl::UnsubscribeFromSigninEvents() {
IdentityManagerFactory::GetForProfile(profile_)->RemoveObserver(this); identity_manager_->RemoveObserver(this);
} }
void PasswordStoreSigninNotifierImpl::OnPrimaryAccountCleared( void PasswordStoreSigninNotifierImpl::OnPrimaryAccountCleared(
...@@ -37,8 +35,7 @@ void PasswordStoreSigninNotifierImpl::OnPrimaryAccountCleared( ...@@ -37,8 +35,7 @@ void PasswordStoreSigninNotifierImpl::OnPrimaryAccountCleared(
void PasswordStoreSigninNotifierImpl::OnExtendedAccountInfoRemoved( void PasswordStoreSigninNotifierImpl::OnExtendedAccountInfoRemoved(
const AccountInfo& info) { const AccountInfo& info) {
// Only reacts to content area (non-primary) Gaia account sign-out event. // Only reacts to content area (non-primary) Gaia account sign-out event.
if (info.account_id != if (info.account_id != identity_manager_->GetPrimaryAccountId()) {
IdentityManagerFactory::GetForProfile(profile_)->GetPrimaryAccountId()) {
NotifySignedOut(info.email, /* primary_account= */ false); NotifySignedOut(info.email, /* primary_account= */ false);
} }
} }
......
...@@ -6,12 +6,9 @@ ...@@ -6,12 +6,9 @@
#define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_SIGNIN_NOTIFIER_IMPL_H_ #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_SIGNIN_NOTIFIER_IMPL_H_
#include "base/macros.h" #include "base/macros.h"
#include "components/password_manager/core/browser/password_store_signin_notifier.h" #include "components/password_manager/core/browser/password_store_signin_notifier.h"
#include "components/signin/public/identity_manager/identity_manager.h" #include "components/signin/public/identity_manager/identity_manager.h"
class Profile;
namespace password_manager { namespace password_manager {
// Responsible for subscribing to Chrome sign-in events and passing them to // Responsible for subscribing to Chrome sign-in events and passing them to
...@@ -20,7 +17,8 @@ class PasswordStoreSigninNotifierImpl ...@@ -20,7 +17,8 @@ class PasswordStoreSigninNotifierImpl
: public PasswordStoreSigninNotifier, : public PasswordStoreSigninNotifier,
public identity::IdentityManager::Observer { public identity::IdentityManager::Observer {
public: public:
explicit PasswordStoreSigninNotifierImpl(Profile* profile); explicit PasswordStoreSigninNotifierImpl(
identity::IdentityManager* identity_manager);
~PasswordStoreSigninNotifierImpl() override; ~PasswordStoreSigninNotifierImpl() override;
// PasswordStoreSigninNotifier implementations. // PasswordStoreSigninNotifier implementations.
...@@ -32,7 +30,7 @@ class PasswordStoreSigninNotifierImpl ...@@ -32,7 +30,7 @@ class PasswordStoreSigninNotifierImpl
void OnExtendedAccountInfoRemoved(const AccountInfo& info) override; void OnExtendedAccountInfoRemoved(const AccountInfo& info) override;
private: private:
Profile* const profile_; identity::IdentityManager* identity_manager_ = nullptr;
}; };
} // namespace password_manager } // namespace password_manager
......
...@@ -5,12 +5,11 @@ ...@@ -5,12 +5,11 @@
#include "chrome/browser/password_manager/password_store_signin_notifier_impl.h" #include "chrome/browser/password_manager/password_store_signin_notifier_impl.h"
#include "base/bind.h" #include "base/bind.h"
#include "chrome/browser/signin/identity_test_environment_profile_adaptor.h" #include "base/test/scoped_task_environment.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/public/identity_manager/accounts_mutator.h" #include "components/signin/public/identity_manager/accounts_mutator.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "components/signin/public/identity_manager/primary_account_mutator.h" #include "components/signin/public/identity_manager/primary_account_mutator.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using testing::_; using testing::_;
...@@ -21,12 +20,6 @@ namespace { ...@@ -21,12 +20,6 @@ namespace {
class PasswordStoreSigninNotifierImplTest : public testing::Test { class PasswordStoreSigninNotifierImplTest : public testing::Test {
public: public:
PasswordStoreSigninNotifierImplTest() { PasswordStoreSigninNotifierImplTest() {
testing_profile_ = IdentityTestEnvironmentProfileAdaptor::
CreateProfileForIdentityTestEnvironment();
identity_test_env_adaptor_ =
std::make_unique<IdentityTestEnvironmentProfileAdaptor>(
testing_profile_.get());
store_ = new MockPasswordStore(); store_ = new MockPasswordStore();
} }
...@@ -35,21 +28,23 @@ class PasswordStoreSigninNotifierImplTest : public testing::Test { ...@@ -35,21 +28,23 @@ class PasswordStoreSigninNotifierImplTest : public testing::Test {
} }
identity::IdentityTestEnvironment* identity_test_env() { identity::IdentityTestEnvironment* identity_test_env() {
return identity_test_env_adaptor_->identity_test_env(); return &identity_test_env_;
}
identity::IdentityManager* identity_manager() {
return identity_test_env()->identity_manager();
} }
protected: protected:
content::TestBrowserThreadBundle thread_bundle; base::test::ScopedTaskEnvironment scoped_task_environment_;
std::unique_ptr<TestingProfile> testing_profile_; identity::IdentityTestEnvironment identity_test_env_;
std::unique_ptr<IdentityTestEnvironmentProfileAdaptor>
identity_test_env_adaptor_;
scoped_refptr<MockPasswordStore> store_; scoped_refptr<MockPasswordStore> store_;
}; };
// Checks that if a notifier is subscribed on sign-in events, then // Checks that if a notifier is subscribed on sign-in events, then
// a password store receives sign-in notifications. // a password store receives sign-in notifications.
TEST_F(PasswordStoreSigninNotifierImplTest, Subscribed) { TEST_F(PasswordStoreSigninNotifierImplTest, Subscribed) {
PasswordStoreSigninNotifierImpl notifier(testing_profile_.get()); PasswordStoreSigninNotifierImpl notifier(identity_manager());
notifier.SubscribeToSigninEvents(store_.get()); notifier.SubscribeToSigninEvents(store_.get());
identity_test_env()->MakePrimaryAccountAvailable("test@example.com"); identity_test_env()->MakePrimaryAccountAvailable("test@example.com");
testing::Mock::VerifyAndClearExpectations(store_.get()); testing::Mock::VerifyAndClearExpectations(store_.get());
...@@ -61,7 +56,7 @@ TEST_F(PasswordStoreSigninNotifierImplTest, Subscribed) { ...@@ -61,7 +56,7 @@ TEST_F(PasswordStoreSigninNotifierImplTest, Subscribed) {
// Checks that if a notifier is unsubscribed on sign-in events, then // Checks that if a notifier is unsubscribed on sign-in events, then
// a password store receives no sign-in notifications. // a password store receives no sign-in notifications.
TEST_F(PasswordStoreSigninNotifierImplTest, Unsubscribed) { TEST_F(PasswordStoreSigninNotifierImplTest, Unsubscribed) {
PasswordStoreSigninNotifierImpl notifier(testing_profile_.get()); PasswordStoreSigninNotifierImpl notifier(identity_manager());
notifier.SubscribeToSigninEvents(store_.get()); notifier.SubscribeToSigninEvents(store_.get());
notifier.UnsubscribeFromSigninEvents(); notifier.UnsubscribeFromSigninEvents();
EXPECT_CALL(*store_, ClearAllGaiaPasswordHash()).Times(0); EXPECT_CALL(*store_, ClearAllGaiaPasswordHash()).Times(0);
...@@ -72,7 +67,7 @@ TEST_F(PasswordStoreSigninNotifierImplTest, Unsubscribed) { ...@@ -72,7 +67,7 @@ TEST_F(PasswordStoreSigninNotifierImplTest, Unsubscribed) {
// Checks that if a notifier is unsubscribed on sign-in events, then // Checks that if a notifier is unsubscribed on sign-in events, then
// a password store receives no sign-in notifications. // a password store receives no sign-in notifications.
TEST_F(PasswordStoreSigninNotifierImplTest, SignOutContentArea) { TEST_F(PasswordStoreSigninNotifierImplTest, SignOutContentArea) {
PasswordStoreSigninNotifierImpl notifier(testing_profile_.get()); PasswordStoreSigninNotifierImpl notifier(identity_manager());
notifier.SubscribeToSigninEvents(store_.get()); notifier.SubscribeToSigninEvents(store_.get());
identity_test_env()->MakePrimaryAccountAvailable("username"); identity_test_env()->MakePrimaryAccountAvailable("username");
......
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