Commit bfc60d54 authored by Elizabeth Popova's avatar Elizabeth Popova Committed by Chromium LUCI CQ

[Autofill] Give the label priority over the name for Turkish addresses

The feature is implemented behind
kAutofillEnableLabelPrecedenceForTurkishAddresses flag. It is intended
to fix city and state misclassifications in Turkish forms when label and
name match different types. See go/autofill-turkey-failure.

Bug: 1154727
Change-Id: I9606aadc6ec5f4817f15bf5630c4dd0a747bd5b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2577781Reviewed-by: default avatarChristoph Schwering <schwering@google.com>
Commit-Queue: Elizabeth Popova <lizapopova@google.com>
Cr-Commit-Position: refs/heads/master@{#835383}
parent 475dd7b6
......@@ -512,24 +512,26 @@ bool AddressField::ParseCityStateCountryZipCode(
if (maybe_state && maybe_country && !maybe_city && !maybe_zip)
return SetFieldAndAdvanceCursor(scanner, &country_);
// Otherwise give the name priority over the label.
if (city_result == RESULT_MATCH_NAME)
return SetFieldAndAdvanceCursor(scanner, &city_);
if (state_result == RESULT_MATCH_NAME)
return SetFieldAndAdvanceCursor(scanner, &state_);
if (country_result == RESULT_MATCH_NAME)
return SetFieldAndAdvanceCursor(scanner, &country_);
if (zip_result == RESULT_MATCH_NAME)
return ParseZipCode(scanner, page_language);
// By default give the name priority over the label.
ParseNameLabelResult resultsToMatch[] = {RESULT_MATCH_NAME,
RESULT_MATCH_LABEL};
if (page_language == LanguageCode("tr") &&
base::FeatureList::IsEnabled(
features::kAutofillEnableLabelPrecedenceForTurkishAddresses)) {
// Give the label priority over the name.
std::swap(resultsToMatch[0], resultsToMatch[1]);
}
if (city_result == RESULT_MATCH_LABEL)
for (auto result : resultsToMatch) {
if (city_result == result)
return SetFieldAndAdvanceCursor(scanner, &city_);
if (state_result == RESULT_MATCH_LABEL)
if (state_result == result)
return SetFieldAndAdvanceCursor(scanner, &state_);
if (country_result == RESULT_MATCH_LABEL)
if (country_result == result)
return SetFieldAndAdvanceCursor(scanner, &country_);
if (zip_result == RESULT_MATCH_LABEL)
if (zip_result == result)
return ParseZipCode(scanner, page_language);
}
return false;
}
......
......@@ -30,15 +30,21 @@ class AddressFieldTest : public testing::Test {
protected:
// Downcast for tests.
static std::unique_ptr<AddressField> Parse(AutofillScanner* scanner) {
// An empty page_language means the language is unknown and patterns of all
// languages are used.
static std::unique_ptr<AddressField> Parse(
AutofillScanner* scanner,
const LanguageCode& page_language) {
std::unique_ptr<FormField> field =
AddressField::Parse(scanner, LanguageCode(""), nullptr);
AddressField::Parse(scanner, page_language, nullptr);
return std::unique_ptr<AddressField>(
static_cast<AddressField*>(field.release()));
}
static std::unique_ptr<AddressField> Parse(AutofillScanner* scanner) {
// An empty page_language means the language is unknown and patterns of all
// languages are used.
return Parse(scanner, LanguageCode(""));
}
FieldRendererId MakeFieldRendererId() {
return FieldRendererId(++id_counter_);
}
......@@ -490,4 +496,41 @@ TEST_F(AddressFieldTest, ParseCountryNameRegion) {
field_candidates_map_[country1].BestHeuristicType());
}
// Tests that city and state fields are classified correctly when their names
// contain keywords for different types. This is achieved by giving the priority
// to the label over the name for pages in Turkish.
TEST_F(AddressFieldTest, ParseTurkishCityStateWithLabelPrecedence) {
// TODO(crbug.com/1156315): Remove once launched.
base::test::ScopedFeatureList enabled;
enabled.InitAndEnableFeature(
features::kAutofillEnableLabelPrecedenceForTurkishAddresses);
FormFieldData field;
field.form_control_type = "text";
field.label = ASCIIToUTF16("Il");
field.name = ASCIIToUTF16("city");
field.unique_renderer_id = MakeFieldRendererId();
list_.push_back(std::make_unique<AutofillField>(field));
FieldRendererId state = list_.back()->unique_renderer_id;
field.label = ASCIIToUTF16("Ilce");
field.name = ASCIIToUTF16("county");
field.unique_renderer_id = MakeFieldRendererId();
list_.push_back(std::make_unique<AutofillField>(field));
FieldRendererId city = list_.back()->unique_renderer_id;
AutofillScanner scanner(list_);
field_ = Parse(&scanner, LanguageCode("tr"));
ASSERT_NE(nullptr, field_.get());
field_->AddClassificationsForTesting(&field_candidates_map_);
ASSERT_TRUE(field_candidates_map_.find(state) != field_candidates_map_.end());
EXPECT_EQ(ADDRESS_HOME_STATE,
field_candidates_map_[state].BestHeuristicType());
ASSERT_TRUE(field_candidates_map_.find(city) != field_candidates_map_.end());
EXPECT_EQ(ADDRESS_HOME_CITY, field_candidates_map_[city].BestHeuristicType());
}
} // namespace autofill
......@@ -96,6 +96,14 @@ const base::Feature kAutofillEnableInfoBarAccountIndicationFooterForSyncUsers{
"AutofillEnableInfoBarAccountIndicationFooterForSyncUsers",
base::FEATURE_DISABLED_BY_DEFAULT};
// When enabled, the precedence is given to the field label over the name when
// they match different types. Applied only for parsing of address forms in
// Turkish.
// TODO(crbug.com/1156315): Remove once launched.
const base::Feature kAutofillEnableLabelPrecedenceForTurkishAddresses{
"AutofillEnableLabelPrecedenceForTurkishAddresses",
base::FEATURE_DISABLED_BY_DEFAULT};
// When enabled and user is signed in, a footer indicating user's e-mail address
// and profile picture will appear at the bottom of corresponding password
// InfoBars.
......
......@@ -37,6 +37,7 @@ extern const base::Feature
kAutofillEnableInfoBarAccountIndicationFooterForSyncUsers;
extern const base::Feature
kAutofillEnablePasswordInfoBarAccountIndicationFooter;
extern const base::Feature kAutofillEnableLabelPrecedenceForTurkishAddresses;
extern const base::Feature kAutofillEnableSupportForMoreStructureInNames;
extern const base::Feature kAutofillEnableSupportForMoreStructureInAddresses;
extern const base::Feature kAutofillEnableSupportForMergingSubsetNames;
......
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