| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 scoped_ptr<Iterator> CreateIterator() override; | 130 scoped_ptr<Iterator> CreateIterator() override; |
| 131 void GetStats(base::StringPairs* stats) override; | 131 void GetStats(base::StringPairs* stats) override; |
| 132 void OnExternalCacheHit(const std::string& key) override; | 132 void OnExternalCacheHit(const std::string& key) override; |
| 133 | 133 |
| 134 // Returns number of times a cache entry was successfully opened. | 134 // Returns number of times a cache entry was successfully opened. |
| 135 int open_count() const { return open_count_; } | 135 int open_count() const { return open_count_; } |
| 136 | 136 |
| 137 // Returns number of times a cache entry was successfully created. | 137 // Returns number of times a cache entry was successfully created. |
| 138 int create_count() const { return create_count_; } | 138 int create_count() const { return create_count_; } |
| 139 | 139 |
| 140 // Resets open_count() and create_count(). Calling this is recommended to |
| 141 // reset the counts after test setup. |
| 142 void ResetCounts(); |
| 143 |
| 140 // Fail any subsequent CreateEntry and OpenEntry. | 144 // Fail any subsequent CreateEntry and OpenEntry. |
| 141 void set_fail_requests() { fail_requests_ = true; } | 145 void set_fail_requests() { fail_requests_ = true; } |
| 142 | 146 |
| 143 // Return entries that fail some of their requests. | 147 // Return entries that fail some of their requests. |
| 144 void set_soft_failures(bool value) { soft_failures_ = value; } | 148 void set_soft_failures(bool value) { soft_failures_ = value; } |
| 145 | 149 |
| 146 // Makes sure that CreateEntry is not called twice for a given key. | 150 // Makes sure that CreateEntry is not called twice for a given key. |
| 147 void set_double_create_check(bool value) { double_create_check_ = value; } | 151 void set_double_create_check(bool value) { double_create_check_ = value; } |
| 148 | 152 |
| 149 // Makes all requests for data ranges to fail as not implemented. | 153 // Makes all requests for data ranges to fail as not implemented. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 192 |
| 189 // Wrapper around http_cache()->CreateTransaction(DEFAULT_PRIORITY...) | 193 // Wrapper around http_cache()->CreateTransaction(DEFAULT_PRIORITY...) |
| 190 int CreateTransaction(scoped_ptr<HttpTransaction>* trans); | 194 int CreateTransaction(scoped_ptr<HttpTransaction>* trans); |
| 191 | 195 |
| 192 // Wrapper to bypass the cache lock for new transactions. | 196 // Wrapper to bypass the cache lock for new transactions. |
| 193 void BypassCacheLock(); | 197 void BypassCacheLock(); |
| 194 | 198 |
| 195 // Wrapper to fail request conditionalization for new transactions. | 199 // Wrapper to fail request conditionalization for new transactions. |
| 196 void FailConditionalizations(); | 200 void FailConditionalizations(); |
| 197 | 201 |
| 202 // Reset the transaction and operation counts. |
| 203 void ResetCounts(); |
| 204 |
| 198 // Helper function for reading response info from the disk cache. | 205 // Helper function for reading response info from the disk cache. |
| 199 static bool ReadResponseInfo(disk_cache::Entry* disk_entry, | 206 static bool ReadResponseInfo(disk_cache::Entry* disk_entry, |
| 200 HttpResponseInfo* response_info, | 207 HttpResponseInfo* response_info, |
| 201 bool* response_truncated); | 208 bool* response_truncated); |
| 202 | 209 |
| 203 // Helper function for writing response info into the disk cache. | 210 // Helper function for writing response info into the disk cache. |
| 204 static bool WriteResponseInfo(disk_cache::Entry* disk_entry, | 211 static bool WriteResponseInfo(disk_cache::Entry* disk_entry, |
| 205 const HttpResponseInfo* response_info, | 212 const HttpResponseInfo* response_info, |
| 206 bool skip_transient_headers, | 213 bool skip_transient_headers, |
| 207 bool response_truncated); | 214 bool response_truncated); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 270 |
| 264 scoped_ptr<disk_cache::Backend>* backend_; | 271 scoped_ptr<disk_cache::Backend>* backend_; |
| 265 CompletionCallback callback_; | 272 CompletionCallback callback_; |
| 266 bool block_; | 273 bool block_; |
| 267 bool fail_; | 274 bool fail_; |
| 268 }; | 275 }; |
| 269 | 276 |
| 270 } // namespace net | 277 } // namespace net |
| 271 | 278 |
| 272 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_ | 279 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_ |
| OLD | NEW |