Commit ab237381 authored by Mathias Carlen's avatar Mathias Carlen Committed by Commit Bot

[Autofill Assistant] Locale cleanup.

Before this patch we used the device/platform locale to set/get things
in autofill profiles. That locale is dropped in the autofill code and
not used at all. This patch removes the locale logic from two actions.

The consequence now is that the mock in tests does not set the full name
and that is used in the completeness comparison. The fix used here is to
always construct the FullName from the first,middle,last triplet when
needed.

R=arbesser@google.com, marianfe@google.com

Bug: 806868
Change-Id: I0835da87a07c409af8832cd052f6654372b8dcf0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1926487
Commit-Queue: Mathias Carlen <mcarlen@chromium.org>
Reviewed-by: default avatarClemens Arbesser <arbesser@google.com>
Cr-Commit-Position: refs/heads/master@{#717615}
parent f20477a9
......@@ -34,8 +34,7 @@ class CollectUserDataAction : public Action,
static bool IsUserDataComplete(
const UserData& user_data,
const CollectUserDataOptions& collect_user_data_options,
const std::string& locale);
const CollectUserDataOptions& collect_user_data_options);
private:
struct LoginDetails {
......
......@@ -513,50 +513,40 @@ TEST_F(CollectUserDataActionTest, ContactDetailsCanHandleUtf8) {
TEST_F(CollectUserDataActionTest, UserDataComplete_Contact) {
UserData user_data;
CollectUserDataOptions options;
std::string locale = "en-US";
EXPECT_TRUE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_TRUE(CollectUserDataAction::IsUserDataComplete(user_data, options));
user_data.contact_profile = std::make_unique<autofill::AutofillProfile>(
base::GenerateGUID(), kFakeUrl);
options.request_payer_email = true;
EXPECT_FALSE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_FALSE(CollectUserDataAction::IsUserDataComplete(user_data, options));
user_data.contact_profile->SetRawInfo(
autofill::ServerFieldType::EMAIL_ADDRESS,
base::UTF8ToUTF16("joedoe@example.com"));
EXPECT_TRUE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_TRUE(CollectUserDataAction::IsUserDataComplete(user_data, options));
options.request_payer_name = true;
EXPECT_FALSE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_FALSE(CollectUserDataAction::IsUserDataComplete(user_data, options));
user_data.contact_profile->SetRawInfo(autofill::ServerFieldType::NAME_FULL,
base::UTF8ToUTF16("Joe Doe"));
EXPECT_TRUE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_TRUE(CollectUserDataAction::IsUserDataComplete(user_data, options));
options.request_payer_phone = true;
EXPECT_FALSE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_FALSE(CollectUserDataAction::IsUserDataComplete(user_data, options));
user_data.contact_profile->SetRawInfo(
autofill::ServerFieldType::PHONE_HOME_WHOLE_NUMBER,
base::UTF8ToUTF16("+1 23 456 789 01"));
EXPECT_TRUE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_TRUE(CollectUserDataAction::IsUserDataComplete(user_data, options));
}
TEST_F(CollectUserDataActionTest, UserDataComplete_Payment) {
UserData user_data;
CollectUserDataOptions options;
std::string locale = "en-US";
options.request_payment_method = true;
EXPECT_FALSE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_FALSE(CollectUserDataAction::IsUserDataComplete(user_data, options));
// Valid credit card, but no billing address.
user_data.card =
......@@ -564,8 +554,7 @@ TEST_F(CollectUserDataActionTest, UserDataComplete_Payment) {
autofill::test::SetCreditCardInfo(user_data.card.get(), "Marion Mitchell",
"4111 1111 1111 1111", "01", "2020",
/* billing_address_id = */ "");
EXPECT_FALSE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_FALSE(CollectUserDataAction::IsUserDataComplete(user_data, options));
// Incomplete billing address.
user_data.billing_address = std::make_unique<autofill::AutofillProfile>(
......@@ -575,71 +564,57 @@ TEST_F(CollectUserDataActionTest, UserDataComplete_Payment) {
"123 Zoo St.", "unit 5", "Hollywood", "CA",
/* zipcode = */ "", "US", "16505678910");
user_data.card->set_billing_address_id(user_data.billing_address->guid());
EXPECT_FALSE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_FALSE(CollectUserDataAction::IsUserDataComplete(user_data, options));
user_data.billing_address->SetRawInfo(autofill::ADDRESS_HOME_ZIP,
base::UTF8ToUTF16("91601"));
EXPECT_TRUE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_TRUE(CollectUserDataAction::IsUserDataComplete(user_data, options));
// Zip code is optional in Argentinian address.
user_data.billing_address->SetRawInfo(autofill::ADDRESS_HOME_ZIP,
base::UTF8ToUTF16(""));
user_data.billing_address->SetRawInfo(autofill::ADDRESS_HOME_COUNTRY,
base::UTF8ToUTF16("AR"));
EXPECT_TRUE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_TRUE(CollectUserDataAction::IsUserDataComplete(user_data, options));
options.require_billing_postal_code = true;
EXPECT_FALSE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_FALSE(CollectUserDataAction::IsUserDataComplete(user_data, options));
user_data.billing_address->SetRawInfo(autofill::ADDRESS_HOME_ZIP,
base::UTF8ToUTF16("B1675"));
EXPECT_TRUE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_TRUE(CollectUserDataAction::IsUserDataComplete(user_data, options));
}
TEST_F(CollectUserDataActionTest, UserDataComplete_Terms) {
UserData user_data;
CollectUserDataOptions options;
std::string locale = "en-US";
options.accept_terms_and_conditions_text.assign("Accept T&C");
EXPECT_FALSE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_FALSE(CollectUserDataAction::IsUserDataComplete(user_data, options));
user_data.terms_and_conditions = REQUIRES_REVIEW;
EXPECT_TRUE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_TRUE(CollectUserDataAction::IsUserDataComplete(user_data, options));
user_data.terms_and_conditions = ACCEPTED;
EXPECT_TRUE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_TRUE(CollectUserDataAction::IsUserDataComplete(user_data, options));
}
TEST_F(CollectUserDataActionTest, UserDataComplete_Login) {
UserData user_data;
CollectUserDataOptions options;
std::string locale = "en-US";
options.request_login_choice = true;
EXPECT_FALSE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_FALSE(CollectUserDataAction::IsUserDataComplete(user_data, options));
user_data.login_choice_identifier.assign("1");
EXPECT_TRUE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_TRUE(CollectUserDataAction::IsUserDataComplete(user_data, options));
}
TEST_F(CollectUserDataActionTest, UserDataComplete_ShippingAddress) {
UserData user_data;
CollectUserDataOptions options;
std::string locale = "en-US";
options.request_shipping = true;
EXPECT_FALSE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_FALSE(CollectUserDataAction::IsUserDataComplete(user_data, options));
// Incomplete address.
user_data.shipping_address = std::make_unique<autofill::AutofillProfile>(
......@@ -648,33 +623,27 @@ TEST_F(CollectUserDataActionTest, UserDataComplete_ShippingAddress) {
"Mitchell", "Morrison", "marion@me.xyz", "Fox",
"123 Zoo St.", "unit 5", "Hollywood", "CA",
/* zipcode = */ "", "US", "16505678910");
EXPECT_FALSE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_FALSE(CollectUserDataAction::IsUserDataComplete(user_data, options));
user_data.shipping_address->SetRawInfo(autofill::ADDRESS_HOME_ZIP,
base::UTF8ToUTF16("91601"));
EXPECT_TRUE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_TRUE(CollectUserDataAction::IsUserDataComplete(user_data, options));
}
TEST_F(CollectUserDataActionTest, UserDataComplete_DateTimeRange) {
UserData user_data;
CollectUserDataOptions options;
std::string locale = "en-US";
options.request_date_time_range = true;
EXPECT_FALSE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_FALSE(CollectUserDataAction::IsUserDataComplete(user_data, options));
SetDateTimeProto(&user_data.date_time_range_start, 2019, 12, 31, 10, 30, 0);
SetDateTimeProto(&user_data.date_time_range_end, 2019, 1, 28, 16, 0, 0);
// Start date not before end date.
EXPECT_FALSE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_FALSE(CollectUserDataAction::IsUserDataComplete(user_data, options));
user_data.date_time_range_end.mutable_date()->set_year(2020);
EXPECT_TRUE(
CollectUserDataAction::IsUserDataComplete(user_data, options, locale));
EXPECT_TRUE(CollectUserDataAction::IsUserDataComplete(user_data, options));
}
TEST_F(CollectUserDataActionTest, SelectDateTimeRange) {
......@@ -961,6 +930,15 @@ TEST_F(CollectUserDataActionTest, SortsCompleteProfilesAlphabetically) {
"adam.west@gmail.com", "", "", "", "", "", "",
"", "");
LOG(ERROR) << "ZZZ raw " << profile_a.GetRawInfo(autofill::NAME_FULL);
LOG(ERROR) << "ZZZ " << profile_a.GetInfo(autofill::NAME_FULL, "en-US");
LOG(ERROR) << "ZZZ raw " << profile_a.GetRawInfo(autofill::NAME_FIRST);
LOG(ERROR) << "ZZZ " << profile_a.GetInfo(autofill::NAME_FIRST, "en-US");
LOG(ERROR) << "ZZZ raw " << profile_a.GetRawInfo(autofill::NAME_LAST);
LOG(ERROR) << "ZZZ " << profile_a.GetInfo(autofill::NAME_LAST, "en-US");
autofill::AutofillProfile profile_b;
autofill::test::SetProfileInfo(&profile_b, "Berta", "", "West",
"berta.west@gmail.com", "", "", "", "", "", "",
......
......@@ -14,6 +14,7 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "components/autofill/core/browser/autofill_data_util.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill_assistant/browser/actions/action_delegate.h"
#include "components/autofill_assistant/browser/actions/required_fields_fallback_handler.h"
......@@ -125,55 +126,55 @@ void UseAddressAction::OnFormFilled(std::unique_ptr<FallbackData> fallback_data,
weak_ptr_factory_.GetWeakPtr()));
}
// This logic is from NameInfo::FullName.
base::string16 FullName(const autofill::AutofillProfile& profile) {
return autofill::data_util::JoinNameParts(
profile.GetRawInfo(autofill::NAME_FIRST),
profile.GetRawInfo(autofill::NAME_MIDDLE),
profile.GetRawInfo(autofill::NAME_LAST));
}
std::unique_ptr<FallbackData> UseAddressAction::CreateFallbackData(
const autofill::AutofillProfile& profile) {
// TODO(crbug.com/806868): Get the locale from the backend.
std::string app_locale = "en-US";
auto fallback_data = std::make_unique<FallbackData>();
fallback_data->field_values.emplace(
(int)UseAddressProto::RequiredField::FIRST_NAME,
base::UTF16ToUTF8(profile.GetInfo(autofill::NAME_FIRST, app_locale)));
base::UTF16ToUTF8(profile.GetRawInfo(autofill::NAME_FIRST)));
fallback_data->field_values.emplace(
(int)UseAddressProto::RequiredField::LAST_NAME,
base::UTF16ToUTF8(profile.GetInfo(autofill::NAME_LAST, app_locale)));
base::UTF16ToUTF8(profile.GetRawInfo(autofill::NAME_LAST)));
fallback_data->field_values.emplace(
(int)UseAddressProto::RequiredField::FULL_NAME,
base::UTF16ToUTF8(profile.GetInfo(autofill::NAME_FIRST, app_locale)));
base::UTF16ToUTF8(FullName(profile)));
fallback_data->field_values.emplace(
(int)UseAddressProto::RequiredField::PHONE_NUMBER,
base::UTF16ToUTF8(
profile.GetInfo(autofill::PHONE_HOME_WHOLE_NUMBER, app_locale)));
base::UTF16ToUTF8(profile.GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER)));
fallback_data->field_values.emplace(
(int)UseAddressProto::RequiredField::EMAIL,
base::UTF16ToUTF8(profile.GetInfo(autofill::EMAIL_ADDRESS, app_locale)));
base::UTF16ToUTF8(profile.GetRawInfo(autofill::EMAIL_ADDRESS)));
fallback_data->field_values.emplace(
(int)UseAddressProto::RequiredField::ORGANIZATION,
base::UTF16ToUTF8(profile.GetInfo(autofill::COMPANY_NAME, app_locale)));
base::UTF16ToUTF8(profile.GetRawInfo(autofill::COMPANY_NAME)));
fallback_data->field_values.emplace(
(int)UseAddressProto::RequiredField::COUNTRY_CODE,
base::UTF16ToUTF8(
profile.GetInfo(autofill::ADDRESS_HOME_COUNTRY, app_locale)));
base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)));
fallback_data->field_values.emplace(
(int)UseAddressProto::RequiredField::REGION,
base::UTF16ToUTF8(
profile.GetInfo(autofill::ADDRESS_HOME_STATE, app_locale)));
base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_STATE)));
fallback_data->field_values.emplace(
(int)UseAddressProto::RequiredField::STREET_ADDRESS,
base::UTF16ToUTF8(
profile.GetInfo(autofill::ADDRESS_HOME_STREET_ADDRESS, app_locale)));
profile.GetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS)));
fallback_data->field_values.emplace(
(int)UseAddressProto::RequiredField::LOCALITY,
base::UTF16ToUTF8(
profile.GetInfo(autofill::ADDRESS_HOME_CITY, app_locale)));
base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_CITY)));
fallback_data->field_values.emplace(
(int)UseAddressProto::RequiredField::DEPENDANT_LOCALITY,
base::UTF16ToUTF8(profile.GetInfo(
autofill::ADDRESS_HOME_DEPENDENT_LOCALITY, app_locale)));
base::UTF16ToUTF8(
profile.GetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY)));
fallback_data->field_values.emplace(
(int)UseAddressProto::RequiredField::POSTAL_CODE,
base::UTF16ToUTF8(
profile.GetInfo(autofill::ADDRESS_HOME_ZIP, app_locale)));
base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_ZIP)));
return fallback_data;
}
......
......@@ -1126,7 +1126,7 @@ void Controller::UpdateCollectUserDataActions() {
}
bool confirm_button_enabled = CollectUserDataAction::IsUserDataComplete(
*user_data_, *collect_user_data_options_, client_->GetLocale());
*user_data_, *collect_user_data_options_);
UserAction confirm(collect_user_data_options_->confirm_action);
confirm.SetEnabled(confirm_button_enabled);
......
......@@ -12,6 +12,7 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "components/autofill/core/browser/autofill_data_util.h"
#include "components/autofill/core/browser/geo/country_names.h"
#include "components/autofill_assistant/browser/trigger_context.h"
#include "components/strings/grit/components_strings.h"
......@@ -76,6 +77,14 @@ std::string FormatDateTimeProto(const DateTimeProto& date_time) {
return std::string();
}
// This logic is from NameInfo::FullName.
base::string16 FullName(const autofill::AutofillProfile& profile) {
return autofill::data_util::JoinNameParts(
profile.GetRawInfo(autofill::NAME_FIRST),
profile.GetRawInfo(autofill::NAME_MIDDLE),
profile.GetRawInfo(autofill::NAME_LAST));
}
} // namespace
Details::Details() = default;
......@@ -113,14 +122,11 @@ bool Details::UpdateFromContactDetails(const ShowDetailsProto& proto,
ShowDetailsProto updated_proto = proto;
auto* profile = client_memory->selected_address(contact_details);
auto* details_proto = updated_proto.mutable_details();
// TODO(crbug.com/806868): Get the actual script locale.
std::string app_locale = "en-US";
details_proto->set_title(
l10n_util::GetStringUTF8(IDS_PAYMENTS_CONTACT_DETAILS_LABEL));
details_proto->set_description_line_1(
base::UTF16ToUTF8(profile->GetInfo(autofill::NAME_FULL, app_locale)));
details_proto->set_description_line_1(base::UTF16ToUTF8(FullName(*profile)));
details_proto->set_description_line_2(
base::UTF16ToUTF8(profile->GetInfo(autofill::EMAIL_ADDRESS, app_locale)));
base::UTF16ToUTF8(profile->GetRawInfo(autofill::EMAIL_ADDRESS)));
details->SetDetailsProto(updated_proto.details());
details->SetDetailsChangesProto(updated_proto.change_flags());
return true;
......@@ -138,25 +144,20 @@ bool Details::UpdateFromShippingAddress(const ShowDetailsProto& proto,
ShowDetailsProto updated_proto = proto;
auto* profile = client_memory->selected_address(shipping_address);
auto* details_proto = updated_proto.mutable_details();
// TODO(crbug.com/806868): Get the actual script locale.
std::string app_locale = "en-US";
autofill::CountryNames* country_names = autofill::CountryNames::GetInstance();
details_proto->set_title(
l10n_util::GetStringUTF8(IDS_PAYMENTS_SHIPPING_ADDRESS_LABEL));
details_proto->set_description_line_1(
base::UTF16ToUTF8(profile->GetInfo(autofill::NAME_FULL, app_locale)));
details_proto->set_description_line_1(base::UTF16ToUTF8(FullName(*profile)));
details_proto->set_description_line_2(base::StrCat({
base::UTF16ToUTF8(
profile->GetInfo(autofill::ADDRESS_HOME_STREET_ADDRESS, app_locale)),
profile->GetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS)),
" ",
base::UTF16ToUTF8(
profile->GetInfo(autofill::ADDRESS_HOME_ZIP, app_locale)),
base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_ZIP)),
" ",
base::UTF16ToUTF8(
profile->GetInfo(autofill::ADDRESS_HOME_CITY, app_locale)),
base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_CITY)),
" ",
country_names->GetCountryCode(
profile->GetInfo(autofill::ADDRESS_HOME_COUNTRY, app_locale)),
profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)),
}));
details->SetDetailsProto(updated_proto.details());
details->SetDetailsChangesProto(updated_proto.change_flags());
......
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