| 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 #include <unordered_map> | 8 #include <unordered_map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 // static | 402 // static |
| 403 const int64_t MockNetworkTransaction::kTotalSentBytes = 100; | 403 const int64_t MockNetworkTransaction::kTotalSentBytes = 100; |
| 404 | 404 |
| 405 int MockNetworkTransaction::StartInternal(const HttpRequestInfo* request, | 405 int MockNetworkTransaction::StartInternal(const HttpRequestInfo* request, |
| 406 const CompletionCallback& callback, | 406 const CompletionCallback& callback, |
| 407 const NetLogWithSource& net_log) { | 407 const NetLogWithSource& net_log) { |
| 408 const MockTransaction* t = FindMockTransaction(request->url); | 408 const MockTransaction* t = FindMockTransaction(request->url); |
| 409 if (!t) | 409 if (!t) |
| 410 return ERR_FAILED; | 410 return ERR_FAILED; |
| 411 | 411 |
| 412 if (!before_network_start_callback_.is_null()) { |
| 413 bool defer = false; |
| 414 before_network_start_callback_.Run(&defer); |
| 415 if (defer) |
| 416 return net::ERR_IO_PENDING; |
| 417 } |
| 418 |
| 412 test_mode_ = t->test_mode; | 419 test_mode_ = t->test_mode; |
| 413 | 420 |
| 414 // Return immediately if we're returning an error. | 421 // Return immediately if we're returning an error. |
| 415 if (OK != t->return_code) { | 422 if (OK != t->return_code) { |
| 416 if (test_mode_ & TEST_MODE_SYNC_NET_START) | 423 if (test_mode_ & TEST_MODE_SYNC_NET_START) |
| 417 return t->return_code; | 424 return t->return_code; |
| 418 CallbackLater(callback, t->return_code); | 425 CallbackLater(callback, t->return_code); |
| 419 return ERR_IO_PENDING; | 426 return ERR_IO_PENDING; |
| 420 } | 427 } |
| 421 | 428 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 452 response_.ssl_info.connection_status = t->ssl_connection_status; | 459 response_.ssl_info.connection_status = t->ssl_connection_status; |
| 453 data_ = resp_data; | 460 data_ = resp_data; |
| 454 content_length_ = response_.headers->GetContentLength(); | 461 content_length_ = response_.headers->GetContentLength(); |
| 455 | 462 |
| 456 if (net_log.net_log()) | 463 if (net_log.net_log()) |
| 457 socket_log_id_ = net_log.net_log()->NextID(); | 464 socket_log_id_ = net_log.net_log()->NextID(); |
| 458 | 465 |
| 459 if (request_->load_flags & LOAD_PREFETCH) | 466 if (request_->load_flags & LOAD_PREFETCH) |
| 460 response_.unused_since_prefetch = true; | 467 response_.unused_since_prefetch = true; |
| 461 | 468 |
| 462 // Pause and resume. | |
| 463 if (!before_network_start_callback_.is_null()) { | |
| 464 bool defer = false; | |
| 465 before_network_start_callback_.Run(&defer); | |
| 466 if (defer) { | |
| 467 callback_ = callback; | |
| 468 return net::ERR_IO_PENDING; | |
| 469 } | |
| 470 } | |
| 471 | |
| 472 if (test_mode_ & TEST_MODE_SYNC_NET_START) | 469 if (test_mode_ & TEST_MODE_SYNC_NET_START) |
| 473 return OK; | 470 return OK; |
| 474 | 471 |
| 475 CallbackLater(callback, OK); | 472 CallbackLater(callback, OK); |
| 476 return ERR_IO_PENDING; | 473 return ERR_IO_PENDING; |
| 477 } | 474 } |
| 478 | 475 |
| 479 void MockNetworkTransaction::SetBeforeNetworkStartCallback( | 476 void MockNetworkTransaction::SetBeforeNetworkStartCallback( |
| 480 const BeforeNetworkStartCallback& callback) { | 477 const BeforeNetworkStartCallback& callback) { |
| 481 before_network_start_callback_ = callback; | 478 before_network_start_callback_ = callback; |
| 482 } | 479 } |
| 483 | 480 |
| 484 void MockNetworkTransaction::SetBeforeHeadersSentCallback( | 481 void MockNetworkTransaction::SetBeforeHeadersSentCallback( |
| 485 const BeforeHeadersSentCallback& callback) {} | 482 const BeforeHeadersSentCallback& callback) {} |
| 486 | 483 |
| 487 int MockNetworkTransaction::ResumeNetworkStart() { | 484 int MockNetworkTransaction::ResumeNetworkStart() { |
| 488 DCHECK(!callback_.is_null()); | 485 // Should not get here. |
| 489 CallbackLater(callback_, OK); | 486 return ERR_FAILED; |
| 490 return ERR_IO_PENDING; | |
| 491 } | 487 } |
| 492 | 488 |
| 493 void MockNetworkTransaction::GetConnectionAttempts( | 489 void MockNetworkTransaction::GetConnectionAttempts( |
| 494 ConnectionAttempts* out) const { | 490 ConnectionAttempts* out) const { |
| 495 NOTIMPLEMENTED(); | 491 NOTIMPLEMENTED(); |
| 496 } | 492 } |
| 497 | 493 |
| 498 void MockNetworkTransaction::CallbackLater(const CompletionCallback& callback, | 494 void MockNetworkTransaction::CallbackLater(const CompletionCallback& callback, |
| 499 int result) { | 495 int result) { |
| 500 base::ThreadTaskRunnerHandle::Get()->PostTask( | 496 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 content.append(buf->data(), rv); | 578 content.append(buf->data(), rv); |
| 583 else if (rv < 0) | 579 else if (rv < 0) |
| 584 return rv; | 580 return rv; |
| 585 } while (rv > 0); | 581 } while (rv > 0); |
| 586 | 582 |
| 587 result->swap(content); | 583 result->swap(content); |
| 588 return OK; | 584 return OK; |
| 589 } | 585 } |
| 590 | 586 |
| 591 } // namespace net | 587 } // namespace net |
| OLD | NEW |