summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/block_files_unittest.cc
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-13 18:41:58 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-13 18:41:58 +0000
commite25d44ddde58a2e0fd05fd4e8f9c9632fb7209af (patch)
tree26054af3acf60a1109f76ba52ff4f827ae205e29 /net/disk_cache/block_files_unittest.cc
parentc369fd304932e51ad62cb3bd9cb5608665518e00 (diff)
downloadchromium_src-e25d44ddde58a2e0fd05fd4e8f9c9632fb7209af.zip
chromium_src-e25d44ddde58a2e0fd05fd4e8f9c9632fb7209af.tar.gz
chromium_src-e25d44ddde58a2e0fd05fd4e8f9c9632fb7209af.tar.bz2
Disk cache: detect block files that are shorter than expected
and return a proper net error code from async IO. BUG=88968 TEST=net_unittests Review URL: http://codereview.chromium.org/7351007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92390 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/block_files_unittest.cc')
-rw-r--r--net/disk_cache/block_files_unittest.cc26
1 files changed, 25 insertions, 1 deletions
diff --git a/net/disk_cache/block_files_unittest.cc b/net/disk_cache/block_files_unittest.cc
index 90bf048..7ee08d3 100644
--- a/net/disk_cache/block_files_unittest.cc
+++ b/net/disk_cache/block_files_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -177,6 +177,30 @@ TEST_F(DiskCacheTest, BlockFiles_ZeroSizeFile) {
ASSERT_FALSE(files.Init(false));
}
+// Handling of truncated files (non empty).
+TEST_F(DiskCacheTest, BlockFiles_TruncatedFile) {
+ FilePath path = GetCacheFilePath();
+ ASSERT_TRUE(DeleteCache(path));
+ ASSERT_TRUE(file_util::CreateDirectory(path));
+
+ BlockFiles files(path);
+ ASSERT_TRUE(files.Init(true));
+ Addr address;
+ EXPECT_TRUE(files.CreateBlock(RANKINGS, 2, &address));
+
+ FilePath filename = files.Name(0);
+ files.CloseFiles();
+ // Truncate one of the files.
+ {
+ scoped_refptr<File> file(new File);
+ ASSERT_TRUE(file->Init(filename));
+ EXPECT_TRUE(file->SetLength(15000));
+ }
+
+ // Initializing should fail, not crash.
+ ASSERT_FALSE(files.Init(false));
+}
+
// An invalid file can be detected after init.
TEST_F(DiskCacheTest, BlockFiles_InvalidFile) {
FilePath path = GetCacheFilePath();