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..cad83ab332786a1d92bd3fa14d76e2b337ac579a 100644 |
--- a/webkit/browser/appcache/appcache_database_unittest.cc |
+++ b/webkit/browser/appcache/appcache_database_unittest.cc |
@@ -73,6 +73,43 @@ 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. |
Scott Hess - ex-Googler
2013/12/13 20:03:45
Does sql::ScopedErrorIgnorer not handle this? The
michaeln
2013/12/13 22:46:05
It does not, other DLOG(FATAL)'s get hit given the
Scott Hess - ex-Googler
2013/12/13 23:15:46
I think CorruptSizeInHeader() will let it get thro
michaeln
2013/12/13 23:57:01
The test is modifed to use that helper, but... it
|
+TEST(AppCacheDatabaseTest, QuickIntegrityCheck) { |
+ // Real files on disk for this test too, a corrupt database file. |
+ base::ScopedTempDir temp_dir; |
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
+ const base::FilePath kDbFile = temp_dir.path().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 = temp_dir.path().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)); |
Scott Hess - ex-Googler
2013/12/13 20:03:45
If I understand things correctly, the AppCacheData
michaeln
2013/12/13 22:46:05
Done.
|
+ 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"); |