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

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

Issue 11552020: Add search_terms_replacement_key field to TemplateURL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed logic to check search_terms_replacement_key in template_url.cc. This is for a next CL. Created 8 years 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
Index: chrome/browser/webdata/web_database_migration_unittest.cc
diff --git a/chrome/browser/webdata/web_database_migration_unittest.cc b/chrome/browser/webdata/web_database_migration_unittest.cc
index 5cca55b96936d6ad6bbe10843bcd21b8a58902fd..aab7278553607ba785c0fe0e462508275d97d1e6 100644
--- a/chrome/browser/webdata/web_database_migration_unittest.cc
+++ b/chrome/browser/webdata/web_database_migration_unittest.cc
@@ -195,7 +195,7 @@ class WebDatabaseMigrationTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest);
};
-const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 47;
+const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 48;
void WebDatabaseMigrationTest::LoadDatabase(const FilePath::StringType& file) {
std::string contents;
@@ -2312,3 +2312,111 @@ TEST_F(WebDatabaseMigrationTest, MigrateVersion46CorruptBackupToCurrent) {
EXPECT_FALSE(connection.DoesTableExist("keywords_backup"));
}
}
+
+#if !defined(GOOGLE_CHROME_BUILD)
+// Tests that the |search_terms_replacement_key| column is added to the keyword
+// table schema for a version 48 database.
+//
+// This is enabled on Chromium only because a valid signature is required for
+// this test, which makes it key-dependent.
+TEST_F(WebDatabaseMigrationTest, MigrateVersion47ToCurrent) {
+ ASSERT_NO_FATAL_FAILURE(
+ LoadDatabase(FILE_PATH_LITERAL("version_47.sql")));
+
+ // Verify pre-conditions. These are expectations for version 47 of the
+ // database.
+ {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+ ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
+
+ sql::MetaTable meta_table;
+ ASSERT_TRUE(meta_table.Init(&connection, 47, 47));
+
+ ASSERT_FALSE(connection.DoesColumnExist("keywords",
+ "search_terms_replacement_key"));
+ ASSERT_FALSE(connection.DoesColumnExist("keywords_backup",
+ "search_terms_replacement_key"));
+ }
+
+ // 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()));
+ ASSERT_FALSE(db.GetKeywordTable()->DidDefaultSearchProviderChange());
+ }
+
+ // Verify post-conditions. These are expectations for current version of the
+ // database.
+ {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+ ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
+
+ // Check version.
+ EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
+
+ // A new column should have been created.
+ EXPECT_TRUE(connection.DoesColumnExist("keywords",
+ "search_terms_replacement_key"));
+ ASSERT_TRUE(connection.DoesColumnExist("keywords_backup",
+ "search_terms_replacement_key"));
+ }
+}
+#endif // !defined(GOOGLE_CHROME_BUILD)
+
+// Like MigrateVersion47ToCurrent above, but with a corrupt backup signature.
+// This should result in us dropping the backup table but successfully migrating
+// otherwise.
+//
+// Because this test doesn't rely on a valid signature, we can run it on
dhollowa 2012/12/13 01:23:08 nit: This comment looks like a copy/paste error si
beaudoin 2012/12/13 17:14:53 "We _can_ run it on official builds as well." :)
+// official builds as well.
+TEST_F(WebDatabaseMigrationTest, MigrateVersion47CorruptBackupToCurrent) {
+ ASSERT_NO_FATAL_FAILURE(
+ LoadDatabase(FILE_PATH_LITERAL("version_47_backup_corrupt.sql")));
+
+ // Verify pre-conditions. These are expectations for version 46 of the
+ // database.
+ {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+ ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
+
+ sql::MetaTable meta_table;
+ ASSERT_TRUE(meta_table.Init(&connection, 47, 47));
+
+ ASSERT_FALSE(connection.DoesColumnExist("keywords",
+ "search_terms_replacement_key"));
+ ASSERT_FALSE(connection.DoesColumnExist("keywords_backup",
+ "search_terms_replacement_key"));
+ }
+
+ // 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()));
+ // We should detect a "search provider change" as a side effect of dropping
+ // the backup table.
+ ASSERT_TRUE(db.GetKeywordTable()->DidDefaultSearchProviderChange());
+ }
+
+ // Verify post-conditions. These are expectations for current version of the
+ // database.
+ {
+ sql::Connection connection;
+ ASSERT_TRUE(connection.Open(GetDatabasePath()));
+ ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
+
+ // Check version.
+ EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
+
+ // A new column should have been created.
+ EXPECT_TRUE(connection.DoesColumnExist("keywords",
+ "search_terms_replacement_key"));
+
+ // The backup table should be gone.
+ EXPECT_FALSE(connection.DoesTableExist("keywords_backup"));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698