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"
18 // Stores information about a field in a form.
19 struct FormFieldData
{
22 ROLE_ATTRIBUTE_PRESENTATION
,
30 // Returns true if two form fields are the same, not counting the value.
31 bool SameFieldAs(const FormFieldData
& field
) const;
33 // Comparison operator exposed for STL map. Uses label, then name to sort.
34 bool operator<(const FormFieldData
& field
) const;
36 // If you add more, be sure to update the comparison operator, SameFieldAs,
37 // serializing functions (in the .cc file) and the constructor.
41 std::string form_control_type
;
42 std::string autocomplete_attribute
;
48 bool should_autocomplete
;
50 base::i18n::TextDirection text_direction
;
52 // For the HTML snippet |<option value="US">United States</option>|, the
53 // value is "US" and the contents are "United States".
54 std::vector
<base::string16
> option_values
;
55 std::vector
<base::string16
> option_contents
;
58 // Serialize and deserialize FormFieldData. These are used when FormData objects
59 // are serialized and deserialized.
60 void SerializeFormFieldData(const FormFieldData
& form_field_data
,
62 bool DeserializeFormFieldData(PickleIterator
* pickle_iterator
,
63 FormFieldData
* form_field_data
);
65 // So we can compare FormFieldDatas with EXPECT_EQ().
66 std::ostream
& operator<<(std::ostream
& os
, const FormFieldData
& field
);
68 // Prefer to use this macro in place of |EXPECT_EQ()| for comparing
69 // |FormFieldData|s in test code.
70 #define EXPECT_FORM_FIELD_DATA_EQUALS(expected, actual) \
72 EXPECT_EQ(expected.label, actual.label); \
73 EXPECT_EQ(expected.name, actual.name); \
74 EXPECT_EQ(expected.value, actual.value); \
75 EXPECT_EQ(expected.form_control_type, actual.form_control_type); \
76 EXPECT_EQ(expected.autocomplete_attribute, actual.autocomplete_attribute); \
77 EXPECT_EQ(expected.max_length, actual.max_length); \
78 EXPECT_EQ(expected.is_autofilled, actual.is_autofilled); \
79 EXPECT_EQ(expected.is_checked, actual.is_checked); \
80 EXPECT_EQ(expected.is_checkable, actual.is_checkable); \
83 } // namespace autofill
85 #endif // COMPONENTS_AUTOFILL_CORE_COMMON_FORM_FIELD_DATA_H_