| 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 <stdint.h> |
| 9 |
| 9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 13 #include "net/base/cache_type.h" | 15 #include "net/base/cache_type.h" |
| 14 #include "net/disk_cache/disk_cache.h" | 16 #include "net/disk_cache/disk_cache.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "testing/platform_test.h" | 18 #include "testing/platform_test.h" |
| 17 | 19 |
| 18 namespace net { | 20 namespace net { |
| 19 | 21 |
| 20 class IOBuffer; | 22 class IOBuffer; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 67 |
| 66 int OpenNextEntry(disk_cache::Entry** next_entry); | 68 int OpenNextEntry(disk_cache::Entry** next_entry); |
| 67 | 69 |
| 68 private: | 70 private: |
| 69 scoped_ptr<disk_cache::Backend::Iterator> iterator_; | 71 scoped_ptr<disk_cache::Backend::Iterator> iterator_; |
| 70 }; | 72 }; |
| 71 | 73 |
| 72 DiskCacheTestWithCache(); | 74 DiskCacheTestWithCache(); |
| 73 ~DiskCacheTestWithCache() override; | 75 ~DiskCacheTestWithCache() override; |
| 74 | 76 |
| 75 void CreateBackend(uint32 flags, base::Thread* thread); | 77 void CreateBackend(uint32_t flags, base::Thread* thread); |
| 76 | 78 |
| 77 void InitCache(); | 79 void InitCache(); |
| 78 void SimulateCrash(); | 80 void SimulateCrash(); |
| 79 void SetTestMode(); | 81 void SetTestMode(); |
| 80 | 82 |
| 81 void SetMemoryOnlyMode() { | 83 void SetMemoryOnlyMode() { |
| 82 memory_only_ = true; | 84 memory_only_ = true; |
| 83 } | 85 } |
| 84 | 86 |
| 85 void SetSimpleCacheMode() { | 87 void SetSimpleCacheMode() { |
| 86 simple_cache_mode_ = true; | 88 simple_cache_mode_ = true; |
| 87 } | 89 } |
| 88 | 90 |
| 89 void SetMask(uint32 mask) { | 91 void SetMask(uint32_t mask) { mask_ = mask; } |
| 90 mask_ = mask; | |
| 91 } | |
| 92 | 92 |
| 93 void SetMaxSize(int size); | 93 void SetMaxSize(int size); |
| 94 | 94 |
| 95 // Deletes and re-creates the files on initialization errors. | 95 // Deletes and re-creates the files on initialization errors. |
| 96 void SetForceCreation() { | 96 void SetForceCreation() { |
| 97 force_creation_ = true; | 97 force_creation_ = true; |
| 98 } | 98 } |
| 99 | 99 |
| 100 void SetNewEviction() { | 100 void SetNewEviction() { |
| 101 new_eviction_ = true; | 101 new_eviction_ = true; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 130 const base::Time end_time); | 130 const base::Time end_time); |
| 131 int CalculateSizeOfAllEntries(); | 131 int CalculateSizeOfAllEntries(); |
| 132 int DoomEntriesSince(const base::Time initial_time); | 132 int DoomEntriesSince(const base::Time initial_time); |
| 133 scoped_ptr<TestIterator> CreateIterator(); | 133 scoped_ptr<TestIterator> CreateIterator(); |
| 134 void FlushQueueForTest(); | 134 void FlushQueueForTest(); |
| 135 void RunTaskForTest(const base::Closure& closure); | 135 void RunTaskForTest(const base::Closure& closure); |
| 136 int ReadData(disk_cache::Entry* entry, int index, int offset, | 136 int ReadData(disk_cache::Entry* entry, int index, int offset, |
| 137 net::IOBuffer* buf, int len); | 137 net::IOBuffer* buf, int len); |
| 138 int WriteData(disk_cache::Entry* entry, int index, int offset, | 138 int WriteData(disk_cache::Entry* entry, int index, int offset, |
| 139 net::IOBuffer* buf, int len, bool truncate); | 139 net::IOBuffer* buf, int len, bool truncate); |
| 140 int ReadSparseData(disk_cache::Entry* entry, int64 offset, net::IOBuffer* buf, | 140 int ReadSparseData(disk_cache::Entry* entry, |
| 141 int64_t offset, |
| 142 net::IOBuffer* buf, |
| 141 int len); | 143 int len); |
| 142 int WriteSparseData(disk_cache::Entry* entry, int64 offset, | 144 int WriteSparseData(disk_cache::Entry* entry, |
| 143 net::IOBuffer* buf, int len); | 145 int64_t offset, |
| 146 net::IOBuffer* buf, |
| 147 int len); |
| 144 | 148 |
| 145 // Asks the cache to trim an entry. If |empty| is true, the whole cache is | 149 // Asks the cache to trim an entry. If |empty| is true, the whole cache is |
| 146 // deleted. | 150 // deleted. |
| 147 void TrimForTest(bool empty); | 151 void TrimForTest(bool empty); |
| 148 | 152 |
| 149 // Asks the cache to trim an entry from the deleted list. If |empty| is | 153 // Asks the cache to trim an entry from the deleted list. If |empty| is |
| 150 // true, the whole list is deleted. | 154 // true, the whole list is deleted. |
| 151 void TrimDeletedListForTest(bool empty); | 155 void TrimDeletedListForTest(bool empty); |
| 152 | 156 |
| 153 // Makes sure that some time passes before continuing the test. Time::Now() | 157 // Makes sure that some time passes before continuing the test. Time::Now() |
| 154 // before and after this method will not be the same. | 158 // before and after this method will not be the same. |
| 155 void AddDelay(); | 159 void AddDelay(); |
| 156 | 160 |
| 157 // DiskCacheTest: | 161 // DiskCacheTest: |
| 158 void TearDown() override; | 162 void TearDown() override; |
| 159 | 163 |
| 160 // cache_ will always have a valid object, regardless of how the cache was | 164 // cache_ will always have a valid object, regardless of how the cache was |
| 161 // initialized. The implementation pointers can be NULL. | 165 // initialized. The implementation pointers can be NULL. |
| 162 scoped_ptr<disk_cache::Backend> cache_; | 166 scoped_ptr<disk_cache::Backend> cache_; |
| 163 disk_cache::BackendImpl* cache_impl_; | 167 disk_cache::BackendImpl* cache_impl_; |
| 164 disk_cache::SimpleBackendImpl* simple_cache_impl_; | 168 disk_cache::SimpleBackendImpl* simple_cache_impl_; |
| 165 disk_cache::MemBackendImpl* mem_cache_; | 169 disk_cache::MemBackendImpl* mem_cache_; |
| 166 | 170 |
| 167 uint32 mask_; | 171 uint32_t mask_; |
| 168 int size_; | 172 int size_; |
| 169 net::CacheType type_; | 173 net::CacheType type_; |
| 170 bool memory_only_; | 174 bool memory_only_; |
| 171 bool simple_cache_mode_; | 175 bool simple_cache_mode_; |
| 172 bool simple_cache_wait_for_index_; | 176 bool simple_cache_wait_for_index_; |
| 173 bool force_creation_; | 177 bool force_creation_; |
| 174 bool new_eviction_; | 178 bool new_eviction_; |
| 175 bool first_cleanup_; | 179 bool first_cleanup_; |
| 176 bool integrity_; | 180 bool integrity_; |
| 177 bool use_current_thread_; | 181 bool use_current_thread_; |
| 178 // This is intentionally left uninitialized, to be used by any test. | 182 // This is intentionally left uninitialized, to be used by any test. |
| 179 bool success_; | 183 bool success_; |
| 180 | 184 |
| 181 private: | 185 private: |
| 182 void InitMemoryCache(); | 186 void InitMemoryCache(); |
| 183 void InitDiskCache(); | 187 void InitDiskCache(); |
| 184 | 188 |
| 185 base::Thread cache_thread_; | 189 base::Thread cache_thread_; |
| 186 DISALLOW_COPY_AND_ASSIGN(DiskCacheTestWithCache); | 190 DISALLOW_COPY_AND_ASSIGN(DiskCacheTestWithCache); |
| 187 }; | 191 }; |
| 188 | 192 |
| 189 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ | 193 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ |
| OLD | NEW |