Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: net/http/mock_http_cache.h

Issue 2774603003: Doom and create new entry when validation is not a match (Closed)
Patch Set: Rebased with refs/heads/master@{#484325} Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_cache_unittest.cc ('k') | net/http/mock_http_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 size_t DumpMemoryStats( 137 size_t DumpMemoryStats(
138 base::trace_event::ProcessMemoryDump* pmd, 138 base::trace_event::ProcessMemoryDump* pmd,
139 const std::string& parent_absolute_name) const override; 139 const std::string& parent_absolute_name) const override;
140 140
141 // Returns number of times a cache entry was successfully opened. 141 // Returns number of times a cache entry was successfully opened.
142 int open_count() const { return open_count_; } 142 int open_count() const { return open_count_; }
143 143
144 // Returns number of times a cache entry was successfully created. 144 // Returns number of times a cache entry was successfully created.
145 int create_count() const { return create_count_; } 145 int create_count() const { return create_count_; }
146 146
147 // Returns number of doomed entries.
148 int doomed_count() const { return doomed_count_; }
149
147 // Fail any subsequent CreateEntry and OpenEntry. 150 // Fail any subsequent CreateEntry and OpenEntry.
148 void set_fail_requests() { fail_requests_ = true; } 151 void set_fail_requests() { fail_requests_ = true; }
149 152
150 // Return entries that fail some of their requests. 153 // Return entries that fail some of their requests.
151 void set_soft_failures(bool value) { soft_failures_ = value; } 154 void set_soft_failures(bool value) { soft_failures_ = value; }
152 155
153 // Makes sure that CreateEntry is not called twice for a given key. 156 // Makes sure that CreateEntry is not called twice for a given key.
154 void set_double_create_check(bool value) { double_create_check_ = value; } 157 void set_double_create_check(bool value) { double_create_check_ = value; }
155 158
156 // Makes all requests for data ranges to fail as not implemented. 159 // Makes all requests for data ranges to fail as not implemented.
157 void set_fail_sparse_requests() { fail_sparse_requests_ = true; } 160 void set_fail_sparse_requests() { fail_sparse_requests_ = true; }
158 161
159 void ReleaseAll(); 162 void ReleaseAll();
160 163
161 bool IsDiskEntryDoomed(const std::string& key); 164 bool IsDiskEntryDoomed(const std::string& key);
162 165
163 private: 166 private:
164 using EntryMap = std::unordered_map<std::string, MockDiskEntry*>; 167 using EntryMap = std::unordered_map<std::string, MockDiskEntry*>;
165 class NotImplementedIterator; 168 class NotImplementedIterator;
166 169
167 void CallbackLater(const CompletionCallback& callback, int result); 170 void CallbackLater(const CompletionCallback& callback, int result);
168 171
169 EntryMap entries_; 172 EntryMap entries_;
170 int open_count_; 173 int open_count_;
171 int create_count_; 174 int create_count_;
175 int doomed_count_;
172 bool fail_requests_; 176 bool fail_requests_;
173 bool soft_failures_; 177 bool soft_failures_;
174 bool double_create_check_; 178 bool double_create_check_;
175 bool fail_sparse_requests_; 179 bool fail_sparse_requests_;
176 }; 180 };
177 181
178 class MockBackendFactory : public HttpCache::BackendFactory { 182 class MockBackendFactory : public HttpCache::BackendFactory {
179 public: 183 public:
180 int CreateBackend(NetLog* net_log, 184 int CreateBackend(NetLog* net_log,
181 std::unique_ptr<disk_cache::Backend>* backend, 185 std::unique_ptr<disk_cache::Backend>* backend,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 293
290 std::unique_ptr<disk_cache::Backend>* backend_; 294 std::unique_ptr<disk_cache::Backend>* backend_;
291 CompletionCallback callback_; 295 CompletionCallback callback_;
292 bool block_; 296 bool block_;
293 bool fail_; 297 bool fail_;
294 }; 298 };
295 299
296 } // namespace net 300 } // namespace net
297 301
298 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_ 302 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_
OLDNEW
« no previous file with comments | « net/http/http_cache_unittest.cc ('k') | net/http/mock_http_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698