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

Unified Diff: chrome/browser/sync/syncable/directory_backing_store_unittest.cc

Issue 1733008: Delete and recreate the sync database if it is corrupt. (Closed)
Patch Set: Use scoped_sqlite_db_ptr Created 10 years, 8 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/sync/syncable/directory_backing_store_unittest.cc
diff --git a/chrome/browser/sync/syncable/directory_backing_store_unittest.cc b/chrome/browser/sync/syncable/directory_backing_store_unittest.cc
index bf5dfde678162d8a3a2a6d7ee9d780e1523e4ecb..777a163a09d9b42c4c5d0f4279e1ca10ab1c7197 100644
--- a/chrome/browser/sync/syncable/directory_backing_store_unittest.cc
+++ b/chrome/browser/sync/syncable/directory_backing_store_unittest.cc
@@ -10,6 +10,7 @@
#include "app/sql/statement.h"
#include "app/sql/transaction.h"
#include "base/file_path.h"
+#include "base/file_util.h"
#include "base/scoped_ptr.h"
#include "base/scoped_temp_dir.h"
#include "base/stl_util-inl.h"
@@ -870,4 +871,27 @@ TEST_F(DirectoryBackingStoreTest, ModelTypeIds) {
}
}
+TEST_F(DirectoryBackingStoreTest, Corruption) {
+ {
+ scoped_ptr<DirectoryBackingStore> dbs(
+ new DirectoryBackingStore(GetUsername(), GetDatabasePath()));
+ EXPECT_TRUE(dbs->BeginLoad());
+ }
+ std::string bad_data("BAD DATA");
+ EXPECT_TRUE(file_util::WriteFile(GetDatabasePath(), bad_data.data(),
+ bad_data.size()));
+ {
+ scoped_ptr<DirectoryBackingStore> dbs(
+ new DirectoryBackingStore(GetUsername(), GetDatabasePath()));
+
+ // In release mode, we expect the sync database to nuke itself and start
+ // over if it detects invalid/corrupted data.
+#if defined(NDEBUG)
+ EXPECT_TRUE(dbs->BeginLoad());
+#else
+ EXPECT_DEATH(dbs->BeginLoad(), "sqlite error");
+#endif
+ }
+}
+
} // namespace syncable

Powered by Google App Engine
This is Rietveld 408576698