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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
13 #include "net/base/cache_type.h" | 13 #include "net/base/cache_type.h" |
14 #include "net/disk_cache/disk_cache.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "testing/platform_test.h" | 16 #include "testing/platform_test.h" |
16 | 17 |
17 namespace net { | 18 namespace net { |
18 | 19 |
19 class IOBuffer; | 20 class IOBuffer; |
20 | 21 |
21 } // namespace net | 22 } // namespace net |
22 | 23 |
23 namespace disk_cache { | 24 namespace disk_cache { |
(...skipping 26 matching lines...) Expand all Loading... | |
50 base::FilePath cache_path_; | 51 base::FilePath cache_path_; |
51 | 52 |
52 private: | 53 private: |
53 base::ScopedTempDir temp_dir_; | 54 base::ScopedTempDir temp_dir_; |
54 scoped_ptr<base::MessageLoop> message_loop_; | 55 scoped_ptr<base::MessageLoop> message_loop_; |
55 }; | 56 }; |
56 | 57 |
57 // Provides basic support for cache related tests. | 58 // Provides basic support for cache related tests. |
58 class DiskCacheTestWithCache : public DiskCacheTest { | 59 class DiskCacheTestWithCache : public DiskCacheTest { |
59 protected: | 60 protected: |
61 class TestIterator FINAL { | |
rvargas (doing something else)
2014/09/18 02:32:12
global nit: Using FINAL looks like extra noise on
gavinp
2014/09/18 18:13:04
Done.
| |
62 public: | |
63 explicit TestIterator(scoped_ptr<disk_cache::Backend::Iterator> iterator); | |
64 ~TestIterator(); | |
65 | |
66 int OpenNextEntry(disk_cache::Entry** next_entry); | |
67 | |
68 private: | |
69 scoped_ptr<disk_cache::Backend::Iterator> iterator_; | |
70 }; | |
71 | |
60 DiskCacheTestWithCache(); | 72 DiskCacheTestWithCache(); |
61 virtual ~DiskCacheTestWithCache(); | 73 virtual ~DiskCacheTestWithCache(); |
62 | 74 |
63 void CreateBackend(uint32 flags, base::Thread* thread); | 75 void CreateBackend(uint32 flags, base::Thread* thread); |
64 | 76 |
65 void InitCache(); | 77 void InitCache(); |
66 void SimulateCrash(); | 78 void SimulateCrash(); |
67 void SetTestMode(); | 79 void SetTestMode(); |
68 | 80 |
69 void SetMemoryOnlyMode() { | 81 void SetMemoryOnlyMode() { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 } | 122 } |
111 | 123 |
112 // Utility methods to access the cache and wait for each operation to finish. | 124 // Utility methods to access the cache and wait for each operation to finish. |
113 int OpenEntry(const std::string& key, disk_cache::Entry** entry); | 125 int OpenEntry(const std::string& key, disk_cache::Entry** entry); |
114 int CreateEntry(const std::string& key, disk_cache::Entry** entry); | 126 int CreateEntry(const std::string& key, disk_cache::Entry** entry); |
115 int DoomEntry(const std::string& key); | 127 int DoomEntry(const std::string& key); |
116 int DoomAllEntries(); | 128 int DoomAllEntries(); |
117 int DoomEntriesBetween(const base::Time initial_time, | 129 int DoomEntriesBetween(const base::Time initial_time, |
118 const base::Time end_time); | 130 const base::Time end_time); |
119 int DoomEntriesSince(const base::Time initial_time); | 131 int DoomEntriesSince(const base::Time initial_time); |
120 int OpenNextEntry(void** iter, disk_cache::Entry** next_entry); | 132 scoped_ptr<TestIterator> CreateIterator(); |
121 void FlushQueueForTest(); | 133 void FlushQueueForTest(); |
122 void RunTaskForTest(const base::Closure& closure); | 134 void RunTaskForTest(const base::Closure& closure); |
123 int ReadData(disk_cache::Entry* entry, int index, int offset, | 135 int ReadData(disk_cache::Entry* entry, int index, int offset, |
124 net::IOBuffer* buf, int len); | 136 net::IOBuffer* buf, int len); |
125 int WriteData(disk_cache::Entry* entry, int index, int offset, | 137 int WriteData(disk_cache::Entry* entry, int index, int offset, |
126 net::IOBuffer* buf, int len, bool truncate); | 138 net::IOBuffer* buf, int len, bool truncate); |
127 int ReadSparseData(disk_cache::Entry* entry, int64 offset, net::IOBuffer* buf, | 139 int ReadSparseData(disk_cache::Entry* entry, int64 offset, net::IOBuffer* buf, |
128 int len); | 140 int len); |
129 int WriteSparseData(disk_cache::Entry* entry, int64 offset, | 141 int WriteSparseData(disk_cache::Entry* entry, int64 offset, |
130 net::IOBuffer* buf, int len); | 142 net::IOBuffer* buf, int len); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 | 179 |
168 private: | 180 private: |
169 void InitMemoryCache(); | 181 void InitMemoryCache(); |
170 void InitDiskCache(); | 182 void InitDiskCache(); |
171 | 183 |
172 base::Thread cache_thread_; | 184 base::Thread cache_thread_; |
173 DISALLOW_COPY_AND_ASSIGN(DiskCacheTestWithCache); | 185 DISALLOW_COPY_AND_ASSIGN(DiskCacheTestWithCache); |
174 }; | 186 }; |
175 | 187 |
176 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ | 188 #endif // NET_DISK_CACHE_DISK_CACHE_TEST_BASE_H_ |
OLD | NEW |