| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/quic/chromium/bidirectional_stream_quic_impl.h" | 5 #include "net/quic/chromium/bidirectional_stream_quic_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 next_proto_(kProtoUnknown), | 76 next_proto_(kProtoUnknown), |
| 77 received_bytes_(0), | 77 received_bytes_(0), |
| 78 sent_bytes_(0), | 78 sent_bytes_(0), |
| 79 has_load_timing_info_(false), | 79 has_load_timing_info_(false), |
| 80 error_(OK), | 80 error_(OK), |
| 81 on_data_read_count_(0), | 81 on_data_read_count_(0), |
| 82 on_data_sent_count_(0), | 82 on_data_sent_count_(0), |
| 83 not_expect_callback_(false), | 83 not_expect_callback_(false), |
| 84 on_failed_called_(false), | 84 on_failed_called_(false), |
| 85 send_request_headers_automatically_(true), | 85 send_request_headers_automatically_(true), |
| 86 is_ready_(false) { | 86 is_ready_(false), |
| 87 trailers_expected_(false), |
| 88 trailers_received_(false) { |
| 87 loop_.reset(new base::RunLoop); | 89 loop_.reset(new base::RunLoop); |
| 88 } | 90 } |
| 89 | 91 |
| 90 ~TestDelegateBase() override {} | 92 ~TestDelegateBase() override {} |
| 91 | 93 |
| 92 void OnStreamReady(bool request_headers_sent) override { | 94 void OnStreamReady(bool request_headers_sent) override { |
| 93 CHECK(!is_ready_); | 95 CHECK(!is_ready_); |
| 94 CHECK(!on_failed_called_); | 96 CHECK(!on_failed_called_); |
| 95 EXPECT_EQ(send_request_headers_automatically_, request_headers_sent); | 97 EXPECT_EQ(send_request_headers_automatically_, request_headers_sent); |
| 96 CHECK(!not_expect_callback_); | 98 CHECK(!not_expect_callback_); |
| 97 is_ready_ = true; | 99 is_ready_ = true; |
| 98 loop_->Quit(); | 100 loop_->Quit(); |
| 99 } | 101 } |
| 100 | 102 |
| 101 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override { | 103 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override { |
| 102 CHECK(!on_failed_called_); | 104 CHECK(!on_failed_called_); |
| 103 CHECK(!not_expect_callback_); | 105 CHECK(!not_expect_callback_); |
| 104 | 106 |
| 105 response_headers_ = response_headers.Clone(); | 107 response_headers_ = response_headers.Clone(); |
| 106 loop_->Quit(); | 108 loop_->Quit(); |
| 107 } | 109 } |
| 108 | 110 |
| 109 void OnDataRead(int bytes_read) override { | 111 void OnDataRead(int bytes_read) override { |
| 110 CHECK(!on_failed_called_); | 112 CHECK(!on_failed_called_); |
| 111 CHECK(!not_expect_callback_); | 113 CHECK(!not_expect_callback_); |
| 112 CHECK(!callback_.is_null()); | 114 CHECK(!callback_.is_null()); |
| 113 | 115 |
| 116 // If read EOF, make sure this callback is after trailers callback. |
| 117 if (bytes_read == 0) |
| 118 EXPECT_TRUE(!trailers_expected_ || trailers_received_); |
| 114 ++on_data_read_count_; | 119 ++on_data_read_count_; |
| 115 CHECK_GE(bytes_read, OK); | 120 CHECK_GE(bytes_read, OK); |
| 116 data_received_.append(read_buf_->data(), bytes_read); | 121 data_received_.append(read_buf_->data(), bytes_read); |
| 117 base::ResetAndReturn(&callback_).Run(bytes_read); | 122 base::ResetAndReturn(&callback_).Run(bytes_read); |
| 118 } | 123 } |
| 119 | 124 |
| 120 void OnDataSent() override { | 125 void OnDataSent() override { |
| 121 CHECK(!on_failed_called_); | 126 CHECK(!on_failed_called_); |
| 122 CHECK(!not_expect_callback_); | 127 CHECK(!not_expect_callback_); |
| 123 | 128 |
| 124 ++on_data_sent_count_; | 129 ++on_data_sent_count_; |
| 125 loop_->Quit(); | 130 loop_->Quit(); |
| 126 } | 131 } |
| 127 | 132 |
| 128 void OnTrailersReceived(const SpdyHeaderBlock& trailers) override { | 133 void OnTrailersReceived(const SpdyHeaderBlock& trailers) override { |
| 129 CHECK(!on_failed_called_); | 134 CHECK(!on_failed_called_); |
| 130 CHECK(!not_expect_callback_); | 135 CHECK(!not_expect_callback_); |
| 131 | 136 |
| 137 trailers_received_ = true; |
| 132 trailers_ = trailers.Clone(); | 138 trailers_ = trailers.Clone(); |
| 133 loop_->Quit(); | 139 loop_->Quit(); |
| 134 } | 140 } |
| 135 | 141 |
| 136 void OnFailed(int error) override { | 142 void OnFailed(int error) override { |
| 137 CHECK(!on_failed_called_); | 143 CHECK(!on_failed_called_); |
| 138 CHECK(!not_expect_callback_); | 144 CHECK(!not_expect_callback_); |
| 139 CHECK_EQ(OK, error_); | 145 CHECK_EQ(OK, error_); |
| 140 CHECK_NE(OK, error); | 146 CHECK_NE(OK, error); |
| 141 | 147 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 225 |
| 220 // Deletes |stream_|. | 226 // Deletes |stream_|. |
| 221 void DeleteStream() { | 227 void DeleteStream() { |
| 222 next_proto_ = stream_->GetProtocol(); | 228 next_proto_ = stream_->GetProtocol(); |
| 223 received_bytes_ = stream_->GetTotalReceivedBytes(); | 229 received_bytes_ = stream_->GetTotalReceivedBytes(); |
| 224 sent_bytes_ = stream_->GetTotalSentBytes(); | 230 sent_bytes_ = stream_->GetTotalSentBytes(); |
| 225 has_load_timing_info_ = stream_->GetLoadTimingInfo(&load_timing_info_); | 231 has_load_timing_info_ = stream_->GetLoadTimingInfo(&load_timing_info_); |
| 226 stream_.reset(); | 232 stream_.reset(); |
| 227 } | 233 } |
| 228 | 234 |
| 235 void set_trailers_expected(bool trailers_expected) { |
| 236 trailers_expected_ = trailers_expected; |
| 237 } |
| 229 // Const getters for internal states. | 238 // Const getters for internal states. |
| 230 const std::string& data_received() const { return data_received_; } | 239 const std::string& data_received() const { return data_received_; } |
| 231 int error() const { return error_; } | 240 int error() const { return error_; } |
| 232 const SpdyHeaderBlock& response_headers() const { return response_headers_; } | 241 const SpdyHeaderBlock& response_headers() const { return response_headers_; } |
| 233 const SpdyHeaderBlock& trailers() const { return trailers_; } | 242 const SpdyHeaderBlock& trailers() const { return trailers_; } |
| 234 int on_data_read_count() const { return on_data_read_count_; } | 243 int on_data_read_count() const { return on_data_read_count_; } |
| 235 int on_data_sent_count() const { return on_data_sent_count_; } | 244 int on_data_sent_count() const { return on_data_sent_count_; } |
| 236 bool on_failed_called() const { return on_failed_called_; } | 245 bool on_failed_called() const { return on_failed_called_; } |
| 237 bool is_ready() const { return is_ready_; } | 246 bool is_ready() const { return is_ready_; } |
| 238 | 247 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 257 int error_; | 266 int error_; |
| 258 int on_data_read_count_; | 267 int on_data_read_count_; |
| 259 int on_data_sent_count_; | 268 int on_data_sent_count_; |
| 260 // This is to ensure that delegate callback is not invoked synchronously when | 269 // This is to ensure that delegate callback is not invoked synchronously when |
| 261 // calling into |stream_|. | 270 // calling into |stream_|. |
| 262 bool not_expect_callback_; | 271 bool not_expect_callback_; |
| 263 bool on_failed_called_; | 272 bool on_failed_called_; |
| 264 CompletionCallback callback_; | 273 CompletionCallback callback_; |
| 265 bool send_request_headers_automatically_; | 274 bool send_request_headers_automatically_; |
| 266 bool is_ready_; | 275 bool is_ready_; |
| 276 bool trailers_expected_; |
| 277 bool trailers_received_; |
| 267 | 278 |
| 268 DISALLOW_COPY_AND_ASSIGN(TestDelegateBase); | 279 DISALLOW_COPY_AND_ASSIGN(TestDelegateBase); |
| 269 }; | 280 }; |
| 270 | 281 |
| 271 // A delegate that deletes the stream in a particular callback. | 282 // A delegate that deletes the stream in a particular callback. |
| 272 class DeleteStreamDelegate : public TestDelegateBase { | 283 class DeleteStreamDelegate : public TestDelegateBase { |
| 273 public: | 284 public: |
| 274 // Specifies in which callback the stream can be deleted. | 285 // Specifies in which callback the stream can be deleted. |
| 275 enum Phase { | 286 enum Phase { |
| 276 ON_HEADERS_RECEIVED, | 287 ON_HEADERS_RECEIVED, |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 | 710 |
| 700 BidirectionalStreamRequestInfo request; | 711 BidirectionalStreamRequestInfo request; |
| 701 request.method = "GET"; | 712 request.method = "GET"; |
| 702 request.url = GURL("http://www.google.com/"); | 713 request.url = GURL("http://www.google.com/"); |
| 703 request.end_stream_on_headers = true; | 714 request.end_stream_on_headers = true; |
| 704 request.priority = DEFAULT_PRIORITY; | 715 request.priority = DEFAULT_PRIORITY; |
| 705 | 716 |
| 706 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); | 717 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); |
| 707 std::unique_ptr<TestDelegateBase> delegate( | 718 std::unique_ptr<TestDelegateBase> delegate( |
| 708 new TestDelegateBase(read_buffer.get(), kReadBufferSize)); | 719 new TestDelegateBase(read_buffer.get(), kReadBufferSize)); |
| 720 delegate->set_trailers_expected(true); |
| 709 delegate->Start(&request, net_log().bound(), session()->GetWeakPtr()); | 721 delegate->Start(&request, net_log().bound(), session()->GetWeakPtr()); |
| 710 delegate->WaitUntilNextCallback(); // OnStreamReady | 722 delegate->WaitUntilNextCallback(); // OnStreamReady |
| 711 ConfirmHandshake(); | 723 ConfirmHandshake(); |
| 712 | 724 |
| 713 // Server acks the request. | 725 // Server acks the request. |
| 714 ProcessPacket(ConstructServerAckPacket(1, 0, 0)); | 726 ProcessPacket(ConstructServerAckPacket(1, 0, 0)); |
| 715 | 727 |
| 716 // Server sends the response headers. | 728 // Server sends the response headers. |
| 717 SpdyHeaderBlock response_headers = ConstructResponseHeaders("200"); | 729 SpdyHeaderBlock response_headers = ConstructResponseHeaders("200"); |
| 718 | 730 |
| (...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1757 | 1769 |
| 1758 base::RunLoop().RunUntilIdle(); | 1770 base::RunLoop().RunUntilIdle(); |
| 1759 | 1771 |
| 1760 EXPECT_EQ(1, delegate->on_data_read_count()); | 1772 EXPECT_EQ(1, delegate->on_data_read_count()); |
| 1761 EXPECT_EQ(0, delegate->on_data_sent_count()); | 1773 EXPECT_EQ(0, delegate->on_data_sent_count()); |
| 1762 } | 1774 } |
| 1763 | 1775 |
| 1764 } // namespace test | 1776 } // namespace test |
| 1765 | 1777 |
| 1766 } // namespace net | 1778 } // namespace net |
| OLD | NEW |