[DataModel] Avoid profile default construction in autofill table.
This CL is part of our efforts of making the AutofillProfile require a
country code during construction (e.g. by removing the default
constructor). The CL avoids the default initialization in autofill
table.
Bug: 1464568
Change-Id: If6398552cba8a30ac94e4c3221e42b6c187607ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5001876
Reviewed-by: Florian Leimgruber <fleimgruber@google.com>
Commit-Queue: Norge Vizcay <vizcay@google.com>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1220207}
diff --git a/components/autofill/core/browser/webdata/autofill_table.cc b/components/autofill/core/browser/webdata/autofill_table.cc
index 6995108..f953304 100644
--- a/components/autofill/core/browser/webdata/autofill_table.cc
+++ b/components/autofill/core/browser/webdata/autofill_table.cc
@@ -1833,7 +1833,9 @@
}
auto profile = std::make_unique<AutofillProfile>(
- guid, AutofillProfile::Source::kLocalOrSyncable);
+ guid, AutofillProfile::Source::kLocalOrSyncable,
+ i18n_model_definition::kLegacyHierarchyCountryCode);
+
DCHECK(base::Uuid::ParseCaseInsensitive(profile->guid()).is_valid());
// Get associated name info using guid.
diff --git a/components/autofill/core/browser/webdata/autofill_table_unittest.cc b/components/autofill/core/browser/webdata/autofill_table_unittest.cc
index 01d0b36..ce49b63e 100644
--- a/components/autofill/core/browser/webdata/autofill_table_unittest.cc
+++ b/components/autofill/core/browser/webdata/autofill_table_unittest.cc
@@ -3,7 +3,6 @@
// found in the LICENSE file.
#include "components/autofill/core/browser/webdata/autofill_table.h"
-#include "components/autofill/core/browser/field_types.h"
#include <map>
#include <memory>
@@ -24,12 +23,14 @@
#include "build/build_config.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/autofill_type.h"
+#include "components/autofill/core/browser/country_type.h"
#include "components/autofill/core/browser/data_model/autofill_metadata.h"
#include "components/autofill/core/browser/data_model/autofill_offer_data.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/data_model/autofill_wallet_usage_data.h"
#include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/data_model/credit_card_cloud_token_data.h"
+#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/payments/payments_customer_data.h"
#include "components/autofill/core/browser/profile_token_quality.h"
#include "components/autofill/core/browser/profile_token_quality_test_api.h"
@@ -212,7 +213,7 @@
// Creates an `AutofillProfile` with `profile_source()` as its source.
AutofillProfile CreateAutofillProfile() const {
- return AutofillProfile(profile_source());
+ return AutofillProfile(profile_source(), AddressCountryCode("ES"));
}
// Depending on the `profile_source()`, the AutofillProfiles are stored in a
@@ -1010,8 +1011,10 @@
// Not part of the `AutofillTableProfileTest` fixture, as it doesn't benefit
// from parameterization on the `profile_source()`.
TEST_F(AutofillTableTest, GetAutofillProfiles) {
- AutofillProfile local_profile(AutofillProfile::Source::kLocalOrSyncable);
- AutofillProfile account_profile(AutofillProfile::Source::kAccount);
+ AutofillProfile local_profile(AutofillProfile::Source::kLocalOrSyncable,
+ AddressCountryCode("ES"));
+ AutofillProfile account_profile(AutofillProfile::Source::kAccount,
+ AddressCountryCode("ES"));
EXPECT_TRUE(table_->AddAutofillProfile(local_profile));
EXPECT_TRUE(table_->AddAutofillProfile(account_profile));
@@ -1570,7 +1573,7 @@
profile.SetRawInfo(ADDRESS_HOME_CITY, u"Los Angeles");
profile.SetRawInfo(ADDRESS_HOME_STATE, u"CA");
profile.SetRawInfo(ADDRESS_HOME_ZIP, u"90025");
- profile.SetRawInfo(ADDRESS_HOME_COUNTRY, u"US");
+ profile.SetRawInfo(ADDRESS_HOME_COUNTRY, u"ES");
profile.SetRawInfo(ADDRESS_HOME_OVERFLOW, u"Andar 1, Apto. 12");
profile.SetRawInfo(ADDRESS_HOME_LANDMARK, u"Landmark");
profile.SetRawInfo(ADDRESS_HOME_BETWEEN_STREETS, u"Marcos y Oliva");
@@ -2318,7 +2321,8 @@
}
TEST_F(AutofillTableTest, UpdateServerAddressMetadataDoesNotChangeData) {
- AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123");
+ AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123",
+ AddressCountryCode("ES"));
std::vector<AutofillProfile> inputs;
inputs.push_back(one);
table_->SetServerProfiles(inputs);
@@ -2522,7 +2526,8 @@
}
TEST_F(AutofillTableTest, SetServerAddressesData) {
- AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123");
+ AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123",
+ AddressCountryCode("ES"));
std::vector<AutofillProfile> inputs;
inputs.push_back(one);
table_->SetServerAddressesData(inputs);
@@ -2782,7 +2787,8 @@
}
TEST_F(AutofillTableTest, SetServerProfile) {
- AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123");
+ AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123",
+ AddressCountryCode("ES"));
std::vector<AutofillProfile> inputs;
inputs.push_back(one);
table_->SetServerProfiles(inputs);
@@ -2795,7 +2801,8 @@
outputs.clear();
// Set a different profile.
- AutofillProfile two(AutofillProfile::SERVER_PROFILE, "b456");
+ AutofillProfile two(AutofillProfile::SERVER_PROFILE, "b456",
+ AddressCountryCode("ES"));
inputs[0] = two;
table_->SetServerProfiles(inputs);
@@ -2808,7 +2815,8 @@
}
TEST_F(AutofillTableTest, SetServerProfileUpdateUsageStats) {
- AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123");
+ AutofillProfile one(AutofillProfile::SERVER_PROFILE, "a123",
+ AddressCountryCode("ES"));
std::vector<AutofillProfile> inputs;
inputs.push_back(one);
table_->SetServerProfiles(inputs);