| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 void set_soft_failures(bool value) { soft_failures_ = value; } | 151 void set_soft_failures(bool value) { soft_failures_ = value; } |
| 152 | 152 |
| 153 // Makes sure that CreateEntry is not called twice for a given key. | 153 // Makes sure that CreateEntry is not called twice for a given key. |
| 154 void set_double_create_check(bool value) { double_create_check_ = value; } | 154 void set_double_create_check(bool value) { double_create_check_ = value; } |
| 155 | 155 |
| 156 // Makes all requests for data ranges to fail as not implemented. | 156 // Makes all requests for data ranges to fail as not implemented. |
| 157 void set_fail_sparse_requests() { fail_sparse_requests_ = true; } | 157 void set_fail_sparse_requests() { fail_sparse_requests_ = true; } |
| 158 | 158 |
| 159 void ReleaseAll(); | 159 void ReleaseAll(); |
| 160 | 160 |
| 161 bool IsDiskEntryDoomed(const std::string& key); |
| 162 |
| 161 private: | 163 private: |
| 162 using EntryMap = std::unordered_map<std::string, MockDiskEntry*>; | 164 using EntryMap = std::unordered_map<std::string, MockDiskEntry*>; |
| 163 class NotImplementedIterator; | 165 class NotImplementedIterator; |
| 164 | 166 |
| 165 void CallbackLater(const CompletionCallback& callback, int result); | 167 void CallbackLater(const CompletionCallback& callback, int result); |
| 166 | 168 |
| 167 EntryMap entries_; | 169 EntryMap entries_; |
| 168 int open_count_; | 170 int open_count_; |
| 169 int create_count_; | 171 int create_count_; |
| 170 bool fail_requests_; | 172 bool fail_requests_; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 disk_cache::Entry** entry, | 229 disk_cache::Entry** entry, |
| 228 NetLog* net_log); | 230 NetLog* net_log); |
| 229 | 231 |
| 230 // Returns the test mode after considering the global override. | 232 // Returns the test mode after considering the global override. |
| 231 static int GetTestMode(int test_mode); | 233 static int GetTestMode(int test_mode); |
| 232 | 234 |
| 233 // Overrides the test mode for a given operation. Remember to reset it after | 235 // Overrides the test mode for a given operation. Remember to reset it after |
| 234 // the test! (by setting test_mode to zero). | 236 // the test! (by setting test_mode to zero). |
| 235 static void SetTestMode(int test_mode); | 237 static void SetTestMode(int test_mode); |
| 236 | 238 |
| 239 // Functions to test the state of ActiveEntry. |
| 240 |
| 241 bool IsWriterPresent(const std::string& key); |
| 242 bool IsHeadersTransactionPresent(const std::string& key); |
| 243 int GetCountReaders(const std::string& key); |
| 244 int GetCountAddToEntryQueue(const std::string& key); |
| 245 int GetCountDoneHeadersQueue(const std::string& key); |
| 246 |
| 237 private: | 247 private: |
| 238 HttpCache http_cache_; | 248 HttpCache http_cache_; |
| 239 }; | 249 }; |
| 240 | 250 |
| 241 // This version of the disk cache doesn't invoke CreateEntry callbacks. | 251 // This version of the disk cache doesn't invoke CreateEntry callbacks. |
| 242 class MockDiskCacheNoCB : public MockDiskCache { | 252 class MockDiskCacheNoCB : public MockDiskCache { |
| 243 int CreateEntry(const std::string& key, | 253 int CreateEntry(const std::string& key, |
| 244 disk_cache::Entry** entry, | 254 disk_cache::Entry** entry, |
| 245 const CompletionCallback& callback) override; | 255 const CompletionCallback& callback) override; |
| 246 }; | 256 }; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 276 | 286 |
| 277 std::unique_ptr<disk_cache::Backend>* backend_; | 287 std::unique_ptr<disk_cache::Backend>* backend_; |
| 278 CompletionCallback callback_; | 288 CompletionCallback callback_; |
| 279 bool block_; | 289 bool block_; |
| 280 bool fail_; | 290 bool fail_; |
| 281 }; | 291 }; |
| 282 | 292 |
| 283 } // namespace net | 293 } // namespace net |
| 284 | 294 |
| 285 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_ | 295 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_ |
| OLD | NEW |