| Index: net/disk_cache/block_files_unittest.cc
|
| diff --git a/net/disk_cache/block_files_unittest.cc b/net/disk_cache/block_files_unittest.cc
|
| index 90bf0487477b32adc5e72f0534b1772964075251..4455dab54b180f1940e6df4d20b4370ac57ba87a 100644
|
| --- a/net/disk_cache/block_files_unittest.cc
|
| +++ b/net/disk_cache/block_files_unittest.cc
|
| @@ -28,11 +28,9 @@ int NumberOfFiles(const FilePath& path) {
|
| namespace disk_cache {
|
|
|
| TEST_F(DiskCacheTest, BlockFiles_Grow) {
|
| - FilePath path = GetCacheFilePath();
|
| - ASSERT_TRUE(DeleteCache(path));
|
| - ASSERT_TRUE(file_util::CreateDirectory(path));
|
| + ScopedTestCache test_cache;
|
|
|
| - BlockFiles files(path);
|
| + BlockFiles files(test_cache.path());
|
| ASSERT_TRUE(files.Init(true));
|
|
|
| const int kMaxSize = 35000;
|
| @@ -42,7 +40,7 @@ TEST_F(DiskCacheTest, BlockFiles_Grow) {
|
| for (int i = 0; i < kMaxSize; i++) {
|
| EXPECT_TRUE(files.CreateBlock(RANKINGS, 4, &address[i]));
|
| }
|
| - EXPECT_EQ(6, NumberOfFiles(path));
|
| + EXPECT_EQ(6, NumberOfFiles(test_cache.path()));
|
|
|
| // Make sure we don't keep adding files.
|
| for (int i = 0; i < kMaxSize * 4; i += 2) {
|
| @@ -50,16 +48,14 @@ TEST_F(DiskCacheTest, BlockFiles_Grow) {
|
| files.DeleteBlock(address[target], false);
|
| EXPECT_TRUE(files.CreateBlock(RANKINGS, 4, &address[target]));
|
| }
|
| - EXPECT_EQ(6, NumberOfFiles(path));
|
| + EXPECT_EQ(6, NumberOfFiles(test_cache.path()));
|
| }
|
|
|
| // We should be able to delete empty block files.
|
| TEST_F(DiskCacheTest, BlockFiles_Shrink) {
|
| - FilePath path = GetCacheFilePath();
|
| - ASSERT_TRUE(DeleteCache(path));
|
| - ASSERT_TRUE(file_util::CreateDirectory(path));
|
| + ScopedTestCache test_cache;
|
|
|
| - BlockFiles files(path);
|
| + BlockFiles files(test_cache.path());
|
| ASSERT_TRUE(files.Init(true));
|
|
|
| const int kMaxSize = 35000;
|
| @@ -74,16 +70,14 @@ TEST_F(DiskCacheTest, BlockFiles_Shrink) {
|
| for (int i = 0; i < kMaxSize; i++) {
|
| files.DeleteBlock(address[i], false);
|
| }
|
| - EXPECT_EQ(4, NumberOfFiles(path));
|
| + EXPECT_EQ(4, NumberOfFiles(test_cache.path()));
|
| }
|
|
|
| // Handling of block files not properly closed.
|
| TEST_F(DiskCacheTest, BlockFiles_Recover) {
|
| - FilePath path = GetCacheFilePath();
|
| - ASSERT_TRUE(DeleteCache(path));
|
| - ASSERT_TRUE(file_util::CreateDirectory(path));
|
| + ScopedTestCache test_cache;
|
|
|
| - BlockFiles files(path);
|
| + BlockFiles files(test_cache.path());
|
| ASSERT_TRUE(files.Init(true));
|
|
|
| const int kNumEntries = 2000;
|
| @@ -157,11 +151,9 @@ TEST_F(DiskCacheTest, BlockFiles_Recover) {
|
|
|
| // Handling of truncated files.
|
| TEST_F(DiskCacheTest, BlockFiles_ZeroSizeFile) {
|
| - FilePath path = GetCacheFilePath();
|
| - ASSERT_TRUE(DeleteCache(path));
|
| - ASSERT_TRUE(file_util::CreateDirectory(path));
|
| + ScopedTestCache test_cache;
|
|
|
| - BlockFiles files(path);
|
| + BlockFiles files(test_cache.path());
|
| ASSERT_TRUE(files.Init(true));
|
|
|
| FilePath filename = files.Name(0);
|
| @@ -179,11 +171,9 @@ TEST_F(DiskCacheTest, BlockFiles_ZeroSizeFile) {
|
|
|
| // An invalid file can be detected after init.
|
| TEST_F(DiskCacheTest, BlockFiles_InvalidFile) {
|
| - FilePath path = GetCacheFilePath();
|
| - ASSERT_TRUE(DeleteCache(path));
|
| - ASSERT_TRUE(file_util::CreateDirectory(path));
|
| + ScopedTestCache test_cache;
|
|
|
| - BlockFiles files(path);
|
| + BlockFiles files(test_cache.path());
|
| ASSERT_TRUE(files.Init(true));
|
|
|
| // Let's access block 10 of file 5. (There is no file).
|
| @@ -205,10 +195,11 @@ TEST_F(DiskCacheTest, BlockFiles_InvalidFile) {
|
|
|
| // Tests that we generate the correct file stats.
|
| TEST_F(DiskCacheTest, BlockFiles_Stats) {
|
| - ASSERT_TRUE(CopyTestCache("remove_load1"));
|
| - FilePath path = GetCacheFilePath();
|
| + ScopedTestCache test_cache;
|
|
|
| - BlockFiles files(path);
|
| + ASSERT_TRUE(CopyTestCache("remove_load1", test_cache.path()));
|
| +
|
| + BlockFiles files(test_cache.path());
|
| ASSERT_TRUE(files.Init(false));
|
| int used, load;
|
|
|
| @@ -227,11 +218,9 @@ TEST_F(DiskCacheTest, BlockFiles_Stats) {
|
|
|
| // Tests that we add and remove blocks correctly.
|
| TEST_F(DiskCacheTest, AllocationMap) {
|
| - FilePath path = GetCacheFilePath();
|
| - ASSERT_TRUE(DeleteCache(path));
|
| - ASSERT_TRUE(file_util::CreateDirectory(path));
|
| + ScopedTestCache test_cache;
|
|
|
| - BlockFiles files(path);
|
| + BlockFiles files(test_cache.path());
|
| ASSERT_TRUE(files.Init(true));
|
|
|
| // Create a bunch of entries.
|
|
|