| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 class MockDiskCache : public disk_cache::Backend { | 96 class MockDiskCache : public disk_cache::Backend { |
| 97 public: | 97 public: |
| 98 MockDiskCache(); | 98 MockDiskCache(); |
| 99 virtual ~MockDiskCache(); | 99 virtual ~MockDiskCache(); |
| 100 | 100 |
| 101 virtual net::CacheType GetCacheType() const OVERRIDE; | 101 virtual net::CacheType GetCacheType() const OVERRIDE; |
| 102 virtual int32 GetEntryCount() const OVERRIDE; | 102 virtual int32 GetEntryCount() const OVERRIDE; |
| 103 virtual int OpenEntry(const std::string& key, disk_cache::Entry** entry, | 103 virtual int OpenEntry(const std::string& key, disk_cache::Entry** entry, |
| 104 const net::CompletionCallback& callback) OVERRIDE; | 104 const net::CompletionCallback& callback) OVERRIDE; |
| 105 int OpenDoomedEntry(const std::string& key, |
| 106 disk_cache::Entry** entry, |
| 107 const net::CompletionCallback& callback); |
| 105 virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry, | 108 virtual int CreateEntry(const std::string& key, disk_cache::Entry** entry, |
| 106 const net::CompletionCallback& callback) OVERRIDE; | 109 const net::CompletionCallback& callback) OVERRIDE; |
| 107 virtual int DoomEntry(const std::string& key, | 110 virtual int DoomEntry(const std::string& key, |
| 108 const net::CompletionCallback& callback) OVERRIDE; | 111 const net::CompletionCallback& callback) OVERRIDE; |
| 109 virtual int DoomAllEntries(const net::CompletionCallback& callback) OVERRIDE; | 112 virtual int DoomAllEntries(const net::CompletionCallback& callback) OVERRIDE; |
| 110 virtual int DoomEntriesBetween( | 113 virtual int DoomEntriesBetween( |
| 111 base::Time initial_time, | 114 base::Time initial_time, |
| 112 base::Time end_time, | 115 base::Time end_time, |
| 113 const net::CompletionCallback& callback) OVERRIDE; | 116 const net::CompletionCallback& callback) OVERRIDE; |
| 114 virtual int DoomEntriesSince( | 117 virtual int DoomEntriesSince( |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 187 |
| 185 // Helper function for writing response info into the disk cache. | 188 // Helper function for writing response info into the disk cache. |
| 186 static bool WriteResponseInfo(disk_cache::Entry* disk_entry, | 189 static bool WriteResponseInfo(disk_cache::Entry* disk_entry, |
| 187 const net::HttpResponseInfo* response_info, | 190 const net::HttpResponseInfo* response_info, |
| 188 bool skip_transient_headers, | 191 bool skip_transient_headers, |
| 189 bool response_truncated); | 192 bool response_truncated); |
| 190 | 193 |
| 191 // Helper function to synchronously open a backend entry. | 194 // Helper function to synchronously open a backend entry. |
| 192 bool OpenBackendEntry(const std::string& key, disk_cache::Entry** entry); | 195 bool OpenBackendEntry(const std::string& key, disk_cache::Entry** entry); |
| 193 | 196 |
| 197 // Helper function to synchronously open a doomed backend entry. |
| 198 bool OpenBackendDoomedEntry(const std::string& key, |
| 199 disk_cache::Entry** entry); |
| 200 |
| 194 // Helper function to synchronously create a backend entry. | 201 // Helper function to synchronously create a backend entry. |
| 195 bool CreateBackendEntry(const std::string& key, disk_cache::Entry** entry, | 202 bool CreateBackendEntry(const std::string& key, disk_cache::Entry** entry, |
| 196 net::NetLog* net_log); | 203 net::NetLog* net_log); |
| 197 | 204 |
| 198 // Returns the test mode after considering the global override. | 205 // Returns the test mode after considering the global override. |
| 199 static int GetTestMode(int test_mode); | 206 static int GetTestMode(int test_mode); |
| 200 | 207 |
| 201 // Overrides the test mode for a given operation. Remember to reset it after | 208 // Overrides the test mode for a given operation. Remember to reset it after |
| 202 // the test! (by setting test_mode to zero). | 209 // the test! (by setting test_mode to zero). |
| 203 static void SetTestMode(int test_mode); | 210 static void SetTestMode(int test_mode); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 private: | 248 private: |
| 242 int Result() { return fail_ ? net::ERR_FAILED : net::OK; } | 249 int Result() { return fail_ ? net::ERR_FAILED : net::OK; } |
| 243 | 250 |
| 244 scoped_ptr<disk_cache::Backend>* backend_; | 251 scoped_ptr<disk_cache::Backend>* backend_; |
| 245 net::CompletionCallback callback_; | 252 net::CompletionCallback callback_; |
| 246 bool block_; | 253 bool block_; |
| 247 bool fail_; | 254 bool fail_; |
| 248 }; | 255 }; |
| 249 | 256 |
| 250 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_ | 257 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_ |
| OLD | NEW |