summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-15 20:40:30 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-15 20:40:30 +0000
commitef5ca9f09640a9fd464561286b3fba1c7c23a620 (patch)
tree40eb0cd64685f00a2194bef3d9d1644ea2f42097 /chrome/browser/autofill
parent816b27302cb12e8f2852aeba85b08eaf10b729d3 (diff)
downloadchromium_src-ef5ca9f09640a9fd464561286b3fba1c7c23a620.zip
chromium_src-ef5ca9f09640a9fd464561286b3fba1c7c23a620.tar.gz
chromium_src-ef5ca9f09640a9fd464561286b3fba1c7c23a620.tar.bz2
AutoFill phone field unit tests.
Adds unit tests for AutoFill phone_field.cc/h. Coverage for Ecml and heuristic based phone field matching. BUG=none TEST=PhoneFieldTest Review URL: http://codereview.chromium.org/985002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41625 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill')
-rw-r--r--chrome/browser/autofill/phone_field.cc4
-rw-r--r--chrome/browser/autofill/phone_field_unittest.cc167
2 files changed, 171 insertions, 0 deletions
diff --git a/chrome/browser/autofill/phone_field.cc b/chrome/browser/autofill/phone_field.cc
index ea9ec71c..82d4537 100644
--- a/chrome/browser/autofill/phone_field.cc
+++ b/chrome/browser/autofill/phone_field.cc
@@ -12,6 +12,10 @@
// static
PhoneField* PhoneField::Parse(std::vector<AutoFillField*>::const_iterator* iter,
bool is_ecml) {
+ DCHECK(iter);
+ if (!iter)
+ return NULL;
+
if (is_ecml)
return ParseECML(iter);
diff --git a/chrome/browser/autofill/phone_field_unittest.cc b/chrome/browser/autofill/phone_field_unittest.cc
new file mode 100644
index 0000000..4417f9e
--- /dev/null
+++ b/chrome/browser/autofill/phone_field_unittest.cc
@@ -0,0 +1,167 @@
+// 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/phone_field.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
+#include "webkit/glue/form_field_values.h"
+
+namespace {
+
+class PhoneFieldTest : public testing::Test {
+ public:
+ PhoneFieldTest() {}
+
+ protected:
+ ScopedVector<AutoFillField> list_;
+ scoped_ptr<PhoneField> field_;
+ FieldTypeMap field_type_map_;
+ std::vector<AutoFillField*>::const_iterator iter_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PhoneFieldTest);
+};
+
+TEST_F(PhoneFieldTest, DeathOnNull) {
+ ASSERT_DEBUG_DEATH(PhoneField::Parse(NULL, false), "");
+}
+
+TEST_F(PhoneFieldTest, Empty) {
+ list_.push_back(NULL);
+ iter_ = list_.begin();
+ field_.reset(PhoneField::Parse(&iter_, false));
+ ASSERT_EQ(static_cast<PhoneField*>(NULL), field_.get());
+}
+
+TEST_F(PhoneFieldTest, NonParse) {
+ list_.push_back(new AutoFillField);
+ list_.push_back(NULL);
+ iter_ = list_.begin();
+ field_.reset(PhoneField::Parse(&iter_, false));
+ ASSERT_EQ(static_cast<PhoneField*>(NULL), field_.get());
+}
+
+TEST_F(PhoneFieldTest, ParseOneLinePhone) {
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Phone"),
+ ASCIIToUTF16("phone"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebKit::WebInputElement::Text),
+ ASCIIToUTF16("phone1")));
+ list_.push_back(NULL);
+ iter_ = list_.begin();
+ field_.reset(PhoneField::Parse(&iter_, false));
+ ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get());
+ ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("phone1")) != field_type_map_.end());
+ EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, field_type_map_[ASCIIToUTF16("phone1")]);
+}
+
+TEST_F(PhoneFieldTest, ParseOneLinePhoneEcml) {
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Phone"),
+ kEcmlShipToPhone,
+ string16(),
+ ASCIIToUTF16("text"),
+ WebKit::WebInputElement::Text),
+ ASCIIToUTF16("phone1")));
+ list_.push_back(NULL);
+ iter_ = list_.begin();
+ field_.reset(PhoneField::Parse(&iter_, true));
+ ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get());
+ ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("phone1")) != field_type_map_.end());
+ EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, field_type_map_[ASCIIToUTF16("phone1")]);
+}
+
+TEST_F(PhoneFieldTest, ParseTwoLinePhone) {
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Area Code"),
+ ASCIIToUTF16("area code"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebKit::WebInputElement::Text),
+ ASCIIToUTF16("areacode1")));
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Phone"),
+ ASCIIToUTF16("phone"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebKit::WebInputElement::Text),
+ ASCIIToUTF16("phone1")));
+ list_.push_back(NULL);
+ iter_ = list_.begin();
+ field_.reset(PhoneField::Parse(&iter_, false));
+ ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get());
+ ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("areacode1")) != field_type_map_.end());
+ EXPECT_EQ(PHONE_HOME_CITY_CODE, field_type_map_[ASCIIToUTF16("areacode1")]);
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("phone1")) != field_type_map_.end());
+ EXPECT_EQ(PHONE_HOME_NUMBER, field_type_map_[ASCIIToUTF16("phone1")]);
+}
+
+TEST_F(PhoneFieldTest, ParseTwoLinePhoneEcmlShipTo) {
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Area Code"),
+ kEcmlShipToPostalCode,
+ string16(),
+ ASCIIToUTF16("text"),
+ WebKit::WebInputElement::Text),
+ ASCIIToUTF16("areacode1")));
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Phone"),
+ kEcmlShipToPhone,
+ string16(),
+ ASCIIToUTF16("text"),
+ WebKit::WebInputElement::Text),
+ ASCIIToUTF16("phone1")));
+ list_.push_back(NULL);
+ iter_ = list_.begin();
+ field_.reset(PhoneField::Parse(&iter_, false));
+ ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get());
+ ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("areacode1")) != field_type_map_.end());
+ EXPECT_EQ(PHONE_HOME_CITY_CODE, field_type_map_[ASCIIToUTF16("areacode1")]);
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("phone1")) != field_type_map_.end());
+ EXPECT_EQ(PHONE_HOME_NUMBER, field_type_map_[ASCIIToUTF16("phone1")]);
+}
+
+TEST_F(PhoneFieldTest, ParseTwoLinePhoneEcmlBillTo) {
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Area Code"),
+ kEcmlBillToPostalCode,
+ string16(),
+ ASCIIToUTF16("text"),
+ WebKit::WebInputElement::Text),
+ ASCIIToUTF16("areacode1")));
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Phone"),
+ kEcmlBillToPhone,
+ string16(),
+ ASCIIToUTF16("text"),
+ WebKit::WebInputElement::Text),
+ ASCIIToUTF16("phone1")));
+ list_.push_back(NULL);
+ iter_ = list_.begin();
+ field_.reset(PhoneField::Parse(&iter_, false));
+ ASSERT_NE(static_cast<PhoneField*>(NULL), field_.get());
+ ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("areacode1")) != field_type_map_.end());
+ EXPECT_EQ(PHONE_HOME_CITY_CODE, field_type_map_[ASCIIToUTF16("areacode1")]);
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("phone1")) != field_type_map_.end());
+ EXPECT_EQ(PHONE_HOME_NUMBER, field_type_map_[ASCIIToUTF16("phone1")]);
+}
+
+} // namespace