| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "net/http/http_transaction.h" | 9 #include "net/http/http_transaction.h" |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
| 17 #include "base/string16.h" | 17 #include "base/string16.h" |
| 18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "base/stringprintf.h" |
| 19 #include "net/base/io_buffer.h" | 20 #include "net/base/io_buffer.h" |
| 21 #include "net/base/load_flags.h" |
| 20 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 21 #include "net/base/load_flags.h" | |
| 22 #include "net/base/test_completion_callback.h" | 23 #include "net/base/test_completion_callback.h" |
| 23 #include "net/disk_cache/disk_cache.h" | 24 #include "net/disk_cache/disk_cache.h" |
| 24 #include "net/http/http_cache.h" | 25 #include "net/http/http_cache.h" |
| 25 #include "net/http/http_request_info.h" | 26 #include "net/http/http_request_info.h" |
| 26 #include "net/http/http_response_headers.h" | 27 #include "net/http/http_response_headers.h" |
| 27 #include "net/http/http_response_info.h" | 28 #include "net/http/http_response_info.h" |
| 28 | 29 |
| 29 //----------------------------------------------------------------------------- | 30 //----------------------------------------------------------------------------- |
| 30 // mock transaction data | 31 // mock transaction data |
| 31 | 32 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 const MockTransaction* t = FindMockTransaction(request->url); | 220 const MockTransaction* t = FindMockTransaction(request->url); |
| 220 if (!t) | 221 if (!t) |
| 221 return net::ERR_FAILED; | 222 return net::ERR_FAILED; |
| 222 | 223 |
| 223 std::string resp_status = t->status; | 224 std::string resp_status = t->status; |
| 224 std::string resp_headers = t->response_headers; | 225 std::string resp_headers = t->response_headers; |
| 225 std::string resp_data = t->data; | 226 std::string resp_data = t->data; |
| 226 if (t->handler) | 227 if (t->handler) |
| 227 (t->handler)(request, &resp_status, &resp_headers, &resp_data); | 228 (t->handler)(request, &resp_status, &resp_headers, &resp_data); |
| 228 | 229 |
| 229 std::string header_data = | 230 std::string header_data = base::StringPrintf( |
| 230 StringPrintf("%s\n%s\n", resp_status.c_str(), resp_headers.c_str()); | 231 "%s\n%s\n", resp_status.c_str(), resp_headers.c_str()); |
| 231 std::replace(header_data.begin(), header_data.end(), '\n', '\0'); | 232 std::replace(header_data.begin(), header_data.end(), '\n', '\0'); |
| 232 | 233 |
| 233 response_.request_time = base::Time::Now(); | 234 response_.request_time = base::Time::Now(); |
| 234 if (!t->request_time.is_null()) | 235 if (!t->request_time.is_null()) |
| 235 response_.request_time = t->request_time; | 236 response_.request_time = t->request_time; |
| 236 | 237 |
| 237 response_.was_cached = false; | 238 response_.was_cached = false; |
| 238 | 239 |
| 239 response_.response_time = base::Time::Now(); | 240 response_.response_time = base::Time::Now(); |
| 240 if (!t->response_time.is_null()) | 241 if (!t->response_time.is_null()) |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 }; | 347 }; |
| 347 | 348 |
| 348 | 349 |
| 349 //----------------------------------------------------------------------------- | 350 //----------------------------------------------------------------------------- |
| 350 // helpers | 351 // helpers |
| 351 | 352 |
| 352 // read the transaction completely | 353 // read the transaction completely |
| 353 int ReadTransaction(net::HttpTransaction* trans, std::string* result); | 354 int ReadTransaction(net::HttpTransaction* trans, std::string* result); |
| 354 | 355 |
| 355 #endif // NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ | 356 #endif // NET_HTTP_HTTP_TRANSACTION_UNITTEST_H_ |
| OLD | NEW |