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