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

Unified Diff: trunk/src/chrome/browser/history/thumbnail_database_unittest.cc

Issue 74933002: Revert 235492 "[sql] Recover Favicons v5 databases, with more re..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 1 month 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 | « trunk/src/chrome/browser/history/thumbnail_database.cc ('k') | trunk/src/sql/connection_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trunk/src/chrome/browser/history/thumbnail_database_unittest.cc
===================================================================
--- trunk/src/chrome/browser/history/thumbnail_database_unittest.cc (revision 235594)
+++ trunk/src/chrome/browser/history/thumbnail_database_unittest.cc (working copy)
@@ -790,7 +790,12 @@
{
sql::Connection raw_db;
EXPECT_TRUE(raw_db.Open(file_name_));
- ASSERT_EQ("ok", sql::test::IntegrityCheck(&raw_db));
+ {
+ sql::Statement statement(
+ raw_db.GetUniqueStatement("PRAGMA integrity_check"));
+ EXPECT_TRUE(statement.Step());
+ ASSERT_EQ("ok", statement.ColumnString(0));
+ }
const char kIndexName[] = "icon_mapping_page_url_idx";
const int idx_root_page = GetRootPage(&raw_db, kIndexName);
@@ -813,7 +818,10 @@
{
sql::Connection raw_db;
EXPECT_TRUE(raw_db.Open(file_name_));
- ASSERT_NE("ok", sql::test::IntegrityCheck(&raw_db));
+ sql::Statement statement(
+ raw_db.GetUniqueStatement("PRAGMA integrity_check"));
+ EXPECT_TRUE(statement.Step());
+ ASSERT_NE("ok", statement.ColumnString(0));
}
// Open the database and access the corrupt index.
@@ -836,7 +844,10 @@
{
sql::Connection raw_db;
EXPECT_TRUE(raw_db.Open(file_name_));
- ASSERT_EQ("ok", sql::test::IntegrityCheck(&raw_db));
+ sql::Statement statement(
+ raw_db.GetUniqueStatement("PRAGMA integrity_check"));
+ EXPECT_TRUE(statement.Step());
+ EXPECT_EQ("ok", statement.ColumnString(0));
// Check that the expected tables exist.
VerifyTablesAndColumns(&raw_db);
@@ -856,8 +867,21 @@
kIconUrl1, kLargeSize, sizeof(kBlob1), kBlob1));
}
- // Corrupt the database again by adjusting the header.
- EXPECT_TRUE(sql::test::CorruptSizeInHeader(file_name_));
+ // Corrupt the database again by making the actual file shorter than
+ // the header expects.
+ {
+ int64 db_size = 0;
+ EXPECT_TRUE(file_util::GetFileSize(file_name_, &db_size));
+ {
+ sql::Connection raw_db;
+ EXPECT_TRUE(raw_db.Open(file_name_));
+ EXPECT_TRUE(raw_db.Execute("CREATE TABLE t(x)"));
+ }
+ file_util::ScopedFILE file(file_util::OpenFile(file_name_, "rb+"));
+ ASSERT_TRUE(file.get() != NULL);
+ EXPECT_EQ(0, fseek(file.get(), static_cast<long>(db_size), SEEK_SET));
+ EXPECT_TRUE(file_util::TruncateFile(file.get()));
+ }
// Database is unusable at the SQLite level.
{
@@ -894,10 +918,23 @@
// (which would upgrade it).
EXPECT_TRUE(CreateDatabaseFromSQL(file_name_, "Favicons.v6.sql"));
- // Corrupt the database again by adjusting the header. This form of
- // corruption will cause immediate failures during Open(), before
- // the migration code runs, so the version-6 recovery will occur.
- EXPECT_TRUE(sql::test::CorruptSizeInHeader(file_name_));
+ // Corrupt the database by making the actual file shorter than the
+ // SQLite header expects. This form of corruption will cause
+ // immediate failures during Open(), before the migration code runs,
+ // so the version-6 recovery will occur.
+ {
+ int64 db_size = 0;
+ EXPECT_TRUE(file_util::GetFileSize(file_name_, &db_size));
+ {
+ sql::Connection raw_db;
+ EXPECT_TRUE(raw_db.Open(file_name_));
+ EXPECT_TRUE(raw_db.Execute("CREATE TABLE t(x)"));
+ }
+ file_util::ScopedFILE file(file_util::OpenFile(file_name_, "rb+"));
+ ASSERT_TRUE(file.get() != NULL);
+ EXPECT_EQ(0, fseek(file.get(), static_cast<long>(db_size), SEEK_SET));
+ EXPECT_TRUE(file_util::TruncateFile(file.get()));
+ }
// Database is unusable at the SQLite level.
{
@@ -933,64 +970,16 @@
{
sql::Connection raw_db;
EXPECT_TRUE(raw_db.Open(file_name_));
- ASSERT_EQ("ok", sql::test::IntegrityCheck(&raw_db));
+ sql::Statement statement(
+ raw_db.GetUniqueStatement("PRAGMA integrity_check"));
+ EXPECT_TRUE(statement.Step());
+ EXPECT_EQ("ok", statement.ColumnString(0));
// Check that the expected tables exist.
VerifyTablesAndColumns(&raw_db);
}
}
-TEST_F(ThumbnailDatabaseTest, Recovery5) {
- // Create an example database without loading into ThumbnailDatabase
- // (which would upgrade it).
- EXPECT_TRUE(CreateDatabaseFromSQL(file_name_, "Favicons.v5.sql"));
-
- // Corrupt the database again by adjusting the header. This form of
- // corruption will cause immediate failures during Open(), before
- // the migration code runs, so the version-5 recovery will occur.
- EXPECT_TRUE(sql::test::CorruptSizeInHeader(file_name_));
-
- // Database is unusable at the SQLite level.
- {
- sql::ScopedErrorIgnorer ignore_errors;
- ignore_errors.IgnoreError(SQLITE_CORRUPT);
- sql::Connection raw_db;
- EXPECT_TRUE(raw_db.Open(file_name_));
- EXPECT_FALSE(raw_db.IsSQLValid("PRAGMA integrity_check"));
- ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
- }
-
- // Database should be recovered during open.
- {
- sql::ScopedErrorIgnorer ignore_errors;
- ignore_errors.IgnoreError(SQLITE_CORRUPT);
- ThumbnailDatabase db;
- ASSERT_EQ(sql::INIT_OK, db.Init(file_name_));
-
- // Test that some data is present, copied from
- // ThumbnailDatabaseTest.Version5 .
- EXPECT_TRUE(
- CheckPageHasIcon(&db, kPageUrl3, chrome::FAVICON,
- kIconUrl1, gfx::Size(), sizeof(kBlob1), kBlob1));
- EXPECT_TRUE(
- CheckPageHasIcon(&db, kPageUrl3, chrome::TOUCH_ICON,
- kIconUrl3, gfx::Size(), sizeof(kBlob2), kBlob2));
-
- ASSERT_TRUE(ignore_errors.CheckIgnoredErrors());
- }
-
- // Check that the database is recovered at a SQLite level, and that
- // the current schema is in place.
- {
- sql::Connection raw_db;
- EXPECT_TRUE(raw_db.Open(file_name_));
- ASSERT_EQ("ok", sql::test::IntegrityCheck(&raw_db));
-
- // Check that the expected tables exist.
- VerifyTablesAndColumns(&raw_db);
- }
-}
-
// Test that various broken schema found in the wild can be opened
// successfully, and result in the correct schema.
TEST_F(ThumbnailDatabaseTest, WildSchema) {
« no previous file with comments | « trunk/src/chrome/browser/history/thumbnail_database.cc ('k') | trunk/src/sql/connection_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698