diff options
-rw-r--r-- | chrome/browser/autofill/fax_field.cc | 25 | ||||
-rw-r--r-- | chrome/browser/autofill/fax_field.h | 29 | ||||
-rw-r--r-- | chrome/browser/autofill/fax_field_unittest.cc | 59 | ||||
-rw-r--r-- | chrome/browser/autofill/form_field.cc | 4 | ||||
-rw-r--r-- | chrome/browser/autofill/form_field.h | 4 | ||||
-rw-r--r-- | chrome/browser/autofill/form_structure_unittest.cc | 8 | ||||
-rw-r--r-- | chrome/browser/autofill/phone_field_unittest.cc | 1 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 |
9 files changed, 126 insertions, 7 deletions
diff --git a/chrome/browser/autofill/fax_field.cc b/chrome/browser/autofill/fax_field.cc new file mode 100644 index 0000000..a437ee0 --- /dev/null +++ b/chrome/browser/autofill/fax_field.cc @@ -0,0 +1,25 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/autofill/fax_field.h" + +#include "base/logging.h" +#include "chrome/browser/autofill/autofill_field.h" + +// static +FaxField* FaxField::Parse(std::vector<AutoFillField*>::const_iterator* iter) { + DCHECK(iter); + + FaxField fax_field; + if (ParseText(iter, ASCIIToUTF16("fax"), &fax_field.number_)) + return new FaxField(fax_field); + + return NULL; +} + +bool FaxField::GetFieldInfo(FieldTypeMap* field_type_map) const { + return Add(field_type_map, number_, AutoFillType(PHONE_FAX_WHOLE_NUMBER)); +} + +FaxField::FaxField() : number_(NULL) {} diff --git a/chrome/browser/autofill/fax_field.h b/chrome/browser/autofill/fax_field.h new file mode 100644 index 0000000..71228ca --- /dev/null +++ b/chrome/browser/autofill/fax_field.h @@ -0,0 +1,29 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_AUTOFILL_FAX_FIELD_H_ +#define CHROME_BROWSER_AUTOFILL_FAX_FIELD_H_ + +#include <vector> + +#include "chrome/browser/autofill/autofill_type.h" +#include "chrome/browser/autofill/form_field.h" + +class AutoFillField; + +// A class that identifies itself as a fax field using heuristics. +class FaxField : public FormField { + public: + static FaxField* Parse(std::vector<AutoFillField*>::const_iterator* iter); + + virtual bool GetFieldInfo(FieldTypeMap* field_type_map) const; + + private: + FaxField(); + + // The fax number field. + AutoFillField* number_; +}; + +#endif // CHROME_BROWSER_AUTOFILL_FAX_FIELD_H_ diff --git a/chrome/browser/autofill/fax_field_unittest.cc b/chrome/browser/autofill/fax_field_unittest.cc new file mode 100644 index 0000000..4cccac4 --- /dev/null +++ b/chrome/browser/autofill/fax_field_unittest.cc @@ -0,0 +1,59 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/scoped_ptr.h" +#include "base/scoped_vector.h" +#include "chrome/browser/autofill/fax_field.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "webkit/glue/form_field.h" + +namespace { + +class FaxFieldTest : public testing::Test { + public: + FaxFieldTest() {} + + protected: + ScopedVector<AutoFillField> list_; + scoped_ptr<FaxField> field_; + FieldTypeMap field_type_map_; + std::vector<AutoFillField*>::const_iterator iter_; + + private: + DISALLOW_COPY_AND_ASSIGN(FaxFieldTest); +}; + +TEST_F(FaxFieldTest, Empty) { + list_.push_back(NULL); + iter_ = list_.begin(); + field_.reset(FaxField::Parse(&iter_)); + ASSERT_EQ(static_cast<FaxField*>(NULL), field_.get()); +} + +TEST_F(FaxFieldTest, NonParse) { + list_.push_back(new AutoFillField); + list_.push_back(NULL); + iter_ = list_.begin(); + field_.reset(FaxField::Parse(&iter_)); + ASSERT_EQ(static_cast<FaxField*>(NULL), field_.get()); +} + +TEST_F(FaxFieldTest, ParseOneLineFax) { + list_.push_back( + new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Fax"), + ASCIIToUTF16("faxnumber"), + string16(), + ASCIIToUTF16("text")), + ASCIIToUTF16("fax1"))); + list_.push_back(NULL); + iter_ = list_.begin(); + field_.reset(FaxField::Parse(&iter_)); + ASSERT_NE(static_cast<FaxField*>(NULL), field_.get()); + ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_)); + ASSERT_TRUE( + field_type_map_.find(ASCIIToUTF16("fax1")) != field_type_map_.end()); + EXPECT_EQ(PHONE_FAX_WHOLE_NUMBER, field_type_map_[ASCIIToUTF16("fax1")]); +} + +} // namespace diff --git a/chrome/browser/autofill/form_field.cc b/chrome/browser/autofill/form_field.cc index 0c59e40..f14e172 100644 --- a/chrome/browser/autofill/form_field.cc +++ b/chrome/browser/autofill/form_field.cc @@ -8,6 +8,7 @@ #include "chrome/browser/autofill/address_field.h" #include "chrome/browser/autofill/autofill_field.h" #include "chrome/browser/autofill/credit_card_field.h" +#include "chrome/browser/autofill/fax_field.h" #include "chrome/browser/autofill/name_field.h" #include "chrome/browser/autofill/phone_field.h" #include "third_party/WebKit/WebKit/chromium/public/WebRegularExpression.h" @@ -96,6 +97,9 @@ FormField* FormField::ParseFormField( field = PhoneField::Parse(iter, is_ecml); if (field != NULL) return field; + field = FaxField::Parse(iter); + if (field != NULL) + return field; field = AddressField::Parse(iter, is_ecml); if (field != NULL) return field; diff --git a/chrome/browser/autofill/form_field.h b/chrome/browser/autofill/form_field.h index 2e01791..61787c1 100644 --- a/chrome/browser/autofill/form_field.h +++ b/chrome/browser/autofill/form_field.h @@ -33,7 +33,7 @@ static string16 kEcmlShipToCountry = ASCIIToUTF16("ecom_shipto_postal_countrycod static string16 kEcmlShipToPhone = ASCIIToUTF16("ecom_shipto_telecom_phone_number"); static string16 kEcmlShipToEmail = ASCIIToUTF16("ecom_shipto_online_email"); - // billing name/address fields +// billing name/address fields static string16 kEcmlBillToTitle = ASCIIToUTF16("ecom_billto_postal_name_prefix"); static string16 kEcmlBillToFirstName = ASCIIToUTF16("ecom_billto_postal_name_first"); static string16 kEcmlBillToMiddleName = ASCIIToUTF16("ecom_billto_postal_name_middle"); @@ -50,7 +50,7 @@ static string16 kEcmlBillToCountry = ASCIIToUTF16("ecom_billto_postal_countrycod static string16 kEcmlBillToPhone = ASCIIToUTF16("ecom_billto_telecom_phone_number"); static string16 kEcmlBillToEmail = ASCIIToUTF16("ecom_billto_online_email"); - // credit card fields +// credit card fields static string16 kEcmlCardHolder = ASCIIToUTF16("ecom_payment_card_name"); static string16 kEcmlCardType = ASCIIToUTF16("ecom_payment_card_type"); static string16 kEcmlCardNumber = ASCIIToUTF16("ecom_payment_card_number"); diff --git a/chrome/browser/autofill/form_structure_unittest.cc b/chrome/browser/autofill/form_structure_unittest.cc index 2bd5328..ad0b383 100644 --- a/chrome/browser/autofill/form_structure_unittest.cc +++ b/chrome/browser/autofill/form_structure_unittest.cc @@ -234,8 +234,8 @@ TEST(FormStructureTest, HeuristicsContactInfo) { // Phone. EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, form_structure->field(3)->heuristic_type()); - // Fax. Note, we don't currently match fax. - EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(4)->heuristic_type()); + // Fax. + EXPECT_EQ(PHONE_FAX_WHOLE_NUMBER, form_structure->field(4)->heuristic_type()); // Address. EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(5)->heuristic_type()); // City. @@ -507,8 +507,8 @@ TEST(FormStructureTest, HeuristicsLabelsOnly) { // Phone. EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, form_structure->field(3)->heuristic_type()); - // Fax. Note, we don't currently match fax. - EXPECT_EQ(UNKNOWN_TYPE, form_structure->field(4)->heuristic_type()); + // Fax. + EXPECT_EQ(PHONE_FAX_WHOLE_NUMBER, form_structure->field(4)->heuristic_type()); // Address. EXPECT_EQ(ADDRESS_HOME_LINE1, form_structure->field(5)->heuristic_type()); // Address Line 2. diff --git a/chrome/browser/autofill/phone_field_unittest.cc b/chrome/browser/autofill/phone_field_unittest.cc index 2a4c8c7..f2fa01f 100644 --- a/chrome/browser/autofill/phone_field_unittest.cc +++ b/chrome/browser/autofill/phone_field_unittest.cc @@ -6,7 +6,6 @@ #include "base/scoped_vector.h" #include "chrome/browser/autofill/phone_field.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" #include "webkit/glue/form_field.h" namespace { diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index b71849a..08663f8 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -152,6 +152,8 @@ 'browser/autofill/credit_card_field.h', 'browser/autofill/credit_card.cc', 'browser/autofill/credit_card.h', + 'browser/autofill/fax_field.cc', + 'browser/autofill/fax_field.h', 'browser/autofill/fax_number.h', 'browser/autofill/field_types.h', 'browser/autofill/form_field.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 486e2ed..aa90b8c 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -567,6 +567,7 @@ 'browser/autofill/billing_address_unittest.cc', 'browser/autofill/credit_card_field_unittest.cc', 'browser/autofill/credit_card_unittest.cc', + 'browser/autofill/fax_field_unittest.cc', 'browser/autofill/form_structure_unittest.cc', 'browser/autofill/name_field_unittest.cc', 'browser/autofill/personal_data_manager_unittest.cc', |