OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This is a mock of the http cache and related testing classes. To be fair, it | 5 // This is a mock of the http cache and related testing classes. To be fair, it |
6 // is not really a mock http cache given that it uses the real implementation of | 6 // is not really a mock http cache given that it uses the real implementation of |
7 // the http cache, but it has fake implementations of all required components, | 7 // the http cache, but it has fake implementations of all required components, |
8 // so it is useful for unit tests at the http layer. | 8 // so it is useful for unit tests at the http layer. |
9 | 9 |
10 #ifndef NET_HTTP_MOCK_HTTP_CACHE_H_ | 10 #ifndef NET_HTTP_MOCK_HTTP_CACHE_H_ |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 void set_soft_failures(bool value) { soft_failures_ = value; } | 149 void set_soft_failures(bool value) { soft_failures_ = value; } |
150 | 150 |
151 // Makes sure that CreateEntry is not called twice for a given key. | 151 // Makes sure that CreateEntry is not called twice for a given key. |
152 void set_double_create_check(bool value) { double_create_check_ = value; } | 152 void set_double_create_check(bool value) { double_create_check_ = value; } |
153 | 153 |
154 // Makes all requests for data ranges to fail as not implemented. | 154 // Makes all requests for data ranges to fail as not implemented. |
155 void set_fail_sparse_requests() { fail_sparse_requests_ = true; } | 155 void set_fail_sparse_requests() { fail_sparse_requests_ = true; } |
156 | 156 |
157 void ReleaseAll(); | 157 void ReleaseAll(); |
158 | 158 |
| 159 bool IsDiskEntryDoomed(const std::string& key); |
| 160 |
159 private: | 161 private: |
160 using EntryMap = std::unordered_map<std::string, MockDiskEntry*>; | 162 using EntryMap = std::unordered_map<std::string, MockDiskEntry*>; |
161 class NotImplementedIterator; | 163 class NotImplementedIterator; |
162 | 164 |
163 void CallbackLater(const CompletionCallback& callback, int result); | 165 void CallbackLater(const CompletionCallback& callback, int result); |
164 | 166 |
165 EntryMap entries_; | 167 EntryMap entries_; |
166 int open_count_; | 168 int open_count_; |
167 int create_count_; | 169 int create_count_; |
168 bool fail_requests_; | 170 bool fail_requests_; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 disk_cache::Entry** entry, | 227 disk_cache::Entry** entry, |
226 NetLog* net_log); | 228 NetLog* net_log); |
227 | 229 |
228 // Returns the test mode after considering the global override. | 230 // Returns the test mode after considering the global override. |
229 static int GetTestMode(int test_mode); | 231 static int GetTestMode(int test_mode); |
230 | 232 |
231 // Overrides the test mode for a given operation. Remember to reset it after | 233 // Overrides the test mode for a given operation. Remember to reset it after |
232 // the test! (by setting test_mode to zero). | 234 // the test! (by setting test_mode to zero). |
233 static void SetTestMode(int test_mode); | 235 static void SetTestMode(int test_mode); |
234 | 236 |
| 237 // Functions to test the state of ActiveEntry. |
| 238 |
| 239 bool IsWriterPresent(const std::string& key); |
| 240 bool IsHeadersTransactionPresent(const std::string& key); |
| 241 int GetCountReaders(const std::string& key); |
| 242 int GetCountAddToEntryQueue(const std::string& key); |
| 243 int GetCountDoneHeadersQueue(const std::string& key); |
| 244 |
235 private: | 245 private: |
236 HttpCache http_cache_; | 246 HttpCache http_cache_; |
237 }; | 247 }; |
238 | 248 |
239 // This version of the disk cache doesn't invoke CreateEntry callbacks. | 249 // This version of the disk cache doesn't invoke CreateEntry callbacks. |
240 class MockDiskCacheNoCB : public MockDiskCache { | 250 class MockDiskCacheNoCB : public MockDiskCache { |
241 int CreateEntry(const std::string& key, | 251 int CreateEntry(const std::string& key, |
242 disk_cache::Entry** entry, | 252 disk_cache::Entry** entry, |
243 const CompletionCallback& callback) override; | 253 const CompletionCallback& callback) override; |
244 }; | 254 }; |
(...skipping 29 matching lines...) Expand all Loading... |
274 | 284 |
275 std::unique_ptr<disk_cache::Backend>* backend_; | 285 std::unique_ptr<disk_cache::Backend>* backend_; |
276 CompletionCallback callback_; | 286 CompletionCallback callback_; |
277 bool block_; | 287 bool block_; |
278 bool fail_; | 288 bool fail_; |
279 }; | 289 }; |
280 | 290 |
281 } // namespace net | 291 } // namespace net |
282 | 292 |
283 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_ | 293 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_ |
OLD | NEW |