Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Unified Diff: components/password_manager/core/browser/password_form_manager_unittest.cc

Issue 2090583003: Introduce password_manager::FormSaver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/password_manager/core/browser/password_form_manager_unittest.cc
diff --git a/components/password_manager/core/browser/password_form_manager_unittest.cc b/components/password_manager/core/browser/password_form_manager_unittest.cc
index 35377086853440553bc7e29020e754d0fdf39c0a..5b245a11dac00d769cadf11f3f1c05598142f83e 100644
--- a/components/password_manager/core/browser/password_form_manager_unittest.cc
+++ b/components/password_manager/core/browser/password_form_manager_unittest.cc
@@ -30,6 +30,7 @@
#include "components/password_manager/core/browser/password_manager_test_utils.h"
#include "components/password_manager/core/browser/password_store.h"
#include "components/password_manager/core/browser/statistics_table.h"
+#include "components/password_manager/core/browser/stub_form_saver.h"
#include "components/password_manager/core/browser/stub_password_manager_client.h"
#include "components/password_manager/core/browser/stub_password_manager_driver.h"
#include "components/password_manager/core/common/password_manager_features.h"
@@ -46,17 +47,47 @@ using autofill::PasswordForm;
using base::ASCIIToUTF16;
using ::testing::_;
using ::testing::ElementsAre;
+using ::testing::IsEmpty;
using ::testing::Mock;
using ::testing::NiceMock;
using ::testing::Pointee;
using ::testing::Return;
using ::testing::SaveArg;
+using ::testing::SaveArgPointee;
using ::testing::UnorderedElementsAre;
namespace password_manager {
namespace {
+class MockFormSaver : public StubFormSaver {
+ public:
+ MockFormSaver() = default;
+
+ ~MockFormSaver() override = default;
+
+ // FormSaver:
+ MOCK_METHOD1(PermanentlyBlacklist, void(autofill::PasswordForm* observed));
+ MOCK_METHOD3(Save,
+ void(const autofill::PasswordForm& pending,
+ const autofill::PasswordFormMap& best_matches,
+ const autofill::PasswordForm* old_primary_key));
+ MOCK_METHOD4(Update,
+ void(const autofill::PasswordForm& pending,
+ const autofill::PasswordFormMap& best_matches,
+ const std::vector<const autofill::PasswordForm*>*
+ credentials_to_update,
+ const autofill::PasswordForm* old_primary_key));
+
+ // Convenience downcasting method.
+ static MockFormSaver& Get(PasswordFormManager* form_manager) {
+ return *static_cast<MockFormSaver*>(form_manager->form_saver());
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockFormSaver);
+};
+
// Invokes the password store consumer with a copy of all forms.
ACTION_P4(InvokeConsumer, form1, form2, form3, form4) {
ScopedVector<PasswordForm> result;
@@ -71,6 +102,10 @@ MATCHER_P(CheckUsername, username_value, "Username incorrect") {
return arg.username_value == username_value;
}
+MATCHER_P(CheckUsernamePtr, username_value, "Username incorrect") {
+ return arg && arg->username_value == username_value;
+}
+
MATCHER_P2(CheckUploadedAutofillTypesAndSignature,
form_signature,
expected_types,
@@ -377,7 +412,7 @@ class PasswordFormManagerTest : public testing::Test {
password_manager_.reset(new PasswordManager(client_.get()));
form_manager_.reset(new PasswordFormManager(
password_manager_.get(), client_.get(), client_.get()->driver(),
- observed_form_, false));
+ observed_form_, false, base::WrapUnique(new MockFormSaver())));
}
void TearDown() override {
@@ -419,7 +454,8 @@ class PasswordFormManagerTest : public testing::Test {
form.form_data = observed_form_data;
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), form, false);
+ client()->driver(), form, false,
+ base::WrapUnique(new MockFormSaver()));
ScopedVector<PasswordForm> result;
result.push_back(CreateSavedMatch(false));
result[0]->generation_upload_status = status;
@@ -495,9 +531,9 @@ class PasswordFormManagerTest : public testing::Test {
observed_form()->form_data.fields.push_back(field);
client()->set_is_update_password_ui_enabled(true);
- PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), *observed_form(),
- false);
+ PasswordFormManager form_manager(
+ password_manager(), client(), client()->driver(), *observed_form(),
+ false, base::WrapUnique(new MockFormSaver()));
SimulateMatchingPhase(&form_manager, RESULT_SAVED_MATCH);
@@ -625,7 +661,8 @@ class PasswordFormManagerTest : public testing::Test {
}
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), form, false);
+ client()->driver(), form, false,
+ base::WrapUnique(new MockFormSaver()));
ScopedVector<PasswordForm> result;
form_manager.SimulateFetchMatchingLoginsFromPasswordStore();
@@ -797,9 +834,8 @@ TEST_F(PasswordFormManagerTest, TestBlacklist) {
const PasswordForm pending_form = form_manager()->pending_credentials();
PasswordForm actual_add_form;
- EXPECT_CALL(*mock_store(), RemoveLogin(_)).Times(0);
- EXPECT_CALL(*mock_store(), AddLogin(_))
- .WillOnce(SaveArg<0>(&actual_add_form));
+ EXPECT_CALL(MockFormSaver::Get(form_manager()), PermanentlyBlacklist(_))
+ .WillOnce(SaveArgPointee<0>(&actual_add_form));
form_manager()->PermanentlyBlacklist();
EXPECT_EQ(pending_form, form_manager()->pending_credentials());
EXPECT_TRUE(form_manager()->IsBlacklisted());
@@ -812,7 +848,8 @@ TEST_F(PasswordFormManagerTest, TestBlacklistMatching) {
observed_form()->action = GURL("http://accounts.google.com/a/Login");
observed_form()->signon_realm = "http://accounts.google.com";
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), *observed_form(), false);
+ client()->driver(), *observed_form(), false,
+ base::WrapUnique(new MockFormSaver()));
form_manager.SimulateFetchMatchingLoginsFromPasswordStore();
// Doesn't match because of PSL.
@@ -933,9 +970,8 @@ TEST_F(PasswordFormManagerTest, PSLMatchedCredentialsMetadataUpdated) {
expected_available_field_types.insert(autofill::ACCOUNT_CREATION_PASSWORD);
EXPECT_CALL(
*client()->mock_driver()->mock_autofill_download_manager(),
- StartUploadRequest(_, false, expected_available_field_types, _, true))
- .Times(1);
- EXPECT_CALL(*mock_store(), AddLogin(_))
+ StartUploadRequest(_, false, expected_available_field_types, _, true));
+ EXPECT_CALL(MockFormSaver::Get(form_manager()), Save(_, _, nullptr))
.WillOnce(SaveArg<0>(&actual_saved_form));
form_manager()->Save();
@@ -951,7 +987,8 @@ TEST_F(PasswordFormManagerTest, TestNewLoginFromNewPasswordElement) {
observed_form()->username_marked_by_site = true;
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), *observed_form(), false);
+ client()->driver(), *observed_form(), false,
+ base::WrapUnique(new MockFormSaver()));
SimulateMatchingPhase(&form_manager, RESULT_NO_MATCH);
// User enters current and new credentials to the observed form.
@@ -1025,13 +1062,14 @@ TEST_F(PasswordFormManagerTest, TestUpdatePasswordFromNewPasswordElement) {
// should not serve as a source for updating meta-information stored with the
// old credentials, such as element names, as they are likely going to be
// different between change password and login forms. To test this in depth,
- // forcibly wipe |submit_element|, which should normally trigger updating this
- // field from |observed_form| in the UpdateLogin() step as a special case. We
- // will verify in the end that this did not happen.
+ // forcibly wipe |submit_element|, which should normally trigger updating
+ // this field from |observed_form| during updating as a special case. We will
+ // verify in the end that this did not happen.
saved_match()->submit_element.clear();
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), *observed_form(), false);
+ client()->driver(), *observed_form(), false,
+ base::WrapUnique(new MockFormSaver()));
SimulateMatchingPhase(&form_manager, RESULT_SAVED_MATCH);
// User submits current and new credentials to the observed form.
@@ -1056,9 +1094,9 @@ TEST_F(PasswordFormManagerTest, TestUpdatePasswordFromNewPasswordElement) {
EXPECT_TRUE(form_manager.pending_credentials().new_password_element.empty());
EXPECT_TRUE(form_manager.pending_credentials().new_password_value.empty());
- // Trigger saving to exercise some special case handling in UpdateLogin().
+ // Trigger saving to exercise some special case handling for updating.
PasswordForm new_credentials;
- EXPECT_CALL(*mock_store(), UpdateLogin(_))
+ EXPECT_CALL(MockFormSaver::Get(&form_manager), Update(_, _, _, nullptr))
.WillOnce(testing::SaveArg<0>(&new_credentials));
form_manager.Save();
@@ -1073,9 +1111,9 @@ TEST_F(PasswordFormManagerTest, TestUpdatePasswordFromNewPasswordElement) {
TEST_F(PasswordFormManagerTest, TestIgnoreResult_SSL) {
const bool kObservedFormSSLValid = false;
- PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), *observed_form(),
- kObservedFormSSLValid);
+ PasswordFormManager form_manager(
+ password_manager(), client(), client()->driver(), *observed_form(),
+ kObservedFormSSLValid, base::WrapUnique(new MockFormSaver()));
PasswordForm saved_form = *observed_form();
saved_form.ssl_valid = !kObservedFormSSLValid;
@@ -1103,7 +1141,8 @@ TEST_F(PasswordFormManagerTest, TestIgnoreResult_Paths) {
observed.signon_realm = "https://accounts.google.com";
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), observed, false);
+ client()->driver(), observed, false,
+ base::WrapUnique(new MockFormSaver()));
PasswordForm saved_form = observed;
saved_form.origin = GURL("https://accounts.google.com/a/OtherLoginAuth");
@@ -1124,7 +1163,8 @@ TEST_F(PasswordFormManagerTest, TestIgnoreResult_IgnoredCredentials) {
observed.signon_realm = "https://accounts.google.com";
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), observed, false);
+ client()->driver(), observed, false,
+ base::WrapUnique(new MockFormSaver()));
client()->FilterAllResults();
PasswordForm saved_form = observed;
@@ -1208,10 +1248,8 @@ TEST_F(PasswordFormManagerTest, TestAlternateUsername_NoChange) {
EXPECT_FALSE(form_manager()->IsNewLogin());
PasswordForm saved_result;
- EXPECT_CALL(*mock_store(), UpdateLogin(_))
+ EXPECT_CALL(MockFormSaver::Get(form_manager()), Update(_, _, _, nullptr))
.WillOnce(SaveArg<0>(&saved_result));
- EXPECT_CALL(*mock_store(), UpdateLoginWithPrimaryKey(_, _)).Times(0);
- EXPECT_CALL(*mock_store(), AddLogin(_)).Times(0);
EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(),
StartUploadRequest(_, false, _, _, true));
@@ -1248,11 +1286,9 @@ TEST_F(PasswordFormManagerTest, TestAlternateUsername_OtherUsername) {
PasswordForm saved_result;
// Changing the username changes the primary key of the stored credential.
- EXPECT_CALL(*mock_store(), UpdateLoginWithPrimaryKey(
- _, CheckUsername(saved_form.username_value)))
+ EXPECT_CALL(MockFormSaver::Get(form_manager()),
+ Update(_, _, _, CheckUsernamePtr(saved_form.username_value)))
.WillOnce(SaveArg<0>(&saved_result));
- EXPECT_CALL(*mock_store(), UpdateLogin(_)).Times(0);
- EXPECT_CALL(*mock_store(), AddLogin(_)).Times(0);
form_manager()->Save();
@@ -1294,7 +1330,8 @@ TEST_F(PasswordFormManagerTest,
signup_form.new_password_element = base::ASCIIToUTF16("new_password_field");
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), signup_form, false);
+ client()->driver(), signup_form, false,
+ base::WrapUnique(new MockFormSaver()));
EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_))
.Times(1);
form_manager.SimulateFetchMatchingLoginsFromPasswordStore();
@@ -1406,9 +1443,8 @@ TEST_F(PasswordFormManagerTest, TestSanitizePossibleUsernames) {
credentials, PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES);
PasswordForm saved_result;
- EXPECT_CALL(*mock_store(), UpdateLogin(_)).Times(0);
- EXPECT_CALL(*mock_store(), UpdateLoginWithPrimaryKey(_, _)).Times(0);
- EXPECT_CALL(*mock_store(), AddLogin(_)).WillOnce(SaveArg<0>(&saved_result));
+ EXPECT_CALL(MockFormSaver::Get(form_manager()), Save(_, _, nullptr))
+ .WillOnce(SaveArg<0>(&saved_result));
form_manager()->Save();
// Possible credit card number and SSN are stripped.
@@ -1439,9 +1475,8 @@ TEST_F(PasswordFormManagerTest, TestSanitizePossibleUsernamesDuplicates) {
credentials, PasswordFormManager::ALLOW_OTHER_POSSIBLE_USERNAMES);
PasswordForm saved_result;
- EXPECT_CALL(*mock_store(), UpdateLogin(_)).Times(0);
- EXPECT_CALL(*mock_store(), UpdateLoginWithPrimaryKey(_, _)).Times(0);
- EXPECT_CALL(*mock_store(), AddLogin(_)).WillOnce(SaveArg<0>(&saved_result));
+ EXPECT_CALL(MockFormSaver::Get(form_manager()), Save(_, _, nullptr))
+ .WillOnce(SaveArg<0>(&saved_result));
form_manager()->Save();
// SSN, duplicate in |other_possible_usernames| and duplicate of
@@ -1463,7 +1498,8 @@ TEST_F(PasswordFormManagerTest, TestUpdateIncompleteCredentials) {
EXPECT_CALL(*(client()->mock_driver()), AllowPasswordGenerationForForm(_));
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), encountered_form, false);
+ client()->driver(), encountered_form, false,
+ base::WrapUnique(new MockFormSaver()));
EXPECT_CALL(*mock_store(), GetLogins(encountered_form, &form_manager));
form_manager.FetchDataFromPasswordStore();
@@ -1503,8 +1539,8 @@ TEST_F(PasswordFormManagerTest, TestUpdateIncompleteCredentials) {
obsolete_form.times_used = 1;
// Check that PasswordStore receives an update request with the complete form.
- EXPECT_CALL(*mock_store(),
- UpdateLoginWithPrimaryKey(complete_form, obsolete_form));
+ EXPECT_CALL(MockFormSaver::Get(&form_manager),
+ Update(complete_form, _, _, Pointee(obsolete_form)));
form_manager.Save();
}
@@ -1576,10 +1612,8 @@ TEST_F(PasswordFormManagerTest, AndroidCredentialsAreAutofilled) {
EXPECT_FALSE(form_manager()->IsNewLogin());
PasswordForm updated_credential;
- EXPECT_CALL(*mock_store(), UpdateLogin(_))
+ EXPECT_CALL(MockFormSaver::Get(form_manager()), Update(_, _, _, nullptr))
.WillOnce(testing::SaveArg<0>(&updated_credential));
- EXPECT_CALL(*mock_store(), UpdateLoginWithPrimaryKey(_, _)).Times(0);
- EXPECT_CALL(*mock_store(), AddLogin(_)).Times(0);
form_manager()->Save();
Mock::VerifyAndClearExpectations(mock_store());
@@ -1652,9 +1686,9 @@ TEST_F(PasswordFormManagerTest, InvalidActionURLsDoNotMatch) {
PasswordFormManager::RESULT_ACTION_MATCH);
// Then when the observed form has an invalid URL:
PasswordForm valid_action_form(*observed_form());
- PasswordFormManager invalid_manager(password_manager(), client(),
- client()->driver(), invalid_action_form,
- false);
+ PasswordFormManager invalid_manager(
+ password_manager(), client(), client()->driver(), invalid_action_form,
+ false, base::WrapUnique(new MockFormSaver()));
EXPECT_EQ(0,
invalid_manager.DoesManage(valid_action_form) &
PasswordFormManager::RESULT_ACTION_MATCH);
@@ -1670,9 +1704,9 @@ TEST_F(PasswordFormManagerTest, EmptyActionURLsDoNotMatchNonEmpty) {
PasswordFormManager::RESULT_ACTION_MATCH);
// Then when the observed form has an empty URL:
PasswordForm valid_action_form(*observed_form());
- PasswordFormManager empty_action_manager(password_manager(), client(),
- client()->driver(),
- empty_action_form, false);
+ PasswordFormManager empty_action_manager(
+ password_manager(), client(), client()->driver(), empty_action_form,
+ false, base::WrapUnique(new MockFormSaver()));
EXPECT_EQ(0,
empty_action_manager.DoesManage(valid_action_form) &
PasswordFormManager::RESULT_ACTION_MATCH);
@@ -1688,7 +1722,8 @@ TEST_F(PasswordFormManagerTest, NonHTMLFormsDoNotMatchHTMLForms) {
// The other way round: observing a non-HTML form, don't match a HTML form.
PasswordForm html_form(*observed_form());
PasswordFormManager non_html_manager(password_manager(), client(), kNoDriver,
- non_html_form, false);
+ non_html_form, false,
+ base::WrapUnique(new MockFormSaver()));
EXPECT_EQ(0, non_html_manager.DoesManage(html_form) &
PasswordFormManager::RESULT_HTML_ATTRIBUTES_MATCH);
}
@@ -1723,9 +1758,9 @@ TEST_F(PasswordFormManagerTest,
PasswordForm secure_observed_form(*observed_form());
secure_observed_form.origin = GURL("https://accounts.google.com/a/LoginAuth");
- PasswordFormManager secure_manager(password_manager(), client(),
- client()->driver(), secure_observed_form,
- true);
+ PasswordFormManager secure_manager(
+ password_manager(), client(), client()->driver(), secure_observed_form,
+ true, base::WrapUnique(new MockFormSaver()));
// Also for HTTPS in the observed form, and HTTP in the compared form, an
// exact path match is expected.
EXPECT_EQ(0, secure_manager.DoesManage(form_longer_path) &
@@ -1786,10 +1821,8 @@ TEST_F(PasswordFormManagerTest, CorrectlyUpdatePasswordsWithSameUsername) {
EXPECT_FALSE(form_manager()->IsNewLogin());
PasswordForm saved_result;
- EXPECT_CALL(*mock_store(), UpdateLogin(_))
- .WillOnce(SaveArg<0>(&saved_result));
- EXPECT_CALL(*mock_store(), UpdateLoginWithPrimaryKey(_, _)).Times(0);
- EXPECT_CALL(*mock_store(), AddLogin(_)).Times(0);
+ EXPECT_CALL(MockFormSaver::Get(form_manager()), Update(_, _, _, nullptr))
+ .WillOnce(testing::SaveArg<0>(&saved_result));
EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(),
StartUploadRequest(_, false, _, _, true));
@@ -1803,7 +1836,8 @@ TEST_F(PasswordFormManagerTest, UploadFormData_NewPassword) {
// For newly saved passwords, upload a password vote for autofill::PASSWORD.
// Don't vote for the username field yet.
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), *saved_match(), false);
+ client()->driver(), *saved_match(), false,
+ base::WrapUnique(new MockFormSaver()));
SimulateMatchingPhase(&form_manager, RESULT_NO_MATCH);
PasswordForm form_to_save(*saved_match());
@@ -1824,7 +1858,8 @@ TEST_F(PasswordFormManagerTest, UploadFormData_NewPassword) {
// Do not upload a vote if the user is blacklisting the form.
PasswordFormManager blacklist_form_manager(
- password_manager(), client(), client()->driver(), *saved_match(), false);
+ password_manager(), client(), client()->driver(), *saved_match(), false,
+ base::WrapUnique(new MockFormSaver()));
SimulateMatchingPhase(&blacklist_form_manager, RESULT_NO_MATCH);
expected_available_field_types.clear();
@@ -1892,9 +1927,8 @@ TEST_F(PasswordFormManagerTest, CorrectlySavePasswordWithoutUsernameFields) {
EXPECT_TRUE(form_manager()->IsNewLogin());
PasswordForm saved_result;
- EXPECT_CALL(*mock_store(), UpdateLogin(_)).Times(0);
- EXPECT_CALL(*mock_store(), UpdateLoginWithPrimaryKey(_, _)).Times(0);
- EXPECT_CALL(*mock_store(), AddLogin(_)).WillOnce(SaveArg<0>(&saved_result));
+ EXPECT_CALL(MockFormSaver::Get(form_manager()), Save(_, _, nullptr))
+ .WillOnce(SaveArg<0>(&saved_result));
form_manager()->Save();
@@ -1920,7 +1954,8 @@ TEST_F(PasswordFormManagerTest, DriverDeletedBeforeStoreDone) {
form->submit_element = ASCIIToUTF16("s");
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), *form, false);
+ client()->driver(), *form, false,
+ base::WrapUnique(new MockFormSaver()));
EXPECT_CALL(*mock_store(), GetLogins(*form, &form_manager));
form_manager.FetchDataFromPasswordStore();
@@ -1967,7 +2002,8 @@ TEST_F(PasswordFormManagerTest,
base::ASCIIToUTF16("new_password_field");
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), *observed_form(), false);
+ client()->driver(), *observed_form(), false,
+ base::WrapUnique(new MockFormSaver()));
SimulateMatchingPhase(&form_manager, RESULT_SAVED_MATCH);
// The user submits a password on a change-password form, which does not use
@@ -2065,7 +2101,8 @@ TEST_F(PasswordFormManagerTest, TestSuggestingPasswordChangeForms) {
base::ASCIIToUTF16("new_pwd");
PasswordFormManager manager_creds(password_manager(), client(),
client()->driver(),
- observed_change_password_form, false);
+ observed_change_password_form, false,
+ base::WrapUnique(new MockFormSaver()));
manager_creds.SimulateFetchMatchingLoginsFromPasswordStore();
ScopedVector<PasswordForm> simulated_results;
simulated_results.push_back(CreateSavedMatch(false));
@@ -2094,14 +2131,15 @@ TEST_F(PasswordFormManagerTest, TestUpdateMethod) {
// should not serve as a source for updating meta-information stored with the
// old credentials, such as element names, as they are likely going to be
// different between change password and login forms. To test this in depth,
- // forcibly wipe |submit_element|, which should normally trigger updating this
- // field from |observed_form| in the UpdateLogin() step as a special case. We
- // will verify in the end that this did not happen.
+ // forcibly wipe |submit_element|, which should normally trigger updating
+ // this field from |observed_form| during updating as a special case. We will
+ // verify in the end that this did not happen.
saved_match()->submit_element.clear();
client()->set_is_update_password_ui_enabled(true);
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), *observed_form(), false);
+ client()->driver(), *observed_form(), false,
+ base::WrapUnique(new MockFormSaver()));
SimulateMatchingPhase(&form_manager, RESULT_SAVED_MATCH);
// User submits current and new credentials to the observed form.
@@ -2127,9 +2165,9 @@ TEST_F(PasswordFormManagerTest, TestUpdateMethod) {
form_manager.pending_credentials().password_value);
EXPECT_TRUE(form_manager.pending_credentials().new_password_value.empty());
- // Trigger saving to exercise some special case handling in UpdateLogin().
+ // Trigger saving to exercise some special case handling during updating.
PasswordForm new_credentials;
- EXPECT_CALL(*mock_store(), UpdateLogin(_))
+ EXPECT_CALL(MockFormSaver::Get(&form_manager), Update(_, _, _, nullptr))
.WillOnce(SaveArg<0>(&new_credentials));
form_manager.Update(*saved_match());
@@ -2157,13 +2195,14 @@ TEST_F(PasswordFormManagerTest, TestUpdateNoUsernameTextfieldPresent) {
// old credentials, such as element names, as they are likely going to be
// different between change password and login forms. To test this in depth,
// forcibly wipe |submit_element|, which should normally trigger updating this
- // field from |observed_form| in the UpdateLogin() step as a special case. We
+ // field from |observed_form| during updating as a special case. We
// will verify in the end that this did not happen.
saved_match()->submit_element.clear();
client()->set_is_update_password_ui_enabled(true);
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), *observed_form(), false);
+ client()->driver(), *observed_form(), false,
+ base::WrapUnique(new MockFormSaver()));
SimulateMatchingPhase(&form_manager, RESULT_SAVED_MATCH);
// User submits current and new credentials to the observed form.
@@ -2191,9 +2230,9 @@ TEST_F(PasswordFormManagerTest, TestUpdateNoUsernameTextfieldPresent) {
form_manager.pending_credentials().password_value);
EXPECT_TRUE(form_manager.pending_credentials().new_password_value.empty());
- // Trigger saving to exercise some special case handling in UpdateLogin().
+ // Trigger saving to exercise some special case handling during updating.
PasswordForm new_credentials;
- EXPECT_CALL(*mock_store(), UpdateLogin(_))
+ EXPECT_CALL(MockFormSaver::Get(&form_manager), Update(_, _, _, nullptr))
.WillOnce(SaveArg<0>(&new_credentials));
form_manager.Update(form_manager.pending_credentials());
@@ -2212,7 +2251,8 @@ TEST_F(PasswordFormManagerTest, WipeStoreCopyIfOutdated_BeforeStoreCallback) {
ASSERT_FALSE(form.password_value.empty());
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), form, false);
+ client()->driver(), form, false,
+ base::WrapUnique(new MockFormSaver()));
// Do not notify the store observer after this GetLogins call.
EXPECT_CALL(*mock_store(), GetLogins(_, _));
@@ -2236,7 +2276,8 @@ TEST_F(PasswordFormManagerTest, WipeStoreCopyIfOutdated_NotOutdated) {
ASSERT_FALSE(form.password_value.empty());
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), form, false);
+ client()->driver(), form, false,
+ base::WrapUnique(new MockFormSaver()));
// For GAIA authentication, the first two usernames are equivalent to
// test@gmail.com, but the third is not.
@@ -2266,7 +2307,8 @@ TEST_F(PasswordFormManagerTest, WipeStoreCopyIfOutdated_Outdated) {
ASSERT_FALSE(form.password_value.empty());
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), form, false);
+ client()->driver(), form, false,
+ base::WrapUnique(new MockFormSaver()));
// For GAIA authentication, the first two usernames are equivalent to
// test@gmail.com, but the third is not.
@@ -2296,143 +2338,6 @@ TEST_F(PasswordFormManagerTest, WipeStoreCopyIfOutdated_Outdated) {
1);
}
-TEST_F(PasswordFormManagerTest, RemoveNoUsernameAccounts) {
- PasswordForm saved_form = *saved_match();
- saved_form.username_value.clear();
- ScopedVector<PasswordForm> result;
- result.push_back(new PasswordForm(saved_form));
- form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
- form_manager()->OnGetPasswordStoreResults(std::move(result));
-
- PasswordForm submitted_form(*observed_form());
- submitted_form.preferred = true;
- submitted_form.username_value = saved_match()->username_value;
- submitted_form.password_value = saved_match()->password_value;
-
- saved_form.preferred = false;
- EXPECT_CALL(*mock_store(),
- AddLogin(CheckUsername(saved_match()->username_value)));
- EXPECT_CALL(*mock_store(), RemoveLogin(saved_form));
-
- form_manager()->ProvisionallySave(
- submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
- form_manager()->Save();
-}
-
-TEST_F(PasswordFormManagerTest, NotRemovePSLNoUsernameAccounts) {
- PasswordForm saved_form = *saved_match();
- saved_form.username_value.clear();
- saved_form.is_public_suffix_match = true;
- ScopedVector<PasswordForm> result;
- result.push_back(new PasswordForm(saved_form));
- form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
- form_manager()->OnGetPasswordStoreResults(std::move(result));
-
- PasswordForm submitted_form(*observed_form());
- submitted_form.preferred = true;
- submitted_form.username_value = saved_match()->username_value;
- submitted_form.password_value = saved_match()->password_value;
-
- EXPECT_CALL(*mock_store(),
- AddLogin(CheckUsername(saved_match()->username_value)));
- EXPECT_CALL(*mock_store(), RemoveLogin(_)).Times(0);
-
- form_manager()->ProvisionallySave(
- submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
- form_manager()->Save();
-}
-
-TEST_F(PasswordFormManagerTest, NotRemoveCredentialsWithUsername) {
- PasswordForm saved_form = *saved_match();
- ASSERT_FALSE(saved_form.username_value.empty());
- ScopedVector<PasswordForm> result;
- result.push_back(new PasswordForm(saved_form));
- form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
- form_manager()->OnGetPasswordStoreResults(std::move(result));
-
- PasswordForm submitted_form(*observed_form());
- submitted_form.preferred = true;
- base::string16 username = saved_form.username_value + ASCIIToUTF16("1");
- submitted_form.username_value = username;
- submitted_form.password_value = saved_match()->password_value;
-
- EXPECT_CALL(*mock_store(), AddLogin(CheckUsername(username)));
- EXPECT_CALL(*mock_store(), RemoveLogin(_)).Times(0);
-
- form_manager()->ProvisionallySave(
- submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
- form_manager()->Save();
-}
-
-TEST_F(PasswordFormManagerTest, NotRemoveCredentialsWithDiferrentPassword) {
- PasswordForm saved_form = *saved_match();
- saved_form.username_value.clear();
- ScopedVector<PasswordForm> result;
- result.push_back(new PasswordForm(saved_form));
- form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
- form_manager()->OnGetPasswordStoreResults(std::move(result));
-
- PasswordForm submitted_form(*observed_form());
- submitted_form.preferred = true;
- submitted_form.username_value = saved_match()->username_value;
- submitted_form.password_value = saved_form.password_value + ASCIIToUTF16("1");
-
- EXPECT_CALL(*mock_store(),
- AddLogin(CheckUsername(saved_match()->username_value)));
- EXPECT_CALL(*mock_store(), RemoveLogin(_)).Times(0);
-
- form_manager()->ProvisionallySave(
- submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
- form_manager()->Save();
-}
-
-TEST_F(PasswordFormManagerTest, SaveNoUsernameEvenIfWithUsernamePresent) {
- PasswordForm* saved_form = saved_match();
- ASSERT_FALSE(saved_match()->username_value.empty());
- ScopedVector<PasswordForm> result;
- result.push_back(new PasswordForm(*saved_form));
- form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
- form_manager()->OnGetPasswordStoreResults(std::move(result));
-
- PasswordForm submitted_form(*observed_form());
- submitted_form.preferred = true;
- submitted_form.username_value.clear();
-
- EXPECT_CALL(*mock_store(), AddLogin(CheckUsername(base::string16())));
- EXPECT_CALL(*mock_store(), RemoveLogin(_)).Times(0);
-
- form_manager()->ProvisionallySave(
- submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
- form_manager()->Save();
-}
-
-TEST_F(PasswordFormManagerTest, NotRemoveOnUpdate) {
- ScopedVector<PasswordForm> result;
- PasswordForm saved_form = *saved_match();
- ASSERT_FALSE(saved_form.username_value.empty());
- result.push_back(new PasswordForm(saved_form));
- saved_form.username_value.clear();
- saved_form.preferred = false;
- result.push_back(new PasswordForm(saved_form));
- form_manager()->SimulateFetchMatchingLoginsFromPasswordStore();
- form_manager()->OnGetPasswordStoreResults(std::move(result));
-
- PasswordForm submitted_form(*observed_form());
- submitted_form.preferred = true;
- submitted_form.username_value = saved_match()->username_value;
- submitted_form.password_value = saved_form.password_value + ASCIIToUTF16("1");
-
- EXPECT_CALL(*mock_store(),
- UpdateLogin(CheckUsername(saved_match()->username_value)));
- EXPECT_CALL(*mock_store(), RemoveLogin(_)).Times(0);
- EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(),
- StartUploadRequest(_, false, _, _, true));
-
- form_manager()->ProvisionallySave(
- submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
- form_manager()->Save();
-}
-
TEST_F(PasswordFormManagerTest, GenerationStatusChangedWithPassword) {
EXPECT_CALL(*mock_store(), GetLogins(*observed_form(), form_manager()));
form_manager()->FetchDataFromPasswordStore();
@@ -2455,7 +2360,7 @@ TEST_F(PasswordFormManagerTest, GenerationStatusChangedWithPassword) {
submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
PasswordForm new_credentials;
- EXPECT_CALL(*mock_store(), UpdateLogin(_))
+ EXPECT_CALL(MockFormSaver::Get(form_manager()), Update(_, _, _, nullptr))
.WillOnce(testing::SaveArg<0>(&new_credentials));
form_manager()->Save();
@@ -2485,7 +2390,7 @@ TEST_F(PasswordFormManagerTest, GenerationStatusNotUpdatedIfPasswordUnchanged) {
submitted_form, PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
PasswordForm new_credentials;
- EXPECT_CALL(*mock_store(), UpdateLogin(_))
+ EXPECT_CALL(MockFormSaver::Get(form_manager()), Update(_, _, _, nullptr))
.WillOnce(testing::SaveArg<0>(&new_credentials));
form_manager()->Save();
@@ -2607,7 +2512,8 @@ TEST_F(PasswordFormManagerTest, UploadChangePasswordForm_NOT_NEW_PASSWORD) {
TEST_F(PasswordFormManagerTest, TestUpdatePSLMatchedCredentials) {
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), *observed_form(), false);
+ client()->driver(), *observed_form(), false,
+ base::WrapUnique(new MockFormSaver()));
SimulateMatchingPhase(&form_manager, RESULT_SAVED_MATCH | RESULT_PSL_MATCH);
// User submits a credentials with an old username and a new password.
@@ -2623,11 +2529,12 @@ TEST_F(PasswordFormManagerTest, TestUpdatePSLMatchedCredentials) {
// login.
EXPECT_FALSE(form_manager.IsNewLogin());
- // Trigger saving to exercise some special case handling in UpdateLogin().
- PasswordForm new_credentials[2];
- EXPECT_CALL(*mock_store(), UpdateLogin(_))
- .WillOnce(testing::SaveArg<0>(&new_credentials[0]))
- .WillOnce(testing::SaveArg<0>(&new_credentials[1]));
+ // Trigger saving to exercise some special case handling during updating.
+ PasswordForm new_credentials;
+ std::vector<const autofill::PasswordForm*> credentials_to_update;
+ EXPECT_CALL(MockFormSaver::Get(&form_manager), Update(_, _, _, nullptr))
+ .WillOnce(testing::DoAll(SaveArg<0>(&new_credentials),
+ SaveArgPointee<2>(&credentials_to_update)));
EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(),
StartUploadRequest(_, false, _, _, true));
@@ -2635,28 +2542,29 @@ TEST_F(PasswordFormManagerTest, TestUpdatePSLMatchedCredentials) {
Mock::VerifyAndClearExpectations(mock_store());
// No meta-information should be updated, only the password.
- EXPECT_EQ(credentials.password_value, new_credentials[0].password_value);
- EXPECT_EQ(saved_match()->username_value, new_credentials[0].username_value);
- EXPECT_EQ(saved_match()->username_element,
- new_credentials[0].username_element);
- EXPECT_EQ(saved_match()->password_element,
- new_credentials[0].password_element);
- EXPECT_EQ(saved_match()->origin, new_credentials[0].origin);
-
- EXPECT_EQ(credentials.password_value, new_credentials[1].password_value);
+ EXPECT_EQ(credentials.password_value, new_credentials.password_value);
+ EXPECT_EQ(saved_match()->username_value, new_credentials.username_value);
+ EXPECT_EQ(saved_match()->username_element, new_credentials.username_element);
+ EXPECT_EQ(saved_match()->password_element, new_credentials.password_element);
+ EXPECT_EQ(saved_match()->origin, new_credentials.origin);
+
+ ASSERT_EQ(1u, credentials_to_update.size());
+ EXPECT_EQ(credentials.password_value,
+ credentials_to_update[0]->password_value);
EXPECT_EQ(psl_saved_match()->username_element,
- new_credentials[1].username_element);
+ credentials_to_update[0]->username_element);
EXPECT_EQ(psl_saved_match()->username_element,
- new_credentials[1].username_element);
+ credentials_to_update[0]->username_element);
EXPECT_EQ(psl_saved_match()->password_element,
- new_credentials[1].password_element);
- EXPECT_EQ(psl_saved_match()->origin, new_credentials[1].origin);
+ credentials_to_update[0]->password_element);
+ EXPECT_EQ(psl_saved_match()->origin, credentials_to_update[0]->origin);
}
TEST_F(PasswordFormManagerTest,
TestNotUpdatePSLMatchedCredentialsWithAnotherUsername) {
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), *observed_form(), false);
+ client()->driver(), *observed_form(), false,
+ base::WrapUnique(new MockFormSaver()));
psl_saved_match()->username_value += ASCIIToUTF16("1");
SimulateMatchingPhase(&form_manager, RESULT_SAVED_MATCH | RESULT_PSL_MATCH);
@@ -2673,9 +2581,10 @@ TEST_F(PasswordFormManagerTest,
// login.
EXPECT_FALSE(form_manager.IsNewLogin());
- // Trigger saving to exercise some special case handling in UpdateLogin().
+ // Trigger saving to exercise some special case handling during updating.
PasswordForm new_credentials;
- EXPECT_CALL(*mock_store(), UpdateLogin(_))
+ EXPECT_CALL(MockFormSaver::Get(&form_manager),
+ Update(_, _, Pointee(IsEmpty()), nullptr))
.WillOnce(testing::SaveArg<0>(&new_credentials));
EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(),
StartUploadRequest(_, false, _, _, true));
@@ -2694,7 +2603,8 @@ TEST_F(PasswordFormManagerTest,
TEST_F(PasswordFormManagerTest,
TestNotUpdatePSLMatchedCredentialsWithAnotherPassword) {
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), *observed_form(), false);
+ client()->driver(), *observed_form(), false,
+ base::WrapUnique(new MockFormSaver()));
psl_saved_match()->password_value += ASCIIToUTF16("1");
SimulateMatchingPhase(&form_manager, RESULT_SAVED_MATCH | RESULT_PSL_MATCH);
@@ -2711,9 +2621,10 @@ TEST_F(PasswordFormManagerTest,
// login.
EXPECT_FALSE(form_manager.IsNewLogin());
- // Trigger saving to exercise some special case handling in UpdateLogin().
+ // Trigger saving to exercise some special case handling during updating.
PasswordForm new_credentials;
- EXPECT_CALL(*mock_store(), UpdateLogin(_))
+ EXPECT_CALL(MockFormSaver::Get(&form_manager),
+ Update(_, _, Pointee(IsEmpty()), nullptr))
.WillOnce(testing::SaveArg<0>(&new_credentials));
EXPECT_CALL(*client()->mock_driver()->mock_autofill_download_manager(),
StartUploadRequest(_, false, _, _, true));
@@ -2731,7 +2642,8 @@ TEST_F(PasswordFormManagerTest,
TEST_F(PasswordFormManagerTest, TestNotUpdateWhenOnlyPSLMatched) {
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), *observed_form(), false);
+ client()->driver(), *observed_form(), false,
+ base::WrapUnique(new MockFormSaver()));
SimulateMatchingPhase(&form_manager, RESULT_PSL_MATCH);
// User submits a credentials with an old username and a new password.
@@ -2747,8 +2659,7 @@ TEST_F(PasswordFormManagerTest, TestNotUpdateWhenOnlyPSLMatched) {
// PSL matched credential should not be updated, since we are not sure that
// this is the same credential as submitted one.
PasswordForm new_credentials;
- EXPECT_CALL(*mock_store(), UpdateLogin(_)).Times(0);
- EXPECT_CALL(*mock_store(), AddLogin(_))
+ EXPECT_CALL(MockFormSaver::Get(&form_manager), Save(_, _, nullptr))
.WillOnce(testing::SaveArg<0>(&new_credentials));
form_manager.Save();
@@ -2916,7 +2827,8 @@ TEST_F(PasswordFormManagerTest,
client()->set_is_update_password_ui_enabled(true);
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), *observed_form(), false);
+ client()->driver(), *observed_form(), false,
+ base::WrapUnique(new MockFormSaver()));
SimulateMatchingPhase(&form_manager, RESULT_SAVED_MATCH);
@@ -2992,7 +2904,8 @@ TEST_F(PasswordFormManagerTest, FormClassifierVoteUpload) {
submitted_form.password_value = saved_match()->password_value;
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), form, false);
+ client()->driver(), form, false,
+ base::WrapUnique(new MockFormSaver()));
base::string16 generation_element = form.password_element;
if (found_generation_element)
form_manager.SaveGenerationFieldDetectedByClassifier(generation_element);
@@ -3025,7 +2938,8 @@ TEST_F(PasswordFormManagerTest, TestSavingAPIFormsWithSamePassword) {
saved_match()->type = autofill::PasswordForm::TYPE_API;
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), *observed_form(), false);
+ client()->driver(), *observed_form(), false,
+ base::WrapUnique(new MockFormSaver()));
SimulateMatchingPhase(&form_manager, RESULT_SAVED_MATCH);
// User submits new credentials with the same password as in already saved
@@ -3042,7 +2956,7 @@ TEST_F(PasswordFormManagerTest, TestSavingAPIFormsWithSamePassword) {
EXPECT_TRUE(form_manager.IsNewLogin());
PasswordForm new_credentials;
- EXPECT_CALL(*mock_store(), AddLogin(_))
+ EXPECT_CALL(MockFormSaver::Get(&form_manager), Save(_, _, nullptr))
.WillOnce(SaveArg<0>(&new_credentials));
form_manager.Save();
@@ -3081,7 +2995,8 @@ TEST_F(PasswordFormManagerTest, ProbablyAccountCreationUpload) {
form.form_data = saved_match()->form_data;
PasswordFormManager form_manager(password_manager(), client(),
- client()->driver(), form, false);
+ client()->driver(), form, false,
+ base::WrapUnique(new MockFormSaver()));
PasswordForm form_to_save(form);
form_to_save.preferred = true;

Powered by Google App Engine
This is Rietveld 408576698