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. 4 5 #ifndef COMPONENTS_AUTOFILL_CORE_COMMON_FORM_FIELD_DATA_H_ 6 #define COMPONENTS_AUTOFILL_CORE_COMMON_FORM_FIELD_DATA_H_ 7 8 #include <vector> 9 10 #include "base/i18n/rtl.h" 11 #include "base/strings/string16.h" 12 13 class Pickle; 14 class PickleIterator; 15 16 namespace autofill { 17 18 // Stores information about a field in a form. 19 struct FormFieldData { 20 FormFieldData(); 21 ~FormFieldData(); 22 23 // Equality tests for identity which does not include |value| or 24 // |is_autofilled|. 25 // TODO(dhollowa): These operators need to be revised when we implement field 26 // ids. 27 bool operator==(const FormFieldData& field) const; 28 bool operator!=(const FormFieldData& field) const; 29 // Comparison operator exposed for STL map. Uses label, then name to sort. 30 bool operator<(const FormFieldData& field) const; 31 32 base::string16 label; 33 base::string16 name; 34 base::string16 value; 35 std::string form_control_type; 36 std::string autocomplete_attribute; 37 size_t max_length; 38 bool is_autofilled; 39 bool is_checked; 40 bool is_checkable; 41 bool is_focusable; 42 bool should_autocomplete; 43 base::i18n::TextDirection text_direction; 44 45 // For the HTML snippet |<option value="US">United States</option>|, the 46 // value is "US" and the contents are "United States". 47 std::vector<base::string16> option_values; 48 std::vector<base::string16> option_contents; 49 }; 50 51 // Serialize and deserialize FormFieldData. These are used when FormData objects 52 // are serialized and deserialized. 53 void SerializeFormFieldData(const FormFieldData& form_field_data, 54 Pickle* serialized); 55 bool DeserializeFormFieldData(PickleIterator* pickle_iterator, 56 FormFieldData* form_field_data); 57 58 // So we can compare FormFieldDatas with EXPECT_EQ(). 59 std::ostream& operator<<(std::ostream& os, const FormFieldData& field); 60 61 // Prefer to use this macro in place of |EXPECT_EQ()| for comparing 62 // |FormFieldData|s in test code. 63 #define EXPECT_FORM_FIELD_DATA_EQUALS(expected, actual) \ 64 do { \ 65 EXPECT_EQ(expected.label, actual.label); \ 66 EXPECT_EQ(expected.name, actual.name); \ 67 EXPECT_EQ(expected.value, actual.value); \ 68 EXPECT_EQ(expected.form_control_type, actual.form_control_type); \ 69 EXPECT_EQ(expected.autocomplete_attribute, actual.autocomplete_attribute); \ 70 EXPECT_EQ(expected.max_length, actual.max_length); \ 71 EXPECT_EQ(expected.is_autofilled, actual.is_autofilled); \ 72 EXPECT_EQ(expected.is_checked, actual.is_checked); \ 73 EXPECT_EQ(expected.is_checkable, actual.is_checkable); \ 74 } while (0) 75 76 } // namespace autofill 77 78 #endif // COMPONENTS_AUTOFILL_CORE_COMMON_FORM_FIELD_DATA_H_ 79