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

[Autofill][Leipzig] Migration logic for structured addresses.

This CL adds migration logic for structured addresses.
In the migration process, all tokens that are present in unstructured
addresses are either set to being observed or verified depending on the
verification status of the overall AutofillProfile.

Change-Id: I4fdb9eb528a6a474448fc682ffde2571d2639b5e
Bug: 1099202
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2440663
Commit-Queue: Matthias Körber <koerber@google.com>
Reviewed-by: default avatarChristoph Schwering <schwering@google.com>
Cr-Commit-Position: refs/heads/master@{#812645}
parent b2bce896
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "components/autofill/core/browser/data_model/autofill_structured_address.h" #include "components/autofill/core/browser/data_model/autofill_structured_address.h"
#include <iostream>
#include <utility> #include <utility>
#include "base/i18n/case_conversion.h" #include "base/i18n/case_conversion.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
...@@ -364,12 +365,24 @@ Address::Address(AddressComponent* parent) ...@@ -364,12 +365,24 @@ Address::Address(AddressComponent* parent)
Address::~Address() = default; Address::~Address() = default;
void Address::MigrateLegacyStructure(bool is_verified_profile) { void Address::MigrateLegacyStructure(bool is_verified_profile) {
VerificationStatus status = is_verified_profile // If this component already has a verification status, no profile is regarded
// as already verified.
std::cout << "APply migration" << std::endl;
if (GetVerificationStatus() != VerificationStatus::kNoStatus)
return;
// Otherwise set the status of the subcomponents either to observed or
// verified depending on |is_verified_profile| if they already have a value
// assigned. Note, those are all the tokens that are already present in the
// unstructured address representation.
for (auto* component : Subcomponents()) {
if (!component->GetValue().empty() &&
component->GetVerificationStatus() == VerificationStatus::kNoStatus) {
component->SetValue(component->GetValue(),
is_verified_profile
? VerificationStatus::kUserVerified ? VerificationStatus::kUserVerified
: VerificationStatus::kObserved; : VerificationStatus::kObserved);
if (GetVerificationStatus() == VerificationStatus::kNoStatus && }
!GetValue().empty()) {
SetValue(GetValue(), status);
} }
} }
......
...@@ -343,6 +343,145 @@ TEST(AutofillStructuredAddress, TestGettingAddressLines_JoinedAdditionalLines) { ...@@ -343,6 +343,145 @@ TEST(AutofillStructuredAddress, TestGettingAddressLines_JoinedAdditionalLines) {
VerifyTestValues(&address, expectation); VerifyTestValues(&address, expectation);
} }
// Tests that a structured address gets successfully migrated and subsequently
// completed.
TEST(AutofillStructuredAddress, TestMigrationAndFinalization) {
Address address;
AddressComponentTestValues test_values = {
{.type = ADDRESS_HOME_STREET_ADDRESS,
.value = "123 Street name",
.status = VerificationStatus::kNoStatus},
{.type = ADDRESS_HOME_COUNTRY,
.value = "US",
.status = VerificationStatus::kNoStatus},
{.type = ADDRESS_HOME_STATE,
.value = "CA",
.status = VerificationStatus::kNoStatus}};
SetTestValues(&address, test_values, /*finalize=*/false);
// Invoke the migration. This should only change the verification statuses of
// the set values.
address.MigrateLegacyStructure(/*is_verified_profile=*/false);
AddressComponentTestValues expectation_after_migration = {
{.type = ADDRESS_HOME_STREET_ADDRESS,
.value = "123 Street name",
.status = VerificationStatus::kObserved},
{.type = ADDRESS_HOME_COUNTRY,
.value = "US",
.status = VerificationStatus::kObserved},
{.type = ADDRESS_HOME_STATE,
.value = "CA",
.status = VerificationStatus::kObserved},
{.type = ADDRESS_HOME_ADDRESS,
.value = "",
.status = VerificationStatus::kNoStatus},
{.type = ADDRESS_HOME_CITY,
.value = "",
.status = VerificationStatus::kNoStatus},
};
VerifyTestValues(&address, expectation_after_migration);
// Complete the address tree and check the expectations.
address.CompleteFullTree();
AddressComponentTestValues expectation_after_completion = {
{.type = ADDRESS_HOME_STREET_ADDRESS,
.value = "123 Street name",
.status = VerificationStatus::kObserved},
{.type = ADDRESS_HOME_COUNTRY,
.value = "US",
.status = VerificationStatus::kObserved},
{.type = ADDRESS_HOME_STATE,
.value = "CA",
.status = VerificationStatus::kObserved},
{.type = ADDRESS_HOME_ADDRESS,
.value = "123 Street name CA US",
.status = VerificationStatus::kFormatted},
{.type = ADDRESS_HOME_CITY,
.value = "",
.status = VerificationStatus::kNoStatus},
{.type = ADDRESS_HOME_STREET_NAME,
.value = "Street name",
.status = VerificationStatus::kParsed},
{.type = ADDRESS_HOME_HOUSE_NUMBER,
.value = "123",
.status = VerificationStatus::kParsed},
};
VerifyTestValues(&address, expectation_after_completion);
}
// Tests the migration of a structured address in a verified profile.
TEST(AutofillStructuredAddress, TestMigrationOfVerifiedProfile) {
Address address;
AddressComponentTestValues test_values = {
{.type = ADDRESS_HOME_STREET_ADDRESS,
.value = "123 Street name",
.status = VerificationStatus::kNoStatus},
{.type = ADDRESS_HOME_COUNTRY,
.value = "US",
.status = VerificationStatus::kNoStatus},
{.type = ADDRESS_HOME_STATE,
.value = "CA",
.status = VerificationStatus::kNoStatus}};
SetTestValues(&address, test_values, /*finalize=*/false);
// Invoke the migration. All non-empty fields should be marked as
// user-verified.
address.MigrateLegacyStructure(/*is_verified_profile=*/true);
AddressComponentTestValues expectation_after_migration = {
{.type = ADDRESS_HOME_STREET_ADDRESS,
.value = "123 Street name",
.status = VerificationStatus::kUserVerified},
{.type = ADDRESS_HOME_COUNTRY,
.value = "US",
.status = VerificationStatus::kUserVerified},
{.type = ADDRESS_HOME_STATE,
.value = "CA",
.status = VerificationStatus::kUserVerified},
{.type = ADDRESS_HOME_ADDRESS,
.value = "",
.status = VerificationStatus::kNoStatus},
{.type = ADDRESS_HOME_CITY,
.value = "",
.status = VerificationStatus::kNoStatus},
};
VerifyTestValues(&address, expectation_after_migration);
}
// Tests that the migration does not happen of the root node
// (ADDRESS_HOME_ADDRESS) already has a verification status.
TEST(AutofillStructuredAddress, TestMigrationAndFinalization_AlreadyMigrated) {
Address address;
AddressComponentTestValues test_values = {
{.type = ADDRESS_HOME_STREET_ADDRESS,
.value = "123 Street name",
.status = VerificationStatus::kNoStatus},
{.type = ADDRESS_HOME_COUNTRY,
.value = "US",
.status = VerificationStatus::kNoStatus},
{.type = ADDRESS_HOME_STATE,
.value = "CA",
.status = VerificationStatus::kNoStatus},
{.type = ADDRESS_HOME_ADDRESS,
.value = "the address",
.status = VerificationStatus::kFormatted}};
SetTestValues(&address, test_values, /*finalize=*/false);
// Invoke the migration. Since the ADDRESS_HOME_ADDRESS node already has a
// verification status, the address is considered as already migrated.
address.MigrateLegacyStructure(/*is_verified_profile=*/false);
// Verify that the address was not changed by the migration.
VerifyTestValues(&address, test_values);
}
} // namespace } // namespace
} // namespace structured_address } // namespace structured_address
} // namespace autofill } // namespace autofill
...@@ -415,9 +415,9 @@ TEST_P(FormDataImporterTest, ...@@ -415,9 +415,9 @@ TEST_P(FormDataImporterTest,
TEST_P(FormDataImporterTest, TEST_P(FormDataImporterTest,
ImportStructuredAddressProfile_GermanStreetNameAndHouseNumber) { ImportStructuredAddressProfile_GermanStreetNameAndHouseNumber) {
base::test::ScopedFeatureList structured_addresses_feature; // This test is only applicable if structured addresses are enabled.
structured_addresses_feature.InitAndEnableFeature( if (!StructuredAddresses())
features::kAutofillEnableSupportForMoreStructureInAddresses); return;
FormData form; FormData form;
form.url = GURL("https://wwww.foo.com"); form.url = GURL("https://wwww.foo.com");
......
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