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 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/thread.h" | 9 #include "base/thread.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 virtual void TearDown(); | 29 virtual void TearDown(); |
30 }; | 30 }; |
31 | 31 |
32 // Provides basic support for cache related tests. | 32 // Provides basic support for cache related tests. |
33 class DiskCacheTestWithCache : public DiskCacheTest { | 33 class DiskCacheTestWithCache : public DiskCacheTest { |
34 protected: | 34 protected: |
35 DiskCacheTestWithCache() | 35 DiskCacheTestWithCache() |
36 : cache_(NULL), cache_impl_(NULL), mem_cache_(NULL), mask_(0), size_(0), | 36 : cache_(NULL), cache_impl_(NULL), mem_cache_(NULL), mask_(0), size_(0), |
37 memory_only_(false), implementation_(false), force_creation_(false), | 37 memory_only_(false), implementation_(false), force_creation_(false), |
38 new_eviction_(false), first_cleanup_(true), integrity_(true), | 38 new_eviction_(false), first_cleanup_(true), integrity_(true), |
39 use_current_thread_(false), cache_thread_("CacheThread") {} | 39 cache_thread_("CacheThread") {} |
40 | 40 |
41 void InitCache(); | 41 void InitCache(); |
42 virtual void TearDown(); | 42 virtual void TearDown(); |
43 void SimulateCrash(); | 43 void SimulateCrash(); |
44 void SetTestMode(); | 44 void SetTestMode(); |
45 | 45 |
46 void SetMemoryOnlyMode() { | 46 void SetMemoryOnlyMode() { |
47 memory_only_ = true; | 47 memory_only_ = true; |
48 } | 48 } |
49 | 49 |
(...skipping 18 matching lines...) Expand all Loading... |
68 } | 68 } |
69 | 69 |
70 void DisableFirstCleanup() { | 70 void DisableFirstCleanup() { |
71 first_cleanup_ = false; | 71 first_cleanup_ = false; |
72 } | 72 } |
73 | 73 |
74 void DisableIntegrityCheck() { | 74 void DisableIntegrityCheck() { |
75 integrity_ = false; | 75 integrity_ = false; |
76 } | 76 } |
77 | 77 |
78 void UseCurrentThread() { | |
79 use_current_thread_ = true; | |
80 } | |
81 | |
82 // Utility methods to access the cache and wait for each operation to finish. | 78 // Utility methods to access the cache and wait for each operation to finish. |
83 int OpenEntry(const std::string& key, disk_cache::Entry** entry); | 79 int OpenEntry(const std::string& key, disk_cache::Entry** entry); |
84 int CreateEntry(const std::string& key, disk_cache::Entry** entry); | 80 int CreateEntry(const std::string& key, disk_cache::Entry** entry); |
85 int DoomEntry(const std::string& key); | 81 int DoomEntry(const std::string& key); |
86 int DoomAllEntries(); | 82 int DoomAllEntries(); |
87 int DoomEntriesBetween(const base::Time initial_time, | 83 int DoomEntriesBetween(const base::Time initial_time, |
88 const base::Time end_time); | 84 const base::Time end_time); |
89 int DoomEntriesSince(const base::Time initial_time); | 85 int DoomEntriesSince(const base::Time initial_time); |
90 int OpenNextEntry(void** iter, disk_cache::Entry** next_entry); | 86 int OpenNextEntry(void** iter, disk_cache::Entry** next_entry); |
91 void FlushQueueForTest(); | |
92 | 87 |
93 // cache_ will always have a valid object, regardless of how the cache was | 88 // cache_ will always have a valid object, regardless of how the cache was |
94 // initialized. The implementation pointers can be NULL. | 89 // initialized. The implementation pointers can be NULL. |
95 disk_cache::Backend* cache_; | 90 disk_cache::Backend* cache_; |
96 disk_cache::BackendImpl* cache_impl_; | 91 disk_cache::BackendImpl* cache_impl_; |
97 disk_cache::MemBackendImpl* mem_cache_; | 92 disk_cache::MemBackendImpl* mem_cache_; |
98 | 93 |
99 uint32 mask_; | 94 uint32 mask_; |
100 int size_; | 95 int size_; |
101 bool memory_only_; | 96 bool memory_only_; |
102 bool implementation_; | 97 bool implementation_; |
103 bool force_creation_; | 98 bool force_creation_; |
104 bool new_eviction_; | 99 bool new_eviction_; |
105 bool first_cleanup_; | 100 bool first_cleanup_; |
106 bool integrity_; | 101 bool integrity_; |
107 bool use_current_thread_; | |
108 // This is intentionally left uninitialized, to be used by any test. | 102 // This is intentionally left uninitialized, to be used by any test. |
109 bool success_; | 103 bool success_; |
110 | 104 |
111 private: | 105 private: |
112 void InitMemoryCache(); | 106 void InitMemoryCache(); |
113 void InitDiskCache(); | 107 void InitDiskCache(); |
114 void InitDiskCacheImpl(const FilePath& path); | 108 void InitDiskCacheImpl(const FilePath& path); |
115 | 109 |
116 base::Thread cache_thread_; | 110 base::Thread cache_thread_; |
117 DISALLOW_COPY_AND_ASSIGN(DiskCacheTestWithCache); | 111 DISALLOW_COPY_AND_ASSIGN(DiskCacheTestWithCache); |
118 }; | 112 }; |
119 | 113 |
120 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ | 114 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ |
OLD | NEW |