Index: webkit/browser/appcache/appcache_database_unittest.cc |
diff --git a/webkit/browser/appcache/appcache_database_unittest.cc b/webkit/browser/appcache/appcache_database_unittest.cc |
index 71e4a089caa9ab2600266d12e0613f6ec7893f93..798bca9342ca00ca49af6642f28927bb83f89848 100644 |
--- a/webkit/browser/appcache/appcache_database_unittest.cc |
+++ b/webkit/browser/appcache/appcache_database_unittest.cc |
@@ -73,6 +73,46 @@ TEST(AppCacheDatabaseTest, ReCreate) { |
EXPECT_FALSE(base::PathExists(kOtherFile)); |
} |
+#ifdef NDEBUG |
+// Only run in release builds because sql::Connection and familiy |
+// crank up DLOG(FATAL)'ness and this test presents it with |
+// intentionally bad data which causes debug builds to exit instead |
+// of run to completion. In release builds, errors the are deliverd |
+// to the consumer so we can test the error handling of the consumer. |
+TEST(AppCacheDatabaseTest, QuickIntegrityCheck) { |
+ // Real files on disk for this test too, a corrupt database file. |
+ base::ScopedTempDir temp_dir; |
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
+ base::FilePath mock_dir = temp_dir.path().AppendASCII("mock"); |
+ ASSERT_TRUE(base::CreateDirectory(mock_dir)); |
Scott Hess - ex-Googler
2013/12/13 23:15:46
Yeah, that's what I meant.
|
+ |
+ const base::FilePath kDbFile = mock_dir.AppendASCII("appcache.db"); |
+ const std::string kCorruptData("deadbeef"); |
+ EXPECT_EQ(static_cast<int>(kCorruptData.length()), |
+ file_util::WriteFile( |
+ kDbFile, kCorruptData.data(), kCorruptData.length())); |
+ const base::FilePath kOtherFile = mock_dir.AppendASCII("other_file"); |
+ EXPECT_EQ(3, file_util::WriteFile(kOtherFile, "foo", 3)); |
+ |
+ // See that the sql::Connection opens, but fails to pass the integrity check. |
+ sql::Connection raw_db; |
+ EXPECT_TRUE(raw_db.Open(kDbFile)); |
+ EXPECT_FALSE(raw_db.QuickIntegrityCheck()); |
+ raw_db.Close(); |
+ |
+ // Should delete the corrupt data and start over. |
+ AppCacheDatabase db(kDbFile); |
+ EXPECT_TRUE(db.LazyOpen(true)); |
+ EXPECT_FALSE(base::PathExists(kOtherFile)); |
+ EXPECT_TRUE(base::PathExists(kDbFile)); |
+ db.CloseConnection(); |
+ |
+ // See that the Connection now passes its integrity check. |
+ EXPECT_TRUE(raw_db.Open(kDbFile)); |
+ EXPECT_TRUE(raw_db.QuickIntegrityCheck()); |
+} |
+#endif // NDEBUG |
+ |
TEST(AppCacheDatabaseTest, ExperimentalFlags) { |
const char kExperimentFlagsKey[] = "ExperimentFlags"; |
std::string kInjectedFlags("exp1,exp2"); |