Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Unified Diff: chrome/browser/autofill/name_field_unittest.cc

Issue 3067029: AutoFill: Add more NameField tests and fix incorrect logic in ParseEmpty. (Closed)
Patch Set: Fix test. Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/autofill/form_field.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autofill/name_field_unittest.cc
diff --git a/chrome/browser/autofill/name_field_unittest.cc b/chrome/browser/autofill/name_field_unittest.cc
index 7240004d24858435085fc6691eae78aaeacf10b1..04b797d26f6fd52fb8f9e902157191cd06674d8b 100644
--- a/chrome/browser/autofill/name_field_unittest.cc
+++ b/chrome/browser/autofill/name_field_unittest.cc
@@ -196,4 +196,202 @@ TEST_F(NameFieldTest, FirstLastMiddleWithSpaces) {
EXPECT_EQ(NAME_LAST, field_type_map_[ASCIIToUTF16("name3")]);
}
+TEST_F(NameFieldTest, FirstLastEmpty) {
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Name"),
+ ASCIIToUTF16("first_name"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("name1")));
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(string16(),
+ ASCIIToUTF16("last_name"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("name2")));
+ list_.push_back(NULL);
+ iter_ = list_.begin();
+ field_.reset(NameField::Parse(&iter_, false));
+ ASSERT_NE(static_cast<NameField*>(NULL), field_.get());
+ ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
+ EXPECT_EQ(NAME_FIRST, field_type_map_[ASCIIToUTF16("name1")]);
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("name2")) != field_type_map_.end());
+ EXPECT_EQ(NAME_LAST, field_type_map_[ASCIIToUTF16("name2")]);
+}
+
+TEST_F(NameFieldTest, FirstMiddleLastEmpty) {
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Name"),
+ ASCIIToUTF16("first_name"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("name1")));
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(string16(),
+ ASCIIToUTF16("middle_name"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("name2")));
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(string16(),
+ ASCIIToUTF16("last_name"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("name3")));
+ list_.push_back(NULL);
+ iter_ = list_.begin();
+ field_.reset(NameField::Parse(&iter_, false));
+ ASSERT_NE(static_cast<NameField*>(NULL), field_.get());
+ ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
+ EXPECT_EQ(NAME_FIRST, field_type_map_[ASCIIToUTF16("name1")]);
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("name2")) != field_type_map_.end());
+ EXPECT_EQ(NAME_MIDDLE_INITIAL, field_type_map_[ASCIIToUTF16("name2")]);
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("name3")) != field_type_map_.end());
+ EXPECT_EQ(NAME_LAST, field_type_map_[ASCIIToUTF16("name3")]);
+}
+
+TEST_F(NameFieldTest, MiddleInitial) {
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("First Name"),
+ ASCIIToUTF16("first_name"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("name1")));
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("MI"),
+ ASCIIToUTF16("middle_name"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("name2")));
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Last Name"),
+ ASCIIToUTF16("last_name"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("name3")));
+ list_.push_back(NULL);
+ iter_ = list_.begin();
+ field_.reset(NameField::Parse(&iter_, false));
+ ASSERT_NE(static_cast<NameField*>(NULL), field_.get());
+ ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
+ EXPECT_EQ(NAME_FIRST, field_type_map_[ASCIIToUTF16("name1")]);
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("name2")) != field_type_map_.end());
+ EXPECT_EQ(NAME_MIDDLE_INITIAL, field_type_map_[ASCIIToUTF16("name2")]);
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("name3")) != field_type_map_.end());
+ EXPECT_EQ(NAME_LAST, field_type_map_[ASCIIToUTF16("name3")]);
+}
+
+TEST_F(NameFieldTest, MiddleInitialNoLastName) {
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("First Name"),
+ ASCIIToUTF16("first_name"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("name1")));
+ list_.push_back(
+ new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("MI"),
+ ASCIIToUTF16("middle_name"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("name2")));
+ list_.push_back(NULL);
+ iter_ = list_.begin();
+ field_.reset(NameField::Parse(&iter_, false));
+ ASSERT_EQ(static_cast<NameField*>(NULL), field_.get());
+}
+
+TEST_F(NameFieldTest, ECMLNoName) {
+ list_.push_back(new AutoFillField(
+ webkit_glue::FormField(ASCIIToUTF16("Company"),
+ ASCIIToUTF16("ecom_shipto_postal_company"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("field1")));
+ list_.push_back(NULL);
+ iter_ = list_.begin();
+ field_.reset(NameField::Parse(&iter_, true));
+ ASSERT_EQ(static_cast<NameField*>(NULL), field_.get());
+}
+
+TEST_F(NameFieldTest, ECMLMiddleInitialNoLastName) {
+ list_.push_back(new AutoFillField(
+ webkit_glue::FormField(ASCIIToUTF16("First Name"),
+ ASCIIToUTF16("ecom_shipto_postal_name_first"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("name1")));
+ list_.push_back(new AutoFillField(
+ webkit_glue::FormField(ASCIIToUTF16("Middle"),
+ ASCIIToUTF16("ecom_shipto_postal_name_middle"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("name2")));
+ list_.push_back(NULL);
+ iter_ = list_.begin();
+ field_.reset(NameField::Parse(&iter_, true));
+ ASSERT_EQ(static_cast<NameField*>(NULL), field_.get());
+}
+
+TEST_F(NameFieldTest, ECMLFirstMiddleLast) {
+ list_.push_back(new AutoFillField(
+ webkit_glue::FormField(string16(),
+ ASCIIToUTF16("ecom_shipto_postal_name_first"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("name1")));
+ list_.push_back(new AutoFillField(
+ webkit_glue::FormField(string16(),
+ ASCIIToUTF16("ecom_shipto_postal_name_middle"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("name2")));
+ list_.push_back(new AutoFillField(
+ webkit_glue::FormField(string16(),
+ ASCIIToUTF16("ecom_shipto_postal_name_last"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 0),
+ ASCIIToUTF16("name3")));
+ list_.push_back(NULL);
+ iter_ = list_.begin();
+ field_.reset(NameField::Parse(&iter_, true));
+ ASSERT_NE(static_cast<NameField*>(NULL), field_.get());
+ ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
+ EXPECT_EQ(NAME_FIRST, field_type_map_[ASCIIToUTF16("name1")]);
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("name2")) != field_type_map_.end());
+ EXPECT_EQ(NAME_MIDDLE, field_type_map_[ASCIIToUTF16("name2")]);
+ ASSERT_TRUE(
+ field_type_map_.find(ASCIIToUTF16("name3")) != field_type_map_.end());
+ EXPECT_EQ(NAME_LAST, field_type_map_[ASCIIToUTF16("name3")]);
+}
+
} // namespace
« no previous file with comments | « chrome/browser/autofill/form_field.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698