Commit 11cd1e9d authored by sandromaggi's avatar sandromaggi Committed by Commit Bot

[Autofill Assistant] Use state as fallback for state name

If the state name cannot be resolved from the hardcoded list,
use the state value itself. This guarantees a value in state
name (if there is a value in state).

For addresses created from Desktop, the state field can be
free text, it is not guaranteed to map to a known state. The
same goes for countries outside of the US, where the state
name cannot be resolved in the first place.

This also changes the expectation in the unit test, to not block
the addition of new fields. Note that we still assert the minimum
set of expected fields, essentially blocking the removal of
previously available information.

Bug: b/169562881
Bug: b/167491545
Change-Id: I1b392e7a7e8a21981d751d6b9ae982de4adfff3b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2438352
Commit-Queue: Sandro Maggi <sandromaggi@google.com>
Reviewed-by: default avatarClemens Arbesser <arbesser@google.com>
Cr-Commit-Position: refs/heads/master@{#812094}
parent d8809db3
...@@ -95,7 +95,11 @@ CreateAutofillMappings<autofill::AutofillProfile>( ...@@ -95,7 +95,11 @@ CreateAutofillMappings<autofill::AutofillProfile>(
// TODO(b/159309560): Capitalize first letter of the state name. // TODO(b/159309560): Capitalize first letter of the state name.
auto state_name = auto state_name =
base::UTF16ToUTF8(autofill::state_names::GetNameForAbbreviation(state)); base::UTF16ToUTF8(autofill::state_names::GetNameForAbbreviation(state));
if (!state_name.empty()) { if (state_name.empty()) {
mappings[base::NumberToString(
static_cast<int>(AutofillFormatProto::ADDRESS_HOME_STATE_NAME))] =
base::UTF16ToUTF8(state);
} else {
mappings[base::NumberToString(static_cast<int>( mappings[base::NumberToString(static_cast<int>(
AutofillFormatProto::ADDRESS_HOME_STATE_NAME))] = state_name; AutofillFormatProto::ADDRESS_HOME_STATE_NAME))] = state_name;
} }
......
...@@ -19,7 +19,7 @@ const char kFakeUrl[] = "https://www.example.com"; ...@@ -19,7 +19,7 @@ const char kFakeUrl[] = "https://www.example.com";
using ::testing::_; using ::testing::_;
using ::testing::Eq; using ::testing::Eq;
using ::testing::UnorderedElementsAreArray; using ::testing::IsSupersetOf;
TEST(FieldFormatterTest, FormatString) { TEST(FieldFormatterTest, FormatString) {
std::map<std::string, std::string> mappings = { std::map<std::string, std::string> mappings = {
...@@ -72,7 +72,7 @@ TEST(FieldFormatterTest, AutofillProfile) { ...@@ -72,7 +72,7 @@ TEST(FieldFormatterTest, AutofillProfile) {
"XY"); "XY");
EXPECT_EQ(FormatString("${-6}", CreateAutofillMappings(unknown_state_profile, EXPECT_EQ(FormatString("${-6}", CreateAutofillMappings(unknown_state_profile,
"en-US")), "en-US")),
base::nullopt); "XY");
// UNKNOWN_TYPE // UNKNOWN_TYPE
EXPECT_EQ(FormatString("${1}", CreateAutofillMappings(profile, "en-US")), EXPECT_EQ(FormatString("${1}", CreateAutofillMappings(profile, "en-US")),
...@@ -156,6 +156,7 @@ TEST(FieldFormatterTest, DifferentLocales) { ...@@ -156,6 +156,7 @@ TEST(FieldFormatterTest, DifferentLocales) {
TEST(FieldFormatterTest, AddsAllProfileFields) { TEST(FieldFormatterTest, AddsAllProfileFields) {
std::map<std::string, std::string> expected_values = { std::map<std::string, std::string> expected_values = {
{"-6", "Canton Zurich"},
{"3", "Alpha"}, {"3", "Alpha"},
{"4", "Beta"}, {"4", "Beta"},
{"5", "Gamma"}, {"5", "Gamma"},
...@@ -183,7 +184,7 @@ TEST(FieldFormatterTest, AddsAllProfileFields) { ...@@ -183,7 +184,7 @@ TEST(FieldFormatterTest, AddsAllProfileFields) {
"Canton Zurich", "8002", "CH", "+41791234567"); "Canton Zurich", "8002", "CH", "+41791234567");
EXPECT_THAT(CreateAutofillMappings(profile, "en-US"), EXPECT_THAT(CreateAutofillMappings(profile, "en-US"),
UnorderedElementsAreArray(expected_values)); IsSupersetOf(expected_values));
} }
TEST(FieldFormatterTest, AddsAllCreditCardFields) { TEST(FieldFormatterTest, AddsAllCreditCardFields) {
...@@ -207,7 +208,7 @@ TEST(FieldFormatterTest, AddsAllCreditCardFields) { ...@@ -207,7 +208,7 @@ TEST(FieldFormatterTest, AddsAllCreditCardFields) {
"4111111111111111", "8", "2050", ""); "4111111111111111", "8", "2050", "");
EXPECT_THAT(CreateAutofillMappings(credit_card, "en-US"), EXPECT_THAT(CreateAutofillMappings(credit_card, "en-US"),
UnorderedElementsAreArray(expected_values)); IsSupersetOf(expected_values));
} }
} // namespace } // namespace
......
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