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
{
22 // Copied to components/autofill/ios/browser/resources/autofill_controller.js.
25 ROLE_ATTRIBUTE_PRESENTATION
,
33 // Returns true if two form fields are the same, not counting the value.
34 bool SameFieldAs(const FormFieldData
& field
) const;
36 // Comparison operator exposed for STL map. Uses label, then name to sort.
37 bool operator<(const FormFieldData
& field
) const;
39 // If you add more, be sure to update the comparison operator, SameFieldAs,
40 // serializing functions (in the .cc file) and the constructor.
44 std::string form_control_type
;
45 std::string autocomplete_attribute
;
51 bool should_autocomplete
;
53 base::i18n::TextDirection text_direction
;
55 // For the HTML snippet |<option value="US">United States</option>|, the
56 // value is "US" and the contents are "United States".
57 std::vector
<base::string16
> option_values
;
58 std::vector
<base::string16
> option_contents
;
61 // Serialize and deserialize FormFieldData. These are used when FormData objects
62 // are serialized and deserialized.
63 void SerializeFormFieldData(const FormFieldData
& form_field_data
,
64 base::Pickle
* serialized
);
65 bool DeserializeFormFieldData(base::PickleIterator
* pickle_iterator
,
66 FormFieldData
* form_field_data
);
68 // So we can compare FormFieldDatas with EXPECT_EQ().
69 std::ostream
& operator<<(std::ostream
& os
, const FormFieldData
& field
);
71 // Prefer to use this macro in place of |EXPECT_EQ()| for comparing
72 // |FormFieldData|s in test code.
73 #define EXPECT_FORM_FIELD_DATA_EQUALS(expected, actual) \
75 EXPECT_EQ(expected.label, actual.label); \
76 EXPECT_EQ(expected.name, actual.name); \
77 EXPECT_EQ(expected.value, actual.value); \
78 EXPECT_EQ(expected.form_control_type, actual.form_control_type); \
79 EXPECT_EQ(expected.autocomplete_attribute, actual.autocomplete_attribute); \
80 EXPECT_EQ(expected.max_length, actual.max_length); \
81 EXPECT_EQ(expected.is_autofilled, actual.is_autofilled); \
82 EXPECT_EQ(expected.is_checked, actual.is_checked); \
83 EXPECT_EQ(expected.is_checkable, actual.is_checkable); \
86 } // namespace autofill
88 #endif // COMPONENTS_AUTOFILL_CORE_COMMON_FORM_FIELD_DATA_H_