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