| 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 ASSERT_TRUE(file_util::CreateDirectory(path)); | 163 ASSERT_TRUE(file_util::CreateDirectory(path)); |
| 164 | 164 |
| 165 BlockFiles files(path); | 165 BlockFiles files(path); |
| 166 ASSERT_TRUE(files.Init(true)); | 166 ASSERT_TRUE(files.Init(true)); |
| 167 | 167 |
| 168 std::wstring filename = files.Name(0); | 168 std::wstring filename = files.Name(0); |
| 169 files.CloseFiles(); | 169 files.CloseFiles(); |
| 170 // Truncate one of the files. | 170 // Truncate one of the files. |
| 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(FilePath::FromWStringHack(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. | 181 // An invalid file can be detected after init. |
| 182 TEST_F(DiskCacheTest, BlockFiles_InvalidFile) { | 182 TEST_F(DiskCacheTest, BlockFiles_InvalidFile) { |
| 183 std::wstring path = GetCachePath(); | 183 std::wstring path = GetCachePath(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 198 EXPECT_EQ(kBlockHeaderSize, | 198 EXPECT_EQ(kBlockHeaderSize, |
| 199 file_util::WriteFile(filename, header, kBlockHeaderSize)); | 199 file_util::WriteFile(filename, header, kBlockHeaderSize)); |
| 200 | 200 |
| 201 EXPECT_TRUE(NULL == files.GetFile(addr)); | 201 EXPECT_TRUE(NULL == files.GetFile(addr)); |
| 202 | 202 |
| 203 // The file should not have been cached (it is still invalid). | 203 // The file should not have been cached (it is still invalid). |
| 204 EXPECT_TRUE(NULL == files.GetFile(addr)); | 204 EXPECT_TRUE(NULL == files.GetFile(addr)); |
| 205 } | 205 } |
| 206 | 206 |
| 207 } // namespace disk_cache | 207 } // namespace disk_cache |
| OLD | NEW |