| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 <algorithm> | 10 #include <algorithm> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 typedef void (*MockTransactionHandler)(const net::HttpRequestInfo* request, | 38 typedef void (*MockTransactionHandler)(const net::HttpRequestInfo* request, |
| 39 std::string* response_status, | 39 std::string* response_status, |
| 40 std::string* response_headers, | 40 std::string* response_headers, |
| 41 std::string* response_data); | 41 std::string* response_data); |
| 42 | 42 |
| 43 struct MockTransaction { | 43 struct MockTransaction { |
| 44 const char* url; | 44 const char* url; |
| 45 const char* method; | 45 const char* method; |
| 46 // If |request_time| is unspecified, the current time will be used. |
| 47 base::Time request_time; |
| 46 const char* request_headers; | 48 const char* request_headers; |
| 47 int load_flags; | 49 int load_flags; |
| 48 const char* status; | 50 const char* status; |
| 49 const char* response_headers; | 51 const char* response_headers; |
| 50 // If |response_time| is unspecified, the current time will be used. | 52 // If |response_time| is unspecified, the current time will be used. |
| 51 base::Time response_time; | 53 base::Time response_time; |
| 52 const char* data; | 54 const char* data; |
| 53 int test_mode; | 55 int test_mode; |
| 54 MockTransactionHandler handler; | 56 MockTransactionHandler handler; |
| 55 int cert_status; | 57 int cert_status; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 std::string resp_headers = t->response_headers; | 214 std::string resp_headers = t->response_headers; |
| 213 std::string resp_data = t->data; | 215 std::string resp_data = t->data; |
| 214 if (t->handler) | 216 if (t->handler) |
| 215 (t->handler)(request, &resp_status, &resp_headers, &resp_data); | 217 (t->handler)(request, &resp_status, &resp_headers, &resp_data); |
| 216 | 218 |
| 217 std::string header_data = | 219 std::string header_data = |
| 218 StringPrintf("%s\n%s\n", resp_status.c_str(), resp_headers.c_str()); | 220 StringPrintf("%s\n%s\n", resp_status.c_str(), resp_headers.c_str()); |
| 219 std::replace(header_data.begin(), header_data.end(), '\n', '\0'); | 221 std::replace(header_data.begin(), header_data.end(), '\n', '\0'); |
| 220 | 222 |
| 221 response_.request_time = base::Time::Now(); | 223 response_.request_time = base::Time::Now(); |
| 224 if (!t->request_time.is_null()) |
| 225 response_.request_time = t->request_time; |
| 226 |
| 222 response_.was_cached = false; | 227 response_.was_cached = false; |
| 223 | 228 |
| 224 response_.response_time = base::Time::Now(); | 229 response_.response_time = base::Time::Now(); |
| 225 if (!t->response_time.is_null()) | 230 if (!t->response_time.is_null()) |
| 226 response_.response_time = t->response_time; | 231 response_.response_time = t->response_time; |
| 227 | 232 |
| 228 response_.headers = new net::HttpResponseHeaders(header_data); | 233 response_.headers = new net::HttpResponseHeaders(header_data); |
| 229 response_.ssl_info.cert_status = t->cert_status; | 234 response_.ssl_info.cert_status = t->cert_status; |
| 230 data_ = resp_data; | 235 data_ = resp_data; |
| 231 test_mode_ = t->test_mode; | 236 test_mode_ = t->test_mode; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 }; | 328 }; |
| 324 | 329 |
| 325 | 330 |
| 326 //----------------------------------------------------------------------------- | 331 //----------------------------------------------------------------------------- |
| 327 // helpers | 332 // helpers |
| 328 | 333 |
| 329 // read the transaction completely | 334 // read the transaction completely |
| 330 int ReadTransaction(net::HttpTransaction* trans, std::string* result); | 335 int ReadTransaction(net::HttpTransaction* trans, std::string* result); |
| 331 | 336 |
| 332 #endif // NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ | 337 #endif // NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ |
| OLD | NEW |