This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include <string>
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/address.h"
#include "components/autofill/core/browser/autofill_type.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::ASCIIToUTF16;
namespace autofill {
TEST(AddressTest, GetCountry) {
Address address;
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY));
base::string16 country =
address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US");
EXPECT_EQ(base::string16(), country);
address.SetInfo(
AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("US"), "en-US");
country = address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US");
EXPECT_EQ(ASCIIToUTF16("United States"), country);
country = address.GetInfo(
AutofillType(HTML_TYPE_COUNTRY_NAME, HTML_MODE_NONE), "en-US");
EXPECT_EQ(ASCIIToUTF16("United States"), country);
country = address.GetInfo(
AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE), "en-US");
EXPECT_EQ(ASCIIToUTF16("US"), country);
address.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA"));
country = address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US");
EXPECT_EQ(ASCIIToUTF16("Canada"), country);
country = address.GetInfo(
AutofillType(HTML_TYPE_COUNTRY_NAME, HTML_MODE_NONE), "en-US");
EXPECT_EQ(ASCIIToUTF16("Canada"), country);
country = address.GetInfo(
AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE), "en-US");
EXPECT_EQ(ASCIIToUTF16("CA"), country);
}
TEST(AddressTest, SetCountry) {
Address address;
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY));
address.SetInfo(
AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("United States"),
"en-US");
base::string16 country =
address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US");
EXPECT_EQ(ASCIIToUTF16("US"), address.GetRawInfo(ADDRESS_HOME_COUNTRY));
EXPECT_EQ(ASCIIToUTF16("United States"), country);
address.SetInfo(
AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("USA"), "en-US");
country = address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US");
EXPECT_EQ(ASCIIToUTF16("US"), address.GetRawInfo(ADDRESS_HOME_COUNTRY));
EXPECT_EQ(ASCIIToUTF16("United States"), country);
address.SetInfo(
AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("canADA"), "en-US");
country = address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US");
EXPECT_EQ(ASCIIToUTF16("CA"), address.GetRawInfo(ADDRESS_HOME_COUNTRY));
EXPECT_EQ(ASCIIToUTF16("Canada"), country);
address.SetInfo(
AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("JP"), "en-US");
country = address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US");
EXPECT_EQ(ASCIIToUTF16("JP"), address.GetRawInfo(ADDRESS_HOME_COUNTRY));
EXPECT_EQ(ASCIIToUTF16("Japan"), country);
address.SetInfo(
AutofillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("Unknown"), "en-US");
country = address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US");
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY));
EXPECT_EQ(base::string16(), country);
AutofillType html_type_country_code =
AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE);
address.SetInfo(html_type_country_code, ASCIIToUTF16("US"), "en-US");
country = address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US");
EXPECT_EQ(ASCIIToUTF16("US"), address.GetRawInfo(ADDRESS_HOME_COUNTRY));
EXPECT_EQ(ASCIIToUTF16("United States"), country);
address.SetInfo(html_type_country_code, ASCIIToUTF16("cA"), "en-US");
country = address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US");
EXPECT_EQ(ASCIIToUTF16("CA"), address.GetRawInfo(ADDRESS_HOME_COUNTRY));
EXPECT_EQ(ASCIIToUTF16("Canada"), country);
address.SetInfo(html_type_country_code, ASCIIToUTF16("unknown"), "en-US");
country = address.GetInfo(AutofillType(ADDRESS_HOME_COUNTRY), "en-US");
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY));
EXPECT_EQ(base::string16(), country);
}
TEST(AddressTest, IsCountry) {
Address address;
address.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
const char* const kValidMatches[] = {
"United States",
"USA",
"US",
"United states",
"us"
};
for (size_t i = 0; i < arraysize(kValidMatches); ++i) {
SCOPED_TRACE(kValidMatches[i]);
ServerFieldTypeSet matching_types;
address.GetMatchingTypes(ASCIIToUTF16(kValidMatches[i]), "US",
&matching_types);
ASSERT_EQ(1U, matching_types.size());
EXPECT_EQ(ADDRESS_HOME_COUNTRY, *matching_types.begin());
}
const char* const kInvalidMatches[] = {
"United",
"Garbage"
};
for (size_t i = 0; i < arraysize(kInvalidMatches); ++i) {
ServerFieldTypeSet matching_types;
address.GetMatchingTypes(ASCIIToUTF16(kInvalidMatches[i]), "US",
&matching_types);
EXPECT_EQ(0U, matching_types.size());
}
address.SetRawInfo(ADDRESS_HOME_COUNTRY, base::string16());
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_COUNTRY));
ServerFieldTypeSet matching_types;
address.GetMatchingTypes(ASCIIToUTF16("Garbage"), "US", &matching_types);
EXPECT_EQ(0U, matching_types.size());
}
TEST(AddressTest, GetStreetAddress) {
const AutofillType type = AutofillType(ADDRESS_HOME_STREET_ADDRESS);
Address address;
EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
EXPECT_EQ(base::string16(), address.GetInfo(type, "en-US"));
address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave."));
EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
EXPECT_EQ(ASCIIToUTF16("123 Example Ave."), address.GetInfo(type, "en-US"));
address.SetRawInfo(ADDRESS_HOME_LINE1, base::string16());
address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt 42."));
EXPECT_TRUE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
EXPECT_EQ(ASCIIToUTF16("\nApt 42."), address.GetInfo(type, "en-US"));
address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave."));
address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42"));
EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
EXPECT_EQ(ASCIIToUTF16("123 Example Ave.\n"
"Apt. 42"),
address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS));
EXPECT_EQ(ASCIIToUTF16("123 Example Ave.\n"
"Apt. 42"),
address.GetInfo(type, "en-US"));
}
TEST(AddressTest, GetStreetAddressAfterOverwritingLongAddressWithShorterOne) {
Address address;
address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave."));
address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42"));
address.SetRawInfo(ADDRESS_HOME_LINE2, base::string16());
EXPECT_EQ(ASCIIToUTF16("123 Example Ave."),
address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS));
address.SetRawInfo(ADDRESS_HOME_LINE1, base::string16());
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS));
}
TEST(AddressTest, SetRawStreetAddress) {
const base::string16 empty_street_address;
const base::string16 short_street_address = ASCIIToUTF16("456 Nowhere Ln.");
const base::string16 long_street_address =
ASCIIToUTF16("123 Example Ave.\n"
"Apt. 42\n"
"(The one with the blue door)");
Address address;
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1));
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2));
address.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, long_street_address);
EXPECT_EQ(ASCIIToUTF16("123 Example Ave."),
address.GetRawInfo(ADDRESS_HOME_LINE1));
EXPECT_EQ(ASCIIToUTF16("Apt. 42"), address.GetRawInfo(ADDRESS_HOME_LINE2));
EXPECT_EQ(long_street_address,
address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS));
address.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, short_street_address);
EXPECT_EQ(ASCIIToUTF16("456 Nowhere Ln."),
address.GetRawInfo(ADDRESS_HOME_LINE1));
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2));
address.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, long_street_address);
address.SetRawInfo(ADDRESS_HOME_STREET_ADDRESS, empty_street_address);
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1));
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2));
}
TEST(AddressTest, SetStreetAddress) {
const base::string16 empty_street_address;
const base::string16 one_line_street_address =
ASCIIToUTF16("456 New St., Apt. 17");
const base::string16 multi_line_street_address =
ASCIIToUTF16("789 Fancy Pkwy.\n"
"Unit 3.14");
const AutofillType type = AutofillType(ADDRESS_HOME_STREET_ADDRESS);
Address address;
address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave."));
address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42"));
EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
EXPECT_FALSE(address.SetInfo(type, one_line_street_address, "en-US"));
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1));
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2));
EXPECT_TRUE(address.SetInfo(type, multi_line_street_address, "en-US"));
EXPECT_EQ(ASCIIToUTF16("789 Fancy Pkwy."),
address.GetRawInfo(ADDRESS_HOME_LINE1));
EXPECT_EQ(ASCIIToUTF16("Unit 3.14"), address.GetRawInfo(ADDRESS_HOME_LINE2));
EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
EXPECT_TRUE(address.SetInfo(type, empty_street_address, "en-US"));
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1));
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2));
}
TEST(AddressTest, SetStreetAddressRejectsAddressesWithInteriorBlankLines) {
Address address;
address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave."));
address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42"));
EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS).empty());
EXPECT_FALSE(address.SetInfo(AutofillType(ADDRESS_HOME_STREET_ADDRESS),
ASCIIToUTF16("Address line 1\n"
"\n"
"Address line 3"),
"en-US"));
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1));
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2));
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS));
}
TEST(AddressTest, SetStreetAddressRejectsAddressesWithLeadingBlankLines) {
Address address;
address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave."));
address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42"));
EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS).empty());
EXPECT_FALSE(address.SetInfo(AutofillType(ADDRESS_HOME_STREET_ADDRESS),
ASCIIToUTF16("\n"
"Address line 2"
"Address line 3"),
"en-US"));
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1));
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2));
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS));
}
TEST(AddressTest, SetStreetAddressRejectsAddressesWithTrailingBlankLines) {
Address address;
address.SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("123 Example Ave."));
address.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("Apt. 42"));
EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE1).empty());
EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_LINE2).empty());
EXPECT_FALSE(address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS).empty());
EXPECT_FALSE(address.SetInfo(AutofillType(ADDRESS_HOME_STREET_ADDRESS),
ASCIIToUTF16("Address line 1"
"Address line 2"
"\n"),
"en-US"));
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE1));
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_LINE2));
EXPECT_EQ(base::string16(), address.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS));
}
}