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

[Autofill][Leipzig] Add SQL support for structured address tokens

This CL adds support to store all address tokens and their verification
statuses in the profile address table.

Change-Id: Iad73aeb2e6464b872a8689b7077457cf39b01e1c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2421450Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Commit-Queue: Matthias Körber <koerber@google.com>
Cr-Commit-Position: refs/heads/master@{#809266}
parent b5193792
......@@ -114,6 +114,16 @@ struct PaymentsCustomerData;
// house_number The house number.
// subpremise The floor, apartment number and staircase.
// apartment number.
// dependent_locality
// A sub-classification beneath the city, e.g. an
// inner-city district or suburb.
// city The city information of the address.
// state The state information of the address.
// zip_code The zip code of the address.
// country_code The code of the country of the address.
// sorting_code Similar to the zipcode column, but used for businesses
// or organizations that might not be geographically
// contiguous.
// premise_name The name of the premise.
// street_address_status
// street_name_status
......@@ -121,6 +131,12 @@ struct PaymentsCustomerData;
// house_number_status
// subpremise_status
// premise_name_status
// dependent_locality_status
// city_status
// state_status
// zip_code_status
// country_code_status
// sorting_code_status
// Each token of the address has an additional validation
// status that indicates if Autofill parsed the value out
// of an unstructured (last) name, or if autofill formatted
......@@ -657,6 +673,7 @@ class AutofillTable : public WebDatabaseTable,
bool MigrateToVersion87AddCreditCardNicknameColumn();
bool MigrateToVersion88AddNewNameColumns();
bool MigrateToVersion89AddInstrumentIdColumnToMaskedCreditCard();
bool MigrateToVersion90AddNewStructuredAddressColumns();
// Max data length saved in the table, AKA the maximum length allowed for
// form data.
......
......@@ -1034,9 +1034,12 @@ TEST_F(AutofillTableTest,
}
TEST_F(AutofillTableTest, AutofillProfile_StructuredAddresses) {
// Enable the structured addresses.
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillAddressEnhancementVotes);
// Enable the structured addresses features.
scoped_feature_list_.InitWithFeatures(
{features::kAutofillAddressEnhancementVotes,
features::kAutofillEnableSupportForMoreStructureInAddresses},
{});
;
AutofillProfile profile;
profile.set_origin(std::string());
......@@ -1047,9 +1050,30 @@ TEST_F(AutofillTableTest, AutofillProfile_StructuredAddresses) {
profile.SetRawInfoWithVerificationStatus(ADDRESS_HOME_STREET_NAME,
ASCIIToUTF16("Street Name"),
VerificationStatus::kFormatted);
profile.SetRawInfoWithVerificationStatus(ADDRESS_HOME_DEPENDENT_LOCALITY,
ASCIIToUTF16("Dependent Locality"),
VerificationStatus::kObserved);
profile.SetRawInfoWithVerificationStatus(
ADDRESS_HOME_CITY, ASCIIToUTF16("City"), VerificationStatus::kObserved);
profile.SetRawInfoWithVerificationStatus(
ADDRESS_HOME_STATE, ASCIIToUTF16("State"), VerificationStatus::kObserved);
profile.SetRawInfoWithVerificationStatus(ADDRESS_HOME_SORTING_CODE,
ASCIIToUTF16("Sorting Code"),
VerificationStatus::kObserved);
profile.SetRawInfoWithVerificationStatus(
ADDRESS_HOME_ZIP, ASCIIToUTF16("ZIP"), VerificationStatus::kObserved);
profile.SetRawInfoWithVerificationStatus(
ADDRESS_HOME_COUNTRY, ASCIIToUTF16("DE"), VerificationStatus::kObserved);
profile.SetRawInfoWithVerificationStatus(
ADDRESS_HOME_DEPENDENT_STREET_NAME, ASCIIToUTF16("Dependent Street Name"),
VerificationStatus::kObserved);
profile.SetRawInfoWithVerificationStatus(ADDRESS_HOME_HOUSE_NUMBER,
ASCIIToUTF16("House Number"),
VerificationStatus::kUserVerified);
......@@ -1065,10 +1089,45 @@ TEST_F(AutofillTableTest, AutofillProfile_StructuredAddresses) {
// Add the profile to the table.
EXPECT_TRUE(table_->AddAutofillProfile(profile));
// Read the profile from the table and verify the correct values.
std::unique_ptr<AutofillProfile> db_profile =
table_->GetAutofillProfile(profile.guid());
ASSERT_TRUE(db_profile);
EXPECT_EQ(db_profile->GetVerificationStatus(ADDRESS_HOME_STREET_NAME),
VerificationStatus::kFormatted);
EXPECT_EQ(
db_profile->GetVerificationStatus(ADDRESS_HOME_DEPENDENT_STREET_NAME),
VerificationStatus::kObserved);
EXPECT_EQ(db_profile->GetVerificationStatus(ADDRESS_HOME_HOUSE_NUMBER),
VerificationStatus::kUserVerified);
EXPECT_EQ(db_profile->GetVerificationStatus(ADDRESS_HOME_SUBPREMISE),
VerificationStatus::kUserVerified);
EXPECT_EQ(db_profile->GetVerificationStatus(ADDRESS_HOME_PREMISE_NAME),
VerificationStatus::kUserVerified);
EXPECT_EQ(db_profile->GetVerificationStatus(ADDRESS_HOME_DEPENDENT_LOCALITY),
VerificationStatus::kObserved);
EXPECT_EQ(db_profile->GetVerificationStatus(ADDRESS_HOME_CITY),
VerificationStatus::kObserved);
EXPECT_EQ(db_profile->GetVerificationStatus(ADDRESS_HOME_STATE),
VerificationStatus::kObserved);
EXPECT_EQ(db_profile->GetVerificationStatus(ADDRESS_HOME_SORTING_CODE),
VerificationStatus::kObserved);
EXPECT_EQ(db_profile->GetVerificationStatus(ADDRESS_HOME_ZIP),
VerificationStatus::kObserved);
EXPECT_EQ(db_profile->GetVerificationStatus(ADDRESS_HOME_COUNTRY),
VerificationStatus::kObserved);
EXPECT_EQ(db_profile->GetRawInfo(ADDRESS_HOME_STREET_NAME),
ASCIIToUTF16("Street Name"));
EXPECT_EQ(db_profile->GetRawInfo(ADDRESS_HOME_DEPENDENT_STREET_NAME),
......@@ -1079,16 +1138,26 @@ TEST_F(AutofillTableTest, AutofillProfile_StructuredAddresses) {
ASCIIToUTF16("Subpremise"));
EXPECT_EQ(db_profile->GetRawInfo(ADDRESS_HOME_PREMISE_NAME),
ASCIIToUTF16("Premise"));
EXPECT_EQ(db_profile->GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY),
ASCIIToUTF16("Dependent Locality"));
EXPECT_EQ(db_profile->GetRawInfo(ADDRESS_HOME_CITY), ASCIIToUTF16("City"));
EXPECT_EQ(db_profile->GetRawInfo(ADDRESS_HOME_STATE), ASCIIToUTF16("State"));
EXPECT_EQ(db_profile->GetRawInfo(ADDRESS_HOME_SORTING_CODE),
ASCIIToUTF16("Sorting Code"));
EXPECT_EQ(db_profile->GetRawInfo(ADDRESS_HOME_ZIP), ASCIIToUTF16("ZIP"));
EXPECT_EQ(db_profile->GetRawInfo(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("DE"));
// Verify that it is correct.
EXPECT_EQ(profile, *db_profile);
}
TEST_F(AutofillTableTest,
AutofillProfile_StructuredAddresses_Eventual_Deletion) {
// Enable the structured addresses.
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillAddressEnhancementVotes);
scoped_feature_list_.InitWithFeatures(
{features::kAutofillAddressEnhancementVotes,
features::kAutofillEnableSupportForMoreStructureInAddresses},
{});
;
AutofillProfile profile;
profile.set_origin(std::string());
......@@ -1135,10 +1204,11 @@ TEST_F(AutofillTableTest,
EXPECT_EQ(db_profile->GetRawInfo(ADDRESS_HOME_PREMISE_NAME),
ASCIIToUTF16("Premise"));
// Deactivate the feature.
// Deactivate the features.
scoped_feature_list_.Reset();
scoped_feature_list_.InitAndDisableFeature(
features::kAutofillAddressEnhancementVotes);
scoped_feature_list_.InitWithFeatures(
{}, {features::kAutofillAddressEnhancementVotes,
features::kAutofillEnableSupportForMoreStructureInAddresses});
// Retrieve the address and verify that the structured tokens are not written.
std::unique_ptr<AutofillProfile> legacy_db_profile =
......@@ -1177,7 +1247,7 @@ TEST_F(AutofillTableTest,
ASSERT_TRUE(s.is_valid());
ASSERT_TRUE(s.Run());
// And very that it is written.
// And verify that it is written.
sql::Statement s1(db_->GetSQLConnection()->GetUniqueStatement(
"SELECT count(*) "
"FROM autofill_profile_addresses "
......@@ -1189,29 +1259,17 @@ TEST_F(AutofillTableTest,
// Enable the feature again and load the profile.
scoped_feature_list_.Reset();
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillAddressEnhancementVotes);
// Retrieve the address and verify that the structured tokens are not written
// because the data is in an inconsistent state that should trigger a complete
// removal of the structured address.
scoped_feature_list_.InitWithFeatures(
{features::kAutofillAddressEnhancementVotes,
features::kAutofillEnableSupportForMoreStructureInAddresses},
{});
;
// Retrieve the address and manually query the data base to verify that the
// structured address was deleted.
std::unique_ptr<AutofillProfile> migrated_db_profile =
table_->GetAutofillProfile(profile.guid());
ASSERT_TRUE(migrated_db_profile);
EXPECT_EQ(migrated_db_profile->GetRawInfo(ADDRESS_HOME_STREET_NAME),
base::string16());
EXPECT_EQ(migrated_db_profile->GetRawInfo(ADDRESS_HOME_DEPENDENT_STREET_NAME),
base::string16());
EXPECT_EQ(migrated_db_profile->GetRawInfo(ADDRESS_HOME_HOUSE_NUMBER),
base::string16());
EXPECT_EQ(migrated_db_profile->GetRawInfo(ADDRESS_HOME_SUBPREMISE),
base::string16());
EXPECT_EQ(migrated_db_profile->GetRawInfo(ADDRESS_HOME_PREMISE_NAME),
base::string16());
// Manually query the data base to verify that the structured address was
// deleted.
sql::Statement s2(db_->GetSQLConnection()->GetUniqueStatement(
"SELECT count(*) "
"FROM autofill_profile_addresses "
......
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY, value LONGVARCHAR);
INSERT INTO meta VALUES('mmap_status','-1');
INSERT INTO meta VALUES('version','88');
INSERT INTO meta VALUES('last_compatible_version','83');
INSERT INTO meta VALUES('Builtin Keyword Version','117');
CREATE TABLE token_service (service VARCHAR PRIMARY KEY NOT NULL,encrypted_token BLOB);
CREATE TABLE keywords (id INTEGER PRIMARY KEY,short_name VARCHAR NOT NULL,keyword VARCHAR NOT NULL,favicon_url VARCHAR NOT NULL,url VARCHAR NOT NULL,safe_for_autoreplace INTEGER,originating_url VARCHAR,date_created INTEGER DEFAULT 0,usage_count INTEGER DEFAULT 0,input_encodings VARCHAR,suggest_url VARCHAR,prepopulate_id INTEGER DEFAULT 0,created_by_policy INTEGER DEFAULT 0,last_modified INTEGER DEFAULT 0,sync_guid VARCHAR,alternate_urls VARCHAR,image_url VARCHAR,search_url_post_params VARCHAR,suggest_url_post_params VARCHAR,image_url_post_params VARCHAR,new_tab_url VARCHAR,last_visited INTEGER DEFAULT 0, created_from_play_api INTEGER DEFAULT 0);
CREATE TABLE autofill (name VARCHAR, value VARCHAR, value_lower VARCHAR, date_created INTEGER DEFAULT 0, date_last_used INTEGER DEFAULT 0, count INTEGER DEFAULT 1, PRIMARY KEY (name, value));
CREATE TABLE credit_cards ( guid VARCHAR PRIMARY KEY, name_on_card VARCHAR, expiration_month INTEGER, expiration_year INTEGER, card_number_encrypted BLOB, date_modified INTEGER NOT NULL DEFAULT 0, origin VARCHAR DEFAULT '', use_count INTEGER NOT NULL DEFAULT 0, use_date INTEGER NOT NULL DEFAULT 0, billing_address_id VARCHAR, nickname VARCHAR);
CREATE TABLE autofill_profiles ( guid VARCHAR PRIMARY KEY, company_name VARCHAR, street_address VARCHAR, dependent_locality VARCHAR, city VARCHAR, state VARCHAR, zipcode VARCHAR, sorting_code VARCHAR, country_code VARCHAR, date_modified INTEGER NOT NULL DEFAULT 0, origin VARCHAR DEFAULT '', language_code VARCHAR, use_count INTEGER NOT NULL DEFAULT 0, use_date INTEGER NOT NULL DEFAULT 0, validity_bitfield UNSIGNED NOT NULL DEFAULT 0, is_client_validity_states_updated BOOL NOT NULL DEFAULT FALSE);
CREATE TABLE autofill_profile_names ( guid VARCHAR, first_name VARCHAR, middle_name VARCHAR, last_name VARCHAR, full_name VARCHAR, honorific_prefix VARCHAR, first_last_name VARCHAR, conjunction_last_name VARCHAR, second_last_name VARCHAR, honorific_prefix_status INTEGER DEFAULT 0, first_name_status INTEGER DEFAULT 0, middle_name_status INTEGER DEFAULT 0, last_name_status INTEGER DEFAULT 0, first_last_name_status INTEGER DEFAULT 0, conjunction_last_name_status INTEGER DEFAULT 0, second_last_name_status INTEGER DEFAULT 0, full_name_status INTEGER DEFAULT 0);
INSERT INTO "autofill_profile_names" VALUES('B41FE6E0-B13E-2A2A-BF0B-29FCE2C3ADBD','Jon','','Smith', 'Jon Smith', 'Sir', 'Smith', 'Notsmith', 'Moresmith', 0, 0, 0, 0, 0, 0, 0, 0);
CREATE TABLE autofill_profile_emails ( guid VARCHAR, email VARCHAR);
CREATE TABLE autofill_profile_phones ( guid VARCHAR, number VARCHAR);
CREATE TABLE autofill_profiles_trash ( guid VARCHAR);
CREATE TABLE masked_credit_cards (id VARCHAR,status VARCHAR,name_on_card VARCHAR,network VARCHAR,last_four VARCHAR,exp_month INTEGER DEFAULT 0,exp_year INTEGER DEFAULT 0, bank_name VARCHAR, nickname VARCHAR, card_issuer INTEGER DEFAULT 0);
CREATE TABLE unmasked_credit_cards (id VARCHAR,card_number_encrypted VARCHAR,unmask_date INTEGER NOT NULL DEFAULT 0);
CREATE TABLE server_card_metadata (id VARCHAR NOT NULL,use_count INTEGER NOT NULL DEFAULT 0, use_date INTEGER NOT NULL DEFAULT 0, billing_address_id VARCHAR);
CREATE TABLE server_addresses (id VARCHAR,company_name VARCHAR,street_address VARCHAR,address_1 VARCHAR,address_2 VARCHAR,address_3 VARCHAR,address_4 VARCHAR,postal_code VARCHAR,sorting_code VARCHAR,country_code VARCHAR,language_code VARCHAR, recipient_name VARCHAR, phone_number VARCHAR);
CREATE TABLE server_address_metadata (id VARCHAR NOT NULL,use_count INTEGER NOT NULL DEFAULT 0, use_date INTEGER NOT NULL DEFAULT 0, has_converted BOOL NOT NULL DEFAULT FALSE);
CREATE TABLE autofill_sync_metadata (model_type INTEGER NOT NULL, storage_key VARCHAR NOT NULL, value BLOB, PRIMARY KEY (model_type, storage_key));
CREATE TABLE autofill_model_type_state (model_type INTEGER NOT NULL PRIMARY KEY, value BLOB);
CREATE TABLE payments_customer_data (customer_id VARCHAR);
CREATE TABLE payments_upi_vpa (vpa VARCHAR);
CREATE TABLE server_card_cloud_token_data ( id VARCHAR, suffix VARCHAR, exp_month INTEGER DEFAULT 0, exp_year INTEGER DEFAULT 0, card_art_url VARCHAR, instrument_token VARCHAR);
CREATE INDEX autofill_name ON autofill (name);
CREATE INDEX autofill_name_value_lower ON autofill (name, value_lower);
COMMIT;
\ No newline at end of file
......@@ -76,6 +76,7 @@ bundle_data("unit_tests_bundle_data") {
"//components/test/data/web_database/version_86.sql",
"//components/test/data/web_database/version_87.sql",
"//components/test/data/web_database/version_88.sql",
"//components/test/data/web_database/version_89.sql",
]
outputs = [ "{{bundle_resources_dir}}/" +
"{{source_root_relative_dir}}/{{source_file_part}}" ]
......
......@@ -14,7 +14,7 @@
// corresponding changes must happen in the unit tests, and new migration test
// added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|.
// static
const int WebDatabase::kCurrentVersionNumber = 89;
const int WebDatabase::kCurrentVersionNumber = 90;
const int WebDatabase::kDeprecatedVersionNumber = 51;
......
......@@ -126,7 +126,7 @@ class WebDatabaseMigrationTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest);
};
const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 89;
const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 90;
void WebDatabaseMigrationTest::LoadDatabase(
const base::FilePath::StringType& file) {
......
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