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_ |
11 #define NET_HTTP_MOCK_HTTP_CACHE_H_ | 11 #define NET_HTTP_MOCK_HTTP_CACHE_H_ |
12 | 12 |
13 #include <stdint.h> | 13 #include <stdint.h> |
14 | 14 |
15 #include <unordered_map> | 15 #include "base/containers/hash_tables.h" |
16 | |
17 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
18 #include "net/disk_cache/disk_cache.h" | 17 #include "net/disk_cache/disk_cache.h" |
19 #include "net/http/http_cache.h" | 18 #include "net/http/http_cache.h" |
20 #include "net/http/http_transaction_test_util.h" | 19 #include "net/http/http_transaction_test_util.h" |
21 | 20 |
22 namespace net { | 21 namespace net { |
23 | 22 |
24 //----------------------------------------------------------------------------- | 23 //----------------------------------------------------------------------------- |
25 // Mock disk cache (a very basic memory cache implementation). | 24 // Mock disk cache (a very basic memory cache implementation). |
26 | 25 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 148 |
150 // Makes sure that CreateEntry is not called twice for a given key. | 149 // Makes sure that CreateEntry is not called twice for a given key. |
151 void set_double_create_check(bool value) { double_create_check_ = value; } | 150 void set_double_create_check(bool value) { double_create_check_ = value; } |
152 | 151 |
153 // Makes all requests for data ranges to fail as not implemented. | 152 // Makes all requests for data ranges to fail as not implemented. |
154 void set_fail_sparse_requests() { fail_sparse_requests_ = true; } | 153 void set_fail_sparse_requests() { fail_sparse_requests_ = true; } |
155 | 154 |
156 void ReleaseAll(); | 155 void ReleaseAll(); |
157 | 156 |
158 private: | 157 private: |
159 using EntryMap = std::unordered_map<std::string, MockDiskEntry*>; | 158 typedef base::hash_map<std::string, MockDiskEntry*> EntryMap; |
160 class NotImplementedIterator; | 159 class NotImplementedIterator; |
161 | 160 |
162 void CallbackLater(const CompletionCallback& callback, int result); | 161 void CallbackLater(const CompletionCallback& callback, int result); |
163 | 162 |
164 EntryMap entries_; | 163 EntryMap entries_; |
165 int open_count_; | 164 int open_count_; |
166 int create_count_; | 165 int create_count_; |
167 bool fail_requests_; | 166 bool fail_requests_; |
168 bool soft_failures_; | 167 bool soft_failures_; |
169 bool double_create_check_; | 168 bool double_create_check_; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 267 |
269 scoped_ptr<disk_cache::Backend>* backend_; | 268 scoped_ptr<disk_cache::Backend>* backend_; |
270 CompletionCallback callback_; | 269 CompletionCallback callback_; |
271 bool block_; | 270 bool block_; |
272 bool fail_; | 271 bool fail_; |
273 }; | 272 }; |
274 | 273 |
275 } // namespace net | 274 } // namespace net |
276 | 275 |
277 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_ | 276 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_ |
OLD | NEW |