OLD | NEW |
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 // Mac, so this needs to be a PlatformTest. Even tests that do not require a | 33 // Mac, so this needs to be a PlatformTest. Even tests that do not require a |
34 // cache (and that do not need to be a DiskCacheTestWithCache) are susceptible | 34 // cache (and that do not need to be a DiskCacheTestWithCache) are susceptible |
35 // to this problem; all such tests should use TEST_F(DiskCacheTest, ...). | 35 // to this problem; all such tests should use TEST_F(DiskCacheTest, ...). |
36 class DiskCacheTest : public PlatformTest { | 36 class DiskCacheTest : public PlatformTest { |
37 virtual void TearDown(); | 37 virtual void TearDown(); |
38 }; | 38 }; |
39 | 39 |
40 // Provides basic support for cache related tests. | 40 // Provides basic support for cache related tests. |
41 class DiskCacheTestWithCache : public DiskCacheTest { | 41 class DiskCacheTestWithCache : public DiskCacheTest { |
42 protected: | 42 protected: |
43 DiskCacheTestWithCache() | 43 DiskCacheTestWithCache(); |
44 : cache_(NULL), cache_impl_(NULL), mem_cache_(NULL), mask_(0), size_(0), | 44 virtual ~DiskCacheTestWithCache(); |
45 type_(net::DISK_CACHE), memory_only_(false), implementation_(false), | |
46 force_creation_(false), new_eviction_(false), first_cleanup_(true), | |
47 integrity_(true), use_current_thread_(false), | |
48 cache_thread_("CacheThread") {} | |
49 | 45 |
50 void InitCache(); | 46 void InitCache(); |
51 virtual void TearDown(); | |
52 void SimulateCrash(); | 47 void SimulateCrash(); |
53 void SetTestMode(); | 48 void SetTestMode(); |
54 | 49 |
55 void SetMemoryOnlyMode() { | 50 void SetMemoryOnlyMode() { |
56 memory_only_ = true; | 51 memory_only_ = true; |
57 } | 52 } |
58 | 53 |
59 // Use the implementation directly instead of the factory provided object. | 54 // Use the implementation directly instead of the factory provided object. |
60 void SetDirectMode() { | 55 void SetDirectMode() { |
61 implementation_ = true; | 56 implementation_ = true; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 void RunTaskForTest(Task* task); | 100 void RunTaskForTest(Task* task); |
106 int ReadData(disk_cache::Entry* entry, int index, int offset, | 101 int ReadData(disk_cache::Entry* entry, int index, int offset, |
107 net::IOBuffer* buf, int len); | 102 net::IOBuffer* buf, int len); |
108 int WriteData(disk_cache::Entry* entry, int index, int offset, | 103 int WriteData(disk_cache::Entry* entry, int index, int offset, |
109 net::IOBuffer* buf, int len, bool truncate); | 104 net::IOBuffer* buf, int len, bool truncate); |
110 int ReadSparseData(disk_cache::Entry* entry, int64 offset, net::IOBuffer* buf, | 105 int ReadSparseData(disk_cache::Entry* entry, int64 offset, net::IOBuffer* buf, |
111 int len); | 106 int len); |
112 int WriteSparseData(disk_cache::Entry* entry, int64 offset, | 107 int WriteSparseData(disk_cache::Entry* entry, int64 offset, |
113 net::IOBuffer* buf, int len); | 108 net::IOBuffer* buf, int len); |
114 | 109 |
| 110 // DiskCacheTest: |
| 111 virtual void TearDown(); |
| 112 |
115 // cache_ will always have a valid object, regardless of how the cache was | 113 // cache_ will always have a valid object, regardless of how the cache was |
116 // initialized. The implementation pointers can be NULL. | 114 // initialized. The implementation pointers can be NULL. |
117 disk_cache::Backend* cache_; | 115 disk_cache::Backend* cache_; |
118 disk_cache::BackendImpl* cache_impl_; | 116 disk_cache::BackendImpl* cache_impl_; |
119 disk_cache::MemBackendImpl* mem_cache_; | 117 disk_cache::MemBackendImpl* mem_cache_; |
120 | 118 |
121 uint32 mask_; | 119 uint32 mask_; |
122 int size_; | 120 int size_; |
123 net::CacheType type_; | 121 net::CacheType type_; |
124 bool memory_only_; | 122 bool memory_only_; |
125 bool implementation_; | 123 bool implementation_; |
126 bool force_creation_; | 124 bool force_creation_; |
127 bool new_eviction_; | 125 bool new_eviction_; |
128 bool first_cleanup_; | 126 bool first_cleanup_; |
129 bool integrity_; | 127 bool integrity_; |
130 bool use_current_thread_; | 128 bool use_current_thread_; |
131 // This is intentionally left uninitialized, to be used by any test. | 129 // This is intentionally left uninitialized, to be used by any test. |
132 bool success_; | 130 bool success_; |
133 | 131 |
134 private: | 132 private: |
135 void InitMemoryCache(); | 133 void InitMemoryCache(); |
136 void InitDiskCache(); | 134 void InitDiskCache(); |
137 void InitDiskCacheImpl(const FilePath& path); | 135 void InitDiskCacheImpl(const FilePath& path); |
138 | 136 |
139 base::Thread cache_thread_; | 137 base::Thread cache_thread_; |
140 DISALLOW_COPY_AND_ASSIGN(DiskCacheTestWithCache); | 138 DISALLOW_COPY_AND_ASSIGN(DiskCacheTestWithCache); |
141 }; | 139 }; |
142 | 140 |
143 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ | 141 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ |
OLD | NEW |