OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "net/disk_cache/block_files.h" | 6 #include "net/disk_cache/block_files.h" |
7 #include "net/disk_cache/disk_cache.h" | 7 #include "net/disk_cache/disk_cache.h" |
8 #include "net/disk_cache/disk_cache_test_base.h" | 8 #include "net/disk_cache/disk_cache_test_base.h" |
9 #include "net/disk_cache/disk_cache_test_util.h" | 9 #include "net/disk_cache/disk_cache_test_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 { | 171 { |
172 scoped_refptr<File> file(new File); | 172 scoped_refptr<File> file(new File); |
173 ASSERT_TRUE(file->Init(filename)); | 173 ASSERT_TRUE(file->Init(filename)); |
174 EXPECT_TRUE(file->SetLength(0)); | 174 EXPECT_TRUE(file->SetLength(0)); |
175 } | 175 } |
176 | 176 |
177 // Initializing should fail, not crash. | 177 // Initializing should fail, not crash. |
178 ASSERT_FALSE(files.Init(false)); | 178 ASSERT_FALSE(files.Init(false)); |
179 } | 179 } |
180 | 180 |
| 181 // An invalid file can be detected after init. |
| 182 TEST_F(DiskCacheTest, BlockFiles_InvalidFile) { |
| 183 std::wstring path = GetCachePath(); |
| 184 ASSERT_TRUE(DeleteCache(path.c_str())); |
| 185 ASSERT_TRUE(file_util::CreateDirectory(path)); |
| 186 |
| 187 BlockFiles files(path); |
| 188 ASSERT_TRUE(files.Init(true)); |
| 189 |
| 190 // Let's access block 10 of file 5. (There is no file). |
| 191 Addr addr(BLOCK_256, 1, 5, 10); |
| 192 EXPECT_TRUE(NULL == files.GetFile(addr)); |
| 193 |
| 194 // Let's create an invalid file. |
| 195 FilePath filename(FilePath::FromWStringHack(files.Name(5))); |
| 196 char header[kBlockHeaderSize]; |
| 197 memset(header, 'a', kBlockHeaderSize); |
| 198 EXPECT_EQ(kBlockHeaderSize, |
| 199 file_util::WriteFile(filename, header, kBlockHeaderSize)); |
| 200 |
| 201 EXPECT_TRUE(NULL == files.GetFile(addr)); |
| 202 |
| 203 // The file should not have been cached (it is still invalid). |
| 204 EXPECT_TRUE(NULL == files.GetFile(addr)); |
| 205 } |
| 206 |
181 } // namespace disk_cache | 207 } // namespace disk_cache |
OLD | NEW |