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

Unified Diff: trunk/src/sql/connection_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_unittest.cc ('k') | trunk/src/sql/recovery.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trunk/src/sql/connection_unittest.cc
===================================================================
--- trunk/src/sql/connection_unittest.cc (revision 235594)
+++ trunk/src/sql/connection_unittest.cc (working copy)
@@ -11,7 +11,6 @@
#include "sql/statement.h"
#include "sql/test/error_callback_support.h"
#include "sql/test/scoped_error_ignorer.h"
-#include "sql/test/test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/sqlite/sqlite3.h"
@@ -503,14 +502,32 @@
// essential for cases where the Open() can fail entirely, so the
// Raze() cannot happen later. Additionally test that when the
// callback does this during Open(), the open is retried and succeeds.
+//
+// Most corruptions seen in the wild seem to happen when two pages in
+// the database were not written transactionally (the transaction
+// changed both, but one wasn't successfully written for some reason).
+// A special case of that is when the header indicates that the
+// database contains more pages than are in the file. This breaks
+// things at a very basic level, verify that Raze() can handle it.
TEST_F(SQLConnectionTest, RazeCallbackReopen) {
const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)";
ASSERT_TRUE(db().Execute(kCreateSql));
ASSERT_EQ(1, SqliteMasterCount(&db()));
+ int page_size = 0;
+ {
+ sql::Statement s(db().GetUniqueStatement("PRAGMA page_size"));
+ ASSERT_TRUE(s.Step());
+ page_size = s.ColumnInt(0);
+ }
db().Close();
- // Corrupt the database so that nothing works, including PRAGMAs.
- ASSERT_TRUE(sql::test::CorruptSizeInHeader(db_path()));
+ // Trim a single page from the end of the file.
+ {
+ file_util::ScopedFILE file(file_util::OpenFile(db_path(), "rb+"));
+ ASSERT_TRUE(file.get() != NULL);
+ ASSERT_EQ(0, fseek(file.get(), -page_size, SEEK_END));
+ ASSERT_TRUE(file_util::TruncateFile(file.get()));
+ }
// Open() will succeed, even though the PRAGMA calls within will
// fail with SQLITE_CORRUPT, as will this PRAGMA.
« no previous file with comments | « trunk/src/chrome/browser/history/thumbnail_database_unittest.cc ('k') | trunk/src/sql/recovery.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698