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

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

Issue 2089783002: [net/cache] Avoid the cache for responses exceeding 2GB. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build for configurations where DCHECK is disabled. Created 4 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/http_transaction_test_util.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ 5 #ifndef NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_
6 #define NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ 6 #define NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_
7 7
8 #include "net/http/http_transaction.h" 8 #include "net/http/http_transaction.h"
9 9
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 TEST_MODE_SYNC_NET_READ = 1 << 1, 47 TEST_MODE_SYNC_NET_READ = 1 << 1,
48 TEST_MODE_SYNC_CACHE_START = 1 << 2, 48 TEST_MODE_SYNC_CACHE_START = 1 << 2,
49 TEST_MODE_SYNC_CACHE_READ = 1 << 3, 49 TEST_MODE_SYNC_CACHE_READ = 1 << 3,
50 TEST_MODE_SYNC_CACHE_WRITE = 1 << 4, 50 TEST_MODE_SYNC_CACHE_WRITE = 1 << 4,
51 TEST_MODE_SYNC_ALL = (TEST_MODE_SYNC_NET_START | TEST_MODE_SYNC_NET_READ | 51 TEST_MODE_SYNC_ALL = (TEST_MODE_SYNC_NET_START | TEST_MODE_SYNC_NET_READ |
52 TEST_MODE_SYNC_CACHE_START | TEST_MODE_SYNC_CACHE_READ | 52 TEST_MODE_SYNC_CACHE_START | TEST_MODE_SYNC_CACHE_READ |
53 TEST_MODE_SYNC_CACHE_WRITE), 53 TEST_MODE_SYNC_CACHE_WRITE),
54 TEST_MODE_SLOW_READ = 1 << 5 54 TEST_MODE_SLOW_READ = 1 << 5
55 }; 55 };
56 56
57 typedef void (*MockTransactionHandler)(const HttpRequestInfo* request, 57 using MockTransactionReadHandler = int (*)(int64_t content_length,
58 std::string* response_status, 58 int64_t offset,
59 std::string* response_headers, 59 IOBuffer* buf,
60 std::string* response_data); 60 int buf_len);
61 using MockTransactionHandler = void (*)(const HttpRequestInfo* request,
62 std::string* response_status,
63 std::string* response_headers,
64 std::string* response_data);
61 65
62 struct MockTransaction { 66 struct MockTransaction {
63 const char* url; 67 const char* url;
64 const char* method; 68 const char* method;
65 // If |request_time| is unspecified, the current time will be used. 69 // If |request_time| is unspecified, the current time will be used.
66 base::Time request_time; 70 base::Time request_time;
67 const char* request_headers; 71 const char* request_headers;
68 int load_flags; 72 int load_flags;
69 const char* status; 73 const char* status;
70 const char* response_headers; 74 const char* response_headers;
71 // If |response_time| is unspecified, the current time will be used. 75 // If |response_time| is unspecified, the current time will be used.
72 base::Time response_time; 76 base::Time response_time;
73 const char* data; 77 const char* data;
74 int test_mode; 78 int test_mode;
75 MockTransactionHandler handler; 79 MockTransactionHandler handler;
80 MockTransactionReadHandler read_handler;
76 scoped_refptr<X509Certificate> cert; 81 scoped_refptr<X509Certificate> cert;
77 CertStatus cert_status; 82 CertStatus cert_status;
78 int ssl_connection_status; 83 int ssl_connection_status;
79 // Value returned by MockNetworkTransaction::Start (potentially 84 // Value returned by MockNetworkTransaction::Start (potentially
80 // asynchronously if |!(test_mode & TEST_MODE_SYNC_NET_START)|.) 85 // asynchronously if |!(test_mode & TEST_MODE_SYNC_NET_START)|.)
81 Error return_code; 86 Error return_code;
82 }; 87 };
83 88
84 extern const MockTransaction kSimpleGET_Transaction; 89 extern const MockTransaction kSimpleGET_Transaction;
85 extern const MockTransaction kSimplePOST_Transaction; 90 extern const MockTransaction kSimplePOST_Transaction;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 private: 256 private:
252 int StartInternal(const HttpRequestInfo* request, 257 int StartInternal(const HttpRequestInfo* request,
253 const CompletionCallback& callback, 258 const CompletionCallback& callback,
254 const BoundNetLog& net_log); 259 const BoundNetLog& net_log);
255 void CallbackLater(const CompletionCallback& callback, int result); 260 void CallbackLater(const CompletionCallback& callback, int result);
256 void RunCallback(const CompletionCallback& callback, int result); 261 void RunCallback(const CompletionCallback& callback, int result);
257 262
258 const HttpRequestInfo* request_; 263 const HttpRequestInfo* request_;
259 HttpResponseInfo response_; 264 HttpResponseInfo response_;
260 std::string data_; 265 std::string data_;
261 int data_cursor_; 266 int64_t data_cursor_;
267 int64_t content_length_;
262 int test_mode_; 268 int test_mode_;
263 RequestPriority priority_; 269 RequestPriority priority_;
270 MockTransactionReadHandler read_handler_;
264 CreateHelper* websocket_handshake_stream_create_helper_; 271 CreateHelper* websocket_handshake_stream_create_helper_;
272 BeforeNetworkStartCallback before_network_start_callback_;
265 base::WeakPtr<MockNetworkLayer> transaction_factory_; 273 base::WeakPtr<MockNetworkLayer> transaction_factory_;
266 int64_t received_bytes_; 274 int64_t received_bytes_;
267 int64_t sent_bytes_; 275 int64_t sent_bytes_;
268 276
269 // NetLog ID of the fake / non-existent underlying socket used by the 277 // NetLog ID of the fake / non-existent underlying socket used by the
270 // connection. Requires Start() be passed a BoundNetLog with a real NetLog to 278 // connection. Requires Start() be passed a BoundNetLog with a real NetLog to
271 // be initialized. 279 // be initialized.
272 unsigned int socket_log_id_; 280 unsigned int socket_log_id_;
273 281
274 bool done_reading_called_; 282 bool done_reading_called_;
275 283
276 base::WeakPtrFactory<MockNetworkTransaction> weak_factory_; 284 base::WeakPtrFactory<MockNetworkTransaction> weak_factory_;
277 285
278 }; 286 };
279 287
280 class MockNetworkLayer : public HttpTransactionFactory, 288 class MockNetworkLayer : public HttpTransactionFactory,
281 public base::SupportsWeakPtr<MockNetworkLayer> { 289 public base::SupportsWeakPtr<MockNetworkLayer> {
282 public: 290 public:
283 MockNetworkLayer(); 291 MockNetworkLayer();
284 ~MockNetworkLayer() override; 292 ~MockNetworkLayer() override;
285 293
286 int transaction_count() const { return transaction_count_; } 294 int transaction_count() const { return transaction_count_; }
287 bool done_reading_called() const { return done_reading_called_; } 295 bool done_reading_called() const { return done_reading_called_; }
288 bool stop_caching_called() const { return stop_caching_called_; } 296 bool stop_caching_called() const { return stop_caching_called_; }
289 void TransactionDoneReading(); 297 void TransactionDoneReading();
290 void TransactionStopCaching(); 298 void TransactionStopCaching();
291 299
300 // Resets the transaction count. Can be called after test setup in order to
301 // make test expectations independent of how test setup is performed.
302 void ResetTransactionCount();
303
292 // Returns the last priority passed to CreateTransaction, or 304 // Returns the last priority passed to CreateTransaction, or
293 // DEFAULT_PRIORITY if it hasn't been called yet. 305 // DEFAULT_PRIORITY if it hasn't been called yet.
294 RequestPriority last_create_transaction_priority() const { 306 RequestPriority last_create_transaction_priority() const {
295 return last_create_transaction_priority_; 307 return last_create_transaction_priority_;
296 } 308 }
297 309
298 // Returns the last transaction created by 310 // Returns the last transaction created by
299 // CreateTransaction. Returns a NULL WeakPtr if one has not been 311 // CreateTransaction. Returns a NULL WeakPtr if one has not been
300 // created yet, or the last transaction has been destroyed, or 312 // created yet, or the last transaction has been destroyed, or
301 // ClearLastTransaction() has been called and a new transaction 313 // ClearLastTransaction() has been called and a new transaction
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 350
339 //----------------------------------------------------------------------------- 351 //-----------------------------------------------------------------------------
340 // helpers 352 // helpers
341 353
342 // read the transaction completely 354 // read the transaction completely
343 int ReadTransaction(HttpTransaction* trans, std::string* result); 355 int ReadTransaction(HttpTransaction* trans, std::string* result);
344 356
345 } // namespace net 357 } // namespace net
346 358
347 #endif // NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ 359 #endif // NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_
OLDNEW
« no previous file with comments | « net/http/http_cache_unittest.cc ('k') | net/http/http_transaction_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698