Commit b57c43e3 authored by Christoph Schwering's avatar Christoph Schwering Committed by Commit Bot

[Autofill] Cleaned up FormDataPredictions, FormFieldDataPredictions.

Removed FormFieldDataPredictions::field.

Moved FormdDataPredictions::operator==(),
FormdDataPredictions::operator!=(),
FormFieldDataPredictions::operator==(),
FormFieldDataPredictions::operator!=(),
to autofill_test_util.{h,cc} since they are used (only) in two tests.

Bug: 1007974
Change-Id: Ibfb1034e3659625194e445ede54f766cf04fdb9d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2224866Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Commit-Queue: Christoph Schwering <schwering@google.com>
Auto-Submit: Christoph Schwering <schwering@google.com>
Cr-Commit-Position: refs/heads/master@{#786003}
parent b5c63f04
...@@ -476,7 +476,7 @@ bool FormCache::ShowPredictions(const FormDataPredictions& form, ...@@ -476,7 +476,7 @@ bool FormCache::ShowPredictions(const FormDataPredictions& form,
std::string form_id = std::string form_id =
base::NumberToString(form.data.unique_renderer_id.value()); base::NumberToString(form.data.unique_renderer_id.value());
std::string field_id = std::string field_id =
base::NumberToString(field.field.unique_renderer_id.value()); base::NumberToString(field_data.unique_renderer_id.value());
std::string title = std::string title =
base::StrCat({"overall type: ", field.overall_type, // base::StrCat({"overall type: ", field.overall_type, //
......
...@@ -24,7 +24,9 @@ ...@@ -24,7 +24,9 @@
#include "components/autofill/core/common/autofill_prefs.h" #include "components/autofill/core/common/autofill_prefs.h"
#include "components/autofill/core/common/autofill_util.h" #include "components/autofill/core/common/autofill_util.h"
#include "components/autofill/core/common/form_data.h" #include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/form_data_predictions.h"
#include "components/autofill/core/common/form_field_data.h" #include "components/autofill/core/common/form_field_data.h"
#include "components/autofill/core/common/form_field_data_predictions.h"
#include "components/autofill/core/common/renderer_id.h" #include "components/autofill/core/common/renderer_id.h"
#include "components/os_crypt/os_crypt_mocker.h" #include "components/os_crypt/os_crypt_mocker.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
...@@ -37,6 +39,21 @@ ...@@ -37,6 +39,21 @@
using base::ASCIIToUTF16; using base::ASCIIToUTF16;
namespace autofill { namespace autofill {
bool operator==(const FormFieldDataPredictions& a,
const FormFieldDataPredictions& b) {
auto members = [](const FormFieldDataPredictions& p) {
return std::tie(p.signature, p.heuristic_type, p.server_type,
p.overall_type, p.parseable_name, p.section);
};
return members(a) == members(b);
}
bool operator==(const FormDataPredictions& a, const FormDataPredictions& b) {
return a.data.SameFormAs(b.data) && a.signature == b.signature &&
a.fields == b.fields;
}
namespace test { namespace test {
namespace { namespace {
......
...@@ -31,6 +31,26 @@ class AutofillProfile; ...@@ -31,6 +31,26 @@ class AutofillProfile;
class AutofillTable; class AutofillTable;
struct FormData; struct FormData;
struct FormFieldData; struct FormFieldData;
struct FormDataPredictions;
struct FormFieldDataPredictions;
// Defined by pair-wise equality of all members.
bool operator==(const FormFieldDataPredictions& a,
const FormFieldDataPredictions& b);
inline bool operator!=(const FormFieldDataPredictions& a,
const FormFieldDataPredictions& b) {
return !(a == b);
}
// Holds iff the underlying FormDatas sans field values are equal and the
// remaining members are pairwise equal.
bool operator==(const FormDataPredictions& a, const FormDataPredictions& b);
inline bool operator!=(const FormDataPredictions& a,
const FormDataPredictions& b) {
return !(a == b);
}
// Common utilities shared amongst Autofill tests. // Common utilities shared amongst Autofill tests.
namespace test { namespace test {
......
...@@ -916,7 +916,6 @@ std::vector<FormDataPredictions> FormStructure::GetFieldTypePredictions( ...@@ -916,7 +916,6 @@ std::vector<FormDataPredictions> FormStructure::GetFieldTypePredictions(
for (const auto& field : form_structure->fields_) { for (const auto& field : form_structure->fields_) {
FormFieldDataPredictions annotated_field; FormFieldDataPredictions annotated_field;
annotated_field.field = *field;
annotated_field.signature = field->FieldSignatureAsStr(); annotated_field.signature = field->FieldSignatureAsStr();
annotated_field.heuristic_type = annotated_field.heuristic_type =
AutofillType(field->heuristic_type()).ToString(); AutofillType(field->heuristic_type()).ToString();
......
...@@ -20,15 +20,4 @@ FormDataPredictions& FormDataPredictions::operator=(FormDataPredictions&&) = ...@@ -20,15 +20,4 @@ FormDataPredictions& FormDataPredictions::operator=(FormDataPredictions&&) =
FormDataPredictions::~FormDataPredictions() = default; FormDataPredictions::~FormDataPredictions() = default;
bool FormDataPredictions::operator==(
const FormDataPredictions& predictions) const {
return (data.SameFormAs(predictions.data) &&
signature == predictions.signature && fields == predictions.fields);
}
bool FormDataPredictions::operator!=(
const FormDataPredictions& predictions) const {
return !operator==(predictions);
}
} // namespace autofill } // namespace autofill
...@@ -15,11 +15,8 @@ namespace autofill { ...@@ -15,11 +15,8 @@ namespace autofill {
// Holds information about a form to be filled and/or submitted. // Holds information about a form to be filled and/or submitted.
struct FormDataPredictions { struct FormDataPredictions {
// Data for this form.
FormData data; FormData data;
// The form signature for communication with the crowdsourcing server.
std::string signature; std::string signature;
// The form fields and their predicted field types.
std::vector<FormFieldDataPredictions> fields; std::vector<FormFieldDataPredictions> fields;
FormDataPredictions(); FormDataPredictions();
...@@ -28,10 +25,6 @@ struct FormDataPredictions { ...@@ -28,10 +25,6 @@ struct FormDataPredictions {
FormDataPredictions(FormDataPredictions&&); FormDataPredictions(FormDataPredictions&&);
FormDataPredictions& operator=(FormDataPredictions&&); FormDataPredictions& operator=(FormDataPredictions&&);
~FormDataPredictions(); ~FormDataPredictions();
// Added for the sake of testing.
bool operator==(const FormDataPredictions& predictions) const;
bool operator!=(const FormDataPredictions& predictions) const;
}; };
} // namespace autofill } // namespace autofill
......
...@@ -22,20 +22,4 @@ FormFieldDataPredictions& FormFieldDataPredictions::operator=( ...@@ -22,20 +22,4 @@ FormFieldDataPredictions& FormFieldDataPredictions::operator=(
FormFieldDataPredictions::~FormFieldDataPredictions() = default; FormFieldDataPredictions::~FormFieldDataPredictions() = default;
bool FormFieldDataPredictions::operator==(
const FormFieldDataPredictions& predictions) const {
return (field.SameFieldAs(predictions.field) &&
signature == predictions.signature &&
heuristic_type == predictions.heuristic_type &&
server_type == predictions.server_type &&
overall_type == predictions.overall_type &&
parseable_name == predictions.parseable_name &&
section == predictions.section);
}
bool FormFieldDataPredictions::operator!=(
const FormFieldDataPredictions& predictions) const {
return !operator==(predictions);
}
} // namespace autofill } // namespace autofill
...@@ -21,17 +21,12 @@ struct FormFieldDataPredictions { ...@@ -21,17 +21,12 @@ struct FormFieldDataPredictions {
FormFieldDataPredictions& operator=(FormFieldDataPredictions&&); FormFieldDataPredictions& operator=(FormFieldDataPredictions&&);
~FormFieldDataPredictions(); ~FormFieldDataPredictions();
FormFieldData field;
std::string signature; std::string signature;
std::string heuristic_type; std::string heuristic_type;
std::string server_type; std::string server_type;
std::string overall_type; std::string overall_type;
std::string parseable_name; std::string parseable_name;
std::string section; std::string section;
// Added for the sake of testing.
bool operator==(const FormFieldDataPredictions& predictions) const;
bool operator!=(const FormFieldDataPredictions& predictions) const;
}; };
} // namespace autofill } // namespace autofill
......
...@@ -182,7 +182,6 @@ struct FormData { ...@@ -182,7 +182,6 @@ struct FormData {
// autofill::FormFieldDataPredictions // autofill::FormFieldDataPredictions
struct FormFieldDataPredictions { struct FormFieldDataPredictions {
FormFieldData field;
string signature; string signature;
string heuristic_type; string heuristic_type;
string server_type; string server_type;
......
...@@ -168,8 +168,6 @@ bool StructTraits<autofill::mojom::FormFieldDataPredictionsDataView, ...@@ -168,8 +168,6 @@ bool StructTraits<autofill::mojom::FormFieldDataPredictionsDataView,
autofill::FormFieldDataPredictions>:: autofill::FormFieldDataPredictions>::
Read(autofill::mojom::FormFieldDataPredictionsDataView data, Read(autofill::mojom::FormFieldDataPredictionsDataView data,
autofill::FormFieldDataPredictions* out) { autofill::FormFieldDataPredictions* out) {
if (!data.ReadField(&out->field))
return false;
if (!data.ReadSignature(&out->signature)) if (!data.ReadSignature(&out->signature))
return false; return false;
if (!data.ReadHeuristicType(&out->heuristic_type)) if (!data.ReadHeuristicType(&out->heuristic_type))
......
...@@ -280,11 +280,6 @@ struct StructTraits<autofill::mojom::FormDataDataView, autofill::FormData> { ...@@ -280,11 +280,6 @@ struct StructTraits<autofill::mojom::FormDataDataView, autofill::FormData> {
template <> template <>
struct StructTraits<autofill::mojom::FormFieldDataPredictionsDataView, struct StructTraits<autofill::mojom::FormFieldDataPredictionsDataView,
autofill::FormFieldDataPredictions> { autofill::FormFieldDataPredictions> {
static const autofill::FormFieldData& field(
const autofill::FormFieldDataPredictions& r) {
return r.field;
}
static const std::string& signature( static const std::string& signature(
const autofill::FormFieldDataPredictions& r) { const autofill::FormFieldDataPredictions& r) {
return r.signature; return r.signature;
......
...@@ -37,8 +37,6 @@ bool EquivalentData(const T& a, const T& b) { ...@@ -37,8 +37,6 @@ bool EquivalentData(const T& a, const T& b) {
void CreateTestFieldDataPredictions(const std::string& signature, void CreateTestFieldDataPredictions(const std::string& signature,
FormFieldDataPredictions* field_predict) { FormFieldDataPredictions* field_predict) {
test::CreateTestSelectField("TestLabel", "TestName", "TestValue", kOptions,
kOptions, 4, &field_predict->field);
field_predict->signature = signature; field_predict->signature = signature;
field_predict->heuristic_type = "TestSignature"; field_predict->heuristic_type = "TestSignature";
field_predict->server_type = "TestServerType"; field_predict->server_type = "TestServerType";
......
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