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

Unified Diff: net/disk_cache/block_files_unittest.cc

Issue 164336: Disk Cache: cleanup of OpenBlockFile.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 4 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
« no previous file with comments | « net/disk_cache/block_files.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/block_files_unittest.cc
===================================================================
--- net/disk_cache/block_files_unittest.cc (revision 22968)
+++ net/disk_cache/block_files_unittest.cc (working copy)
@@ -178,4 +178,30 @@
ASSERT_FALSE(files.Init(false));
}
+// An invalid file can be detected after init.
+TEST_F(DiskCacheTest, BlockFiles_InvalidFile) {
+ std::wstring path = GetCachePath();
+ ASSERT_TRUE(DeleteCache(path.c_str()));
+ ASSERT_TRUE(file_util::CreateDirectory(path));
+
+ BlockFiles files(path);
+ ASSERT_TRUE(files.Init(true));
+
+ // Let's access block 10 of file 5. (There is no file).
+ Addr addr(BLOCK_256, 1, 5, 10);
+ EXPECT_TRUE(NULL == files.GetFile(addr));
+
+ // Let's create an invalid file.
+ FilePath filename(FilePath::FromWStringHack(files.Name(5)));
+ char header[kBlockHeaderSize];
+ memset(header, 'a', kBlockHeaderSize);
+ EXPECT_EQ(kBlockHeaderSize,
+ file_util::WriteFile(filename, header, kBlockHeaderSize));
+
+ EXPECT_TRUE(NULL == files.GetFile(addr));
+
+ // The file should not have been cached (it is still invalid).
+ EXPECT_TRUE(NULL == files.GetFile(addr));
+}
+
} // namespace disk_cache
« no previous file with comments | « net/disk_cache/block_files.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698