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