Commit d626c433 authored by Matthias Körber's avatar Matthias Körber Committed by Commit Bot

[Autofill][Slimshady] Fixed merging of permutated names

This CL adds support to identify permuted name tokens as mergeable.

Change-Id: I048818625aaa95f1dabd163abf5a2efe6868cca1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2349349
Commit-Queue: Matthias Körber <koerber@google.com>
Reviewed-by: default avatarChristoph Schwering <schwering@google.com>
Cr-Commit-Position: refs/heads/master@{#797002}
parent 5c9d3e34
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "components/autofill/core/browser/address_rewriter.h" #include "components/autofill/core/browser/address_rewriter.h"
#include "components/autofill/core/browser/autofill_data_util.h" #include "components/autofill/core/browser/autofill_data_util.h"
#include "components/autofill/core/browser/autofill_metrics.h" #include "components/autofill/core/browser/autofill_metrics.h"
#include "components/autofill/core/browser/data_model/autofill_structured_address_utils.h"
#include "components/autofill/core/browser/geo/autofill_country.h" #include "components/autofill/core/browser/geo/autofill_country.h"
#include "components/autofill/core/browser/geo/state_names.h" #include "components/autofill/core/browser/geo/state_names.h"
#include "components/autofill/core/common/autofill_clock.h" #include "components/autofill/core/common/autofill_clock.h"
...@@ -333,8 +334,7 @@ bool AutofillProfileComparator::MergeNames(const AutofillProfile& p1, ...@@ -333,8 +334,7 @@ bool AutofillProfileComparator::MergeNames(const AutofillProfile& p1,
// structure should be possible. // structure should be possible.
// * One name is a variant of the other. In this scenario, use the non-variant // * One name is a variant of the other. In this scenario, use the non-variant
// name. Note, p1 is the newer profile. // name. Note, p1 is the newer profile.
if (base::FeatureList::IsEnabled( if (structured_address::StructuredNamesEnabled()) {
features::kAutofillEnableSupportForMoreStructureInNames)) {
// First, set info to the original profile. // First, set info to the original profile.
*name_info = p2.GetNameInfo(); *name_info = p2.GetNameInfo();
// If the name of the |p1| is empty, just keep the state of p2. // If the name of the |p1| is empty, just keep the state of p2.
...@@ -1007,6 +1007,12 @@ bool AutofillProfileComparator::HaveMergeableNames( ...@@ -1007,6 +1007,12 @@ bool AutofillProfileComparator::HaveMergeableNames(
return true; return true;
} }
// If the two names are just a permutation of each other, they are mergeable
// for structured names.
if (structured_address::StructuredNamesEnabled() &&
structured_address::AreStringTokenEquivalent(full_name_1, full_name_2))
return true;
base::string16 canon_full_name_1 = NormalizeForComparison(full_name_1); base::string16 canon_full_name_1 = NormalizeForComparison(full_name_1);
base::string16 canon_full_name_2 = NormalizeForComparison(full_name_2); base::string16 canon_full_name_2 = NormalizeForComparison(full_name_2);
......
...@@ -752,6 +752,57 @@ TEST_P(AutofillProfileComparatorTest, AreMergeable) { ...@@ -752,6 +752,57 @@ TEST_P(AutofillProfileComparatorTest, AreMergeable) {
EXPECT_FALSE(comparator_.AreMergeable(p, not_mergeable_by_phone_number)); EXPECT_FALSE(comparator_.AreMergeable(p, not_mergeable_by_phone_number));
} }
TEST_P(AutofillProfileComparatorTest, MergeStructuredNames_WithPermutation) {
// This test is only applicable to structured names.
if (!StructuredNames())
return;
// The first name has an observed structure.
NameInfo name1;
name1.SetRawInfoWithVerificationStatus(
NAME_FIRST, UTF8ToUTF16("Thomas"),
autofill::structured_address::VerificationStatus::kObserved);
name1.SetRawInfoWithVerificationStatus(
NAME_MIDDLE, UTF8ToUTF16("A."),
autofill::structured_address::VerificationStatus::kObserved);
name1.SetRawInfoWithVerificationStatus(
NAME_LAST, UTF8ToUTF16("Anderson"),
autofill::structured_address::VerificationStatus::kObserved);
AutofillProfile profile1 = CreateProfileWithName(name1);
profile1.FinalizeAfterImport();
EXPECT_EQ(profile1.GetRawInfo(NAME_FULL), UTF8ToUTF16("Thomas A. Anderson"));
EXPECT_EQ(profile1.GetVerificationStatus(NAME_FULL),
autofill::structured_address::VerificationStatus::kFormatted);
// The second name has an observed full name that uses a custom formatting.
NameInfo name2;
name2.SetRawInfoWithVerificationStatus(
NAME_FULL, UTF8ToUTF16("Anderson, Thomas A."),
autofill::structured_address::VerificationStatus::kObserved);
AutofillProfile profile2 = CreateProfileWithName(name2);
profile2.FinalizeAfterImport();
NameInfo merged_name;
comparator_.MergeNames(profile1, profile2, &merged_name);
// The merged name should maintain the structure but use the observation of
// the custom-formatted full name.
EXPECT_EQ(merged_name.GetRawInfo(NAME_FULL),
UTF8ToUTF16("Anderson, Thomas A."));
EXPECT_EQ(merged_name.GetVerificationStatus(NAME_FULL),
autofill::structured_address::VerificationStatus::kObserved);
EXPECT_EQ(merged_name.GetRawInfo(NAME_FIRST), UTF8ToUTF16("Thomas"));
EXPECT_EQ(merged_name.GetVerificationStatus(NAME_FIRST),
autofill::structured_address::VerificationStatus::kObserved);
EXPECT_EQ(merged_name.GetRawInfo(NAME_MIDDLE), UTF8ToUTF16("A."));
EXPECT_EQ(merged_name.GetVerificationStatus(NAME_MIDDLE),
autofill::structured_address::VerificationStatus::kObserved);
EXPECT_EQ(merged_name.GetRawInfo(NAME_LAST), UTF8ToUTF16("Anderson"));
EXPECT_EQ(merged_name.GetVerificationStatus(NAME_LAST),
autofill::structured_address::VerificationStatus::kObserved);
}
TEST_P(AutofillProfileComparatorTest, MergeNames) { TEST_P(AutofillProfileComparatorTest, MergeNames) {
NameInfo name1; NameInfo name1;
name1.SetRawInfo(NAME_FULL, UTF8ToUTF16("John Quincy Public")); name1.SetRawInfo(NAME_FULL, UTF8ToUTF16("John Quincy Public"));
......
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