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

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

Issue 10381016: Remove the "autogenerate keyword" bit on TemplateURL. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 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
Index: chrome/browser/webdata/web_database_migration_unittest.cc
===================================================================
--- chrome/browser/webdata/web_database_migration_unittest.cc (revision 135424)
+++ chrome/browser/webdata/web_database_migration_unittest.cc (working copy)
@@ -194,7 +194,7 @@
DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest);
};
-const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 44;
+const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 45;
void WebDatabaseMigrationTest::LoadDatabase(const FilePath::StringType& file) {
std::string contents;
@@ -303,7 +303,6 @@
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
@@ -329,50 +328,9 @@
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) {
- // This schema is taken from a build prior to the addition of the |keywords|
- // |logo_id| column.
- ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_24.sql")));
-
- // 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"));
- }
-}
-
// Tests that the |keywords| |created_by_policy| column gets added to the schema
// for a version 25 database.
TEST_F(WebDatabaseMigrationTest, MigrateVersion25ToCurrent) {
@@ -618,12 +576,10 @@
EXPECT_EQ(std::string("{google:baseSuggestURL}search?client=chrome&hl="
"{language}&q={searchTerms}"), s2.ColumnString(11));
EXPECT_EQ(1, s2.ColumnInt(12));
- EXPECT_TRUE(s2.ColumnBool(13));
- EXPECT_EQ(6245, s2.ColumnInt(14));
- EXPECT_FALSE(s2.ColumnBool(15));
+ EXPECT_EQ(false, s2.ColumnBool(13));
+ EXPECT_EQ(std::string(), s2.ColumnString(14));
+ EXPECT_EQ(0, s2.ColumnInt(15));
EXPECT_EQ(std::string(), s2.ColumnString(16));
- EXPECT_EQ(0, s2.ColumnInt(17));
- EXPECT_EQ(std::string(), s2.ColumnString(18));
}
}
@@ -1845,14 +1801,12 @@
EXPECT_EQ("{google:baseSuggestURL}search?client=chrome&hl={language}&"
"q={searchTerms}", s.ColumnString(11));
EXPECT_EQ(1, s.ColumnInt(12));
- EXPECT_TRUE(s.ColumnBool(13));
- EXPECT_EQ(6262, s.ColumnInt(14));
- EXPECT_FALSE(s.ColumnBool(15));
+ EXPECT_EQ(false, s.ColumnBool(13));
EXPECT_EQ("{google:baseURL}webhp?{google:RLZ}sourceid=chrome-instant&"
"ie={inputEncoding}&ion=1{searchTerms}&nord=1",
- s.ColumnString(16));
- EXPECT_EQ(0, s.ColumnInt(17));
- EXPECT_EQ("{1234-5678-90AB-CDEF}", s.ColumnString(18));
+ s.ColumnString(14));
+ EXPECT_EQ(0, s.ColumnInt(15));
+ EXPECT_EQ("{1234-5678-90AB-CDEF}", s.ColumnString(16));
EXPECT_FALSE(s.Step());
}
@@ -1936,3 +1890,133 @@
EXPECT_FALSE(default_search_provider_id_backup_signature.empty());
}
}
+
+#if !defined(GOOGLE_CHROME_BUILD)
+// Tests that the |autogenerate_keyword| and |logo_id| columns get removed from
+// the keyword table schema for a version 45 database.
+//
+// This is enabled on Chromium only because a valid signature is required for
+// this test, which makes it key-dependent.
+TEST_F(WebDatabaseMigrationTest, MigrateVersion44ToCurrent) {
+ ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_44.sql")));
+
+ // Verify pre-conditions. These are expectations for version 44 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, 44, 44));
+
+ ASSERT_TRUE(connection.DoesColumnExist("keywords", "autogenerate_keyword"));
+ ASSERT_TRUE(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()));
+ ASSERT_FALSE(db.GetKeywordTable()->DidDefaultSearchProviderChange());
+
+ // The backup table should match the keyword table.
+ std::string keywords_contents;
+ EXPECT_TRUE(db.GetKeywordTable()->GetTableContents("keywords",
+ kCurrentTestedVersionNumber, &keywords_contents));
+ std::string keywords_backup_contents;
+ EXPECT_TRUE(db.GetKeywordTable()->GetTableContents("keywords_backup",
+ kCurrentTestedVersionNumber, &keywords_backup_contents));
+ EXPECT_EQ(keywords_contents, keywords_backup_contents);
+ }
+
+ // 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));
+
+ sql::MetaTable meta_table;
+ ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber,
+ kCurrentTestedVersionNumber));
+
+ // We should have removed this obsolete key.
+ std::string default_search_provider_backup;
+ EXPECT_FALSE(meta_table.GetValue("Default Search Provider Backup",
+ &default_search_provider_backup));
+
+ // Two columns should have been removed.
+ EXPECT_FALSE(connection.DoesColumnExist("keywords",
+ "autogenerate_keyword"));
+ EXPECT_FALSE(connection.DoesColumnExist("keywords", "logo_id"));
+ }
+}
+#endif // !defined(GOOGLE_CHROME_BUILD)
+
+// Like MigrateVersion44ToCurrent 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
+// official builds as well.
+TEST_F(WebDatabaseMigrationTest, MigrateVersion44CorruptBackupToCurrent) {
+ ASSERT_NO_FATAL_FAILURE(
+ LoadDatabase(FILE_PATH_LITERAL("version_44_backup_corrupt.sql")));
+
+ // Verify pre-conditions. These are expectations for version 44 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, 44, 44));
+
+ ASSERT_TRUE(connection.DoesColumnExist("keywords", "autogenerate_keyword"));
+ ASSERT_TRUE(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()));
+ // 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));
+
+ sql::MetaTable meta_table;
+ ASSERT_TRUE(meta_table.Init(&connection, kCurrentTestedVersionNumber,
+ kCurrentTestedVersionNumber));
+
+ // We should have removed this obsolete key.
+ std::string default_search_provider_backup;
+ EXPECT_FALSE(meta_table.GetValue("Default Search Provider Backup",
+ &default_search_provider_backup));
+
+ // Two columns should have been removed.
+ EXPECT_FALSE(connection.DoesColumnExist("keywords",
+ "autogenerate_keyword"));
+ EXPECT_FALSE(connection.DoesColumnExist("keywords", "logo_id"));
+
+ // The backup table should be gone.
+ EXPECT_FALSE(connection.DoesTableExist("keywords_backup"));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698