1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_AUTOFILL_CORE_COMMON_FORM_FIELD_DATA_H_
6 #define COMPONENTS_AUTOFILL_CORE_COMMON_FORM_FIELD_DATA_H_
10 #include "base/i18n/rtl.h"
11 #include "base/strings/string16.h"
20 // Stores information about a field in a form.
21 struct FormFieldData
{
24 ROLE_ATTRIBUTE_PRESENTATION
,
32 // Returns true if two form fields are the same, not counting the value.
33 bool SameFieldAs(const FormFieldData
& field
) const;
35 // Comparison operator exposed for STL map. Uses label, then name to sort.
36 bool operator<(const FormFieldData
& field
) const;
38 // If you add more, be sure to update the comparison operator, SameFieldAs,
39 // serializing functions (in the .cc file) and the constructor.
43 std::string form_control_type
;
44 std::string autocomplete_attribute
;
50 bool should_autocomplete
;
52 base::i18n::TextDirection text_direction
;
54 // For the HTML snippet |<option value="US">United States</option>|, the
55 // value is "US" and the contents are "United States".
56 std::vector
<base::string16
> option_values
;
57 std::vector
<base::string16
> option_contents
;
60 // Serialize and deserialize FormFieldData. These are used when FormData objects
61 // are serialized and deserialized.
62 void SerializeFormFieldData(const FormFieldData
& form_field_data
,
63 base::Pickle
* serialized
);
64 bool DeserializeFormFieldData(base::PickleIterator
* pickle_iterator
,
65 FormFieldData
* form_field_data
);
67 // So we can compare FormFieldDatas with EXPECT_EQ().
68 std::ostream
& operator<<(std::ostream
& os
, const FormFieldData
& field
);
70 // Prefer to use this macro in place of |EXPECT_EQ()| for comparing
71 // |FormFieldData|s in test code.
72 #define EXPECT_FORM_FIELD_DATA_EQUALS(expected, actual) \
74 EXPECT_EQ(expected.label, actual.label); \
75 EXPECT_EQ(expected.name, actual.name); \
76 EXPECT_EQ(expected.value, actual.value); \
77 EXPECT_EQ(expected.form_control_type, actual.form_control_type); \
78 EXPECT_EQ(expected.autocomplete_attribute, actual.autocomplete_attribute); \
79 EXPECT_EQ(expected.max_length, actual.max_length); \
80 EXPECT_EQ(expected.is_autofilled, actual.is_autofilled); \
81 EXPECT_EQ(expected.is_checked, actual.is_checked); \
82 EXPECT_EQ(expected.is_checkable, actual.is_checkable); \
85 } // namespace autofill
87 #endif // COMPONENTS_AUTOFILL_CORE_COMMON_FORM_FIELD_DATA_H_