OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
7 #include "net/disk_cache/cache_util.h" | 7 #include "net/disk_cache/cache_util.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "testing/platform_test.h" | 9 #include "testing/platform_test.h" |
10 | 10 |
11 namespace disk_cache { | 11 namespace disk_cache { |
12 | 12 |
13 class CacheUtilTest : public PlatformTest { | 13 class CacheUtilTest : public PlatformTest { |
14 public: | 14 public: |
15 virtual void SetUp() { | 15 virtual void SetUp() { |
16 PlatformTest::SetUp(); | 16 PlatformTest::SetUp(); |
17 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); | 17 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir()); |
18 cache_dir_ = tmp_dir_.path().Append(FILE_PATH_LITERAL("Cache")); | 18 cache_dir_ = tmp_dir_.path().Append(FILE_PATH_LITERAL("Cache")); |
19 file1_ = base::FilePath(cache_dir_.Append(FILE_PATH_LITERAL("file01"))); | 19 file1_ = base::FilePath(cache_dir_.Append(FILE_PATH_LITERAL("file01"))); |
20 file2_ = base::FilePath(cache_dir_.Append(FILE_PATH_LITERAL(".file02"))); | 20 file2_ = base::FilePath(cache_dir_.Append(FILE_PATH_LITERAL(".file02"))); |
21 dir1_ = base::FilePath(cache_dir_.Append(FILE_PATH_LITERAL("dir01"))); | 21 dir1_ = base::FilePath(cache_dir_.Append(FILE_PATH_LITERAL("dir01"))); |
22 file3_ = base::FilePath(dir1_.Append(FILE_PATH_LITERAL("file03"))); | 22 file3_ = base::FilePath(dir1_.Append(FILE_PATH_LITERAL("file03"))); |
23 ASSERT_TRUE(base::CreateDirectory(cache_dir_)); | 23 ASSERT_TRUE(base::CreateDirectory(cache_dir_)); |
24 FILE *fp = base::OpenFile(file1_, "w"); | 24 FILE* fp = base::OpenFile(file1_, "w"); |
25 ASSERT_TRUE(fp != NULL); | 25 ASSERT_TRUE(fp != NULL); |
26 base::CloseFile(fp); | 26 base::CloseFile(fp); |
27 fp = base::OpenFile(file2_, "w"); | 27 fp = base::OpenFile(file2_, "w"); |
28 ASSERT_TRUE(fp != NULL); | 28 ASSERT_TRUE(fp != NULL); |
29 base::CloseFile(fp); | 29 base::CloseFile(fp); |
30 ASSERT_TRUE(base::CreateDirectory(dir1_)); | 30 ASSERT_TRUE(base::CreateDirectory(dir1_)); |
31 fp = base::OpenFile(file3_, "w"); | 31 fp = base::OpenFile(file3_, "w"); |
32 ASSERT_TRUE(fp != NULL); | 32 ASSERT_TRUE(fp != NULL); |
33 base::CloseFile(fp); | 33 base::CloseFile(fp); |
34 dest_dir_ = tmp_dir_.path().Append(FILE_PATH_LITERAL("old_Cache_001")); | 34 dest_dir_ = tmp_dir_.path().Append(FILE_PATH_LITERAL("old_Cache_001")); |
(...skipping 16 matching lines...) Expand all Loading... |
51 base::FilePath dest_dir1_; | 51 base::FilePath dest_dir1_; |
52 }; | 52 }; |
53 | 53 |
54 TEST_F(CacheUtilTest, MoveCache) { | 54 TEST_F(CacheUtilTest, MoveCache) { |
55 EXPECT_TRUE(disk_cache::MoveCache(cache_dir_, dest_dir_)); | 55 EXPECT_TRUE(disk_cache::MoveCache(cache_dir_, dest_dir_)); |
56 EXPECT_TRUE(base::PathExists(dest_dir_)); | 56 EXPECT_TRUE(base::PathExists(dest_dir_)); |
57 EXPECT_TRUE(base::PathExists(dest_file1_)); | 57 EXPECT_TRUE(base::PathExists(dest_file1_)); |
58 EXPECT_TRUE(base::PathExists(dest_file2_)); | 58 EXPECT_TRUE(base::PathExists(dest_file2_)); |
59 EXPECT_TRUE(base::PathExists(dest_dir1_)); | 59 EXPECT_TRUE(base::PathExists(dest_dir1_)); |
60 #if defined(OS_CHROMEOS) | 60 #if defined(OS_CHROMEOS) |
61 EXPECT_TRUE(base::PathExists(cache_dir_)); // old cache dir stays | 61 EXPECT_TRUE(base::PathExists(cache_dir_)); // old cache dir stays |
62 #else | 62 #else |
63 EXPECT_FALSE(base::PathExists(cache_dir_)); // old cache is gone | 63 EXPECT_FALSE(base::PathExists(cache_dir_)); // old cache is gone |
64 #endif | 64 #endif |
65 EXPECT_FALSE(base::PathExists(file1_)); | 65 EXPECT_FALSE(base::PathExists(file1_)); |
66 EXPECT_FALSE(base::PathExists(file2_)); | 66 EXPECT_FALSE(base::PathExists(file2_)); |
67 EXPECT_FALSE(base::PathExists(dir1_)); | 67 EXPECT_FALSE(base::PathExists(dir1_)); |
68 } | 68 } |
69 | 69 |
70 TEST_F(CacheUtilTest, DeleteCache) { | 70 TEST_F(CacheUtilTest, DeleteCache) { |
71 disk_cache::DeleteCache(cache_dir_, false); | 71 disk_cache::DeleteCache(cache_dir_, false); |
72 EXPECT_TRUE(base::PathExists(cache_dir_)); // cache dir stays | 72 EXPECT_TRUE(base::PathExists(cache_dir_)); // cache dir stays |
73 EXPECT_FALSE(base::PathExists(dir1_)); | 73 EXPECT_FALSE(base::PathExists(dir1_)); |
74 EXPECT_FALSE(base::PathExists(file1_)); | 74 EXPECT_FALSE(base::PathExists(file1_)); |
75 EXPECT_FALSE(base::PathExists(file2_)); | 75 EXPECT_FALSE(base::PathExists(file2_)); |
76 EXPECT_FALSE(base::PathExists(file3_)); | 76 EXPECT_FALSE(base::PathExists(file3_)); |
77 } | 77 } |
78 | 78 |
79 TEST_F(CacheUtilTest, DeleteCacheAndDir) { | 79 TEST_F(CacheUtilTest, DeleteCacheAndDir) { |
80 disk_cache::DeleteCache(cache_dir_, true); | 80 disk_cache::DeleteCache(cache_dir_, true); |
81 EXPECT_FALSE(base::PathExists(cache_dir_)); // cache dir is gone | 81 EXPECT_FALSE(base::PathExists(cache_dir_)); // cache dir is gone |
82 EXPECT_FALSE(base::PathExists(dir1_)); | 82 EXPECT_FALSE(base::PathExists(dir1_)); |
83 EXPECT_FALSE(base::PathExists(file1_)); | 83 EXPECT_FALSE(base::PathExists(file1_)); |
84 EXPECT_FALSE(base::PathExists(file2_)); | 84 EXPECT_FALSE(base::PathExists(file2_)); |
85 EXPECT_FALSE(base::PathExists(file3_)); | 85 EXPECT_FALSE(base::PathExists(file3_)); |
86 } | 86 } |
87 | 87 |
88 TEST_F(CacheUtilTest, DeleteCacheFile) { | 88 TEST_F(CacheUtilTest, DeleteCacheFile) { |
89 EXPECT_TRUE(disk_cache::DeleteCacheFile(file1_)); | 89 EXPECT_TRUE(disk_cache::DeleteCacheFile(file1_)); |
90 EXPECT_FALSE(base::PathExists(file1_)); | 90 EXPECT_FALSE(base::PathExists(file1_)); |
91 EXPECT_TRUE(base::PathExists(cache_dir_)); // cache dir stays | 91 EXPECT_TRUE(base::PathExists(cache_dir_)); // cache dir stays |
92 EXPECT_TRUE(base::PathExists(dir1_)); | 92 EXPECT_TRUE(base::PathExists(dir1_)); |
93 EXPECT_TRUE(base::PathExists(file3_)); | 93 EXPECT_TRUE(base::PathExists(file3_)); |
94 } | 94 } |
95 | 95 |
96 } // namespace disk_cache | 96 } // namespace disk_cache |
OLD | NEW |