| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tools/quic/test_tools/quic_test_client.h" | 5 #include "net/tools/quic/test_tools/quic_test_client.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 response_header_size_ = 0; | 563 response_header_size_ = 0; |
| 564 response_body_size_ = 0; | 564 response_body_size_ = 0; |
| 565 } | 565 } |
| 566 | 566 |
| 567 bool QuicTestClient::HaveActiveStream() { | 567 bool QuicTestClient::HaveActiveStream() { |
| 568 return push_promise_data_to_resend_.get() || | 568 return push_promise_data_to_resend_.get() || |
| 569 (stream_ != nullptr && | 569 (stream_ != nullptr && |
| 570 !client_->session()->IsClosedStream(stream_->id())); | 570 !client_->session()->IsClosedStream(stream_->id())); |
| 571 } | 571 } |
| 572 | 572 |
| 573 void QuicTestClient::WaitUntil(int timeout_ms, std::function<bool()> trigger) { | 573 bool QuicTestClient::WaitUntil(int timeout_ms, std::function<bool()> trigger) { |
| 574 int64_t timeout_us = timeout_ms * base::Time::kMicrosecondsPerMillisecond; | 574 int64_t timeout_us = timeout_ms * base::Time::kMicrosecondsPerMillisecond; |
| 575 int64_t old_timeout_us = epoll_server()->timeout_in_us(); | 575 int64_t old_timeout_us = epoll_server()->timeout_in_us(); |
| 576 if (timeout_us > 0) { | 576 if (timeout_us > 0) { |
| 577 epoll_server()->set_timeout_in_us(timeout_us); | 577 epoll_server()->set_timeout_in_us(timeout_us); |
| 578 } | 578 } |
| 579 const QuicClock* clock = | 579 const QuicClock* clock = |
| 580 QuicConnectionPeer::GetHelper(client()->session()->connection()) | 580 QuicConnectionPeer::GetHelper(client()->session()->connection()) |
| 581 ->GetClock(); | 581 ->GetClock(); |
| 582 QuicTime end_waiting_time = | 582 QuicTime end_waiting_time = |
| 583 clock->Now() + QuicTime::Delta::FromMicroseconds(timeout_us); | 583 clock->Now() + QuicTime::Delta::FromMicroseconds(timeout_us); |
| 584 while (HaveActiveStream() && !(trigger && trigger()) && | 584 while (HaveActiveStream() && !(trigger && trigger()) && |
| 585 (timeout_us < 0 || clock->Now() < end_waiting_time)) { | 585 (timeout_us < 0 || clock->Now() < end_waiting_time)) { |
| 586 client_->WaitForEvents(); | 586 client_->WaitForEvents(); |
| 587 } | 587 } |
| 588 if (timeout_us > 0) { | 588 if (timeout_us > 0) { |
| 589 epoll_server()->set_timeout_in_us(old_timeout_us); | 589 epoll_server()->set_timeout_in_us(old_timeout_us); |
| 590 } | 590 } |
| 591 if (trigger && !trigger()) { | 591 if (trigger && !trigger()) { |
| 592 VLOG(1) << "Client WaitUntil returning with trigger returning false."; | 592 VLOG(1) << "Client WaitUntil returning with trigger returning false."; |
| 593 return false; |
| 593 } | 594 } |
| 595 return true; |
| 594 } | 596 } |
| 595 | 597 |
| 596 ssize_t QuicTestClient::Send(const void* buffer, size_t size) { | 598 ssize_t QuicTestClient::Send(const void* buffer, size_t size) { |
| 597 return SendData(string(static_cast<const char*>(buffer), size), false); | 599 return SendData(string(static_cast<const char*>(buffer), size), false); |
| 598 } | 600 } |
| 599 | 601 |
| 600 bool QuicTestClient::response_headers_complete() const { | 602 bool QuicTestClient::response_headers_complete() const { |
| 601 if (stream_ != nullptr) { | 603 if (stream_ != nullptr) { |
| 602 return stream_->headers_decompressed(); | 604 return stream_->headers_decompressed(); |
| 603 } | 605 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 CHECK(message); | 753 CHECK(message); |
| 752 message->headers()->SetRequestVersion( | 754 message->headers()->SetRequestVersion( |
| 753 HTTPMessage::VersionToString(HttpConstants::HTTP_1_1)); | 755 HTTPMessage::VersionToString(HttpConstants::HTTP_1_1)); |
| 754 message->headers()->SetRequestMethod( | 756 message->headers()->SetRequestMethod( |
| 755 HTTPMessage::MethodToString(HttpConstants::GET)); | 757 HTTPMessage::MethodToString(HttpConstants::GET)); |
| 756 message->headers()->SetRequestUri(uri); | 758 message->headers()->SetRequestUri(uri); |
| 757 } | 759 } |
| 758 | 760 |
| 759 } // namespace test | 761 } // namespace test |
| 760 } // namespace net | 762 } // namespace net |
| OLD | NEW |