Commit 3b8760a3 authored by Caitlin Fischer's avatar Caitlin Fischer Committed by Commit Bot

[Autofill] Changed label format for focused non-street-address fields.

This change applies to address plus phone and address plus email
LabelFormatters.

If a user is focused on a non-street-address field, e.g. city, the
label will display the street address, a separator, and the contact
info, which is either phone or email.

Address plus phone:
https://screenshot.googleplex.com/DEt8qpwi6ZJ

Address plus email:
https://screenshot.googleplex.com/YJhuVTiPySD

Bug: 936168
Change-Id: I67848ec2a963bc5d07fcdc626d8477d25be2dfb4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1562373
Commit-Queue: Caitlin Fischer <caitlinfischer@google.com>
Reviewed-by: default avatarFabio Tirelo <ftirelo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649850}
parent b2fa6047
......@@ -17,12 +17,26 @@ AddressEmailFormLabelFormatter::AddressEmailFormLabelFormatter(
AddressEmailFormLabelFormatter::~AddressEmailFormLabelFormatter() {}
// Note that the order--name, address, and email--in which parts of the label
// are added ensures that the label is formatted correctly for |focused_group|
// and for this kind of formatter.
base::string16 AddressEmailFormLabelFormatter::GetLabelForProfile(
const AutofillProfile& profile,
FieldTypeGroup focused_group) const {
return focused_group == ADDRESS_HOME &&
!IsStreetAddressPart(focused_field_type())
? GetLabelForProfileOnFocusedNonStreetAddress(
form_has_street_address_, profile, app_locale(),
field_types_for_labels(),
GetLabelEmail(profile, app_locale()))
: GetLabelForProfileOnFocusedNameEmailOrStreetAddress(
profile, focused_group);
}
// Note that the order--name, address, and email--in which parts of the label
// are added ensures that the label is formatted correctly for |focused_group|,
// |focused_field_type_| and for this kind of formatter.
base::string16 AddressEmailFormLabelFormatter::
GetLabelForProfileOnFocusedNameEmailOrStreetAddress(
const AutofillProfile& profile,
FieldTypeGroup focused_group) const {
std::vector<base::string16> label_parts;
if (focused_group != NAME) {
......
......@@ -31,6 +31,14 @@ class AddressEmailFormLabelFormatter : public LabelFormatter {
FieldTypeGroup focused_group) const override;
private:
// Returns a label to show the user when |focused_field_type_| is a type
// other than a non-street-address field type. For example,
// |focused_field_type_| could be last name, home street address, or email
// address.
base::string16 GetLabelForProfileOnFocusedNameEmailOrStreetAddress(
const AutofillProfile& profile,
FieldTypeGroup focused_group) const;
// True if this formatter's associated form has a street address field. A
// form may have an address-related field, e.g. zip code, without having a
// street address field. If a form does not include a street address field,
......@@ -40,4 +48,4 @@ class AddressEmailFormLabelFormatter : public LabelFormatter {
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_EMAIL_FORM_LABEL_FORMATTER_H_
\ No newline at end of file
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_EMAIL_FORM_LABEL_FORMATTER_H_
......@@ -30,6 +30,7 @@ std::vector<ServerFieldType> GetFieldTypes() {
ADDRESS_BILLING_LINE2,
ADDRESS_BILLING_CITY,
ADDRESS_BILLING_STATE,
ADDRESS_BILLING_DEPENDENT_LOCALITY,
ADDRESS_BILLING_ZIP,
ADDRESS_BILLING_COUNTRY};
}
......@@ -75,7 +76,7 @@ TEST(AddressEmailFormLabelFormatterTest, GetLabelsForUSProfilesAndFocusedName) {
}
TEST(AddressEmailFormLabelFormatterTest,
GetLabelsForUSProfilesAndFocusedAddress) {
GetLabelsForUSProfilesAndFocusedStreetAddress) {
AutofillProfile profile1 =
AutofillProfile(base::GenerateGUID(), test::kEmptyOrigin);
test::SetProfileInfo(&profile1, "John", "F", "Kennedy", "jfk@gmail.com", "",
......@@ -109,6 +110,41 @@ TEST(AddressEmailFormLabelFormatterTest,
base::ASCIIToUTF16("paul1775@gmail.com"), base::string16()));
}
TEST(AddressEmailFormLabelFormatterTest,
GetLabelsForUSProfilesAndFocusedNonStreetAddress) {
AutofillProfile profile1 =
AutofillProfile(base::GenerateGUID(), test::kEmptyOrigin);
test::SetProfileInfo(&profile1, "John", "F", "Kennedy", "jfk@gmail.com", "",
"333 Washington St", "", "Brookline", "MA", "02445",
"US", "16177302000");
AutofillProfile profile2 =
AutofillProfile(base::GenerateGUID(), test::kEmptyOrigin);
test::SetProfileInfo(&profile2, "Jackie", "", "Kennedy", "", "",
"151 Irving Ave", "", "Hyannis", "MA", "02601", "US",
"");
AutofillProfile profile3 =
AutofillProfile(base::GenerateGUID(), test::kEmptyOrigin);
test::SetProfileInfo(&profile3, "", "", "", "paul1775@gmail.com", "", "", "",
"", "", "", "US", "");
AutofillProfile profile4 =
AutofillProfile(base::GenerateGUID(), test::kEmptyOrigin);
test::SetProfileInfo(&profile4, "", "", "", "", "", "", "", "Quincy", "MA",
"02169", "US", "");
const std::unique_ptr<LabelFormatter> formatter =
LabelFormatter::Create("en-US", ADDRESS_BILLING_ZIP, GetFieldTypes());
EXPECT_THAT(
formatter->GetLabels(std::vector<AutofillProfile*>{&profile1, &profile2,
&profile3, &profile4}),
ElementsAre(FormatExpectedLabel("333 Washington St", "jfk@gmail.com"),
base::ASCIIToUTF16("151 Irving Ave"),
base::ASCIIToUTF16("paul1775@gmail.com"), base::string16()));
}
TEST(AddressEmailFormLabelFormatterTest,
GetLabelsForUSProfilesAndFocusedEmail) {
AutofillProfile profile1 =
......@@ -170,7 +206,7 @@ TEST(AddressEmailFormLabelFormatterTest, GetLabelsForBRProfilesAndFocusedName) {
}
TEST(AddressEmailFormLabelFormatterTest,
GetLabelsForBRProfilesAndFocusedAddress) {
GetLabelsForBRProfilesAndFocusedStreetAddress) {
AutofillProfile profile1 =
AutofillProfile(base::GenerateGUID(), test::kEmptyOrigin);
test::SetProfileInfo(&profile1, "Tarsila", "do", "Amaral", "tarsila@aol.com",
......@@ -194,6 +230,33 @@ TEST(AddressEmailFormLabelFormatterTest,
FormatExpectedLabel("Artur Avila", "aavila@uol.com.br")));
}
TEST(AddressEmailFormLabelFormatterTest,
GetLabelsForBRProfilesAndFocusedNonStreetAddress) {
AutofillProfile profile1 =
AutofillProfile(base::GenerateGUID(), test::kEmptyOrigin);
test::SetProfileInfo(&profile1, "Tarsila", "do", "Amaral", "tarsila@aol.com",
"", "Av. Pedro Álvares Cabral, 1301", "", "Vila Mariana",
"São Paulo", "SP", "04094-050", "BR",
"+55 11 2648-0254");
AutofillProfile profile2 =
AutofillProfile(base::GenerateGUID(), test::kEmptyOrigin);
test::SetProfileInfo(&profile2, "Artur", "", "Avila", "aavila@uol.com.br", "",
"Estr. Dona Castorina, 110", "", "Jardim Botânico",
"Rio de Janeiro", "RJ", "22460-320", "BR",
"21987650000");
const std::unique_ptr<LabelFormatter> formatter = LabelFormatter::Create(
"pt-BR", ADDRESS_BILLING_DEPENDENT_LOCALITY, GetFieldTypes());
EXPECT_THAT(
formatter->GetLabels(std::vector<AutofillProfile*>{&profile1, &profile2}),
ElementsAre(FormatExpectedLabel("Av. Pedro Álvares Cabral, 1301",
"tarsila@aol.com"),
FormatExpectedLabel("Estr. Dona Castorina, 110",
"aavila@uol.com.br")));
}
TEST(AddressEmailFormLabelFormatterTest,
GetLabelsForBRProfilesAndFocusedEmail) {
AutofillProfile profile1 =
......
......@@ -17,12 +17,26 @@ AddressPhoneFormLabelFormatter::AddressPhoneFormLabelFormatter(
AddressPhoneFormLabelFormatter::~AddressPhoneFormLabelFormatter() {}
// Note that the order--name, phone, and address--in which parts of the label
// are added ensures that the label is formatted correctly for |focused_group|
// and for this kind of formatter.
base::string16 AddressPhoneFormLabelFormatter::GetLabelForProfile(
const AutofillProfile& profile,
FieldTypeGroup focused_group) const {
return focused_group == ADDRESS_HOME &&
!IsStreetAddressPart(focused_field_type())
? GetLabelForProfileOnFocusedNonStreetAddress(
form_has_street_address_, profile, app_locale(),
field_types_for_labels(),
GetLabelPhone(profile, app_locale()))
: GetLabelForProfileOnFocusedNamePhoneOrStreetAddress(
profile, focused_group);
}
// Note that the order--name, phone, and address--in which parts of the label
// are added ensures that the label is formatted correctly for |focused_group|,
// |focused_field_type_| and for this kind of formatter.
base::string16 AddressPhoneFormLabelFormatter::
GetLabelForProfileOnFocusedNamePhoneOrStreetAddress(
const AutofillProfile& profile,
FieldTypeGroup focused_group) const {
std::vector<base::string16> label_parts;
if (focused_group != NAME) {
AddLabelPartIfNotEmpty(GetLabelName(profile, app_locale()), &label_parts);
......
......@@ -31,6 +31,13 @@ class AddressPhoneFormLabelFormatter : public LabelFormatter {
FieldTypeGroup focused_group) const override;
private:
// Returns a label to show the user when |focused_field_type_| is a type
// other than a non-street-address field type. For example,
// |focused_field_type_| could be first name, address line 1, or phone number.
base::string16 GetLabelForProfileOnFocusedNamePhoneOrStreetAddress(
const AutofillProfile& profile,
FieldTypeGroup focused_group) const;
// True if this formatter's associated form has a street address field. A
// form may have an address-related field, e.g. zip code, without having a
// street address field. If a form does not include a street address field,
......
......@@ -70,7 +70,7 @@ TEST(AddressPhoneFormLabelFormatterTest, GetLabelsForUSProfilesAndFocusedName) {
}
TEST(AddressPhoneFormLabelFormatterTest,
GetLabelsForUSProfilesAndFocusedAddress) {
GetLabelsForUSProfilesAndFocusedStreetAddress) {
AutofillProfile profile1 =
AutofillProfile(base::GenerateGUID(), test::kEmptyOrigin);
test::SetProfileInfo(&profile1, "John", "F", "Kennedy", "jfk@gmail.com", "",
......@@ -104,6 +104,41 @@ TEST(AddressPhoneFormLabelFormatterTest,
base::ASCIIToUTF16("(617) 523-2338"), base::string16()));
}
TEST(AddressPhoneFormLabelFormatterTest,
GetLabelsForUSProfilesAndFocusedNonStreetAddress) {
AutofillProfile profile1 =
AutofillProfile(base::GenerateGUID(), test::kEmptyOrigin);
test::SetProfileInfo(&profile1, "John", "F", "Kennedy", "jfk@gmail.com", "",
"333 Washington St", "", "Brookline", "MA", "02445",
"US", "16177302000");
AutofillProfile profile2 =
AutofillProfile(base::GenerateGUID(), test::kEmptyOrigin);
test::SetProfileInfo(&profile2, "Jackie", "", "Kennedy", "", "",
"151 Irving Ave", "", "Hyannis", "MA", "02601", "US",
"");
AutofillProfile profile3 =
AutofillProfile(base::GenerateGUID(), test::kEmptyOrigin);
test::SetProfileInfo(&profile3, "", "", "", "", "", "", "", "", "", "", "US",
"6175232338");
AutofillProfile profile4 =
AutofillProfile(base::GenerateGUID(), test::kEmptyOrigin);
test::SetProfileInfo(&profile4, "", "", "", "", "", "", "", "Quincy", "MA",
"02169", "US", "");
const std::unique_ptr<LabelFormatter> formatter =
LabelFormatter::Create("en-US", ADDRESS_HOME_CITY, GetFieldTypes());
EXPECT_THAT(
formatter->GetLabels(std::vector<AutofillProfile*>{&profile1, &profile2,
&profile3, &profile4}),
ElementsAre(FormatExpectedLabel("333 Washington St", "(617) 730-2000"),
base::ASCIIToUTF16("151 Irving Ave"),
base::ASCIIToUTF16("(617) 523-2338"), base::string16()));
}
TEST(AddressPhoneFormLabelFormatterTest,
GetLabelsForUSProfilesAndFocusedPhone) {
AutofillProfile profile1 =
......@@ -167,7 +202,7 @@ TEST(AddressPhoneFormLabelFormatterTest, GetLabelsForBRProfilesAndFocusedName) {
}
TEST(AddressPhoneFormLabelFormatterTest,
GetLabelsForBRProfilesAndFocusedAddress) {
GetLabelsForBRProfilesAndFocusedStreetAddress) {
AutofillProfile profile1 =
AutofillProfile(base::GenerateGUID(), test::kEmptyOrigin);
test::SetProfileInfo(&profile1, "Tarsila", "do", "Amaral", "tarsila@aol.com",
......@@ -191,6 +226,33 @@ TEST(AddressPhoneFormLabelFormatterTest,
FormatExpectedLabel("Artur Avila", "(21) 98765-0000")));
}
TEST(AddressPhoneFormLabelFormatterTest,
GetLabelsForBRProfilesAndFocusedNonStreetAddress) {
AutofillProfile profile1 =
AutofillProfile(base::GenerateGUID(), test::kEmptyOrigin);
test::SetProfileInfo(&profile1, "Tarsila", "do", "Amaral", "tarsila@aol.com",
"", "Av. Pedro Álvares Cabral, 1301", "", "Vila Mariana",
"São Paulo", "SP", "04094-050", "BR",
"+55 11 2648-0254");
AutofillProfile profile2 =
AutofillProfile(base::GenerateGUID(), test::kEmptyOrigin);
test::SetProfileInfo(&profile2, "Artur", "", "Avila", "aavila@uol.com.br", "",
"Estr. Dona Castorina, 110", "", "Jardim Botânico",
"Rio de Janeiro", "RJ", "22460-320", "BR",
"21987650000");
const std::unique_ptr<LabelFormatter> formatter =
LabelFormatter::Create("pt-BR", ADDRESS_HOME_ZIP, GetFieldTypes());
EXPECT_THAT(
formatter->GetLabels(std::vector<AutofillProfile*>{&profile1, &profile2}),
ElementsAre(
FormatExpectedLabel("Av. Pedro Álvares Cabral, 1301",
"(11) 2648-0254"),
FormatExpectedLabel("Estr. Dona Castorina, 110", "(21) 98765-0000")));
}
TEST(AddressPhoneFormLabelFormatterTest,
GetLabelsForBRProfilesAndFocusedPhone) {
AutofillProfile profile1 =
......
......@@ -215,6 +215,20 @@ base::string16 GetLabelStreetAddress(
return base::UTF8ToUTF16(address_line);
}
base::string16 GetLabelForProfileOnFocusedNonStreetAddress(
bool form_has_street_address,
const AutofillProfile& profile,
const std::string& app_locale,
const std::vector<ServerFieldType>& types,
const base::string16& contact_info) {
std::vector<base::string16> label_parts;
AddLabelPartIfNotEmpty(
GetLabelAddress(form_has_street_address, profile, app_locale, types),
&label_parts);
AddLabelPartIfNotEmpty(contact_info, &label_parts);
return ConstructLabelLine(label_parts);
}
base::string16 GetLabelEmail(const AutofillProfile& profile,
const std::string& app_locale) {
const base::string16 email =
......
......@@ -151,6 +151,16 @@ base::string16 GetLabelStreetAddress(const AutofillProfile& profile,
const std::string& app_locale,
const std::vector<ServerFieldType>& types);
// Returns a label to show the user when |focused_field_type_| is not part of
// a street address. For example, city and postal code are non-street-address
// field types.
base::string16 GetLabelForProfileOnFocusedNonStreetAddress(
bool form_has_street_address,
const AutofillProfile& profile,
const std::string& app_locale,
const std::vector<ServerFieldType>& types,
const base::string16& contact_info);
// Returns the email address associated with |profile|, if any; otherwise,
// returns an empty string.
base::string16 GetLabelEmail(const AutofillProfile& profile,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment