Commit a6e1ba19 authored by Vadym Doroshenko's avatar Vadym Doroshenko Committed by Commit Bot

Improve processing of server predictions in PasswordManager.

Checkboxes are not part of calculation of form signature. So despite
the same signature it might be different number of fields. For example
when the site adds or removes checkboxes dynamically. This CL removes
assumption that initially observed form and server predictions have
the same number of fields. Unique_renderer_ids are used for field
identification.

Bug: 831123, 853149
Change-Id: Ibb6551e702cf073562dea1c4be47c5421143f713
Reviewed-on: https://chromium-review.googlesource.com/1118258
Commit-Queue: Vadym Doroshenko <dvadym@chromium.org>
Reviewed-by: default avatarVaclav Brozek <vabr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571919}
parent 8f6dce28
......@@ -40,22 +40,14 @@ CredentialFieldType DeriveFromServerFieldType(ServerFieldType type) {
}
}
FormPredictions ConvertToFormPredictions(const FormData& observed_form,
const FormStructure& form_structure) {
DCHECK_EQ(CalculateFormSignature(observed_form),
form_structure.form_signature());
DCHECK_EQ(observed_form.fields.size(), form_structure.field_count());
FormPredictions ConvertToFormPredictions(const FormStructure& form_structure) {
FormPredictions result;
if (observed_form.fields.size() != form_structure.field_count()) {
// TODO(https://crbug.com/831123). Find the reason why this can happen. See
// https://crbug.com/853149#c6 for some ideas.
return result;
}
for (size_t i = 0; i < observed_form.fields.size(); ++i) {
uint32_t unique_id = observed_form.fields[i].unique_renderer_id;
ServerFieldType server_type = form_structure.field(i)->server_type();
for (const auto& field : form_structure) {
ServerFieldType server_type = field->server_type();
if (IsCredentialRelatedPrediction(server_type))
result[unique_id] = PasswordFieldPrediction{.type = server_type};
result[field->unique_renderer_id] =
PasswordFieldPrediction{.type = server_type};
}
return result;
......
......@@ -11,7 +11,6 @@
#include "components/autofill/core/browser/field_types.h"
namespace autofill {
struct FormData;
class FormStructure;
} // namespace autofill
......@@ -43,9 +42,7 @@ struct PasswordFieldPrediction {
using FormPredictions = std::map<uint32_t, PasswordFieldPrediction>;
// Extracts all password related server predictions from |form_structure|.
// |observed_form| and |form_structure| must correspond to the same form.
FormPredictions ConvertToFormPredictions(
const autofill::FormData& observed_form,
const autofill::FormStructure& form_structure);
} // namespace password_manager
......
......@@ -66,8 +66,7 @@ TEST(FormPredictionsTest, ConvertToFormPredictions) {
++expected_predictions;
}
FormPredictions actual_predictions =
ConvertToFormPredictions(form_data, form_structure);
FormPredictions actual_predictions = ConvertToFormPredictions(form_structure);
// Check whether actual predictions are equal to expected ones.
EXPECT_EQ(expected_predictions, actual_predictions.size());
......
......@@ -213,7 +213,7 @@ void NewPasswordFormManager::ProcessServerPredictions(
for (const FormStructure* form_predictions : predictions) {
if (form_predictions->form_signature() != observed_form_signature)
continue;
predictions_ = ConvertToFormPredictions(observed_form_, *form_predictions);
predictions_ = ConvertToFormPredictions(*form_predictions);
Fill();
break;
}
......
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