Commit c393e5b4 authored by siashah's avatar siashah Committed by Commit Bot

Add card_issuer column to autofill_table

Follow up: Populating and retrieving the card_issuer.

Please refer to the bug for design doc.

Bug: 1063426
Change-Id: I3fb9fa0fc468bdb565dd5cba1218b379664d442a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2142617Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Commit-Queue: Siddharth Shah <siashah@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758561}
parent a5c64f5c
...@@ -493,6 +493,9 @@ bool AutofillTable::MigrateToVersion(int version, ...@@ -493,6 +493,9 @@ bool AutofillTable::MigrateToVersion(int version,
case 84: case 84:
*update_compatible_version = false; *update_compatible_version = false;
return MigrateToVersion84AddNicknameColumn(); return MigrateToVersion84AddNicknameColumn();
case 85:
*update_compatible_version = false;
return MigrateToVersion85AddCardIssuerColumnToMaskedCreditCard();
} }
return true; return true;
} }
...@@ -2783,6 +2786,16 @@ bool AutofillTable::MigrateToVersion84AddNicknameColumn() { ...@@ -2783,6 +2786,16 @@ bool AutofillTable::MigrateToVersion84AddNicknameColumn() {
"ALTER TABLE masked_credit_cards ADD COLUMN nickname VARCHAR"); "ALTER TABLE masked_credit_cards ADD COLUMN nickname VARCHAR");
} }
bool AutofillTable::MigrateToVersion85AddCardIssuerColumnToMaskedCreditCard() {
// Add the new card_issuer column to the masked_credit_cards table and set the
// default value to ISSUER_UNKNOWN.
return db_->DoesColumnExist("masked_credit_cards", "card_issuer") ||
db_->Execute(
"ALTER TABLE masked_credit_cards "
"ADD COLUMN card_issuer INTEGER "
"DEFAULT 0");
}
bool AutofillTable::AddFormFieldValuesTime( bool AutofillTable::AddFormFieldValuesTime(
const std::vector<FormFieldData>& elements, const std::vector<FormFieldData>& elements,
std::vector<AutofillChange>* changes, std::vector<AutofillChange>* changes,
...@@ -3138,7 +3151,8 @@ bool AutofillTable::InitMaskedCreditCardsTable() { ...@@ -3138,7 +3151,8 @@ bool AutofillTable::InitMaskedCreditCardsTable() {
"exp_month INTEGER DEFAULT 0," "exp_month INTEGER DEFAULT 0,"
"exp_year INTEGER DEFAULT 0, " "exp_year INTEGER DEFAULT 0, "
"bank_name VARCHAR, " "bank_name VARCHAR, "
"nickname VARCHAR)")) { "nickname VARCHAR, "
"card_issuer INTEGER DEFAULT 0)")) {
NOTREACHED(); NOTREACHED();
return false; return false;
} }
......
...@@ -177,6 +177,9 @@ struct PaymentsCustomerData; ...@@ -177,6 +177,9 @@ struct PaymentsCustomerData;
// exp_year Four-digit year: 2017 // exp_year Four-digit year: 2017
// bank_name Issuer bank name of the credit card. // bank_name Issuer bank name of the credit card.
// nickname The card's nickname, if it exists. Added in version 84. // nickname The card's nickname, if it exists. Added in version 84.
// card_issuer Issuer for the card. An integer representing the
// CardIssuer.Issuer enum from the Chrome Sync response.
// For example, GOOGLE or ISSUER_UNKNOWN.
// //
// unmasked_credit_cards // unmasked_credit_cards
// When a masked credit credit card is unmasked and the // When a masked credit credit card is unmasked and the
...@@ -554,6 +557,7 @@ class AutofillTable : public WebDatabaseTable, ...@@ -554,6 +557,7 @@ class AutofillTable : public WebDatabaseTable,
bool MigrateToVersion81CleanUpWrongModelTypeData(); bool MigrateToVersion81CleanUpWrongModelTypeData();
bool MigrateToVersion83RemoveServerCardTypeColumn(); bool MigrateToVersion83RemoveServerCardTypeColumn();
bool MigrateToVersion84AddNicknameColumn(); bool MigrateToVersion84AddNicknameColumn();
bool MigrateToVersion85AddCardIssuerColumnToMaskedCreditCard();
// Max data length saved in the table, AKA the maximum length allowed for // Max data length saved in the table, AKA the maximum length allowed for
// form data. // form data.
// Copied to components/autofill/ios/browser/resources/autofill_controller.js. // Copied to components/autofill/ios/browser/resources/autofill_controller.js.
......
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','83');
INSERT INTO meta VALUES('last_compatible_version','79');
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);
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);
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);
INSERT INTO "masked_credit_cards" VALUES('card_1','status','bob','VISA','1234',12,2050,'Chase','');
CREATE TABLE unmasked_credit_cards (id VARCHAR,card_number_encrypted VARCHAR, use_count INTEGER NOT NULL DEFAULT 0, use_date INTEGER NOT NULL DEFAULT 0, 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;
...@@ -71,6 +71,7 @@ bundle_data("unit_tests_bundle_data") { ...@@ -71,6 +71,7 @@ bundle_data("unit_tests_bundle_data") {
"//components/test/data/web_database/version_81.sql", "//components/test/data/web_database/version_81.sql",
"//components/test/data/web_database/version_82.sql", "//components/test/data/web_database/version_82.sql",
"//components/test/data/web_database/version_83.sql", "//components/test/data/web_database/version_83.sql",
"//components/test/data/web_database/version_84.sql",
] ]
outputs = [ "{{bundle_resources_dir}}/" + outputs = [ "{{bundle_resources_dir}}/" +
"{{source_root_relative_dir}}/{{source_file_part}}" ] "{{source_root_relative_dir}}/{{source_file_part}}" ]
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// corresponding changes must happen in the unit tests, and new migration test // corresponding changes must happen in the unit tests, and new migration test
// added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|. // added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|.
// static // static
const int WebDatabase::kCurrentVersionNumber = 84; const int WebDatabase::kCurrentVersionNumber = 85;
const int WebDatabase::kDeprecatedVersionNumber = 51; const int WebDatabase::kDeprecatedVersionNumber = 51;
......
...@@ -126,7 +126,7 @@ class WebDatabaseMigrationTest : public testing::Test { ...@@ -126,7 +126,7 @@ class WebDatabaseMigrationTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest);
}; };
const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 84; const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 85;
void WebDatabaseMigrationTest::LoadDatabase( void WebDatabaseMigrationTest::LoadDatabase(
const base::FilePath::StringType& file) { const base::FilePath::StringType& file) {
...@@ -1862,3 +1862,37 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion83ToCurrent) { ...@@ -1862,3 +1862,37 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion83ToCurrent) {
EXPECT_EQ("", s_masked_cards.ColumnString(0)); EXPECT_EQ("", s_masked_cards.ColumnString(0));
} }
} }
// Tests addition of card_issuer column in masked_credit_cards table.
TEST_F(WebDatabaseMigrationTest, MigrateVersion84ToCurrent) {
ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_84.sql")));
// Verify pre-conditions.
{
sql::Database connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
sql::MetaTable meta_table;
ASSERT_TRUE(meta_table.Init(&connection, 84, 79));
EXPECT_FALSE(
connection.DoesColumnExist("masked_credit_cards", "card_issuer"));
}
DoMigration();
// Verify post-conditions.
{
sql::Database connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
// Check version.
EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
// The card_issuer column should exist.
EXPECT_TRUE(
connection.DoesColumnExist("masked_credit_cards", "card_issuer"));
}
}
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