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_BROWSER_ADDRESS_FIELD_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_FIELD_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/strings/string16.h"
14 #include "components/autofill/core/browser/autofill_type.h"
15 #include "components/autofill/core/browser/form_field.h"
20 class AutofillScanner;
22 class AddressField : public FormField {
24 static FormField* Parse(AutofillScanner* scanner);
28 virtual bool ClassifyField(ServerFieldTypeMap* map) const OVERRIDE;
37 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseOneLineAddress);
38 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseOneLineAddressBilling);
39 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseOneLineAddressShipping);
40 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseTwoLineAddress);
41 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseThreeLineAddress);
42 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseStreetAddressFromTextArea);
43 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseCity);
44 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseState);
45 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseZip);
46 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseStateAndZipOneLabel);
47 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseCountry);
48 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseTwoLineAddressMissingLabel);
49 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseCompany);
53 static bool ParseCompany(AutofillScanner* scanner,
54 AddressField* address_field);
55 static bool ParseAddressLines(AutofillScanner* scanner,
56 AddressField* address_field);
57 static bool ParseCountry(AutofillScanner* scanner,
58 AddressField* address_field);
59 static bool ParseZipCode(AutofillScanner* scanner,
60 AddressField* address_field);
61 static bool ParseCity(AutofillScanner* scanner,
62 AddressField* address_field);
63 static bool ParseState(AutofillScanner* scanner,
64 AddressField* address_field);
66 // Looks for an address type in the given text, which the caller must
67 // convert to lowercase.
68 static AddressType AddressTypeFromText(const base::string16& text);
70 // Tries to determine the billing/shipping type of this address.
71 AddressType FindType() const;
73 const AutofillField* company_; // optional
74 const AutofillField* address1_;
75 const AutofillField* address2_; // optional
76 const AutofillField* city_;
77 const AutofillField* state_; // optional
78 const AutofillField* zip_;
79 const AutofillField* zip4_; // optional ZIP+4; we don't fill this yet
80 const AutofillField* country_; // optional
84 DISALLOW_COPY_AND_ASSIGN(AddressField);
87 } // namespace autofill
89 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_FIELD_H_