Commit a1b74d50 authored by engedy@chromium.org's avatar engedy@chromium.org

Fix check in PasswordManager to allow saving credentials from forms only having a new password.

BUG=375333

Review URL: https://codereview.chromium.org/386933007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282705 0039d316-1c4b-4281-b951-d872f2087c98
parent 213b1bb2
......@@ -141,7 +141,7 @@ void PasswordManager::ProvisionallySavePassword(const PasswordForm& form) {
}
// No password to save? Then don't.
if (form.password_value.empty()) {
if (form.password_value.empty() && form.new_password_value.empty()) {
RecordFailure(EMPTY_PASSWORD, form.origin.host(), logger.get());
return;
}
......
......@@ -119,6 +119,14 @@ class PasswordManagerTest : public testing::Test {
return form;
}
// Create a sign-up form that only has a new password field.
PasswordForm MakeFormWithOnlyNewPasswordField() {
PasswordForm form = MakeSimpleForm();
form.new_password_element.swap(form.password_element);
form.new_password_value.swap(form.password_value);
return form;
}
// Reproduction of the form present on twitter's login page.
PasswordForm MakeTwitterLoginForm() {
PasswordForm form;
......@@ -159,10 +167,14 @@ class PasswordManagerTest : public testing::Test {
return false;
if (lhs.password_element != rhs.password_element)
return false;
if (lhs.new_password_element != rhs.new_password_element)
return false;
if (lhs.username_value != rhs.username_value)
return false;
if (lhs.password_value != rhs.password_value)
return false;
if (lhs.new_password_value != rhs.new_password_value)
return false;
if (lhs.password_autocomplete_set != rhs.password_autocomplete_set)
return false;
if (lhs.submit_element != rhs.submit_element)
......@@ -201,6 +213,7 @@ MATCHER_P(FormMatches, form, "") {
form.action == arg.action &&
form.username_element == arg.username_element &&
form.password_element == arg.password_element &&
form.new_password_element == arg.new_password_element &&
form.password_autocomplete_set == arg.password_autocomplete_set &&
form.submit_element == arg.submit_element;
}
......@@ -237,8 +250,53 @@ TEST_F(PasswordManagerTest, FormSubmitEmptyStore) {
form_to_save->Save();
}
TEST_F(PasswordManagerTest, FormSubmitWithOnlyNewPasswordField) {
// This test is the same as FormSubmitEmptyStore, except that it simulates the
// user entering credentials into a sign-up form that only has a new password
// field.
std::vector<PasswordForm*> result; // Empty password store.
EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0));
EXPECT_CALL(*store_.get(), GetLogins(_, _, _))
.WillOnce(DoAll(WithArg<2>(InvokeConsumer(result)), Return()));
std::vector<PasswordForm> observed;
PasswordForm form(MakeFormWithOnlyNewPasswordField());
observed.push_back(form);
manager()->OnPasswordFormsParsed(observed);
manager()->OnPasswordFormsRendered(observed, true);
// And the form submit contract is to call ProvisionallySavePassword.
manager()->ProvisionallySavePassword(form);
scoped_ptr<PasswordFormManager> form_to_save;
EXPECT_CALL(client_, PromptUserToSavePassword(_))
.WillOnce(WithArg<0>(SaveToScopedPtr(&form_to_save)));
// Now the password manager waits for the navigation to complete.
observed.clear();
manager()->OnPasswordFormsParsed(observed);
manager()->OnPasswordFormsRendered(observed, true);
ASSERT_TRUE(form_to_save.get());
// Simulate saving the form, as if the info bar was accepted.
PasswordForm saved_form;
EXPECT_CALL(*store_.get(), AddLogin(_))
.WillOnce(testing::SaveArg<0>(&saved_form));
form_to_save->Save();
// The value of the new password field should have been promoted to, and saved
// to the password store as the current password, and no password element name
// should have been saved.
PasswordForm expected_form(form);
expected_form.password_value.swap(expected_form.new_password_value);
expected_form.new_password_element.clear();
EXPECT_THAT(saved_form, FormMatches(expected_form));
EXPECT_EQ(expected_form.password_value, saved_form.password_value);
EXPECT_EQ(expected_form.new_password_value, saved_form.new_password_value);
}
TEST_F(PasswordManagerTest, GeneratedPasswordFormSubmitEmptyStore) {
// This test is the same FormSubmitEmptyStore, except that it simulates the
// This test is the same as FormSubmitEmptyStore, except that it simulates the
// user generating the password through the browser.
std::vector<PasswordForm*> result; // Empty password store.
EXPECT_CALL(driver_, FillPasswordForm(_)).Times(Exactly(0));
......
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