Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "net/http/http_transaction_test_util.h" | 5 #include "net/http/http_transaction_test_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 } | 235 } |
| 236 | 236 |
| 237 MockNetworkTransaction::MockNetworkTransaction(RequestPriority priority, | 237 MockNetworkTransaction::MockNetworkTransaction(RequestPriority priority, |
| 238 MockNetworkLayer* factory) | 238 MockNetworkLayer* factory) |
| 239 : request_(NULL), | 239 : request_(NULL), |
| 240 data_cursor_(0), | 240 data_cursor_(0), |
| 241 priority_(priority), | 241 priority_(priority), |
| 242 websocket_handshake_stream_create_helper_(NULL), | 242 websocket_handshake_stream_create_helper_(NULL), |
| 243 transaction_factory_(factory->AsWeakPtr()), | 243 transaction_factory_(factory->AsWeakPtr()), |
| 244 received_bytes_(0), | 244 received_bytes_(0), |
| 245 sent_bytes_(0), | |
| 245 socket_log_id_(NetLog::Source::kInvalidId), | 246 socket_log_id_(NetLog::Source::kInvalidId), |
| 246 weak_factory_(this) { | 247 weak_factory_(this) {} |
| 247 } | |
| 248 | 248 |
| 249 MockNetworkTransaction::~MockNetworkTransaction() {} | 249 MockNetworkTransaction::~MockNetworkTransaction() {} |
| 250 | 250 |
| 251 int MockNetworkTransaction::Start(const HttpRequestInfo* request, | 251 int MockNetworkTransaction::Start(const HttpRequestInfo* request, |
| 252 const CompletionCallback& callback, | 252 const CompletionCallback& callback, |
| 253 const BoundNetLog& net_log) { | 253 const BoundNetLog& net_log) { |
| 254 if (request_) | 254 if (request_) |
| 255 return ERR_FAILED; | 255 return ERR_FAILED; |
| 256 | 256 |
| 257 request_ = request; | 257 request_ = request; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 | 322 |
| 323 bool MockNetworkTransaction::GetFullRequestHeaders( | 323 bool MockNetworkTransaction::GetFullRequestHeaders( |
| 324 HttpRequestHeaders* headers) const { | 324 HttpRequestHeaders* headers) const { |
| 325 return false; | 325 return false; |
| 326 } | 326 } |
| 327 | 327 |
| 328 int64 MockNetworkTransaction::GetTotalReceivedBytes() const { | 328 int64 MockNetworkTransaction::GetTotalReceivedBytes() const { |
| 329 return received_bytes_; | 329 return received_bytes_; |
| 330 } | 330 } |
| 331 | 331 |
| 332 int64_t MockNetworkTransaction::GetTotalSentBytes() const { | |
| 333 return sent_bytes_; | |
| 334 } | |
| 335 | |
| 332 void MockNetworkTransaction::DoneReading() { | 336 void MockNetworkTransaction::DoneReading() { |
| 333 if (transaction_factory_.get()) | 337 if (transaction_factory_.get()) |
| 334 transaction_factory_->TransactionDoneReading(); | 338 transaction_factory_->TransactionDoneReading(); |
| 335 } | 339 } |
| 336 | 340 |
| 337 const HttpResponseInfo* MockNetworkTransaction::GetResponseInfo() const { | 341 const HttpResponseInfo* MockNetworkTransaction::GetResponseInfo() const { |
| 338 return &response_; | 342 return &response_; |
| 339 } | 343 } |
| 340 | 344 |
| 341 LoadState MockNetworkTransaction::GetLoadState() const { | 345 LoadState MockNetworkTransaction::GetLoadState() const { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 test_mode_ = t->test_mode; | 397 test_mode_ = t->test_mode; |
| 394 | 398 |
| 395 // Return immediately if we're returning an error. | 399 // Return immediately if we're returning an error. |
| 396 if (OK != t->return_code) { | 400 if (OK != t->return_code) { |
| 397 if (test_mode_ & TEST_MODE_SYNC_NET_START) | 401 if (test_mode_ & TEST_MODE_SYNC_NET_START) |
| 398 return t->return_code; | 402 return t->return_code; |
| 399 CallbackLater(callback, t->return_code); | 403 CallbackLater(callback, t->return_code); |
| 400 return ERR_IO_PENDING; | 404 return ERR_IO_PENDING; |
| 401 } | 405 } |
| 402 | 406 |
| 407 std::string request_line = | |
| 408 base::StringPrintf("%s %s HTTP/1.1\r\n", request->method.c_str(), | |
| 409 request->url.PathForRequest().c_str()); | |
| 410 sent_bytes_ = request_line.size(); | |
| 411 if (t->request_headers) | |
| 412 sent_bytes_ += strlen(t->request_headers); | |
|
mmenke
2015/09/04 15:21:49
This logic seems ugly and pointless, given that we
sclittle
2015/09/04 22:03:10
Done.
| |
| 413 | |
| 403 std::string resp_status = t->status; | 414 std::string resp_status = t->status; |
| 404 std::string resp_headers = t->response_headers; | 415 std::string resp_headers = t->response_headers; |
| 405 std::string resp_data = t->data; | 416 std::string resp_data = t->data; |
| 406 received_bytes_ = resp_status.size() + resp_headers.size() + resp_data.size(); | 417 received_bytes_ = resp_status.size() + resp_headers.size() + resp_data.size(); |
| 407 if (t->handler) | 418 if (t->handler) |
| 408 (t->handler)(request, &resp_status, &resp_headers, &resp_data); | 419 (t->handler)(request, &resp_status, &resp_headers, &resp_data); |
| 409 | 420 |
| 410 std::string header_data = base::StringPrintf( | 421 std::string header_data = base::StringPrintf( |
| 411 "%s\n%s\n", resp_status.c_str(), resp_headers.c_str()); | 422 "%s\n%s\n", resp_status.c_str(), resp_headers.c_str()); |
| 412 std::replace(header_data.begin(), header_data.end(), '\n', '\0'); | 423 std::replace(header_data.begin(), header_data.end(), '\n', '\0'); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 content.append(buf->data(), rv); | 550 content.append(buf->data(), rv); |
| 540 else if (rv < 0) | 551 else if (rv < 0) |
| 541 return rv; | 552 return rv; |
| 542 } while (rv > 0); | 553 } while (rv > 0); |
| 543 | 554 |
| 544 result->swap(content); | 555 result->swap(content); |
| 545 return OK; | 556 return OK; |
| 546 } | 557 } |
| 547 | 558 |
| 548 } // namespace net | 559 } // namespace net |
| OLD | NEW |