Commit 33ec0933 authored by Vadym Doroshenko's avatar Vadym Doroshenko Committed by Commit Bot

Reset state of PasswordFormManager when the submitted form is incorrect.

Bug: 1042196
Change-Id: I82441af46e4c1a2e0e547ae47c0c9d5d79ddb90e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2029514
Commit-Queue: Vadym Doroshenko <dvadym@chromium.org>
Reviewed-by: default avatarMohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736838}
parent ea4a0109
......@@ -612,11 +612,17 @@ bool PasswordFormManager::ProvisionallySave(
RecordMetricOnReadonly(parser_.readonly_status(), !!parsed_submitted_form,
FormDataParser::Mode::kSaving);
// This function might be called multiple times. Consider as success if the
// submitted form was successfully parsed on a previous call.
if (!parsed_submitted_form ||
!parsed_submitted_form->HasNonEmptyPasswordValue()) {
return is_submitted_;
bool have_password_to_save =
parsed_submitted_form &&
parsed_submitted_form->HasNonEmptyPasswordValue();
if (!have_password_to_save) {
// In case of error during parsing, reset the state.
parsed_submitted_form_.reset();
submitted_form_ = FormData();
password_save_manager_->ResetPendingCrednetials();
is_submitted_ = false;
return false;
}
parsed_submitted_form_ = std::move(parsed_submitted_form);
......
......@@ -318,8 +318,8 @@ class PasswordFormManager : public PasswordFormManagerForUI,
VotesUploader votes_uploader_;
// |is_submitted_| = true means that a submission of the managed form was seen
// and then |submitted_form_| contains the submitted form.
// |is_submitted_| = true means that |*this| is ready for saving.
// TODO(https://crubg.com/875768): Come up with a better name.
bool is_submitted_ = false;
autofill::FormData submitted_form_;
std::unique_ptr<autofill::PasswordForm> parsed_submitted_form_;
......
......@@ -637,12 +637,11 @@ TEST_P(PasswordFormManagerTest, SetSubmittedMultipleTimes) {
// Make the submitted form to be invalid password form.
submitted_form_.fields.clear();
// Expect that |form_manager_| is still in submitted state because the first
// time the submited form was valid.
EXPECT_TRUE(
EXPECT_FALSE(
form_manager_->ProvisionallySave(submitted_form_, &driver_, nullptr));
EXPECT_TRUE(form_manager_->is_submitted());
EXPECT_TRUE(form_manager_->GetSubmittedForm());
EXPECT_FALSE(form_manager_->is_submitted());
EXPECT_FALSE(form_manager_->GetSubmittedForm());
EXPECT_EQ(PasswordForm(), form_manager_->GetPendingCredentials());
}
// Tests that when PasswordFormManager receives saved matches it waits for
......
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