summaryrefslogtreecommitdiffstats
path: root/chrome/browser/webdata
diff options
context:
space:
mode:
authorisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-25 23:47:13 +0000
committerisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-25 23:47:13 +0000
commit3540102a3b99033e6f4838f9843721bff47a2aa8 (patch)
treea4cdae31eaf5beaae1a4d57a6ab936c64073b440 /chrome/browser/webdata
parentad90b5620fc7ec8140b94a64d5f4033356dc5c5b (diff)
downloadchromium_src-3540102a3b99033e6f4838f9843721bff47a2aa8.zip
chromium_src-3540102a3b99033e6f4838f9843721bff47a2aa8.tar.gz
chromium_src-3540102a3b99033e6f4838f9843721bff47a2aa8.tar.bz2
Autofill i18n: Set postal code and state field labels based on the selected country.
* Changes the country field to a <select> field. * Restricts the possible values for the "country" field to a set of known values * Moves the country field to the top of the Autofill dialog * Changes the field labels according to the selected country BUG=56599,56602,56604 TEST= Review URL: http://codereview.chromium.org/6484022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76117 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/webdata')
-rw-r--r--chrome/browser/webdata/web_database.cc84
-rw-r--r--chrome/browser/webdata/web_database_unittest.cc107
2 files changed, 147 insertions, 44 deletions
diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc
index e3c5988..f5ab577 100644
--- a/chrome/browser/webdata/web_database.cc
+++ b/chrome/browser/webdata/web_database.cc
@@ -16,6 +16,7 @@
#include "base/string_util.h"
#include "base/tuple.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autofill/autofill_country.h"
#include "chrome/browser/autofill/autofill_profile.h"
#include "chrome/browser/autofill/autofill_type.h"
#include "chrome/browser/autofill/credit_card.h"
@@ -123,7 +124,9 @@ enum AutoFillPhoneType {
// city
// state
// zipcode
-// country
+// country The country name. Deprecated, should be removed once
+// the stable channel reaches version 11.
+// country_code
// date_modified The date on which this profile was last modified.
// Added in version 30.
//
@@ -189,8 +192,8 @@ typedef std::vector<Tuple3<int64, string16, string16> > AutofillElementList;
// Current version number. Note: when changing the current version number,
// corresponding changes must happen in the unit tests, and new migration test
// added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|.
-const int kCurrentVersionNumber = 33;
-const int kCompatibleVersionNumber = 33;
+const int kCurrentVersionNumber = 34;
+const int kCompatibleVersionNumber = 34;
// ID of the url column in keywords.
const int kUrlIdPosition = 16;
@@ -296,7 +299,9 @@ void BindAutoFillProfileToStatement(const AutoFillProfile& profile,
s->BindString16(6, LimitDataSize(text));
text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY));
s->BindString16(7, LimitDataSize(text));
- s->BindInt64(8, Time::Now().ToTimeT());
+ std::string country_code = profile.CountryCode();
+ s->BindString(8, country_code);
+ s->BindInt64(9, Time::Now().ToTimeT());
}
AutoFillProfile* AutoFillProfileFromStatement(const sql::Statement& s) {
@@ -310,8 +315,9 @@ AutoFillProfile* AutoFillProfileFromStatement(const sql::Statement& s) {
profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY), s.ColumnString16(4));
profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE), s.ColumnString16(5));
profile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP), s.ColumnString16(6));
- profile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), s.ColumnString16(7));
- // Intentionally skip column 8, which stores the profile's modification date.
+ // Intentionally skip column 7, which stores the localized country name.
+ profile->SetCountryCode(s.ColumnString(8));
+ // Intentionally skip column 9, which stores the profile's modification date.
return profile;
}
@@ -943,6 +949,7 @@ bool WebDatabase::InitAutoFillProfilesTable() {
"state VARCHAR, "
"zipcode VARCHAR, "
"country VARCHAR, "
+ "country_code VARCHAR, "
"date_modified INTEGER NOT NULL DEFAULT 0)")) {
NOTREACHED();
return false;
@@ -1843,8 +1850,8 @@ bool WebDatabase::AddAutoFillProfile(const AutoFillProfile& profile) {
sql::Statement s(db_.GetUniqueStatement(
"INSERT INTO autofill_profiles"
"(guid, company_name, address_line_1, address_line_2, city, state,"
- " zipcode, country, date_modified)"
- "VALUES (?,?,?,?,?,?,?,?,?)"));
+ " zipcode, country, country_code, date_modified)"
+ "VALUES (?,?,?,?,?,?,?,?,?,?)"));
if (!s) {
NOTREACHED() << "Statement prepare failed";
return false;
@@ -1869,7 +1876,7 @@ bool WebDatabase::GetAutoFillProfile(const std::string& guid,
DCHECK(profile);
sql::Statement s(db_.GetUniqueStatement(
"SELECT guid, company_name, address_line_1, address_line_2, city, state,"
- " zipcode, country, date_modified "
+ " zipcode, country, country_code, date_modified "
"FROM autofill_profiles "
"WHERE guid=?"));
if (!s) {
@@ -1991,7 +1998,8 @@ bool WebDatabase::UpdateAutoFillProfile(const AutoFillProfile& profile) {
sql::Statement s(db_.GetUniqueStatement(
"UPDATE autofill_profiles "
"SET guid=?, company_name=?, address_line_1=?, address_line_2=?, "
- " city=?, state=?, zipcode=?, country=?, date_modified=? "
+ " city=?, state=?, zipcode=?, country=?, country_code=?, "
+ " date_modified=? "
"WHERE guid=?"));
if (!s) {
NOTREACHED() << "Statement prepare failed";
@@ -1999,7 +2007,7 @@ bool WebDatabase::UpdateAutoFillProfile(const AutoFillProfile& profile) {
}
BindAutoFillProfileToStatement(profile, &s);
- s.BindString(9, profile.guid());
+ s.BindString(10, profile.guid());
bool result = s.Run();
DCHECK_GT(db_.GetLastChangeCount(), 0);
if (!result)
@@ -3008,6 +3016,60 @@ sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded(){
// FALL THROUGH
+ case 33:
+ // Test the existence of the |country_code| column as an indication that
+ // we need a migration. It is possible that the new |autofill_profiles|
+ // schema is in place because the table was newly created when migrating
+ // from a pre-version-22 database.
+ if (!db_.DoesColumnExist("autofill_profiles", "country_code")) {
+ if (!db_.Execute("ALTER TABLE autofill_profiles ADD COLUMN "
+ "country_code VARCHAR")) {
+ LOG(WARNING) << "Unable to update web database to version 33.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+
+ // Set all the |country_code| fields to match existing |country| values.
+ {
+ sql::Statement s(db_.GetUniqueStatement("SELECT guid, country "
+ "FROM autofill_profiles"));
+
+ if (!s) {
+ LOG(WARNING) << "Unable to update web database to version 33.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+
+ while (s.Step()) {
+ sql::Statement update_s(
+ db_.GetUniqueStatement("UPDATE autofill_profiles "
+ "SET country_code=? WHERE guid=?"));
+ if (!update_s) {
+ LOG(WARNING) << "Unable to update web database to version 33.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+ string16 country = s.ColumnString16(1);
+ std::string app_locale = AutoFillCountry::ApplicationLocale();
+ update_s.BindString(0, AutoFillCountry::GetCountryCode(country,
+ app_locale));
+ update_s.BindString(1, s.ColumnString(0));
+
+ if (!update_s.Run()) {
+ LOG(WARNING) << "Unable to update web database to version 33.";
+ NOTREACHED();
+ return sql::INIT_FAILURE;
+ }
+ }
+ }
+ }
+
+ meta_table_.SetVersionNumber(34);
+ meta_table_.SetCompatibleVersionNumber(
+ std::min(34, kCompatibleVersionNumber));
+
+ // FALL THROUGH
+
// Add successive versions here. Each should set the version number and
// compatible version number as appropriate, then fall through to the next
// case.
diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc
index a4241e5..2adae26 100644
--- a/chrome/browser/webdata/web_database_unittest.cc
+++ b/chrome/browser/webdata/web_database_unittest.cc
@@ -1508,7 +1508,7 @@ TEST_F(WebDatabaseTest, AutoFillProfile) {
billing_profile.SetInfo(AutoFillType(ADDRESS_HOME_ZIP),
ASCIIToUTF16("10011"));
billing_profile.SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY),
- ASCIIToUTF16("USA"));
+ ASCIIToUTF16("United States"));
billing_profile.SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER),
ASCIIToUTF16("18181230000"));
billing_profile.SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER),
@@ -2093,7 +2093,7 @@ class WebDatabaseMigrationTest : public testing::Test {
// Like this:
// > .output version_nn.sql
// > .dump
- void LoadDatabase(const FilePath& path);
+ void LoadDatabase(const FilePath::StringType& file);
// Assertion testing for migrating from version 27 and 28.
void MigrateVersion28Assertions();
@@ -2104,11 +2104,11 @@ class WebDatabaseMigrationTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest);
};
-const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 33;
+const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 34;
-void WebDatabaseMigrationTest::LoadDatabase(const FilePath& file) {
+void WebDatabaseMigrationTest::LoadDatabase(const FilePath::StringType& file) {
std::string contents;
- ASSERT_TRUE(GetWebDatabaseData(file, &contents));
+ ASSERT_TRUE(GetWebDatabaseData(FilePath(file), &contents));
sql::Connection connection;
ASSERT_TRUE(connection.Open(GetDatabasePath()));
@@ -2213,8 +2213,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion22ToCurrent) {
// This schema is taken from a build prior to the addition of the
// |credit_card| table. Version 22 of the schema. Contrast this with the
// corrupt version below.
- ASSERT_NO_FATAL_FAILURE(
- LoadDatabase(FilePath(FILE_PATH_LITERAL("version_22.sql"))));
+ ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_22.sql")));
// Verify pre-conditions.
{
@@ -2260,7 +2259,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion22CorruptedToCurrent) {
// table. Due to a bug in the migration logic the version is set incorrectly
// to 22 (it should have been updated to 23 at least).
ASSERT_NO_FATAL_FAILURE(
- LoadDatabase(FilePath(FILE_PATH_LITERAL("version_22_corrupt.sql"))));
+ LoadDatabase(FILE_PATH_LITERAL("version_22_corrupt.sql")));
// Verify pre-conditions. These are expectations for corrupt version 22 of
// the database.
@@ -2308,8 +2307,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion22CorruptedToCurrent) {
TEST_F(WebDatabaseMigrationTest, MigrateVersion24ToCurrent) {
// This schema is taken from a build prior to the addition of the |keywords|
// |logo_id| column.
- ASSERT_NO_FATAL_FAILURE(
- LoadDatabase(FilePath(FILE_PATH_LITERAL("version_24.sql"))));
+ ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_24.sql")));
// Verify pre-conditions. These are expectations for version 24 of the
// database.
@@ -2349,8 +2347,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion24ToCurrent) {
TEST_F(WebDatabaseMigrationTest, MigrateVersion25ToCurrent) {
// This schema is taken from a build prior to the addition of the |keywords|
// |created_by_policy| column.
- ASSERT_NO_FATAL_FAILURE(
- LoadDatabase(FilePath(FILE_PATH_LITERAL("version_25.sql"))));
+ ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_25.sql")));
// Verify pre-conditions. These are expectations for version 25 of the
// database.
@@ -2387,8 +2384,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion25ToCurrent) {
TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringLabels) {
// This schema is taken from a build prior to the change of column type for
// credit_cards.billing_address from string to int.
- ASSERT_NO_FATAL_FAILURE(
- LoadDatabase(FilePath(FILE_PATH_LITERAL("version_26.sql"))));
+ ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_26.sql")));
// Verify pre-conditions. These are expectations for version 26 of the
// database.
@@ -2460,8 +2456,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringLabels) {
TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringIDs) {
// This schema is taken from a build prior to the change of column type for
// credit_cards.billing_address from string to int.
- ASSERT_NO_FATAL_FAILURE(
- LoadDatabase(FilePath(FILE_PATH_LITERAL("version_26.sql"))));
+ ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_26.sql")));
// Verify pre-conditions. These are expectations for version 26 of the
// database.
@@ -2533,8 +2528,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringIDs) {
// as the column added in 28 was nuked in 29.
TEST_F(WebDatabaseMigrationTest, MigrateVersion27ToCurrent) {
// Initialize the database.
- ASSERT_NO_FATAL_FAILURE(
- LoadDatabase(FilePath(FILE_PATH_LITERAL("version_27.sql"))));
+ ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_27.sql")));
// Verify pre-conditions. These are expectations for version 28 of the
// database.
@@ -2552,8 +2546,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion27ToCurrent) {
// Makes sure instant_url is added correctly to keywords.
TEST_F(WebDatabaseMigrationTest, MigrateVersion28ToCurrent) {
// Initialize the database.
- ASSERT_NO_FATAL_FAILURE(
- LoadDatabase(FilePath(FILE_PATH_LITERAL("version_28.sql"))));
+ ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_28.sql")));
// Verify pre-conditions. These are expectations for version 28 of the
// database.
@@ -2572,8 +2565,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion28ToCurrent) {
// credit_cards.
TEST_F(WebDatabaseMigrationTest, MigrateVersion29ToCurrent) {
// Initialize the database.
- ASSERT_NO_FATAL_FAILURE(
- LoadDatabase(FilePath(FILE_PATH_LITERAL("version_29.sql"))));
+ ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_29.sql")));
// Verify pre-conditions. These are expectations for version 29 of the
// database.
@@ -2638,8 +2630,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion29ToCurrent) {
// Makes sure guids are added to autofill_profiles and credit_cards tables.
TEST_F(WebDatabaseMigrationTest, MigrateVersion30ToCurrent) {
// Initialize the database.
- ASSERT_NO_FATAL_FAILURE(
- LoadDatabase(FilePath(FILE_PATH_LITERAL("version_30.sql"))));
+ ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_30.sql")));
// Verify pre-conditions. These are expectations for version 29 of the
// database.
@@ -2691,8 +2682,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion30ToCurrent) {
// columns.
TEST_F(WebDatabaseMigrationTest, MigrateVersion31ToCurrent) {
// Initialize the database.
- ASSERT_NO_FATAL_FAILURE(
- LoadDatabase(FilePath(FILE_PATH_LITERAL("version_31.sql"))));
+ ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_31.sql")));
// Verify pre-conditions. These are expectations for version 30 of the
// database.
@@ -2840,8 +2830,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion31ToCurrent) {
// and phone.
TEST_F(WebDatabaseMigrationTest, MigrateVersion32ToCurrent) {
// Initialize the database.
- ASSERT_NO_FATAL_FAILURE(
- LoadDatabase(FilePath(FILE_PATH_LITERAL("version_32.sql"))));
+ ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_32.sql")));
// Verify pre-conditions. These are expectations for version 32 of the
// database.
@@ -2954,7 +2943,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion32ToCurrent) {
EXPECT_EQ(ASCIIToUTF16("Los Altos"), s1.ColumnString16(4));
EXPECT_EQ(ASCIIToUTF16("CA"), s1.ColumnString16(5));
EXPECT_EQ(ASCIIToUTF16("94022"), s1.ColumnString16(6));
- EXPECT_EQ(ASCIIToUTF16("USA"), s1.ColumnString16(7));
+ EXPECT_EQ(ASCIIToUTF16("United States"), s1.ColumnString16(7));
EXPECT_EQ(1297882100L, s1.ColumnInt64(8));
// John P. Doe.
@@ -2966,7 +2955,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion32ToCurrent) {
EXPECT_EQ(ASCIIToUTF16("Los Altos"), s1.ColumnString16(4));
EXPECT_EQ(ASCIIToUTF16("CA"), s1.ColumnString16(5));
EXPECT_EQ(ASCIIToUTF16("94022"), s1.ColumnString16(6));
- EXPECT_EQ(ASCIIToUTF16("USA"), s1.ColumnString16(7));
+ EXPECT_EQ(ASCIIToUTF16("United States"), s1.ColumnString16(7));
EXPECT_EQ(1297882100L, s1.ColumnInt64(8));
// Dave Smith.
@@ -2978,7 +2967,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion32ToCurrent) {
EXPECT_EQ(ASCIIToUTF16("Los Altos"), s1.ColumnString16(4));
EXPECT_EQ(ASCIIToUTF16("CA"), s1.ColumnString16(5));
EXPECT_EQ(ASCIIToUTF16("94022"), s1.ColumnString16(6));
- EXPECT_EQ(ASCIIToUTF16("USA"), s1.ColumnString16(7));
+ EXPECT_EQ(ASCIIToUTF16("United States"), s1.ColumnString16(7));
EXPECT_EQ(1297882100L, s1.ColumnInt64(8));
// Dave Smith (Part 2).
@@ -2990,7 +2979,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion32ToCurrent) {
EXPECT_EQ(ASCIIToUTF16("Los Altos"), s1.ColumnString16(4));
EXPECT_EQ(ASCIIToUTF16("CA"), s1.ColumnString16(5));
EXPECT_EQ(ASCIIToUTF16("94022"), s1.ColumnString16(6));
- EXPECT_EQ(ASCIIToUTF16("USA"), s1.ColumnString16(7));
+ EXPECT_EQ(ASCIIToUTF16("United States"), s1.ColumnString16(7));
EXPECT_EQ(1297882100L, s1.ColumnInt64(8));
// Alfred E Newman.
@@ -3014,7 +3003,7 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion32ToCurrent) {
EXPECT_EQ(ASCIIToUTF16("Los Altos"), s1.ColumnString16(4));
EXPECT_EQ(ASCIIToUTF16("CA"), s1.ColumnString16(5));
EXPECT_EQ(ASCIIToUTF16("94022"), s1.ColumnString16(6));
- EXPECT_EQ(ASCIIToUTF16("USA"), s1.ColumnString16(7));
+ EXPECT_EQ(ASCIIToUTF16("United States"), s1.ColumnString16(7));
EXPECT_EQ(1297882100L, s1.ColumnInt64(8));
// That should be all.
@@ -3131,3 +3120,55 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion32ToCurrent) {
EXPECT_FALSE(s4.Step());
}
}
+
+// Adds a column for the autofill profile's country code.
+TEST_F(WebDatabaseMigrationTest, MigrateVersion33ToCurrent) {
+ // Initialize the database.
+ ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_33.sql")));
+
+ // Verify pre-conditions. These are expectations for version 33 of the
+ // database.
+ {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+
+ EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles",
+ "country_code"));
+
+ // Check that the country value is the one we expect.
+ sql::Statement s(
+ connection.GetUniqueStatement("SELECT country FROM autofill_profiles"));
+
+ ASSERT_TRUE(s.Step());
+ std::string country = s.ColumnString(0);
+ EXPECT_EQ("United States", country);
+ }
+
+ // Load the database via the WebDatabase class and migrate the database to
+ // the current version.
+ {
+ WebDatabase db;
+ ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath()));
+ }
+
+ // Verify post-conditions. These are expectations for current version of the
+ // database.
+ {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+
+ // Check version.
+ EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
+
+ ASSERT_TRUE(connection.DoesColumnExist("autofill_profiles",
+ "country_code"));
+
+ // Check that the country code is properly converted.
+ sql::Statement s(connection.GetUniqueStatement(
+ "SELECT country_code FROM autofill_profiles"));
+
+ ASSERT_TRUE(s.Step());
+ std::string country_code = s.ColumnString(0);
+ EXPECT_EQ("US", country_code);
+ }
+}