OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ | 5 #ifndef NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ |
6 #define NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ | 6 #define NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 } // namespace disk_cache | 32 } // namespace disk_cache |
33 | 33 |
34 // These tests can use the path service, which uses autoreleased objects on the | 34 // These tests can use the path service, which uses autoreleased objects on the |
35 // Mac, so this needs to be a PlatformTest. Even tests that do not require a | 35 // Mac, so this needs to be a PlatformTest. Even tests that do not require a |
36 // cache (and that do not need to be a DiskCacheTestWithCache) are susceptible | 36 // cache (and that do not need to be a DiskCacheTestWithCache) are susceptible |
37 // to this problem; all such tests should use TEST_F(DiskCacheTest, ...). | 37 // to this problem; all such tests should use TEST_F(DiskCacheTest, ...). |
38 class DiskCacheTest : public PlatformTest { | 38 class DiskCacheTest : public PlatformTest { |
39 protected: | 39 protected: |
40 DiskCacheTest(); | 40 DiskCacheTest(); |
41 virtual ~DiskCacheTest(); | 41 ~DiskCacheTest() override; |
42 | 42 |
43 // Copies a set of cache files from the data folder to the test folder. | 43 // Copies a set of cache files from the data folder to the test folder. |
44 bool CopyTestCache(const std::string& name); | 44 bool CopyTestCache(const std::string& name); |
45 | 45 |
46 // Deletes the contents of |cache_path_|. | 46 // Deletes the contents of |cache_path_|. |
47 bool CleanupCacheDir(); | 47 bool CleanupCacheDir(); |
48 | 48 |
49 virtual void TearDown() override; | 49 void TearDown() override; |
50 | 50 |
51 base::FilePath cache_path_; | 51 base::FilePath cache_path_; |
52 | 52 |
53 private: | 53 private: |
54 base::ScopedTempDir temp_dir_; | 54 base::ScopedTempDir temp_dir_; |
55 scoped_ptr<base::MessageLoop> message_loop_; | 55 scoped_ptr<base::MessageLoop> message_loop_; |
56 }; | 56 }; |
57 | 57 |
58 // Provides basic support for cache related tests. | 58 // Provides basic support for cache related tests. |
59 class DiskCacheTestWithCache : public DiskCacheTest { | 59 class DiskCacheTestWithCache : public DiskCacheTest { |
60 protected: | 60 protected: |
61 class TestIterator { | 61 class TestIterator { |
62 public: | 62 public: |
63 explicit TestIterator(scoped_ptr<disk_cache::Backend::Iterator> iterator); | 63 explicit TestIterator(scoped_ptr<disk_cache::Backend::Iterator> iterator); |
64 ~TestIterator(); | 64 ~TestIterator(); |
65 | 65 |
66 int OpenNextEntry(disk_cache::Entry** next_entry); | 66 int OpenNextEntry(disk_cache::Entry** next_entry); |
67 | 67 |
68 private: | 68 private: |
69 scoped_ptr<disk_cache::Backend::Iterator> iterator_; | 69 scoped_ptr<disk_cache::Backend::Iterator> iterator_; |
70 }; | 70 }; |
71 | 71 |
72 DiskCacheTestWithCache(); | 72 DiskCacheTestWithCache(); |
73 virtual ~DiskCacheTestWithCache(); | 73 ~DiskCacheTestWithCache() override; |
74 | 74 |
75 void CreateBackend(uint32 flags, base::Thread* thread); | 75 void CreateBackend(uint32 flags, base::Thread* thread); |
76 | 76 |
77 void InitCache(); | 77 void InitCache(); |
78 void SimulateCrash(); | 78 void SimulateCrash(); |
79 void SetTestMode(); | 79 void SetTestMode(); |
80 | 80 |
81 void SetMemoryOnlyMode() { | 81 void SetMemoryOnlyMode() { |
82 memory_only_ = true; | 82 memory_only_ = true; |
83 } | 83 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 147 |
148 // Asks the cache to trim an entry from the deleted list. If |empty| is | 148 // Asks the cache to trim an entry from the deleted list. If |empty| is |
149 // true, the whole list is deleted. | 149 // true, the whole list is deleted. |
150 void TrimDeletedListForTest(bool empty); | 150 void TrimDeletedListForTest(bool empty); |
151 | 151 |
152 // Makes sure that some time passes before continuing the test. Time::Now() | 152 // Makes sure that some time passes before continuing the test. Time::Now() |
153 // before and after this method will not be the same. | 153 // before and after this method will not be the same. |
154 void AddDelay(); | 154 void AddDelay(); |
155 | 155 |
156 // DiskCacheTest: | 156 // DiskCacheTest: |
157 virtual void TearDown() override; | 157 void TearDown() override; |
158 | 158 |
159 // cache_ will always have a valid object, regardless of how the cache was | 159 // cache_ will always have a valid object, regardless of how the cache was |
160 // initialized. The implementation pointers can be NULL. | 160 // initialized. The implementation pointers can be NULL. |
161 scoped_ptr<disk_cache::Backend> cache_; | 161 scoped_ptr<disk_cache::Backend> cache_; |
162 disk_cache::BackendImpl* cache_impl_; | 162 disk_cache::BackendImpl* cache_impl_; |
163 disk_cache::SimpleBackendImpl* simple_cache_impl_; | 163 disk_cache::SimpleBackendImpl* simple_cache_impl_; |
164 disk_cache::MemBackendImpl* mem_cache_; | 164 disk_cache::MemBackendImpl* mem_cache_; |
165 | 165 |
166 uint32 mask_; | 166 uint32 mask_; |
167 int size_; | 167 int size_; |
(...skipping 11 matching lines...) Expand all Loading... |
179 | 179 |
180 private: | 180 private: |
181 void InitMemoryCache(); | 181 void InitMemoryCache(); |
182 void InitDiskCache(); | 182 void InitDiskCache(); |
183 | 183 |
184 base::Thread cache_thread_; | 184 base::Thread cache_thread_; |
185 DISALLOW_COPY_AND_ASSIGN(DiskCacheTestWithCache); | 185 DISALLOW_COPY_AND_ASSIGN(DiskCacheTestWithCache); |
186 }; | 186 }; |
187 | 187 |
188 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ | 188 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ |
OLD | NEW |