Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7657)

Unified Diff: chrome/browser/webdata/web_database_unittest.cc

Issue 3295002: Migration unit tests to web database for missing images on the search ballot (Closed)
Patch Set: More EXPECT, remove dead method. Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/webdata/web_database.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/webdata/web_database_unittest.cc
diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc
index 48301ff16f0a18b0c971d301f9d4a9d6637b410b..154abf75f09d5a62832ccbd29da1e930960b9a25 100644
--- a/chrome/browser/webdata/web_database_unittest.cc
+++ b/chrome/browser/webdata/web_database_unittest.cc
@@ -9,8 +9,10 @@
#include <utility>
#include <vector>
+#include "app/sql/statement.h"
#include "base/file_util.h"
#include "base/path_service.h"
+#include "base/scoped_temp_dir.h"
#include "base/stl_util-inl.h"
#include "base/string_number_conversions.h"
#include "base/string16.h"
@@ -89,6 +91,10 @@ bool CompareAutofillEntries(const AutofillEntry& a, const AutofillEntry& b) {
}
class WebDatabaseTest : public testing::Test {
+ public:
+ WebDatabaseTest() {}
+ virtual ~WebDatabaseTest() {}
+
protected:
typedef std::vector<AutofillChange> AutofillChangeList;
typedef std::set<AutofillEntry,
@@ -173,6 +179,9 @@ class WebDatabaseTest : public testing::Test {
}
FilePath file_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(WebDatabaseTest);
};
TEST_F(WebDatabaseTest, Keywords) {
@@ -1507,3 +1516,443 @@ TEST_F(WebDatabaseTest, Autofill_GetAllAutofillEntries_TwoSame) {
EXPECT_EQ(0U, expected_entries.size());
}
+
+// The WebDatabaseMigrationTest encapsulates testing of database migrations.
+// Specifically, these tests are intended to exercise any schema changes in
+// the WebDatabase and data migrations that occur in
+// |WebDatabase::MigrateOldVersionsAsNeeded()|.
+class WebDatabaseMigrationTest : public testing::Test {
+ public:
+ WebDatabaseMigrationTest() {}
+ virtual ~WebDatabaseMigrationTest() {}
+
+ virtual void SetUp() {
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ }
+
+ protected:
+ // Current tested version number. When adding a migration in
+ // |WebDatabase::MigrateOldVersionsAsNeeded()| and changing the version number
+ // |kCurrentVersionNumber| this value should change to reflect the new version
+ // number and a new migration test added below.
+ static const int kCurrentTestedVersionNumber;
+
+ FilePath GetDatabasePath() {
+ const FilePath::CharType kWebDatabaseFilename[] =
+ FILE_PATH_LITERAL("TestWebDatabase.sqlite3");
+ return temp_dir_.path().Append(FilePath(kWebDatabaseFilename));
+ }
+
+ static int VersionFromConnection(sql::Connection* connection) {
+ // Get version.
+ sql::Statement s(connection->GetUniqueStatement(
+ "SELECT value FROM meta WHERE key='version'"));
+ if (!s.Step())
+ return 0;
+ return s.ColumnInt(0);
+ }
+
+ // The tables in these "Setup" routines were generated by launching the
+ // Chromium application prior to schema change, then using the sqlite
+ // command-line application to dump the contents of the "Web Data" database.
+ // Like this:
+ // > .output foo_dump.sql
+ // > .dump
+ void SetUpVersion22Database();
+ void SetUpVersion22CorruptDatabase();
+ void SetUpVersion24Database();
+
+ private:
+ ScopedTempDir temp_dir_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest);
+};
+
+const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 25;
+
+// 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.
+void WebDatabaseMigrationTest::SetUpVersion22Database() {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+ ASSERT_TRUE(connection.BeginTransaction());
+ ASSERT_TRUE(connection.Execute(
+ "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY,"
+ "value LONGVARCHAR);"
+ "INSERT INTO \"meta\" VALUES('version','22');"
+ "INSERT INTO \"meta\" VALUES('last_compatible_version','21');"
+ "INSERT INTO \"meta\" VALUES('Builtin Keyword Version','27');"
+ "INSERT INTO \"meta\" VALUES('Default Search Provider ID','7');"
+ "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,show_in_default_list INTEGER,"
+ "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,"
+ "autogenerate_keyword INTEGER DEFAULT 0);"
+ "INSERT INTO \"keywords\" VALUES(2,'Google','google.com',"
+ "'http://www.google.com/favicon.ico',"
+ "'{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}"
+ "{google:originalQueryForSuggestion}sourceid=chrome&ie={inputEncoding}"
+ "&q={searchTerms}',1,1,'',0,0,'UTF-8','{google:baseSuggestURL}search?"
+ "client=chrome&hl={language}&q={searchTerms}',1,1);"
+ "INSERT INTO \"keywords\" VALUES(3,'Yahoo!','yahoo.com',"
+ "'http://search.yahoo.com/favicon.ico','http://search.yahoo.com/search?"
+ "ei={inputEncoding}&fr=crmas&p={searchTerms}',1,1,'',0,0,'UTF-8',"
+ "'http://ff.search.yahoo.com/gossip?output=fxjson&"
+ "command={searchTerms}',2,0);"
+ "INSERT INTO \"keywords\" VALUES(4,'Bing','bing.com',"
+ "'http://www.bing.com/s/wlflag.ico','http://www.bing.com/search?"
+ "setmkt=en-US&q={searchTerms}',1,1,'',0,0,'UTF-8',"
+ "'http://api.bing.com/osjson.aspx?query={searchTerms}&"
+ "language={language}',3,0);"
+ "INSERT INTO \"keywords\" VALUES(5,'Wikipedia (en)','en.wikipedia.org','',"
+ "'http://en.wikipedia.org/w/index.php?title=Special:Search&"
+ "search={searchTerms}',1,0,'',1283287335,0,'','',0,0);"
+ "INSERT INTO \"keywords\" VALUES(6,'NYTimes','query.nytimes.com','',"
+ "'http://query.nytimes.com/gst/handler.html?query={searchTerms}&"
+ "opensearch=1',1,0,'',1283287335,0,'','',0,0);"
+ "INSERT INTO \"keywords\" VALUES(7,'eBay','rover.ebay.com','',"
+ "'http://rover.ebay.com/rover/1/711-43047-14818-1/4?"
+ "satitle={searchTerms}',1,0,'',1283287335,0,'','',0,0);"
+ "INSERT INTO \"keywords\" VALUES(8,'ff','ff','','http://ff{searchTerms}',"
+ "0,0,'',1283287356,0,'','',0,0);"
+ "CREATE TABLE logins (origin_url VARCHAR NOT NULL, action_url VARCHAR, "
+ "username_element VARCHAR, username_value VARCHAR, "
+ "password_element VARCHAR, password_value BLOB, submit_element VARCHAR,"
+ "signon_realm VARCHAR NOT NULL,ssl_valid INTEGER NOT NULL,"
+ "preferred INTEGER NOT NULL,date_created INTEGER NOT NULL,"
+ "blacklisted_by_user INTEGER NOT NULL,scheme INTEGER NOT NULL,"
+ "UNIQUE (origin_url, username_element, username_value, "
+ "password_element, submit_element, signon_realm));"
+ "CREATE TABLE ie7_logins (url_hash VARCHAR NOT NULL, password_value BLOB, "
+ "date_created INTEGER NOT NULL,UNIQUE (url_hash));"
+ "CREATE TABLE web_app_icons (url LONGVARCHAR,width int,height int,"
+ "image BLOB, UNIQUE (url, width, height));"
+ "CREATE TABLE web_apps (url LONGVARCHAR UNIQUE,"
+ "has_all_images INTEGER NOT NULL);"
+ "CREATE TABLE autofill (name VARCHAR, value VARCHAR, value_lower VARCHAR, "
+ "pair_id INTEGER PRIMARY KEY, count INTEGER DEFAULT 1);"
+ "CREATE TABLE autofill_dates ( pair_id INTEGER DEFAULT 0,"
+ "date_created INTEGER DEFAULT 0);"
+ "CREATE INDEX logins_signon ON logins (signon_realm);"
+ "CREATE INDEX ie7_logins_hash ON ie7_logins (url_hash);"
+ "CREATE INDEX web_apps_url_index ON web_apps (url);"
+ "CREATE INDEX autofill_name ON autofill (name);"
+ "CREATE INDEX autofill_name_value_lower ON autofill (name, value_lower);"
+ "CREATE INDEX autofill_dates_pair_id ON autofill_dates (pair_id);"));
+ ASSERT_TRUE(connection.CommitTransaction());
+}
+
+// This schema is taken from a build after the addition of the |credit_card|
+// 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).
+void WebDatabaseMigrationTest::SetUpVersion22CorruptDatabase() {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+ ASSERT_TRUE(connection.BeginTransaction());
+ ASSERT_TRUE(connection.Execute(
+ "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY,"
+ "value LONGVARCHAR);"
+ "INSERT INTO \"meta\" VALUES('version','22');"
+ "INSERT INTO \"meta\" VALUES('last_compatible_version','21');"
+ "INSERT INTO \"meta\" VALUES('Default Search Provider ID','2');"
+ "INSERT INTO \"meta\" VALUES('Builtin Keyword Version','29');"
+ "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,"
+ "show_in_default_list INTEGER,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,"
+ "autogenerate_keyword INTEGER DEFAULT 0);"
+ "INSERT INTO \"keywords\" VALUES(2,'Google','google.com',"
+ "'http://www.google.com/favicon.ico','{google:baseURL}search?"
+ "{google:RLZ}{google:acceptedSuggestion}"
+ "{google:originalQueryForSuggestion}sourceid=chrome&"
+ "ie={inputEncoding}&q={searchTerms}',1,1,'',0,0,'UTF-8',"
+ "'{google:baseSuggestURL}search?client=chrome&hl={language}&"
+ "q={searchTerms}',1,1);"
+ "INSERT INTO \"keywords\" VALUES(3,'Yahoo!','yahoo.com',"
+ "'http://search.yahoo.com/favicon.ico',"
+ "'http://search.yahoo.com/search?ei={inputEncoding}&fr=crmas&"
+ "p={searchTerms}',1,1,'',0,0,'UTF-8',"
+ "'http://ff.search.yahoo.com/gossip?output=fxjson&"
+ "command={searchTerms}',2,0);"
+ "INSERT INTO \"keywords\" VALUES(4,'Bing','bing.com',"
+ "'http://www.bing.com/s/wlflag.ico','http://www.bing.com/search?"
+ "setmkt=en-US&q={searchTerms}',1,1,'',0,0,'UTF-8',"
+ "'http://api.bing.com/osjson.aspx?query={searchTerms}&"
+ "language={language}',3,0);"
+ "INSERT INTO \"keywords\" VALUES(5,'Wikipedia (en)','en.wikipedia.org',"
+ "'','http://en.wikipedia.org/w/index.php?title=Special:Search&"
+ "search={searchTerms}',1,0,'',1283287335,0,'','',0,0);"
+ "INSERT INTO \"keywords\" VALUES(6,'NYTimes','query.nytimes.com','',"
+ "'http://query.nytimes.com/gst/handler.html?query={searchTerms}&"
+ "opensearch=1',1,0,'',1283287335,0,'','',0,0);"
+ "INSERT INTO \"keywords\" VALUES(7,'eBay','rover.ebay.com','',"
+ "'http://rover.ebay.com/rover/1/711-43047-14818-1/4?"
+ "satitle={searchTerms}',1,0,'',1283287335,0,'','',0,0);"
+ "INSERT INTO \"keywords\" VALUES(8,'ff','ff','','http://ff{searchTerms}'"
+ ",0,0,'',1283287356,0,'','',0,0);"
+ "CREATE TABLE logins (origin_url VARCHAR NOT NULL, action_url VARCHAR, "
+ "username_element VARCHAR, username_value VARCHAR, "
+ "password_element VARCHAR, password_value BLOB, "
+ "submit_element VARCHAR, signon_realm VARCHAR NOT NULL,"
+ "ssl_valid INTEGER NOT NULL,preferred INTEGER NOT NULL,"
+ "date_created INTEGER NOT NULL,blacklisted_by_user INTEGER NOT NULL,"
+ "scheme INTEGER NOT NULL,UNIQUE (origin_url, username_element, "
+ "username_value, password_element, submit_element, signon_realm));"
+ "CREATE TABLE ie7_logins (url_hash VARCHAR NOT NULL, password_value BLOB,"
+ "date_created INTEGER NOT NULL,UNIQUE (url_hash));"
+ "CREATE TABLE web_app_icons (url LONGVARCHAR,width int,height int,"
+ "image BLOB, UNIQUE (url, width, height));"
+ "CREATE TABLE web_apps (url LONGVARCHAR UNIQUE,"
+ "has_all_images INTEGER NOT NULL);"
+ "CREATE TABLE autofill (name VARCHAR, value VARCHAR, value_lower VARCHAR,"
+ "pair_id INTEGER PRIMARY KEY, count INTEGER DEFAULT 1);"
+ "CREATE TABLE autofill_dates ( pair_id INTEGER DEFAULT 0,"
+ "date_created INTEGER DEFAULT 0);"
+ "CREATE TABLE autofill_profiles ( label VARCHAR, "
+ "unique_id INTEGER PRIMARY KEY, first_name VARCHAR, "
+ "middle_name VARCHAR, last_name VARCHAR, email VARCHAR, "
+ "company_name VARCHAR, address_line_1 VARCHAR, "
+ "address_line_2 VARCHAR, city VARCHAR, state VARCHAR, "
+ "zipcode VARCHAR, country VARCHAR, phone VARCHAR, fax VARCHAR);"
+ "CREATE TABLE credit_cards ( label VARCHAR, "
+ "unique_id INTEGER PRIMARY KEY, name_on_card VARCHAR, type VARCHAR,"
+ "card_number VARCHAR, expiration_month INTEGER, "
+ "expiration_year INTEGER, verification_code VARCHAR, "
+ "billing_address VARCHAR, shipping_address VARCHAR, "
+ "card_number_encrypted BLOB, verification_code_encrypted BLOB);"
+ "CREATE INDEX logins_signon ON logins (signon_realm);"
+ "CREATE INDEX ie7_logins_hash ON ie7_logins (url_hash);"
+ "CREATE INDEX web_apps_url_index ON web_apps (url);"
+ "CREATE INDEX autofill_name ON autofill (name);"
+ "CREATE INDEX autofill_name_value_lower ON autofill (name, value_lower);"
+ "CREATE INDEX autofill_dates_pair_id ON autofill_dates (pair_id);"
+ "CREATE INDEX autofill_profiles_label_index ON autofill_profiles (label);"
+ "CREATE INDEX credit_cards_label_index ON credit_cards (label);"));
+ ASSERT_TRUE(connection.CommitTransaction());
+}
+
+// This schema is taken from a build prior to the addition of the |keywords|
+// |logo_id| column.
+void WebDatabaseMigrationTest::SetUpVersion24Database() {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+ ASSERT_TRUE(connection.BeginTransaction());
+ ASSERT_TRUE(connection.Execute(
+ "CREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY,"
+ "value LONGVARCHAR);"
+ "INSERT INTO \"meta\" VALUES('version','24');"
+ "INSERT INTO \"meta\" VALUES('last_compatible_version','24');"
+ "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,show_in_default_list INTEGER,"
+ "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,"
+ "autogenerate_keyword INTEGER DEFAULT 0);"
+ "CREATE TABLE logins (origin_url VARCHAR NOT NULL, action_url VARCHAR,"
+ "username_element VARCHAR, username_value VARCHAR,"
+ "password_element VARCHAR, password_value BLOB, submit_element VARCHAR,"
+ "signon_realm VARCHAR NOT NULL,"
+ "ssl_valid INTEGER NOT NULL,preferred INTEGER NOT NULL,"
+ "date_created INTEGER NOT NULL,blacklisted_by_user INTEGER NOT NULL,"
+ "scheme INTEGER NOT NULL,UNIQUE (origin_url, username_element,"
+ "username_value, password_element, submit_element, signon_realm));"
+ "CREATE TABLE web_app_icons (url LONGVARCHAR,width int,height int,"
+ "image BLOB, UNIQUE (url, width, height));"
+ "CREATE TABLE web_apps (url LONGVARCHAR UNIQUE,"
+ "has_all_images INTEGER NOT NULL);"
+ "CREATE TABLE autofill (name VARCHAR, value VARCHAR, value_lower VARCHAR,"
+ "pair_id INTEGER PRIMARY KEY, count INTEGER DEFAULT 1);"
+ "CREATE TABLE autofill_dates ( pair_id INTEGER DEFAULT 0,"
+ "date_created INTEGER DEFAULT 0);"
+ "CREATE TABLE autofill_profiles ( label VARCHAR,"
+ "unique_id INTEGER PRIMARY KEY, first_name VARCHAR,"
+ "middle_name VARCHAR, last_name VARCHAR, email VARCHAR,"
+ "company_name VARCHAR, address_line_1 VARCHAR, address_line_2 VARCHAR,"
+ "city VARCHAR, state VARCHAR, zipcode VARCHAR, country VARCHAR,"
+ "phone VARCHAR, fax VARCHAR);"
+ "CREATE TABLE credit_cards ( label VARCHAR, unique_id INTEGER PRIMARY KEY,"
+ "name_on_card VARCHAR, type VARCHAR, card_number VARCHAR,"
+ "expiration_month INTEGER, expiration_year INTEGER,"
+ "verification_code VARCHAR, billing_address VARCHAR,"
+ "shipping_address VARCHAR, card_number_encrypted BLOB,"
+ "verification_code_encrypted BLOB);"
+ "CREATE TABLE token_service (service VARCHAR PRIMARY KEY NOT NULL,"
+ "encrypted_token BLOB);"
+ "CREATE INDEX logins_signon ON logins (signon_realm);"
+ "CREATE INDEX web_apps_url_index ON web_apps (url);"
+ "CREATE INDEX autofill_name ON autofill (name);"
+ "CREATE INDEX autofill_name_value_lower ON autofill (name, value_lower);"
+ "CREATE INDEX autofill_dates_pair_id ON autofill_dates (pair_id);"
+ "CREATE INDEX autofill_profiles_label_index ON autofill_profiles (label);"
+ "CREATE INDEX credit_cards_label_index ON credit_cards (label);"));
+ ASSERT_TRUE(connection.CommitTransaction());
+}
+
+// Tests that the all migrations from an empty database succeed.
+TEST_F(WebDatabaseMigrationTest, MigrateEmptyToCurrent) {
+ // 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));
+
+ // Check that expected tables are present.
+ EXPECT_TRUE(connection.DoesTableExist("meta"));
+ EXPECT_TRUE(connection.DoesTableExist("keywords"));
+ EXPECT_TRUE(connection.DoesTableExist("logins"));
+ EXPECT_TRUE(connection.DoesTableExist("web_app_icons"));
+ EXPECT_TRUE(connection.DoesTableExist("web_apps"));
+ EXPECT_TRUE(connection.DoesTableExist("autofill"));
+ EXPECT_TRUE(connection.DoesTableExist("autofill_dates"));
+ EXPECT_TRUE(connection.DoesTableExist("autofill_profiles"));
+ EXPECT_TRUE(connection.DoesTableExist("credit_cards"));
+ EXPECT_TRUE(connection.DoesTableExist("token_service"));
+ }
+}
+
+// Tests that the |credit_card| table gets added to the schema for a version 22
+// database.
+TEST_F(WebDatabaseMigrationTest, MigrateVersion22ToCurrent) {
+ // Initialize the database.
+ SetUpVersion22Database();
+
+ // Verify pre-conditions.
+ {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+
+ // No |credit_card| table prior to version 23.
+ ASSERT_FALSE(connection.DoesColumnExist("credit_cards", "unique_id"));
+ ASSERT_FALSE(
+ connection.DoesColumnExist("credit_cards", "card_number_encrypted"));
+ }
+
+ // 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));
+
+ // |credit_card| table now exists.
+ EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "unique_id"));
+ EXPECT_TRUE(
+ connection.DoesColumnExist("credit_cards", "card_number_encrypted"));
+ }
+}
+
+// Tests that the |credit_card| table gets added to the schema for a corrupt
+// version 22 database. The corruption is that the |credit_cards| table exists
+// but the schema version number was not set correctly to 23 or later. This
+// test exercises code introduced to fix bug http://crbug.com/50699 that
+// resulted from the corruption.
+TEST_F(WebDatabaseMigrationTest, MigrateVersion22CorruptedToCurrent) {
+ // Initialize the database.
+ SetUpVersion22CorruptDatabase();
+
+ // Verify pre-conditions. These are expectations for corrupt version 22 of
+ // the database.
+ {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+
+ // Columns existing and not existing before current version.
+ ASSERT_TRUE(connection.DoesColumnExist("credit_cards", "unique_id"));
+ ASSERT_TRUE(
+ connection.DoesColumnExist("credit_cards", "card_number_encrypted"));
+ ASSERT_TRUE(connection.DoesColumnExist("keywords", "id"));
+ ASSERT_FALSE(connection.DoesColumnExist("keywords", "logo_id"));
+ }
+
+ // 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));
+
+
+ // Columns existing and not existing before version 25.
+ EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "unique_id"));
+ EXPECT_TRUE(
+ connection.DoesColumnExist("credit_cards", "card_number_encrypted"));
+ EXPECT_TRUE(connection.DoesColumnExist("keywords", "id"));
+ EXPECT_TRUE(connection.DoesColumnExist("keywords", "logo_id"));
+ }
+}
+
+// Tests that the |keywords| |logo_id| column gets added to the schema for a
+// version 24 database.
+TEST_F(WebDatabaseMigrationTest, MigrateVersion24ToCurrent) {
+ // Initialize the database.
+ SetUpVersion24Database();
+
+ // Verify pre-conditions. These are expectations for version 24 of the
+ // database.
+ {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+
+ // Columns existing and not existing before current version.
+ ASSERT_TRUE(connection.DoesColumnExist("keywords", "id"));
+ ASSERT_FALSE(connection.DoesColumnExist("keywords", "logo_id"));
+ }
+
+ // 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));
+
+ // |keywords| |logo_id| column should have been added.
+ EXPECT_TRUE(connection.DoesColumnExist("keywords", "id"));
+ EXPECT_TRUE(connection.DoesColumnExist("keywords", "logo_id"));
+ }
+}
« no previous file with comments | « chrome/browser/webdata/web_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698