diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 21:59:03 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 21:59:03 +0000 |
commit | e819b55cf062822a23280b4da7760abfd2a86e64 (patch) | |
tree | 8da62133f794b047ccf3bb57f3bd805ae7f036b8 /net/disk_cache/block_files_unittest.cc | |
parent | f321a984b66500ea0063549612992cf784da12b6 (diff) | |
download | chromium_src-e819b55cf062822a23280b4da7760abfd2a86e64.zip chromium_src-e819b55cf062822a23280b4da7760abfd2a86e64.tar.gz chromium_src-e819b55cf062822a23280b4da7760abfd2a86e64.tar.bz2 |
Disk Cache: cleanup of OpenBlockFile.
Don't add the file to the list of open files until
it passes all sanity checks.
BUG=18174
TEST=unittest
Review URL: http://codereview.chromium.org/164336
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23090 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/block_files_unittest.cc')
-rw-r--r-- | net/disk_cache/block_files_unittest.cc | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/net/disk_cache/block_files_unittest.cc b/net/disk_cache/block_files_unittest.cc index e7647d7..6256a3d 100644 --- a/net/disk_cache/block_files_unittest.cc +++ b/net/disk_cache/block_files_unittest.cc @@ -178,4 +178,30 @@ TEST_F(DiskCacheTest, BlockFiles_ZeroSizeFile) { 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 |