Commit 6554955d authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Passwords] Use strong alias when constructing a TestPasswordStore

Change-Id: Ifc007754b08fad94f9e433311d7f84bae571e6b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2374450Reviewed-by: default avatarJohn Wu <jzw@chromium.org>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801484}
parent 2c9d62ea
...@@ -222,7 +222,7 @@ class CredentialManagerImplTest : public testing::Test, ...@@ -222,7 +222,7 @@ class CredentialManagerImplTest : public testing::Test,
store_->Init(/*prefs=*/nullptr); store_->Init(/*prefs=*/nullptr);
if (base::FeatureList::IsEnabled( if (base::FeatureList::IsEnabled(
features::kEnablePasswordsAccountStorage)) { features::kEnablePasswordsAccountStorage)) {
account_store_ = new TestPasswordStore(/*is_account_store=*/true); account_store_ = new TestPasswordStore(IsAccountStore(true));
ASSERT_TRUE(account_store_->Init(/*prefs=*/nullptr)); ASSERT_TRUE(account_store_->Init(/*prefs=*/nullptr));
} }
client_ = std::make_unique<testing::NiceMock<MockPasswordManagerClient>>( client_ = std::make_unique<testing::NiceMock<MockPasswordManagerClient>>(
......
...@@ -31,10 +31,10 @@ class CredentialManagerPendingPreventSilentAccessTaskTest ...@@ -31,10 +31,10 @@ class CredentialManagerPendingPreventSilentAccessTaskTest
: public ::testing::Test { : public ::testing::Test {
public: public:
CredentialManagerPendingPreventSilentAccessTaskTest() { CredentialManagerPendingPreventSilentAccessTaskTest() {
profile_store_ = new TestPasswordStore(/*is_account_store=*/false); profile_store_ = new TestPasswordStore(IsAccountStore(false));
profile_store_->Init(/*prefs=*/nullptr); profile_store_->Init(/*prefs=*/nullptr);
account_store_ = new TestPasswordStore(/*is_account_store=*/true); account_store_ = new TestPasswordStore(IsAccountStore(true));
account_store_->Init(/*prefs=*/nullptr); account_store_->Init(/*prefs=*/nullptr);
} }
~CredentialManagerPendingPreventSilentAccessTaskTest() override = default; ~CredentialManagerPendingPreventSilentAccessTaskTest() override = default;
......
...@@ -73,10 +73,10 @@ class CredentialManagerPendingRequestTaskDelegateMock ...@@ -73,10 +73,10 @@ class CredentialManagerPendingRequestTaskDelegateMock
class CredentialManagerPendingRequestTaskTest : public ::testing::Test { class CredentialManagerPendingRequestTaskTest : public ::testing::Test {
public: public:
CredentialManagerPendingRequestTaskTest() { CredentialManagerPendingRequestTaskTest() {
profile_store_ = new TestPasswordStore(/*is_account_store=*/false); profile_store_ = new TestPasswordStore(IsAccountStore(false));
profile_store_->Init(/*prefs=*/nullptr); profile_store_->Init(/*prefs=*/nullptr);
account_store_ = new TestPasswordStore(/*is_account_store=*/true); account_store_ = new TestPasswordStore(IsAccountStore(true));
account_store_->Init(/*prefs=*/nullptr); account_store_->Init(/*prefs=*/nullptr);
client_ = std::make_unique<TestPasswordManagerClient>(profile_store_.get(), client_ = std::make_unique<TestPasswordManagerClient>(profile_store_.get(),
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/pickle.h" #include "base/pickle.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/util/type_safety/strong_alias.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/password_manager/core/browser/compromised_credentials_table.h" #include "components/password_manager/core/browser/compromised_credentials_table.h"
#include "components/password_manager/core/browser/field_info_table.h" #include "components/password_manager/core/browser/field_info_table.h"
...@@ -44,8 +43,6 @@ class SQLTableBuilder; ...@@ -44,8 +43,6 @@ class SQLTableBuilder;
extern const int kCurrentVersionNumber; extern const int kCurrentVersionNumber;
extern const int kCompatibleVersionNumber; extern const int kCompatibleVersionNumber;
using IsAccountStore = util::StrongAlias<class IsAccountStoreTag, bool>;
// Interface to the database storage of login information, intended as a helper // Interface to the database storage of login information, intended as a helper
// for PasswordStore on platforms that need internal storage of some or all of // for PasswordStore on platforms that need internal storage of some or all of
// the login information. // the login information.
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "base/observer_list_threadsafe.h" #include "base/observer_list_threadsafe.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/util/type_safety/strong_alias.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/keyed_service/core/refcounted_keyed_service.h" #include "components/keyed_service/core/refcounted_keyed_service.h"
#include "components/password_manager/core/browser/compromised_credentials_table.h" #include "components/password_manager/core/browser/compromised_credentials_table.h"
...@@ -50,6 +51,8 @@ using StateSubscription = ...@@ -50,6 +51,8 @@ using StateSubscription =
namespace password_manager { namespace password_manager {
using IsAccountStore = util::StrongAlias<class IsAccountStoreTag, bool>;
#if defined(SYNC_PASSWORD_REUSE_DETECTION_ENABLED) #if defined(SYNC_PASSWORD_REUSE_DETECTION_ENABLED)
using metrics_util::GaiaPasswordHashChange; using metrics_util::GaiaPasswordHashChange;
#endif #endif
......
...@@ -122,9 +122,9 @@ TEST_P(StoreMetricsReporterTestWithParams, StoreDependentMetrics) { ...@@ -122,9 +122,9 @@ TEST_P(StoreMetricsReporterTestWithParams, StoreDependentMetrics) {
// StoreMetricsReporter directly. // StoreMetricsReporter directly.
TEST_F(StoreMetricsReporterTest, MultiStoreMetrics) { TEST_F(StoreMetricsReporterTest, MultiStoreMetrics) {
auto profile_store = auto profile_store =
base::MakeRefCounted<TestPasswordStore>(/*is_account_store=*/false); base::MakeRefCounted<TestPasswordStore>(IsAccountStore(false));
auto account_store = auto account_store =
base::MakeRefCounted<TestPasswordStore>(/*is_account_store=*/true); base::MakeRefCounted<TestPasswordStore>(IsAccountStore(true));
profile_store->Init(&prefs_); profile_store->Init(&prefs_);
account_store->Init(&prefs_); account_store->Init(&prefs_);
......
...@@ -110,7 +110,8 @@ bool TestPasswordSyncMetadataStore::HasUnsyncedDeletions() { ...@@ -110,7 +110,8 @@ bool TestPasswordSyncMetadataStore::HasUnsyncedDeletions() {
} // namespace } // namespace
TestPasswordStore::TestPasswordStore(bool is_account_store) TestPasswordStore::TestPasswordStore(
password_manager::IsAccountStore is_account_store)
: is_account_store_(is_account_store), : is_account_store_(is_account_store),
metadata_store_(std::make_unique<TestPasswordSyncMetadataStore>()) {} metadata_store_(std::make_unique<TestPasswordSyncMetadataStore>()) {}
...@@ -159,7 +160,7 @@ PasswordStoreChangeList TestPasswordStore::AddLoginImpl( ...@@ -159,7 +160,7 @@ PasswordStoreChangeList TestPasswordStore::AddLoginImpl(
changes.emplace_back(PasswordStoreChange::REMOVE, *iter); changes.emplace_back(PasswordStoreChange::REMOVE, *iter);
changes.emplace_back(PasswordStoreChange::ADD, form); changes.emplace_back(PasswordStoreChange::ADD, form);
*iter = form; *iter = form;
iter->in_store = is_account_store_ iter->in_store = IsAccountStore()
? autofill::PasswordForm::Store::kAccountStore ? autofill::PasswordForm::Store::kAccountStore
: autofill::PasswordForm::Store::kProfileStore; : autofill::PasswordForm::Store::kProfileStore;
return changes; return changes;
...@@ -168,8 +169,8 @@ PasswordStoreChangeList TestPasswordStore::AddLoginImpl( ...@@ -168,8 +169,8 @@ PasswordStoreChangeList TestPasswordStore::AddLoginImpl(
changes.emplace_back(PasswordStoreChange::ADD, form); changes.emplace_back(PasswordStoreChange::ADD, form);
passwords_for_signon_realm.push_back(form); passwords_for_signon_realm.push_back(form);
passwords_for_signon_realm.back().in_store = passwords_for_signon_realm.back().in_store =
is_account_store_ ? autofill::PasswordForm::Store::kAccountStore IsAccountStore() ? autofill::PasswordForm::Store::kAccountStore
: autofill::PasswordForm::Store::kProfileStore; : autofill::PasswordForm::Store::kProfileStore;
return changes; return changes;
} }
...@@ -185,7 +186,7 @@ PasswordStoreChangeList TestPasswordStore::UpdateLoginImpl( ...@@ -185,7 +186,7 @@ PasswordStoreChangeList TestPasswordStore::UpdateLoginImpl(
for (auto& stored_form : forms) { for (auto& stored_form : forms) {
if (ArePasswordFormUniqueKeysEqual(form, stored_form)) { if (ArePasswordFormUniqueKeysEqual(form, stored_form)) {
stored_form = form; stored_form = form;
stored_form.in_store = is_account_store_ stored_form.in_store = IsAccountStore()
? autofill::PasswordForm::Store::kAccountStore ? autofill::PasswordForm::Store::kAccountStore
: autofill::PasswordForm::Store::kProfileStore; : autofill::PasswordForm::Store::kProfileStore;
changes.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form)); changes.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form));
...@@ -338,7 +339,7 @@ std::vector<InteractionsStats> TestPasswordStore::GetAllSiteStatsImpl() { ...@@ -338,7 +339,7 @@ std::vector<InteractionsStats> TestPasswordStore::GetAllSiteStatsImpl() {
bool TestPasswordStore::AddCompromisedCredentialsImpl( bool TestPasswordStore::AddCompromisedCredentialsImpl(
const CompromisedCredentials& compromised_credentials) { const CompromisedCredentials& compromised_credentials) {
CompromisedCredentials cred = compromised_credentials; CompromisedCredentials cred = compromised_credentials;
cred.in_store = is_account_store_ cred.in_store = IsAccountStore()
? autofill::PasswordForm::Store::kAccountStore ? autofill::PasswordForm::Store::kAccountStore
: autofill::PasswordForm::Store::kProfileStore; : autofill::PasswordForm::Store::kProfileStore;
return compromised_credentials_.insert(std::move(cred)).second; return compromised_credentials_.insert(std::move(cred)).second;
...@@ -452,7 +453,7 @@ PasswordStoreSync::MetadataStore* TestPasswordStore::GetMetadataStore() { ...@@ -452,7 +453,7 @@ PasswordStoreSync::MetadataStore* TestPasswordStore::GetMetadataStore() {
} }
bool TestPasswordStore::IsAccountStore() const { bool TestPasswordStore::IsAccountStore() const {
return is_account_store_; return is_account_store_.value();
} }
bool TestPasswordStore::DeleteAndRecreateDatabaseFile() { bool TestPasswordStore::DeleteAndRecreateDatabaseFile() {
......
...@@ -35,7 +35,11 @@ MATCHER_P(MatchesFormExceptStore, expected, "") { ...@@ -35,7 +35,11 @@ MATCHER_P(MatchesFormExceptStore, expected, "") {
// for testing have been implemented. // for testing have been implemented.
class TestPasswordStore : public PasswordStore { class TestPasswordStore : public PasswordStore {
public: public:
explicit TestPasswordStore(bool is_account_store = false); // We need to qualify password_manager::IsAccountStore with the full
// namespace, otherwise, it's confused with the method
// PasswordStoreSync::IsAccountStore().
explicit TestPasswordStore(password_manager::IsAccountStore is_account_store =
password_manager::IsAccountStore(false));
using PasswordMap = std::map<std::string /* signon_realm */, using PasswordMap = std::map<std::string /* signon_realm */,
std::vector<autofill::PasswordForm>, std::vector<autofill::PasswordForm>,
...@@ -150,7 +154,7 @@ class TestPasswordStore : public PasswordStore { ...@@ -150,7 +154,7 @@ class TestPasswordStore : public PasswordStore {
bool DeleteAndRecreateDatabaseFile() override; bool DeleteAndRecreateDatabaseFile() override;
private: private:
const bool is_account_store_; const password_manager::IsAccountStore is_account_store_;
PasswordMap stored_passwords_; PasswordMap stored_passwords_;
CompromisedCredentialsStorage compromised_credentials_; CompromisedCredentialsStorage compromised_credentials_;
......
...@@ -543,9 +543,9 @@ class CompromisedCredentialsManagerWithTwoStoresTest : public ::testing::Test { ...@@ -543,9 +543,9 @@ class CompromisedCredentialsManagerWithTwoStoresTest : public ::testing::Test {
private: private:
base::test::SingleThreadTaskEnvironment task_env_; base::test::SingleThreadTaskEnvironment task_env_;
scoped_refptr<TestPasswordStore> profile_store_ = scoped_refptr<TestPasswordStore> profile_store_ =
base::MakeRefCounted<TestPasswordStore>(/*is_account_store=*/false); base::MakeRefCounted<TestPasswordStore>(IsAccountStore(false));
scoped_refptr<TestPasswordStore> account_store_ = scoped_refptr<TestPasswordStore> account_store_ =
base::MakeRefCounted<TestPasswordStore>(/*is_account_store=*/true); base::MakeRefCounted<TestPasswordStore>(IsAccountStore(true));
SavedPasswordsPresenter presenter_{profile_store_, account_store_}; SavedPasswordsPresenter presenter_{profile_store_, account_store_};
CompromisedCredentialsManager provider_{&presenter_, profile_store_, CompromisedCredentialsManager provider_{&presenter_, profile_store_,
account_store_}; account_store_};
......
...@@ -53,9 +53,9 @@ class CompromisedCredentialsReaderTest : public ::testing::Test { ...@@ -53,9 +53,9 @@ class CompromisedCredentialsReaderTest : public ::testing::Test {
private: private:
base::test::SingleThreadTaskEnvironment task_env_; base::test::SingleThreadTaskEnvironment task_env_;
scoped_refptr<TestPasswordStore> profile_store_ = scoped_refptr<TestPasswordStore> profile_store_ =
base::MakeRefCounted<TestPasswordStore>(/*is_account_store=*/false); base::MakeRefCounted<TestPasswordStore>(IsAccountStore(false));
scoped_refptr<TestPasswordStore> account_store_ = scoped_refptr<TestPasswordStore> account_store_ =
base::MakeRefCounted<TestPasswordStore>(/*is_account_store=*/true); base::MakeRefCounted<TestPasswordStore>(IsAccountStore(true));
CompromisedCredentialsReader reader_{profile_store_.get(), CompromisedCredentialsReader reader_{profile_store_.get(),
account_store_.get()}; account_store_.get()};
}; };
......
...@@ -175,9 +175,9 @@ class SavedPasswordsPresenterWithTwoStoresTest : public ::testing::Test { ...@@ -175,9 +175,9 @@ class SavedPasswordsPresenterWithTwoStoresTest : public ::testing::Test {
private: private:
base::test::SingleThreadTaskEnvironment task_env_; base::test::SingleThreadTaskEnvironment task_env_;
scoped_refptr<TestPasswordStore> profile_store_ = scoped_refptr<TestPasswordStore> profile_store_ =
base::MakeRefCounted<TestPasswordStore>(/*is_account_store=*/false); base::MakeRefCounted<TestPasswordStore>(IsAccountStore(false));
scoped_refptr<TestPasswordStore> account_store_ = scoped_refptr<TestPasswordStore> account_store_ =
base::MakeRefCounted<TestPasswordStore>(/*is_account_store=*/true); base::MakeRefCounted<TestPasswordStore>(IsAccountStore(true));
SavedPasswordsPresenter presenter_{profile_store_, account_store_}; SavedPasswordsPresenter presenter_{profile_store_, account_store_};
}; };
......
...@@ -46,7 +46,7 @@ class WebViewPasswordManagerClientTest : public PlatformTest { ...@@ -46,7 +46,7 @@ class WebViewPasswordManagerClientTest : public PlatformTest {
base::MakeRefCounted<password_manager::TestPasswordStore>()), base::MakeRefCounted<password_manager::TestPasswordStore>()),
account_store_( account_store_(
base::MakeRefCounted<password_manager::TestPasswordStore>( base::MakeRefCounted<password_manager::TestPasswordStore>(
/*is_account_store=*/true)) { password_manager::IsAccountStore(true))) {
scoped_feature.InitAndEnableFeature( scoped_feature.InitAndEnableFeature(
password_manager::features::kEnablePasswordsAccountStorage); password_manager::features::kEnablePasswordsAccountStorage);
......
...@@ -46,7 +46,7 @@ class WebViewSyncClientTest : public PlatformTest { ...@@ -46,7 +46,7 @@ class WebViewSyncClientTest : public PlatformTest {
base::FeatureList::IsEnabled( base::FeatureList::IsEnabled(
password_manager::features::kEnablePasswordsAccountStorage) password_manager::features::kEnablePasswordsAccountStorage)
? base::MakeRefCounted<password_manager::TestPasswordStore>( ? base::MakeRefCounted<password_manager::TestPasswordStore>(
/*is_account_store=*/true) password_manager::IsAccountStore(true))
: nullptr), : nullptr),
client_(profile_web_data_service_.get(), client_(profile_web_data_service_.get(),
account_web_data_service_.get(), account_web_data_service_.get(),
......
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