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