diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-05 22:02:12 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-05 22:02:12 +0000 |
commit | 5ca123393de3a3ee4d28629e855d592374db9bd1 (patch) | |
tree | b507ae4c1c622affe0067f2d538728f9ca3597ce /chrome/browser/autofill/billing_address_unittest.cc | |
parent | 78c7977d2fc51cb7b24f1eb69e1bce64b71cb51a (diff) | |
download | chromium_src-5ca123393de3a3ee4d28629e855d592374db9bd1.zip chromium_src-5ca123393de3a3ee4d28629e855d592374db9bd1.tar.gz chromium_src-5ca123393de3a3ee4d28629e855d592374db9bd1.tar.bz2 |
Add more tests for BillingAddress and fix the issues found by the tests.
BUG=none
TEST=BillingAddressTest
Review URL: http://codereview.chromium.org/669141
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40787 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill/billing_address_unittest.cc')
-rw-r--r-- | chrome/browser/autofill/billing_address_unittest.cc | 604 |
1 files changed, 543 insertions, 61 deletions
diff --git a/chrome/browser/autofill/billing_address_unittest.cc b/chrome/browser/autofill/billing_address_unittest.cc index a8dfb7d..da20211 100644 --- a/chrome/browser/autofill/billing_address_unittest.cc +++ b/chrome/browser/autofill/billing_address_unittest.cc @@ -2,53 +2,75 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <vector> + +#include "base/basictypes.h" +#include "base/scoped_ptr.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/autofill/address.h" #include "chrome/browser/autofill/billing_address.h" #include "testing/gtest/include/gtest/gtest.h" -TEST(BillingAddressTest, GetPossibleFieldTypes) { - BillingAddress address; - address.SetInfo(AutoFillType(ADDRESS_BILLING_LINE1), - UTF8ToUTF16("123 Appian Way")); - address.SetInfo(AutoFillType(ADDRESS_BILLING_LINE2), UTF8ToUTF16("Unit 6")); - address.SetInfo(AutoFillType(ADDRESS_BILLING_APT_NUM), UTF8ToUTF16("#6")); - address.SetInfo(AutoFillType(ADDRESS_BILLING_CITY), UTF8ToUTF16("Paris")); - address.SetInfo(AutoFillType(ADDRESS_BILLING_STATE), UTF8ToUTF16("Texas")); - address.SetInfo(AutoFillType(ADDRESS_BILLING_ZIP), UTF8ToUTF16("12345")); - address.SetInfo(AutoFillType(ADDRESS_BILLING_COUNTRY), UTF8ToUTF16("USA")); - +namespace { + +class BillingAddressTest : public testing::Test { + public: + BillingAddressTest() { + address_.SetInfo(AutoFillType(ADDRESS_BILLING_LINE1), + ASCIIToUTF16("123 Appian Way")); + address_.SetInfo(AutoFillType(ADDRESS_BILLING_LINE2), + ASCIIToUTF16("Unit 6")); + address_.SetInfo(AutoFillType(ADDRESS_BILLING_APT_NUM), ASCIIToUTF16("#6")); + address_.SetInfo(AutoFillType(ADDRESS_BILLING_CITY), ASCIIToUTF16("Paris")); + address_.SetInfo(AutoFillType(ADDRESS_BILLING_STATE), + ASCIIToUTF16("Texas")); + address_.SetInfo(AutoFillType(ADDRESS_BILLING_ZIP), ASCIIToUTF16("12345")); + address_.SetInfo(AutoFillType(ADDRESS_BILLING_COUNTRY), + ASCIIToUTF16("USA")); + } + + protected: + BillingAddress address_; + + DISALLOW_COPY_AND_ASSIGN(BillingAddressTest); +}; + +TEST_F(BillingAddressTest, GetPossibleFieldTypes) { // DCHECK on NULL |possible_types|. - ASSERT_DEBUG_DEATH(address.GetPossibleFieldTypes(string16(), NULL), ""); + ASSERT_DEBUG_DEATH(address_.GetPossibleFieldTypes(string16(), NULL), ""); // Empty string. FieldTypeSet possible_types; - address.GetPossibleFieldTypes(string16(), &possible_types); + address_.GetPossibleFieldTypes(string16(), &possible_types); ASSERT_EQ(0U, possible_types.size()); - // Only use split-chars for the address. + // Only use split-chars for the address_. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("-,#. "), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("-,#. "), &possible_types); ASSERT_EQ(0U, possible_types.size()); // ADDRESS_BILLING_LINE1 ===================================================== // Exact match. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("123 Appian Way"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("123 Appian Way"), + &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE1) != possible_types.end()); // Fields are mixed up. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("Way 123 Appian"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("Way 123 Appian"), + &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE1) != possible_types.end()); // The match is case-insensitive. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("123 aPPiaN wAy"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("123 aPPiaN wAy"), + &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE1) != possible_types.end()); @@ -57,33 +79,41 @@ TEST(BillingAddressTest, GetPossibleFieldTypes) { // do a good job of testing for case-insensitivity because the underlying // algorithm stops search when it matches '123'. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("wAy aPpIAn"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("wAy aPpIAn"), &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE1) != possible_types.end()); // The text is not complete. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("123 Appian"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("123 Appian"), &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE1) != possible_types.end()); // Extra text on the line. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("123 Appian Way #6"), + address_.GetPossibleFieldTypes(ASCIIToUTF16("123 Appian Way #6"), &possible_types); ASSERT_EQ(0U, possible_types.size()); // Extra text in the middle possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("123 Middle Appian Way"), + address_.GetPossibleFieldTypes(ASCIIToUTF16("123 Middle Appian Way"), &possible_types); ASSERT_EQ(0U, possible_types.size()); // Whitespace doesn't matter. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16(" 123 Appian Way "), + address_.GetPossibleFieldTypes(ASCIIToUTF16(" 123 Appian Way "), + &possible_types); + ASSERT_EQ(1U, possible_types.size()); + EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE1) != + possible_types.end()); + + // Address split characters don't matter. + possible_types.clear(); + address_.GetPossibleFieldTypes(ASCIIToUTF16("-123, #Appian.Way"), &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE1) != @@ -93,45 +123,54 @@ TEST(BillingAddressTest, GetPossibleFieldTypes) { // Exact match. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("Unit 6"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("Unit 6"), &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE2) != possible_types.end()); // Fields are mixed up. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("6 Unit"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("6 Unit"), &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE2) != possible_types.end()); // The match is case-insensitive. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("uNiT 6"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("uNiT 6"), &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE2) != possible_types.end()); // The text is not complete. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("Unit"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("Unit"), &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE2) != possible_types.end()); // Extra text on the line. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("Unit 6 Extra"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("Unit 6 Extra"), &possible_types); ASSERT_EQ(0U, possible_types.size()); // Extra text in the middle possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("Unit Middle 6"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("Unit Middle 6"), + &possible_types); ASSERT_EQ(0U, possible_types.size()); // Whitespace doesn't matter. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16(" Unit 6 "), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16(" Unit 6 "), &possible_types); + ASSERT_EQ(1U, possible_types.size()); + EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE2) != + possible_types.end()); + + // Address split characters don't matter. + possible_types.clear(); + address_.GetPossibleFieldTypes(ASCIIToUTF16("-#Unit, .6"), + &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE2) != possible_types.end()); @@ -142,7 +181,7 @@ TEST(BillingAddressTest, GetPossibleFieldTypes) { // 'Unit 6' because of the 6 and the fact that '#' is an address separator, // which is ignored in the search for an address line. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("#6"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("#6"), &possible_types); ASSERT_EQ(2U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_APT_NUM) != possible_types.end()); @@ -151,157 +190,159 @@ TEST(BillingAddressTest, GetPossibleFieldTypes) { // The match is case-insensitive. possible_types.clear(); - address.SetInfo(AutoFillType(ADDRESS_BILLING_APT_NUM), UTF8ToUTF16("Num 10")); - address.GetPossibleFieldTypes(UTF8ToUTF16("nuM 10"), &possible_types); + address_.SetInfo(AutoFillType(ADDRESS_BILLING_APT_NUM), + ASCIIToUTF16("Num 10")); + address_.GetPossibleFieldTypes(ASCIIToUTF16("nuM 10"), &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_APT_NUM) != possible_types.end()); // The text is not complete. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("Num"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("Num"), &possible_types); ASSERT_EQ(0U, possible_types.size()); // Extra text on the line. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("Num 10 More"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("Num 10 More"), &possible_types); ASSERT_EQ(0U, possible_types.size()); // Extra text in the middle possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("Num Middle 10"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("Num Middle 10"), + &possible_types); ASSERT_EQ(0U, possible_types.size()); // Whitespace does matter for apartment number. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16(" Num 10 "), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16(" Num 10 "), &possible_types); ASSERT_EQ(0U, possible_types.size()); // ADDRESS_BILLING_CITY ====================================================== // Exact match. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("Paris"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("Paris"), &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_CITY) != possible_types.end()); // The match is case-insensitive. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("pARiS"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("pARiS"), &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_CITY) != possible_types.end()); // The text is not complete. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("Par"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("Par"), &possible_types); ASSERT_EQ(0U, possible_types.size()); // Extra text on the line. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("Paris City"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("Paris City"), &possible_types); ASSERT_EQ(0U, possible_types.size()); // Whitespace does matter for apartment number. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16(" Paris "), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16(" Paris "), &possible_types); ASSERT_EQ(0U, possible_types.size()); // ADDRESS_BILLING_STATE ===================================================== // Exact match. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("Texas"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("Texas"), &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_STATE) != possible_types.end()); // The match is case-insensitive. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("tExAs"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("tExAs"), &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_STATE) != possible_types.end()); // The text is not complete. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("Tex"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("Tex"), &possible_types); ASSERT_EQ(0U, possible_types.size()); // Extra text on the line. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("Texas State"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("Texas State"), &possible_types); ASSERT_EQ(0U, possible_types.size()); // Whitespace does matter for apartment number. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16(" Texas "), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16(" Texas "), &possible_types); ASSERT_EQ(0U, possible_types.size()); // ADDRESS_BILLING_COUNTRY =================================================== // Exact match. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("USA"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("USA"), &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_COUNTRY) != possible_types.end()); // The match is case-insensitive. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("uSa"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("uSa"), &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_COUNTRY) != possible_types.end()); // The text is not complete. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("US"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("US"), &possible_types); ASSERT_EQ(0U, possible_types.size()); // Extra text on the line. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("US Country"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("US Country"), &possible_types); ASSERT_EQ(0U, possible_types.size()); // Whitespace does matter for apartment number. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16(" US "), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16(" US "), &possible_types); ASSERT_EQ(0U, possible_types.size()); // ADDRESS_BILLING_ZIP ======================================================= // Exact match. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("12345"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("12345"), &possible_types); ASSERT_EQ(1U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_ZIP) != possible_types.end()); // The text is not complete. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("1234"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("1234"), &possible_types); ASSERT_EQ(0U, possible_types.size()); // Extra text on the line. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("12345 678"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("12345 678"), &possible_types); ASSERT_EQ(0U, possible_types.size()); // Whitespace does matter for apartment number. possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16(" 12345 "), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16(" 12345 "), &possible_types); ASSERT_EQ(0U, possible_types.size()); - // Misc ======================================================= + // Misc ====================================================================== // More than one type can match. - address.SetInfo(AutoFillType(ADDRESS_BILLING_LINE1), UTF8ToUTF16("Same")); - address.SetInfo(AutoFillType(ADDRESS_BILLING_LINE2), UTF8ToUTF16("Same")); - address.SetInfo(AutoFillType(ADDRESS_BILLING_APT_NUM), UTF8ToUTF16("Same")); + address_.SetInfo(AutoFillType(ADDRESS_BILLING_LINE1), ASCIIToUTF16("Same")); + address_.SetInfo(AutoFillType(ADDRESS_BILLING_LINE2), ASCIIToUTF16("Same")); + address_.SetInfo(AutoFillType(ADDRESS_BILLING_APT_NUM), ASCIIToUTF16("Same")); possible_types.clear(); - address.GetPossibleFieldTypes(UTF8ToUTF16("Same"), &possible_types); + address_.GetPossibleFieldTypes(ASCIIToUTF16("Same"), &possible_types); ASSERT_EQ(3U, possible_types.size()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_LINE1) != possible_types.end()); @@ -309,4 +350,445 @@ TEST(BillingAddressTest, GetPossibleFieldTypes) { possible_types.end()); EXPECT_TRUE(possible_types.find(ADDRESS_BILLING_APT_NUM) != possible_types.end()); + + // LINE1 is empty. + address_.SetInfo(AutoFillType(ADDRESS_BILLING_LINE1), string16()); + possible_types.clear(); + address_.GetPossibleFieldTypes(string16(), &possible_types); + ASSERT_EQ(0U, possible_types.size()); } + +TEST_F(BillingAddressTest, FindInfoMatches) { + // DCHECK on NULL |matched_text|. + ASSERT_DEBUG_DEATH(address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_LINE1), string16(), NULL), ""); + + // ADDRESS_BILLING_LINE1 ===================================================== + + // Match the beginning of the string. + std::vector<string16> matches; + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_LINE1), ASCIIToUTF16("123"), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), matches[0]); + + // Search has too many characters. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_LINE1), ASCIIToUTF16("123 B"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Whitespace at the beginning of the search. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_LINE1), ASCIIToUTF16(" 123"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Search includes the entire match, but adds extra characters. + matches.clear(); + address_.FindInfoMatches(AutoFillType(ADDRESS_BILLING_LINE1), + ASCIIToUTF16("123 Appian Way B"), + &matches); + ASSERT_EQ(0U, matches.size()); + + // Matching is case-insensitive. + matches.clear(); + address_.FindInfoMatches(AutoFillType(ADDRESS_BILLING_LINE1), + ASCIIToUTF16("123 aPpiAN wAy"), + &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), matches[0]); + + // Search is empty. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_LINE1), string16(), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), matches[0]); + + // ADDRESS_BILLING_LINE2 ===================================================== + + // Match the beginning of the string. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_LINE2), ASCIIToUTF16("Unit"), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("Unit 6"), matches[0]); + + // Search has too many characters. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_LINE2), ASCIIToUTF16("Unita"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Whitespace at the beginning of the search. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_LINE2), ASCIIToUTF16(" Unit"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Search includes the entire match, but adds extra characters. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_LINE2), ASCIIToUTF16("Unit 6B"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Matching is case-insensitive. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_LINE2), ASCIIToUTF16("uNiT 6"), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("Unit 6"), matches[0]); + + // Search is empty. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_LINE2), string16(), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("Unit 6"), matches[0]); + + // ADDRESS_BILLING_APT_NUM =================================================== + + // Match the beginning of the string. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_APT_NUM), ASCIIToUTF16("#"), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("#6"), matches[0]); + + // Search has too many characters. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_APT_NUM), ASCIIToUTF16("#a"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Whitespace at the beginning of the search. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_APT_NUM), ASCIIToUTF16(" #"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Search includes the entire match, but adds extra characters. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_APT_NUM), ASCIIToUTF16("#6B"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Matching is case-insensitive. + matches.clear(); + address_.SetInfo(AutoFillType(ADDRESS_BILLING_APT_NUM), ASCIIToUTF16("6B")); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_APT_NUM), ASCIIToUTF16("6b"), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("6B"), matches[0]); + + // Search is empty. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_APT_NUM), string16(), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("6B"), matches[0]); + + // ADDRESS_BILLING_CITY ====================================================== + + // Match the beginning of the string. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_CITY), ASCIIToUTF16("Par"), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("Paris"), matches[0]); + + // Search has too many characters. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_CITY), ASCIIToUTF16("ParA"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Whitespace at the beginning of the search. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_CITY), ASCIIToUTF16(" Paris"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Search includes the entire match, but adds extra characters. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_CITY), ASCIIToUTF16("ParisB"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Matching is case-insensitive. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_CITY), ASCIIToUTF16("PArIs"), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("Paris"), matches[0]); + + // Search is empty. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_CITY), string16(), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("Paris"), matches[0]); + + // ADDRESS_BILLING_STATE ===================================================== + + // Match the beginning of the string. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_STATE), ASCIIToUTF16("Tex"), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("Texas"), matches[0]); + + // Search has too many characters. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_STATE), ASCIIToUTF16("TexC"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Whitespace at the beginning of the search. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_STATE), ASCIIToUTF16(" Texas"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Search includes the entire match, but adds extra characters. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_STATE), ASCIIToUTF16("TexasB"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Matching is case-insensitive. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_STATE), ASCIIToUTF16("TeXaS"), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("Texas"), matches[0]); + + // Search is empty. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_STATE), string16(), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("Texas"), matches[0]); + + // ADDRESS_BILLING_ZIP ======================================================= + + // Match the beginning of the string. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_ZIP), ASCIIToUTF16("123"), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("12345"), matches[0]); + + // Search has too many characters. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_ZIP), ASCIIToUTF16("123a"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Whitespace at the beginning of the search. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_ZIP), ASCIIToUTF16(" 123"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Search includes the entire match, but adds extra characters. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_ZIP), ASCIIToUTF16("123456"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Matching is case-sensitive because we should only have numbers in the zip. + matches.clear(); + address_.SetInfo(AutoFillType(ADDRESS_BILLING_ZIP), ASCIIToUTF16("12345A")); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_ZIP), ASCIIToUTF16("12345a"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Reset the zip code. + address_.SetInfo(AutoFillType(ADDRESS_BILLING_ZIP), ASCIIToUTF16("12345")); + + // Search is empty. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_ZIP), string16(), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("12345"), matches[0]); + + // ADDRESS_BILLING_COUNTRY =================================================== + + // Match the beginning of the string. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_COUNTRY), ASCIIToUTF16("US"), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("USA"), matches[0]); + + // Search has too many characters. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_COUNTRY), ASCIIToUTF16("USb"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Whitespace at the beginning of the search. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_COUNTRY), ASCIIToUTF16(" US"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Search includes the entire match, but adds extra characters. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_COUNTRY), ASCIIToUTF16("USAB"), &matches); + ASSERT_EQ(0U, matches.size()); + + // Matching is case-insensitive. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_COUNTRY), ASCIIToUTF16("uSa"), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("USA"), matches[0]); + + // Search is empty. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(ADDRESS_BILLING_COUNTRY), string16(), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("USA"), matches[0]); + + // Misc ====================================================================== + + // |type| is not handled by address_. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(NAME_FIRST), ASCIIToUTF16("USA"), &matches); + ASSERT_EQ(0U, matches.size()); + + // |type| is UNKNOWN_TYPE. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(UNKNOWN_TYPE), ASCIIToUTF16("123"), &matches); + ASSERT_EQ(2U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), matches[0]); + EXPECT_EQ(ASCIIToUTF16("12345"), matches[1]); + + // |type| is UNKNOWN_TYPE. Exclude zip because of extra space. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(UNKNOWN_TYPE), ASCIIToUTF16("123 "), &matches); + ASSERT_EQ(1U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), matches[0]); + + // |type| is UNKNOWN_TYPE. Search is empty. + matches.clear(); + address_.FindInfoMatches( + AutoFillType(UNKNOWN_TYPE), string16(), &matches); + ASSERT_EQ(7U, matches.size()); + EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), matches[0]); + EXPECT_EQ(ASCIIToUTF16("Unit 6"), matches[1]); + EXPECT_EQ(ASCIIToUTF16("6B"), matches[2]); + EXPECT_EQ(ASCIIToUTF16("Paris"), matches[3]); + EXPECT_EQ(ASCIIToUTF16("Texas"), matches[4]); + EXPECT_EQ(ASCIIToUTF16("12345"), matches[5]); + EXPECT_EQ(ASCIIToUTF16("USA"), matches[6]); +} + +TEST_F(BillingAddressTest, GetFieldText) { + // Get the field text. + string16 text; + text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_LINE1)); + EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), text); + text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_LINE2)); + EXPECT_EQ(ASCIIToUTF16("Unit 6"), text); + text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_APT_NUM)); + EXPECT_EQ(ASCIIToUTF16("#6"), text); + text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_CITY)); + EXPECT_EQ(ASCIIToUTF16("Paris"), text); + text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_STATE)); + EXPECT_EQ(ASCIIToUTF16("Texas"), text); + text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_ZIP)); + EXPECT_EQ(ASCIIToUTF16("12345"), text); + text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_COUNTRY)); + EXPECT_EQ(ASCIIToUTF16("USA"), text); + + // |type| is not supported by Billingaddress_. + text = address_.GetFieldText(AutoFillType(NAME_FIRST)); + EXPECT_EQ(string16(), text); +} + +TEST_F(BillingAddressTest, Clear) { + // Clear the info. + string16 text; + address_.Clear(); + text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_LINE1)); + EXPECT_EQ(string16(), text); + text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_LINE2)); + EXPECT_EQ(string16(), text); + text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_APT_NUM)); + EXPECT_EQ(string16(), text); + text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_CITY)); + EXPECT_EQ(string16(), text); + text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_STATE)); + EXPECT_EQ(string16(), text); + text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_ZIP)); + EXPECT_EQ(string16(), text); + text = address_.GetFieldText(AutoFillType(ADDRESS_BILLING_COUNTRY)); + EXPECT_EQ(string16(), text); +} + +TEST_F(BillingAddressTest, AddressClone) { + // Clone the info. + string16 text; + BillingAddress clone; + Address* clone_ptr = &clone; + clone_ptr->Clone(address_); + text = clone.GetFieldText(AutoFillType(ADDRESS_BILLING_LINE1)); + EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), text); + text = clone.GetFieldText(AutoFillType(ADDRESS_BILLING_LINE2)); + EXPECT_EQ(ASCIIToUTF16("Unit 6"), text); + text = clone.GetFieldText(AutoFillType(ADDRESS_BILLING_APT_NUM)); + EXPECT_EQ(ASCIIToUTF16("#6"), text); + text = clone.GetFieldText(AutoFillType(ADDRESS_BILLING_CITY)); + EXPECT_EQ(ASCIIToUTF16("Paris"), text); + text = clone.GetFieldText(AutoFillType(ADDRESS_BILLING_STATE)); + EXPECT_EQ(ASCIIToUTF16("Texas"), text); + text = clone.GetFieldText(AutoFillType(ADDRESS_BILLING_ZIP)); + EXPECT_EQ(ASCIIToUTF16("12345"), text); + text = clone.GetFieldText(AutoFillType(ADDRESS_BILLING_COUNTRY)); + EXPECT_EQ(ASCIIToUTF16("USA"), text); + + // Verify that the clone is a copy and not a reference. + address_.SetInfo(AutoFillType(ADDRESS_BILLING_LINE1), + ASCIIToUTF16("654 Bowling Terrace")); + text = clone.GetFieldText(AutoFillType(ADDRESS_BILLING_LINE1)); + EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), text); +} + +TEST_F(BillingAddressTest, BillingAddressClone) { + // Clone the info. + string16 text; + scoped_ptr<FormGroup> clone(address_.Clone()); + ASSERT_NE(static_cast<FormGroup*>(NULL), clone.get()); + text = clone->GetFieldText(AutoFillType(ADDRESS_BILLING_LINE1)); + EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), text); + text = clone->GetFieldText(AutoFillType(ADDRESS_BILLING_LINE2)); + EXPECT_EQ(ASCIIToUTF16("Unit 6"), text); + text = clone->GetFieldText(AutoFillType(ADDRESS_BILLING_APT_NUM)); + EXPECT_EQ(ASCIIToUTF16("#6"), text); + text = clone->GetFieldText(AutoFillType(ADDRESS_BILLING_CITY)); + EXPECT_EQ(ASCIIToUTF16("Paris"), text); + text = clone->GetFieldText(AutoFillType(ADDRESS_BILLING_STATE)); + EXPECT_EQ(ASCIIToUTF16("Texas"), text); + text = clone->GetFieldText(AutoFillType(ADDRESS_BILLING_ZIP)); + EXPECT_EQ(ASCIIToUTF16("12345"), text); + text = clone->GetFieldText(AutoFillType(ADDRESS_BILLING_COUNTRY)); + EXPECT_EQ(ASCIIToUTF16("USA"), text); + + // Verify that the clone is a copy and not a reference. + address_.SetInfo(AutoFillType(ADDRESS_BILLING_LINE1), + ASCIIToUTF16("654 Bowling Terrace")); + text = clone->GetFieldText(AutoFillType(ADDRESS_BILLING_LINE1)); + EXPECT_EQ(ASCIIToUTF16("123 Appian Way"), text); +} + +} // namespace |