Commit 3030e0e7 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Passwords] Enable CredentialManagerImplTest for account storage feature

This CL makes CredentialManagerImplTest paramtereized to make sure
they pass when the the account storage feature is enabled.

This uncovered some bug where the http-->https was invoked twice.

Bug: 1093286
Change-Id: Ieb8db5de2d5f19c144b14cb72797d70888fa2b9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2307255
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790054}
parent 066000bd
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/password_manager/core/browser/android_affiliation/mock_affiliated_match_helper.h" #include "components/password_manager/core/browser/android_affiliation/mock_affiliated_match_helper.h"
...@@ -202,16 +203,26 @@ GURL HttpURLFromHttps(const GURL& https_url) { ...@@ -202,16 +203,26 @@ GURL HttpURLFromHttps(const GURL& https_url) {
} // namespace } // namespace
class CredentialManagerImplTest : public testing::Test { // Test param controls whether to enable the account storage feature.
class CredentialManagerImplTest : public testing::Test,
public testing::WithParamInterface<bool> {
public: public:
CredentialManagerImplTest() = default; CredentialManagerImplTest() {
if (GetParam()) {
feature_list_.InitAndEnableFeature(
password_manager::features::kEnablePasswordsAccountStorage);
} else {
feature_list_.InitAndDisableFeature(
password_manager::features::kEnablePasswordsAccountStorage);
}
}
void SetUp() override { void SetUp() override {
store_ = new TestPasswordStore; store_ = new TestPasswordStore;
store_->Init(/*prefs=*/nullptr); store_->Init(/*prefs=*/nullptr);
if (base::FeatureList::IsEnabled( if (base::FeatureList::IsEnabled(
features::kEnablePasswordsAccountStorage)) { features::kEnablePasswordsAccountStorage)) {
account_store_ = new TestPasswordStore; account_store_ = new TestPasswordStore(/*is_account_store=*/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>>(
...@@ -368,6 +379,7 @@ class CredentialManagerImplTest : public testing::Test { ...@@ -368,6 +379,7 @@ class CredentialManagerImplTest : public testing::Test {
void RunAllPendingTasks() { task_environment_.RunUntilIdle(); } void RunAllPendingTasks() { task_environment_.RunUntilIdle(); }
protected: protected:
base::test::ScopedFeatureList feature_list_;
base::test::TaskEnvironment task_environment_; base::test::TaskEnvironment task_environment_;
autofill::PasswordForm form_; autofill::PasswordForm form_;
autofill::PasswordForm affiliated_form1_; autofill::PasswordForm affiliated_form1_;
...@@ -381,7 +393,7 @@ class CredentialManagerImplTest : public testing::Test { ...@@ -381,7 +393,7 @@ class CredentialManagerImplTest : public testing::Test {
std::unique_ptr<CredentialManagerImpl> cm_service_impl_; std::unique_ptr<CredentialManagerImpl> cm_service_impl_;
}; };
TEST_F(CredentialManagerImplTest, IsZeroClickAllowed) { TEST_P(CredentialManagerImplTest, IsZeroClickAllowed) {
// IsZeroClickAllowed is uneffected by the first-run status. // IsZeroClickAllowed is uneffected by the first-run status.
client_->set_zero_click_enabled(true); client_->set_zero_click_enabled(true);
client_->set_first_run_seen(true); client_->set_first_run_seen(true);
...@@ -400,7 +412,7 @@ TEST_F(CredentialManagerImplTest, IsZeroClickAllowed) { ...@@ -400,7 +412,7 @@ TEST_F(CredentialManagerImplTest, IsZeroClickAllowed) {
EXPECT_FALSE(cm_service_impl()->IsZeroClickAllowed()); EXPECT_FALSE(cm_service_impl()->IsZeroClickAllowed());
} }
TEST_F(CredentialManagerImplTest, CredentialManagerOnStore) { TEST_P(CredentialManagerImplTest, CredentialManagerOnStore) {
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)) EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_))
.Times(testing::Exactly(1)); .Times(testing::Exactly(1));
...@@ -428,7 +440,7 @@ TEST_F(CredentialManagerImplTest, CredentialManagerOnStore) { ...@@ -428,7 +440,7 @@ TEST_F(CredentialManagerImplTest, CredentialManagerOnStore) {
EXPECT_EQ(autofill::PasswordForm::Scheme::kHtml, new_form.scheme); EXPECT_EQ(autofill::PasswordForm::Scheme::kHtml, new_form.scheme);
} }
TEST_F(CredentialManagerImplTest, CredentialManagerOnStoreFederated) { TEST_P(CredentialManagerImplTest, CredentialManagerOnStoreFederated) {
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)) EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_))
.Times(testing::Exactly(1)); .Times(testing::Exactly(1));
EXPECT_CALL(*client_, NotifyStorePasswordCalled()); EXPECT_CALL(*client_, NotifyStorePasswordCalled());
...@@ -459,7 +471,7 @@ TEST_F(CredentialManagerImplTest, CredentialManagerOnStoreFederated) { ...@@ -459,7 +471,7 @@ TEST_F(CredentialManagerImplTest, CredentialManagerOnStoreFederated) {
EXPECT_EQ(autofill::PasswordForm::Scheme::kHtml, new_form.scheme); EXPECT_EQ(autofill::PasswordForm::Scheme::kHtml, new_form.scheme);
} }
TEST_F(CredentialManagerImplTest, StoreFederatedAfterPassword) { TEST_P(CredentialManagerImplTest, StoreFederatedAfterPassword) {
// Populate the PasswordStore with a form. // Populate the PasswordStore with a form.
store_->AddLogin(form_); store_->AddLogin(form_);
...@@ -495,7 +507,7 @@ TEST_F(CredentialManagerImplTest, StoreFederatedAfterPassword) { ...@@ -495,7 +507,7 @@ TEST_F(CredentialManagerImplTest, StoreFederatedAfterPassword) {
ElementsAre(MatchesFormExceptStore(federated))); ElementsAre(MatchesFormExceptStore(federated)));
} }
TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwrite) { TEST_P(CredentialManagerImplTest, CredentialManagerStoreOverwrite) {
// Add an unrelated form to complicate the task. // Add an unrelated form to complicate the task.
store_->AddLogin(origin_path_form_); store_->AddLogin(origin_path_form_);
// Populate the PasswordStore with a form. // Populate the PasswordStore with a form.
...@@ -534,7 +546,7 @@ TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwrite) { ...@@ -534,7 +546,7 @@ TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwrite) {
passwords[form_.signon_realm][1].icon_url); passwords[form_.signon_realm][1].icon_url);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerStorePSLMatchDoesNotTriggerBubble) { CredentialManagerStorePSLMatchDoesNotTriggerBubble) {
autofill::PasswordForm psl_form = subdomain_form_; autofill::PasswordForm psl_form = subdomain_form_;
psl_form.username_value = form_.username_value; psl_form.username_value = form_.username_value;
...@@ -560,7 +572,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -560,7 +572,7 @@ TEST_F(CredentialManagerImplTest,
EXPECT_EQ(1U, passwords[psl_form.signon_realm].size()); EXPECT_EQ(1U, passwords[psl_form.signon_realm].size());
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerStorePSLMatchWithDifferentUsernameTriggersBubble) { CredentialManagerStorePSLMatchWithDifferentUsernameTriggersBubble) {
base::string16 delta = base::ASCIIToUTF16("_totally_different"); base::string16 delta = base::ASCIIToUTF16("_totally_different");
autofill::PasswordForm psl_form = subdomain_form_; autofill::PasswordForm psl_form = subdomain_form_;
...@@ -592,7 +604,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -592,7 +604,7 @@ TEST_F(CredentialManagerImplTest,
EXPECT_EQ(info.password, pending_cred.password_value); EXPECT_EQ(info.password, pending_cred.password_value);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerStorePSLMatchWithDifferentPasswordTriggersBubble) { CredentialManagerStorePSLMatchWithDifferentPasswordTriggersBubble) {
base::string16 delta = base::ASCIIToUTF16("_totally_different"); base::string16 delta = base::ASCIIToUTF16("_totally_different");
autofill::PasswordForm psl_form = subdomain_form_; autofill::PasswordForm psl_form = subdomain_form_;
...@@ -624,7 +636,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -624,7 +636,7 @@ TEST_F(CredentialManagerImplTest,
EXPECT_EQ(info.password, pending_cred.password_value); EXPECT_EQ(info.password, pending_cred.password_value);
} }
TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwriteZeroClick) { TEST_P(CredentialManagerImplTest, CredentialManagerStoreOverwriteZeroClick) {
form_.skip_zero_click = true; form_.skip_zero_click = true;
store_->AddLogin(form_); store_->AddLogin(form_);
RunAllPendingTasks(); RunAllPendingTasks();
...@@ -645,7 +657,7 @@ TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwriteZeroClick) { ...@@ -645,7 +657,7 @@ TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwriteZeroClick) {
EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerFederatedStoreOverwriteZeroClick) { CredentialManagerFederatedStoreOverwriteZeroClick) {
form_.federation_origin = url::Origin::Create(GURL("https://example.com/")); form_.federation_origin = url::Origin::Create(GURL("https://example.com/"));
form_.password_value = base::string16(); form_.password_value = base::string16();
...@@ -670,7 +682,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -670,7 +682,7 @@ TEST_F(CredentialManagerImplTest,
EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
} }
TEST_F(CredentialManagerImplTest, CredentialManagerGetOverwriteZeroClick) { TEST_P(CredentialManagerImplTest, CredentialManagerGetOverwriteZeroClick) {
// Set the global zero click flag on, and populate the PasswordStore with a // Set the global zero click flag on, and populate the PasswordStore with a
// form that's set to skip zero click and has a primary key that won't match // form that's set to skip zero click and has a primary key that won't match
// credentials initially created via `store()`. // credentials initially created via `store()`.
...@@ -703,7 +715,7 @@ TEST_F(CredentialManagerImplTest, CredentialManagerGetOverwriteZeroClick) { ...@@ -703,7 +715,7 @@ TEST_F(CredentialManagerImplTest, CredentialManagerGetOverwriteZeroClick) {
EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerSignInWithSavingDisabledForCurrentPage) { CredentialManagerSignInWithSavingDisabledForCurrentPage) {
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
EXPECT_CALL(*client_, IsSavingAndFillingEnabled(form_.url)) EXPECT_CALL(*client_, IsSavingAndFillingEnabled(form_.url))
...@@ -721,7 +733,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -721,7 +733,7 @@ TEST_F(CredentialManagerImplTest,
EXPECT_FALSE(client_->pending_manager()); EXPECT_FALSE(client_->pending_manager());
} }
TEST_F(CredentialManagerImplTest, CredentialManagerOnPreventSilentAccess) { TEST_P(CredentialManagerImplTest, CredentialManagerOnPreventSilentAccess) {
store_->AddLogin(form_); store_->AddLogin(form_);
store_->AddLogin(subdomain_form_); store_->AddLogin(subdomain_form_);
store_->AddLogin(cross_origin_form_); store_->AddLogin(cross_origin_form_);
...@@ -753,7 +765,7 @@ TEST_F(CredentialManagerImplTest, CredentialManagerOnPreventSilentAccess) { ...@@ -753,7 +765,7 @@ TEST_F(CredentialManagerImplTest, CredentialManagerOnPreventSilentAccess) {
EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnPreventSilentAccessIncognito) { CredentialManagerOnPreventSilentAccessIncognito) {
EXPECT_CALL(*client_, IsSavingAndFillingEnabled(_)) EXPECT_CALL(*client_, IsSavingAndFillingEnabled(_))
.WillRepeatedly(testing::Return(false)); .WillRepeatedly(testing::Return(false));
...@@ -777,7 +789,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -777,7 +789,7 @@ TEST_F(CredentialManagerImplTest,
EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnPreventMediatedAccessIncognito) { CredentialManagerOnPreventMediatedAccessIncognito) {
EXPECT_CALL(*client_, IsIncognito()).WillRepeatedly(testing::Return(true)); EXPECT_CALL(*client_, IsIncognito()).WillRepeatedly(testing::Return(true));
EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr).Times(0); EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr).Times(0);
...@@ -803,7 +815,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -803,7 +815,7 @@ TEST_F(CredentialManagerImplTest,
EXPECT_EQ(CredentialManagerError::SUCCESS, error); EXPECT_EQ(CredentialManagerError::SUCCESS, error);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnPreventSilentAccessWithAffiliation) { CredentialManagerOnPreventSilentAccessWithAffiliation) {
store_->AddLogin(form_); store_->AddLogin(form_);
store_->AddLogin(cross_origin_form_); store_->AddLogin(cross_origin_form_);
...@@ -840,7 +852,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -840,7 +852,7 @@ TEST_F(CredentialManagerImplTest,
EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click); EXPECT_FALSE(passwords[affiliated_form2_.signon_realm][0].skip_zero_click);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialWithEmptyPasswordStore) { CredentialManagerOnRequestCredentialWithEmptyPasswordStore) {
std::vector<GURL> federations; std::vector<GURL> federations;
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)) EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_))
...@@ -853,7 +865,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -853,7 +865,7 @@ TEST_F(CredentialManagerImplTest,
federations, CredentialType::CREDENTIAL_TYPE_EMPTY); federations, CredentialType::CREDENTIAL_TYPE_EMPTY);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialWithEmptyUsernames) { CredentialManagerOnRequestCredentialWithEmptyUsernames) {
form_.username_value.clear(); form_.username_value.clear();
store_->AddLogin(form_); store_->AddLogin(form_);
...@@ -866,7 +878,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -866,7 +878,7 @@ TEST_F(CredentialManagerImplTest,
federations, CredentialType::CREDENTIAL_TYPE_EMPTY); federations, CredentialType::CREDENTIAL_TYPE_EMPTY);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialWithPSLCredential) { CredentialManagerOnRequestCredentialWithPSLCredential) {
store_->AddLogin(subdomain_form_); store_->AddLogin(subdomain_form_);
subdomain_form_.is_public_suffix_match = true; subdomain_form_.is_public_suffix_match = true;
...@@ -881,7 +893,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -881,7 +893,7 @@ TEST_F(CredentialManagerImplTest,
CredentialType::CREDENTIAL_TYPE_PASSWORD); CredentialType::CREDENTIAL_TYPE_PASSWORD);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialWithPSLAndNormalCredentials) { CredentialManagerOnRequestCredentialWithPSLAndNormalCredentials) {
store_->AddLogin(form_); store_->AddLogin(form_);
store_->AddLogin(origin_path_form_); store_->AddLogin(origin_path_form_);
...@@ -899,7 +911,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -899,7 +911,7 @@ TEST_F(CredentialManagerImplTest,
CredentialType::CREDENTIAL_TYPE_PASSWORD); CredentialType::CREDENTIAL_TYPE_PASSWORD);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialWithEmptyAndNonemptyUsernames) { CredentialManagerOnRequestCredentialWithEmptyAndNonemptyUsernames) {
store_->AddLogin(form_); store_->AddLogin(form_);
autofill::PasswordForm empty = form_; autofill::PasswordForm empty = form_;
...@@ -915,7 +927,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -915,7 +927,7 @@ TEST_F(CredentialManagerImplTest,
CredentialType::CREDENTIAL_TYPE_PASSWORD); CredentialType::CREDENTIAL_TYPE_PASSWORD);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialWithDuplicates) { CredentialManagerOnRequestCredentialWithDuplicates) {
// Add 6 credentials. Two buckets of duplicates, one empty username and one // Add 6 credentials. Two buckets of duplicates, one empty username and one
// federated one. There should be just 3 in the account chooser. // federated one. There should be just 3 in the account chooser.
...@@ -959,7 +971,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -959,7 +971,7 @@ TEST_F(CredentialManagerImplTest,
RunAllPendingTasks(); RunAllPendingTasks();
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) { CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) {
store_->AddLogin(cross_origin_form_); store_->AddLogin(cross_origin_form_);
...@@ -974,7 +986,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -974,7 +986,7 @@ TEST_F(CredentialManagerImplTest,
federations, CredentialType::CREDENTIAL_TYPE_EMPTY); federations, CredentialType::CREDENTIAL_TYPE_EMPTY);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialWithFullPasswordStore) { CredentialManagerOnRequestCredentialWithFullPasswordStore) {
client_->set_zero_click_enabled(false); client_->set_zero_click_enabled(false);
store_->AddLogin(form_); store_->AddLogin(form_);
...@@ -996,7 +1008,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -996,7 +1008,7 @@ TEST_F(CredentialManagerImplTest,
EXPECT_EQ(CredentialManagerError::SUCCESS, error); EXPECT_EQ(CredentialManagerError::SUCCESS, error);
} }
TEST_F( TEST_P(
CredentialManagerImplTest, CredentialManagerImplTest,
CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) { CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) {
std::vector<GURL> federations; std::vector<GURL> federations;
...@@ -1008,7 +1020,7 @@ TEST_F( ...@@ -1008,7 +1020,7 @@ TEST_F(
federations); federations);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) { CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) {
store_->AddLogin(form_); store_->AddLogin(form_);
client_->set_first_run_seen(true); client_->set_first_run_seen(true);
...@@ -1022,7 +1034,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -1022,7 +1034,7 @@ TEST_F(CredentialManagerImplTest,
CredentialType::CREDENTIAL_TYPE_PASSWORD); CredentialType::CREDENTIAL_TYPE_PASSWORD);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialWithoutPasswords) { CredentialManagerOnRequestCredentialWithoutPasswords) {
store_->AddLogin(form_); store_->AddLogin(form_);
client_->set_first_run_seen(true); client_->set_first_run_seen(true);
...@@ -1034,7 +1046,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -1034,7 +1046,7 @@ TEST_F(CredentialManagerImplTest,
federations); federations);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialFederatedMatch) { CredentialManagerOnRequestCredentialFederatedMatch) {
form_.federation_origin = url::Origin::Create(GURL("https://example.com/")); form_.federation_origin = url::Origin::Create(GURL("https://example.com/"));
form_.password_value = base::string16(); form_.password_value = base::string16();
...@@ -1051,7 +1063,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -1051,7 +1063,7 @@ TEST_F(CredentialManagerImplTest,
CredentialType::CREDENTIAL_TYPE_FEDERATED); CredentialType::CREDENTIAL_TYPE_FEDERATED);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialFederatedNoMatch) { CredentialManagerOnRequestCredentialFederatedNoMatch) {
form_.federation_origin = url::Origin::Create(GURL("https://example.com/")); form_.federation_origin = url::Origin::Create(GURL("https://example.com/"));
form_.password_value = base::string16(); form_.password_value = base::string16();
...@@ -1067,7 +1079,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -1067,7 +1079,7 @@ TEST_F(CredentialManagerImplTest,
federations); federations);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialAffiliatedPasswordMatch) { CredentialManagerOnRequestCredentialAffiliatedPasswordMatch) {
store_->AddLogin(affiliated_form1_); store_->AddLogin(affiliated_form1_);
client_->set_first_run_seen(true); client_->set_first_run_seen(true);
...@@ -1088,7 +1100,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -1088,7 +1100,7 @@ TEST_F(CredentialManagerImplTest,
CredentialType::CREDENTIAL_TYPE_PASSWORD); CredentialType::CREDENTIAL_TYPE_PASSWORD);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialAffiliatedPasswordNoMatch) { CredentialManagerOnRequestCredentialAffiliatedPasswordNoMatch) {
store_->AddLogin(affiliated_form1_); store_->AddLogin(affiliated_form1_);
client_->set_first_run_seen(true); client_->set_first_run_seen(true);
...@@ -1108,7 +1120,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -1108,7 +1120,7 @@ TEST_F(CredentialManagerImplTest,
federations); federations);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialAffiliatedFederatedMatch) { CredentialManagerOnRequestCredentialAffiliatedFederatedMatch) {
affiliated_form1_.federation_origin = affiliated_form1_.federation_origin =
url::Origin::Create(GURL("https://example.com/")); url::Origin::Create(GURL("https://example.com/"));
...@@ -1132,7 +1144,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -1132,7 +1144,7 @@ TEST_F(CredentialManagerImplTest,
CredentialType::CREDENTIAL_TYPE_FEDERATED); CredentialType::CREDENTIAL_TYPE_FEDERATED);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialAffiliatedFederatedNoMatch) { CredentialManagerOnRequestCredentialAffiliatedFederatedNoMatch) {
affiliated_form1_.federation_origin = affiliated_form1_.federation_origin =
url::Origin::Create(GURL("https://example.com/")); url::Origin::Create(GURL("https://example.com/"));
...@@ -1155,7 +1167,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -1155,7 +1167,7 @@ TEST_F(CredentialManagerImplTest,
federations); federations);
} }
TEST_F(CredentialManagerImplTest, RequestCredentialWithoutFirstRun) { TEST_P(CredentialManagerImplTest, RequestCredentialWithoutFirstRun) {
client_->set_first_run_seen(false); client_->set_first_run_seen(false);
store_->AddLogin(form_); store_->AddLogin(form_);
...@@ -1169,7 +1181,7 @@ TEST_F(CredentialManagerImplTest, RequestCredentialWithoutFirstRun) { ...@@ -1169,7 +1181,7 @@ TEST_F(CredentialManagerImplTest, RequestCredentialWithoutFirstRun) {
federations); federations);
} }
TEST_F(CredentialManagerImplTest, RequestCredentialWithFirstRunAndSkip) { TEST_P(CredentialManagerImplTest, RequestCredentialWithFirstRunAndSkip) {
client_->set_first_run_seen(true); client_->set_first_run_seen(true);
form_.skip_zero_click = true; form_.skip_zero_click = true;
...@@ -1184,7 +1196,7 @@ TEST_F(CredentialManagerImplTest, RequestCredentialWithFirstRunAndSkip) { ...@@ -1184,7 +1196,7 @@ TEST_F(CredentialManagerImplTest, RequestCredentialWithFirstRunAndSkip) {
federations); federations);
} }
TEST_F(CredentialManagerImplTest, RequestCredentialWithTLSErrors) { TEST_P(CredentialManagerImplTest, RequestCredentialWithTLSErrors) {
// If we encounter TLS errors, we won't return credentials. // If we encounter TLS errors, we won't return credentials.
EXPECT_CALL(*client_, IsFillingEnabled(_)) EXPECT_CALL(*client_, IsFillingEnabled(_))
.WillRepeatedly(testing::Return(false)); .WillRepeatedly(testing::Return(false));
...@@ -1197,7 +1209,7 @@ TEST_F(CredentialManagerImplTest, RequestCredentialWithTLSErrors) { ...@@ -1197,7 +1209,7 @@ TEST_F(CredentialManagerImplTest, RequestCredentialWithTLSErrors) {
federations); federations);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) {
store_->AddLogin(form_); store_->AddLogin(form_);
store_->AddLogin(origin_path_form_); store_->AddLogin(origin_path_form_);
...@@ -1212,7 +1224,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -1212,7 +1224,7 @@ TEST_F(CredentialManagerImplTest,
federations, CredentialType::CREDENTIAL_TYPE_EMPTY); federations, CredentialType::CREDENTIAL_TYPE_EMPTY);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
OnRequestCredentialWithZeroClickOnlyAndSkipZeroClickPasswordStore) { OnRequestCredentialWithZeroClickOnlyAndSkipZeroClickPasswordStore) {
form_.skip_zero_click = true; form_.skip_zero_click = true;
store_->AddLogin(form_); store_->AddLogin(form_);
...@@ -1229,7 +1241,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -1229,7 +1241,7 @@ TEST_F(CredentialManagerImplTest,
federations, CredentialType::CREDENTIAL_TYPE_EMPTY); federations, CredentialType::CREDENTIAL_TYPE_EMPTY);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) { OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) {
store_->AddLogin(cross_origin_form_); store_->AddLogin(cross_origin_form_);
...@@ -1247,7 +1259,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -1247,7 +1259,7 @@ TEST_F(CredentialManagerImplTest,
federations, CredentialType::CREDENTIAL_TYPE_EMPTY); federations, CredentialType::CREDENTIAL_TYPE_EMPTY);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
CredentialManagerOnRequestCredentialWhileRequestPending) { CredentialManagerOnRequestCredentialWhileRequestPending) {
client_->set_zero_click_enabled(false); client_->set_zero_click_enabled(false);
store_->AddLogin(form_); store_->AddLogin(form_);
...@@ -1290,7 +1302,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -1290,7 +1302,7 @@ TEST_F(CredentialManagerImplTest,
EXPECT_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, credential_1->type); EXPECT_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, credential_1->type);
} }
TEST_F(CredentialManagerImplTest, ResetSkipZeroClickAfterPrompt) { TEST_P(CredentialManagerImplTest, ResetSkipZeroClickAfterPrompt) {
// Turn on the global zero-click flag, and add two credentials in separate // Turn on the global zero-click flag, and add two credentials in separate
// origins, both set to skip zero-click. // origins, both set to skip zero-click.
client_->set_zero_click_enabled(true); client_->set_zero_click_enabled(true);
...@@ -1339,7 +1351,7 @@ TEST_F(CredentialManagerImplTest, ResetSkipZeroClickAfterPrompt) { ...@@ -1339,7 +1351,7 @@ TEST_F(CredentialManagerImplTest, ResetSkipZeroClickAfterPrompt) {
EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click);
} }
TEST_F(CredentialManagerImplTest, IncognitoZeroClickRequestCredential) { TEST_P(CredentialManagerImplTest, IncognitoZeroClickRequestCredential) {
EXPECT_CALL(*client_, IsIncognito()).WillRepeatedly(testing::Return(true)); EXPECT_CALL(*client_, IsIncognito()).WillRepeatedly(testing::Return(true));
store_->AddLogin(form_); store_->AddLogin(form_);
...@@ -1352,7 +1364,7 @@ TEST_F(CredentialManagerImplTest, IncognitoZeroClickRequestCredential) { ...@@ -1352,7 +1364,7 @@ TEST_F(CredentialManagerImplTest, IncognitoZeroClickRequestCredential) {
federations, CredentialType::CREDENTIAL_TYPE_EMPTY); federations, CredentialType::CREDENTIAL_TYPE_EMPTY);
} }
TEST_F(CredentialManagerImplTest, AutofillAssistantZeroClickRequestCredential) { TEST_P(CredentialManagerImplTest, AutofillAssistantZeroClickRequestCredential) {
store_->AddLogin(form_); store_->AddLogin(form_);
std::vector<GURL> federations; std::vector<GURL> federations;
...@@ -1367,7 +1379,7 @@ TEST_F(CredentialManagerImplTest, AutofillAssistantZeroClickRequestCredential) { ...@@ -1367,7 +1379,7 @@ TEST_F(CredentialManagerImplTest, AutofillAssistantZeroClickRequestCredential) {
federations, CredentialType::CREDENTIAL_TYPE_EMPTY); federations, CredentialType::CREDENTIAL_TYPE_EMPTY);
} }
TEST_F(CredentialManagerImplTest, ZeroClickWithAffiliatedFormInPasswordStore) { TEST_P(CredentialManagerImplTest, ZeroClickWithAffiliatedFormInPasswordStore) {
// Insert the affiliated form into the store, and mock out the association // Insert the affiliated form into the store, and mock out the association
// with the current origin. As it's the only form matching the origin, it // with the current origin. As it's the only form matching the origin, it
// ought to be returned automagically. // ought to be returned automagically.
...@@ -1388,7 +1400,7 @@ TEST_F(CredentialManagerImplTest, ZeroClickWithAffiliatedFormInPasswordStore) { ...@@ -1388,7 +1400,7 @@ TEST_F(CredentialManagerImplTest, ZeroClickWithAffiliatedFormInPasswordStore) {
CredentialType::CREDENTIAL_TYPE_PASSWORD); CredentialType::CREDENTIAL_TYPE_PASSWORD);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
ZeroClickWithTwoAffiliatedFormsInPasswordStore) { ZeroClickWithTwoAffiliatedFormsInPasswordStore) {
// Insert two affiliated forms into the store, and mock out the association // Insert two affiliated forms into the store, and mock out the association
// with the current origin. Multiple forms === no zero-click sign in. // with the current origin. Multiple forms === no zero-click sign in.
...@@ -1410,7 +1422,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -1410,7 +1422,7 @@ TEST_F(CredentialManagerImplTest,
federations); federations);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
ZeroClickWithUnaffiliatedFormsInPasswordStore) { ZeroClickWithUnaffiliatedFormsInPasswordStore) {
// Insert the affiliated form into the store, but don't mock out the // Insert the affiliated form into the store, but don't mock out the
// association with the current origin. No association === no zero-click sign // association with the current origin. No association === no zero-click sign
...@@ -1438,7 +1450,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -1438,7 +1450,7 @@ TEST_F(CredentialManagerImplTest,
federations); federations);
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
ZeroClickWithFormAndUnaffiliatedFormsInPasswordStore) { ZeroClickWithFormAndUnaffiliatedFormsInPasswordStore) {
// Insert the affiliated form into the store, along with a real form for the // Insert the affiliated form into the store, along with a real form for the
// origin, and don't mock out the association with the current origin. No // origin, and don't mock out the association with the current origin. No
...@@ -1460,7 +1472,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -1460,7 +1472,7 @@ TEST_F(CredentialManagerImplTest,
CredentialType::CREDENTIAL_TYPE_PASSWORD); CredentialType::CREDENTIAL_TYPE_PASSWORD);
} }
TEST_F(CredentialManagerImplTest, ZeroClickWithPSLCredential) { TEST_P(CredentialManagerImplTest, ZeroClickWithPSLCredential) {
subdomain_form_.skip_zero_click = false; subdomain_form_.skip_zero_click = false;
store_->AddLogin(subdomain_form_); store_->AddLogin(subdomain_form_);
...@@ -1468,7 +1480,7 @@ TEST_F(CredentialManagerImplTest, ZeroClickWithPSLCredential) { ...@@ -1468,7 +1480,7 @@ TEST_F(CredentialManagerImplTest, ZeroClickWithPSLCredential) {
std::vector<GURL>()); std::vector<GURL>());
} }
TEST_F(CredentialManagerImplTest, ZeroClickWithPSLAndNormalCredentials) { TEST_P(CredentialManagerImplTest, ZeroClickWithPSLAndNormalCredentials) {
form_.password_value.clear(); form_.password_value.clear();
form_.federation_origin = url::Origin::Create(GURL("https://google.com/")); form_.federation_origin = url::Origin::Create(GURL("https://google.com/"));
form_.signon_realm = "federation://" + form_.url.host() + "/google.com"; form_.signon_realm = "federation://" + form_.url.host() + "/google.com";
...@@ -1482,7 +1494,7 @@ TEST_F(CredentialManagerImplTest, ZeroClickWithPSLAndNormalCredentials) { ...@@ -1482,7 +1494,7 @@ TEST_F(CredentialManagerImplTest, ZeroClickWithPSLAndNormalCredentials) {
CredentialType::CREDENTIAL_TYPE_FEDERATED); CredentialType::CREDENTIAL_TYPE_FEDERATED);
} }
TEST_F(CredentialManagerImplTest, ZeroClickAfterMigratingHttpCredential) { TEST_P(CredentialManagerImplTest, ZeroClickAfterMigratingHttpCredential) {
// There is an http credential saved. It should be migrated and used for auto // There is an http credential saved. It should be migrated and used for auto
// sign-in. // sign-in.
form_.url = HttpURLFromHttps(form_.url); form_.url = HttpURLFromHttps(form_.url);
...@@ -1497,7 +1509,7 @@ TEST_F(CredentialManagerImplTest, ZeroClickAfterMigratingHttpCredential) { ...@@ -1497,7 +1509,7 @@ TEST_F(CredentialManagerImplTest, ZeroClickAfterMigratingHttpCredential) {
CredentialType::CREDENTIAL_TYPE_PASSWORD); CredentialType::CREDENTIAL_TYPE_PASSWORD);
} }
TEST_F(CredentialManagerImplTest, ZeroClickOnLocalhost) { TEST_P(CredentialManagerImplTest, ZeroClickOnLocalhost) {
// HTTP scheme is valid for localhost. Nothing should crash. // HTTP scheme is valid for localhost. Nothing should crash.
client_->set_last_committed_url(GURL("http://127.0.0.1:8000/")); client_->set_last_committed_url(GURL("http://127.0.0.1:8000/"));
...@@ -1506,7 +1518,7 @@ TEST_F(CredentialManagerImplTest, ZeroClickOnLocalhost) { ...@@ -1506,7 +1518,7 @@ TEST_F(CredentialManagerImplTest, ZeroClickOnLocalhost) {
federations); federations);
} }
TEST_F(CredentialManagerImplTest, MediationRequiredPreventsAutoSignIn) { TEST_P(CredentialManagerImplTest, MediationRequiredPreventsAutoSignIn) {
form_.skip_zero_click = false; form_.skip_zero_click = false;
store_->AddLogin(form_); store_->AddLogin(form_);
...@@ -1528,7 +1540,7 @@ TEST_F(CredentialManagerImplTest, MediationRequiredPreventsAutoSignIn) { ...@@ -1528,7 +1540,7 @@ TEST_F(CredentialManagerImplTest, MediationRequiredPreventsAutoSignIn) {
EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_PASSWORD, credential->type); EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_PASSWORD, credential->type);
} }
TEST_F(CredentialManagerImplTest, GetSynthesizedFormForOrigin) { TEST_P(CredentialManagerImplTest, GetSynthesizedFormForOrigin) {
PasswordStore::FormDigest synthesized = PasswordStore::FormDigest synthesized =
cm_service_impl_->GetSynthesizedFormForOrigin(); cm_service_impl_->GetSynthesizedFormForOrigin();
EXPECT_EQ(kTestWebOrigin, synthesized.url.spec()); EXPECT_EQ(kTestWebOrigin, synthesized.url.spec());
...@@ -1536,7 +1548,7 @@ TEST_F(CredentialManagerImplTest, GetSynthesizedFormForOrigin) { ...@@ -1536,7 +1548,7 @@ TEST_F(CredentialManagerImplTest, GetSynthesizedFormForOrigin) {
EXPECT_EQ(autofill::PasswordForm::Scheme::kHtml, synthesized.scheme); EXPECT_EQ(autofill::PasswordForm::Scheme::kHtml, synthesized.scheme);
} }
TEST_F(CredentialManagerImplTest, GetBlockedPasswordCredential) { TEST_P(CredentialManagerImplTest, GetBlockedPasswordCredential) {
autofill::PasswordForm blocked_form; autofill::PasswordForm blocked_form;
blocked_form.blocked_by_user = true; blocked_form.blocked_by_user = true;
blocked_form.url = form_.url; blocked_form.url = form_.url;
...@@ -1554,7 +1566,7 @@ TEST_F(CredentialManagerImplTest, GetBlockedPasswordCredential) { ...@@ -1554,7 +1566,7 @@ TEST_F(CredentialManagerImplTest, GetBlockedPasswordCredential) {
federations, CredentialType::CREDENTIAL_TYPE_EMPTY); federations, CredentialType::CREDENTIAL_TYPE_EMPTY);
} }
TEST_F(CredentialManagerImplTest, BlockedPasswordCredential) { TEST_P(CredentialManagerImplTest, BlockedPasswordCredential) {
EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)); EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_));
CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
...@@ -1579,7 +1591,7 @@ TEST_F(CredentialManagerImplTest, BlockedPasswordCredential) { ...@@ -1579,7 +1591,7 @@ TEST_F(CredentialManagerImplTest, BlockedPasswordCredential) {
ElementsAre(MatchesFormExceptStore(blocked_form))); ElementsAre(MatchesFormExceptStore(blocked_form)));
} }
TEST_F(CredentialManagerImplTest, BlockedFederatedCredential) { TEST_P(CredentialManagerImplTest, BlockedFederatedCredential) {
form_.federation_origin = url::Origin::Create(GURL("https://example.com/")); form_.federation_origin = url::Origin::Create(GURL("https://example.com/"));
form_.password_value = base::string16(); form_.password_value = base::string16();
form_.signon_realm = "federation://example.com/example.com"; form_.signon_realm = "federation://example.com/example.com";
...@@ -1609,7 +1621,7 @@ TEST_F(CredentialManagerImplTest, BlockedFederatedCredential) { ...@@ -1609,7 +1621,7 @@ TEST_F(CredentialManagerImplTest, BlockedFederatedCredential) {
ElementsAre(MatchesFormExceptStore(blocked_form))); ElementsAre(MatchesFormExceptStore(blocked_form)));
} }
TEST_F(CredentialManagerImplTest, RespecBlockedPasswordCredential) { TEST_P(CredentialManagerImplTest, RespecBlockedPasswordCredential) {
autofill::PasswordForm blocked_form; autofill::PasswordForm blocked_form;
blocked_form.blocked_by_user = true; blocked_form.blocked_by_user = true;
blocked_form.url = form_.url; blocked_form.url = form_.url;
...@@ -1627,7 +1639,7 @@ TEST_F(CredentialManagerImplTest, RespecBlockedPasswordCredential) { ...@@ -1627,7 +1639,7 @@ TEST_F(CredentialManagerImplTest, RespecBlockedPasswordCredential) {
EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); EXPECT_TRUE(client_->pending_manager()->IsBlacklisted());
} }
TEST_F(CredentialManagerImplTest, RespectBlockedFederatedCredential) { TEST_P(CredentialManagerImplTest, RespectBlockedFederatedCredential) {
autofill::PasswordForm blocked_form; autofill::PasswordForm blocked_form;
blocked_form.blocked_by_user = true; blocked_form.blocked_by_user = true;
blocked_form.url = form_.url; blocked_form.url = form_.url;
...@@ -1648,7 +1660,7 @@ TEST_F(CredentialManagerImplTest, RespectBlockedFederatedCredential) { ...@@ -1648,7 +1660,7 @@ TEST_F(CredentialManagerImplTest, RespectBlockedFederatedCredential) {
EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); EXPECT_TRUE(client_->pending_manager()->IsBlacklisted());
} }
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
ManagePasswordsUICredentialsUpdatedUnconditionallyInSilentMediation) { ManagePasswordsUICredentialsUpdatedUnconditionallyInSilentMediation) {
autofill::PasswordForm federated = origin_path_form_; autofill::PasswordForm federated = origin_path_form_;
federated.federation_origin = federated.federation_origin =
...@@ -1680,7 +1692,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -1680,7 +1692,7 @@ TEST_F(CredentialManagerImplTest,
// Check that following a call to store() a federated credential is not checked // Check that following a call to store() a federated credential is not checked
// for leaks. // for leaks.
TEST_F(CredentialManagerImplTest, TEST_P(CredentialManagerImplTest,
StoreFederatedCredentialDoesNotStartLeakDetection) { StoreFederatedCredentialDoesNotStartLeakDetection) {
auto mock_factory = auto mock_factory =
std::make_unique<testing::StrictMock<MockLeakDetectionCheckFactory>>(); std::make_unique<testing::StrictMock<MockLeakDetectionCheckFactory>>();
...@@ -1698,7 +1710,7 @@ TEST_F(CredentialManagerImplTest, ...@@ -1698,7 +1710,7 @@ TEST_F(CredentialManagerImplTest,
// Check that following a call to store() a password credential is checked for // Check that following a call to store() a password credential is checked for
// leaks. // leaks.
TEST_F(CredentialManagerImplTest, StorePasswordCredentialStartsLeakDetection) { TEST_P(CredentialManagerImplTest, StorePasswordCredentialStartsLeakDetection) {
auto mock_factory = auto mock_factory =
std::make_unique<testing::StrictMock<MockLeakDetectionCheckFactory>>(); std::make_unique<testing::StrictMock<MockLeakDetectionCheckFactory>>();
auto* weak_factory = mock_factory.get(); auto* weak_factory = mock_factory.get();
...@@ -1715,4 +1727,6 @@ TEST_F(CredentialManagerImplTest, StorePasswordCredentialStartsLeakDetection) { ...@@ -1715,4 +1727,6 @@ TEST_F(CredentialManagerImplTest, StorePasswordCredentialStartsLeakDetection) {
RunAllPendingTasks(); RunAllPendingTasks();
} }
INSTANTIATE_TEST_SUITE_P(All, CredentialManagerImplTest, testing::Bool());
} // namespace password_manager } // namespace password_manager
...@@ -114,8 +114,21 @@ CredentialManagerPendingRequestTask::~CredentialManagerPendingRequestTask() = ...@@ -114,8 +114,21 @@ CredentialManagerPendingRequestTask::~CredentialManagerPendingRequestTask() =
void CredentialManagerPendingRequestTask::OnGetPasswordStoreResults( void CredentialManagerPendingRequestTask::OnGetPasswordStoreResults(
std::vector<std::unique_ptr<autofill::PasswordForm>> results) { std::vector<std::unique_ptr<autofill::PasswordForm>> results) {
// This class overrides OnGetPasswordStoreResultsFrom() (the version of this
// method that also receives the originating store), so the store-less version
// never gets called.
NOTREACHED();
}
void CredentialManagerPendingRequestTask::OnGetPasswordStoreResultsFrom(
scoped_refptr<PasswordStore> store,
std::vector<std::unique_ptr<autofill::PasswordForm>> results) {
// localhost is a secure origin but not https. // localhost is a secure origin but not https.
if (results.empty() && origin_.scheme() == url::kHttpsScheme) { if (store.get() == delegate_->client()->GetProfilePasswordStore() &&
results.empty() && origin_.scheme() == url::kHttpsScheme) {
// TODO(crbug.com/1093286): Consider also supporting HTTP->HTTPS migration
// for the account store.
// Try to migrate the HTTP passwords and process them later. // Try to migrate the HTTP passwords and process them later.
http_migrator_ = std::make_unique<HttpPasswordStoreMigrator>( http_migrator_ = std::make_unique<HttpPasswordStoreMigrator>(
origin_, delegate_->client(), this); origin_, delegate_->client(), this);
......
...@@ -75,6 +75,9 @@ class CredentialManagerPendingRequestTask ...@@ -75,6 +75,9 @@ class CredentialManagerPendingRequestTask
// PasswordStoreConsumer: // PasswordStoreConsumer:
void OnGetPasswordStoreResults( void OnGetPasswordStoreResults(
std::vector<std::unique_ptr<autofill::PasswordForm>> results) override; std::vector<std::unique_ptr<autofill::PasswordForm>> results) override;
void OnGetPasswordStoreResultsFrom(
scoped_refptr<PasswordStore> store,
std::vector<std::unique_ptr<autofill::PasswordForm>> results) override;
private: private:
// HttpPasswordStoreMigrator::Consumer: // HttpPasswordStoreMigrator::Consumer:
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
#include "components/password_manager/core/browser/credential_manager_pending_request_task.h" #include "components/password_manager/core/browser/credential_manager_pending_request_task.h"
#include "base/test/task_environment.h"
#include "components/password_manager/core/browser/stub_password_manager_client.h" #include "components/password_manager/core/browser/stub_password_manager_client.h"
#include "components/password_manager/core/browser/test_password_store.h"
#include "components/password_manager/core/common/credential_manager_types.h" #include "components/password_manager/core/common/credential_manager_types.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"
...@@ -12,6 +14,24 @@ ...@@ -12,6 +14,24 @@
namespace password_manager { namespace password_manager {
namespace { namespace {
class TestPasswordManagerClient : public StubPasswordManagerClient {
public:
TestPasswordManagerClient(PasswordStore* profile_store,
PasswordStore* account_store)
: profile_store_(profile_store), account_store_(account_store) {}
PasswordStore* GetProfilePasswordStore() const override {
return profile_store_;
}
PasswordStore* GetAccountPasswordStore() const override {
return account_store_;
}
private:
PasswordStore* profile_store_;
PasswordStore* account_store_;
};
class CredentialManagerPendingRequestTaskDelegateMock class CredentialManagerPendingRequestTaskDelegateMock
: public CredentialManagerPendingRequestTaskDelegate { : public CredentialManagerPendingRequestTaskDelegate {
public: public:
...@@ -37,16 +57,36 @@ class CredentialManagerPendingRequestTaskDelegateMock ...@@ -37,16 +57,36 @@ class CredentialManagerPendingRequestTaskDelegateMock
class CredentialManagerPendingRequestTaskTest : public ::testing::Test { class CredentialManagerPendingRequestTaskTest : public ::testing::Test {
public: public:
CredentialManagerPendingRequestTaskTest() { CredentialManagerPendingRequestTaskTest() {
ON_CALL(delegate_mock_, client).WillByDefault(testing::Return(&client_)); profile_store_ = new TestPasswordStore(/*is_account_store=*/false);
profile_store_->Init(/*prefs=*/nullptr);
account_store_ = new TestPasswordStore(/*is_account_store=*/true);
account_store_->Init(/*prefs=*/nullptr);
client_ = std::make_unique<TestPasswordManagerClient>(profile_store_.get(),
account_store_.get());
ON_CALL(delegate_mock_, client)
.WillByDefault(testing::Return(client_.get()));
} }
~CredentialManagerPendingRequestTaskTest() override = default; ~CredentialManagerPendingRequestTaskTest() override = default;
void TearDown() override {
account_store_->ShutdownOnUIThread();
profile_store_->ShutdownOnUIThread();
// It's needed to cleanup the password store asynchronously.
task_environment_.RunUntilIdle();
}
protected: protected:
testing::NiceMock<CredentialManagerPendingRequestTaskDelegateMock> testing::NiceMock<CredentialManagerPendingRequestTaskDelegateMock>
delegate_mock_; delegate_mock_;
scoped_refptr<TestPasswordStore> profile_store_;
scoped_refptr<TestPasswordStore> account_store_;
private: private:
StubPasswordManagerClient client_; base::test::TaskEnvironment task_environment_;
std::unique_ptr<TestPasswordManagerClient> client_;
}; };
TEST_F(CredentialManagerPendingRequestTaskTest, QueryProfileStore) { TEST_F(CredentialManagerPendingRequestTaskTest, QueryProfileStore) {
...@@ -58,7 +98,7 @@ TEST_F(CredentialManagerPendingRequestTaskTest, QueryProfileStore) { ...@@ -58,7 +98,7 @@ TEST_F(CredentialManagerPendingRequestTaskTest, QueryProfileStore) {
// We are expecting results from only one store, delegate should be called // We are expecting results from only one store, delegate should be called
// upon getting a response from the store. // upon getting a response from the store.
EXPECT_CALL(delegate_mock_, SendCredential); EXPECT_CALL(delegate_mock_, SendCredential);
task.OnGetPasswordStoreResults({}); task.OnGetPasswordStoreResultsFrom(profile_store_, {});
} }
TEST_F(CredentialManagerPendingRequestTaskTest, QueryProfileAndAccountStores) { TEST_F(CredentialManagerPendingRequestTaskTest, QueryProfileAndAccountStores) {
...@@ -70,12 +110,12 @@ TEST_F(CredentialManagerPendingRequestTaskTest, QueryProfileAndAccountStores) { ...@@ -70,12 +110,12 @@ TEST_F(CredentialManagerPendingRequestTaskTest, QueryProfileAndAccountStores) {
// We are expecting results from 2 stores, the delegate shouldn't be called // We are expecting results from 2 stores, the delegate shouldn't be called
// until both stores respond. // until both stores respond.
EXPECT_CALL(delegate_mock_, SendCredential).Times(0); EXPECT_CALL(delegate_mock_, SendCredential).Times(0);
task.OnGetPasswordStoreResults({}); task.OnGetPasswordStoreResultsFrom(profile_store_, {});
testing::Mock::VerifyAndClearExpectations(&delegate_mock_); testing::Mock::VerifyAndClearExpectations(&delegate_mock_);
EXPECT_CALL(delegate_mock_, SendCredential); EXPECT_CALL(delegate_mock_, SendCredential);
task.OnGetPasswordStoreResults({}); task.OnGetPasswordStoreResultsFrom(account_store_, {});
} }
} // namespace password_manager } // namespace password_manager
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