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

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

Issue 2922973003: RFC: use some in-memory state in SimpleCache to quickly cache-miss some CantConditionalize cases
Patch Set: - Implement support for oracle bytes in MockHttpCache, so the code actually gets exercised in tests… Created 3 years, 6 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
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 19 matching lines...) Expand all
30 explicit MockDiskEntry(const std::string& key); 30 explicit MockDiskEntry(const std::string& key);
31 31
32 bool is_doomed() const { return doomed_; } 32 bool is_doomed() const { return doomed_; }
33 33
34 void Doom() override; 34 void Doom() override;
35 void Close() override; 35 void Close() override;
36 std::string GetKey() const override; 36 std::string GetKey() const override;
37 base::Time GetLastUsed() const override; 37 base::Time GetLastUsed() const override;
38 base::Time GetLastModified() const override; 38 base::Time GetLastModified() const override;
39 int32_t GetDataSize(int index) const override; 39 int32_t GetDataSize(int index) const override;
40 uint8_t GetOracleByte() const { return oracle_byte_; }
41 void SetOracleByte(uint8_t val) override;
40 int ReadData(int index, 42 int ReadData(int index,
41 int offset, 43 int offset,
42 IOBuffer* buf, 44 IOBuffer* buf,
43 int buf_len, 45 int buf_len,
44 const CompletionCallback& callback) override; 46 const CompletionCallback& callback) override;
45 int WriteData(int index, 47 int WriteData(int index,
46 int offset, 48 int offset,
47 IOBuffer* buf, 49 IOBuffer* buf,
48 int buf_len, 50 int buf_len,
49 const CompletionCallback& callback, 51 const CompletionCallback& callback,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 // delivers any callback previously stored. 93 // delivers any callback previously stored.
92 static void StoreAndDeliverCallbacks(bool store, 94 static void StoreAndDeliverCallbacks(bool store,
93 MockDiskEntry* entry, 95 MockDiskEntry* entry,
94 const CompletionCallback& callback, 96 const CompletionCallback& callback,
95 int result); 97 int result);
96 98
97 static const int kNumCacheEntryDataIndices = 3; 99 static const int kNumCacheEntryDataIndices = 3;
98 100
99 std::string key_; 101 std::string key_;
100 std::vector<char> data_[kNumCacheEntryDataIndices]; 102 std::vector<char> data_[kNumCacheEntryDataIndices];
103 unsigned char oracle_byte_;
101 int test_mode_; 104 int test_mode_;
102 bool doomed_; 105 bool doomed_;
103 bool sparse_; 106 bool sparse_;
104 bool fail_requests_; 107 bool fail_requests_;
105 bool fail_sparse_requests_; 108 bool fail_sparse_requests_;
106 bool busy_; 109 bool busy_;
107 bool delayed_; 110 bool delayed_;
108 bool cancel_; 111 bool cancel_;
109 static bool ignore_callbacks_; 112 static bool ignore_callbacks_;
110 }; 113 };
111 114
112 class MockDiskCache : public disk_cache::Backend { 115 class MockDiskCache : public disk_cache::Backend {
113 public: 116 public:
114 MockDiskCache(); 117 MockDiskCache();
115 ~MockDiskCache() override; 118 ~MockDiskCache() override;
116 119
117 CacheType GetCacheType() const override; 120 CacheType GetCacheType() const override;
118 int32_t GetEntryCount() const override; 121 int32_t GetEntryCount() const override;
119 int OpenEntry(const std::string& key, 122 int OpenEntry(const std::string& key,
120 disk_cache::Entry** entry, 123 disk_cache::Entry** entry,
121 const CompletionCallback& callback) override; 124 const CompletionCallback& callback) override;
125 int OpenEntryWithOracleByte(const std::string& key,
126 disk_cache::Entry** entry,
127 const OracleCallback& oracle,
128 const CompletionCallback& callback) override;
122 int CreateEntry(const std::string& key, 129 int CreateEntry(const std::string& key,
123 disk_cache::Entry** entry, 130 disk_cache::Entry** entry,
124 const CompletionCallback& callback) override; 131 const CompletionCallback& callback) override;
125 int DoomEntry(const std::string& key, 132 int DoomEntry(const std::string& key,
126 const CompletionCallback& callback) override; 133 const CompletionCallback& callback) override;
127 int DoomAllEntries(const CompletionCallback& callback) override; 134 int DoomAllEntries(const CompletionCallback& callback) override;
128 int DoomEntriesBetween(base::Time initial_time, 135 int DoomEntriesBetween(base::Time initial_time,
129 base::Time end_time, 136 base::Time end_time,
130 const CompletionCallback& callback) override; 137 const CompletionCallback& callback) override;
131 int DoomEntriesSince(base::Time initial_time, 138 int DoomEntriesSince(base::Time initial_time,
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 283
277 std::unique_ptr<disk_cache::Backend>* backend_; 284 std::unique_ptr<disk_cache::Backend>* backend_;
278 CompletionCallback callback_; 285 CompletionCallback callback_;
279 bool block_; 286 bool block_;
280 bool fail_; 287 bool fail_;
281 }; 288 };
282 289
283 } // namespace net 290 } // namespace net
284 291
285 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_ 292 #endif // NET_HTTP_MOCK_HTTP_CACHE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698