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/quic/quic_http_stream.h" | 5 #include "net/quic/quic_http_stream.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 : QuicHttpStream(session) {} | 97 : QuicHttpStream(session) {} |
98 | 98 |
99 void OnHeadersAvailable(const SpdyHeaderBlock& headers, | 99 void OnHeadersAvailable(const SpdyHeaderBlock& headers, |
100 size_t frame_len) override { | 100 size_t frame_len) override { |
101 Close(false); | 101 Close(false); |
102 } | 102 } |
103 | 103 |
104 void OnDataAvailable() override { Close(false); } | 104 void OnDataAvailable() override { Close(false); } |
105 }; | 105 }; |
106 | 106 |
| 107 // UploadDataStream that always returns errors on data read. |
| 108 class ReadErrorUploadDataStream : public UploadDataStream { |
| 109 public: |
| 110 enum class FailureMode { SYNC, ASYNC }; |
| 111 |
| 112 explicit ReadErrorUploadDataStream(FailureMode mode) |
| 113 : UploadDataStream(true, 0), async_(mode), weak_factory_(this) {} |
| 114 ~ReadErrorUploadDataStream() override {} |
| 115 |
| 116 private: |
| 117 void CompleteRead() { UploadDataStream::OnReadCompleted(ERR_FAILED); } |
| 118 |
| 119 // UploadDataStream implementation: |
| 120 int InitInternal() override { return OK; } |
| 121 |
| 122 int ReadInternal(IOBuffer* buf, int buf_len) override { |
| 123 if (async_ == FailureMode::ASYNC) { |
| 124 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 125 FROM_HERE, base::Bind(&ReadErrorUploadDataStream::CompleteRead, |
| 126 weak_factory_.GetWeakPtr()), |
| 127 base::TimeDelta::FromSeconds(1)); |
| 128 return ERR_IO_PENDING; |
| 129 } |
| 130 return ERR_FAILED; |
| 131 } |
| 132 |
| 133 void ResetInternal() override {} |
| 134 |
| 135 const FailureMode async_; |
| 136 |
| 137 base::WeakPtrFactory<ReadErrorUploadDataStream> weak_factory_; |
| 138 |
| 139 DISALLOW_COPY_AND_ASSIGN(ReadErrorUploadDataStream); |
| 140 }; |
| 141 |
107 } // namespace | 142 } // namespace |
108 | 143 |
109 class QuicHttpStreamPeer { | 144 class QuicHttpStreamPeer { |
110 public: | 145 public: |
111 static QuicChromiumClientStream* GetQuicChromiumClientStream( | 146 static QuicChromiumClientStream* GetQuicChromiumClientStream( |
112 QuicHttpStream* stream) { | 147 QuicHttpStream* stream) { |
113 return stream->stream_; | 148 return stream->stream_; |
114 } | 149 } |
115 | 150 |
116 static bool WasHandshakeConfirmed(QuicHttpStream* stream) { | 151 static bool WasHandshakeConfirmed(QuicHttpStream* stream) { |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 QuicPacketNumber packet_number, | 453 QuicPacketNumber packet_number, |
419 QuicPacketNumber largest_received, | 454 QuicPacketNumber largest_received, |
420 QuicPacketNumber ack_least_unacked, | 455 QuicPacketNumber ack_least_unacked, |
421 QuicPacketNumber stop_least_unacked) { | 456 QuicPacketNumber stop_least_unacked) { |
422 return client_maker_.MakeAckAndRstPacket( | 457 return client_maker_.MakeAckAndRstPacket( |
423 packet_number, !kIncludeVersion, stream_id_, QUIC_STREAM_CANCELLED, | 458 packet_number, !kIncludeVersion, stream_id_, QUIC_STREAM_CANCELLED, |
424 largest_received, ack_least_unacked, stop_least_unacked, | 459 largest_received, ack_least_unacked, stop_least_unacked, |
425 !kIncludeCongestionFeedback); | 460 !kIncludeCongestionFeedback); |
426 } | 461 } |
427 | 462 |
| 463 std::unique_ptr<QuicReceivedPacket> ConstructClientRstStreamErrorPacket( |
| 464 QuicPacketNumber packet_number, |
| 465 bool include_version) { |
| 466 return client_maker_.MakeRstPacket(packet_number, include_version, |
| 467 stream_id_, |
| 468 QUIC_ERROR_PROCESSING_STREAM); |
| 469 } |
| 470 |
428 std::unique_ptr<QuicReceivedPacket> ConstructAckAndRstStreamPacket( | 471 std::unique_ptr<QuicReceivedPacket> ConstructAckAndRstStreamPacket( |
429 QuicPacketNumber packet_number) { | 472 QuicPacketNumber packet_number) { |
430 return ConstructAckAndRstStreamPacket(packet_number, 2, 1, 1); | 473 return ConstructAckAndRstStreamPacket(packet_number, 2, 1, 1); |
431 } | 474 } |
432 | 475 |
433 std::unique_ptr<QuicReceivedPacket> ConstructClientAckPacket( | 476 std::unique_ptr<QuicReceivedPacket> ConstructClientAckPacket( |
434 QuicPacketNumber packet_number, | 477 QuicPacketNumber packet_number, |
435 QuicPacketNumber largest_received, | 478 QuicPacketNumber largest_received, |
436 QuicPacketNumber least_unacked) { | 479 QuicPacketNumber least_unacked) { |
437 return client_maker_.MakeAckPacket(packet_number, largest_received, | 480 return client_maker_.MakeAckPacket(packet_number, largest_received, |
(...skipping 1275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1713 EXPECT_TRUE(AtEof()); | 1756 EXPECT_TRUE(AtEof()); |
1714 | 1757 |
1715 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the | 1758 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
1716 // headers and payload. | 1759 // headers and payload. |
1717 EXPECT_EQ(static_cast<int64_t>(spdy_request_header_frame_length), | 1760 EXPECT_EQ(static_cast<int64_t>(spdy_request_header_frame_length), |
1718 promised_stream_->GetTotalSentBytes()); | 1761 promised_stream_->GetTotalSentBytes()); |
1719 EXPECT_EQ(static_cast<int64_t>(spdy_response_header_frame_length), | 1762 EXPECT_EQ(static_cast<int64_t>(spdy_response_header_frame_length), |
1720 promised_stream_->GetTotalReceivedBytes()); | 1763 promised_stream_->GetTotalReceivedBytes()); |
1721 } | 1764 } |
1722 | 1765 |
| 1766 TEST_P(QuicHttpStreamTest, DataReadErrorSynchronous) { |
| 1767 SetRequest("POST", "/", DEFAULT_PRIORITY); |
| 1768 size_t spdy_request_headers_frame_length; |
| 1769 AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, |
| 1770 &spdy_request_headers_frame_length)); |
| 1771 AddWrite(ConstructClientRstStreamErrorPacket(2, kIncludeVersion)); |
| 1772 |
| 1773 Initialize(); |
| 1774 |
| 1775 ReadErrorUploadDataStream upload_data_stream( |
| 1776 ReadErrorUploadDataStream::FailureMode::SYNC); |
| 1777 request_.method = "POST"; |
| 1778 request_.url = GURL("http://www.example.org/"); |
| 1779 request_.upload_data_stream = &upload_data_stream; |
| 1780 ASSERT_EQ(OK, request_.upload_data_stream->Init( |
| 1781 TestCompletionCallback().callback())); |
| 1782 |
| 1783 EXPECT_EQ(OK, |
| 1784 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1785 net_log_.bound(), callback_.callback())); |
| 1786 |
| 1787 int result = stream_->SendRequest(headers_, &response_, callback_.callback()); |
| 1788 EXPECT_EQ(ERR_FAILED, result); |
| 1789 |
| 1790 EXPECT_TRUE(AtEof()); |
| 1791 |
| 1792 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. |
| 1793 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
| 1794 stream_->GetTotalSentBytes()); |
| 1795 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
| 1796 } |
| 1797 |
| 1798 TEST_P(QuicHttpStreamTest, DataReadErrorAsynchronous) { |
| 1799 SetRequest("POST", "/", DEFAULT_PRIORITY); |
| 1800 size_t spdy_request_headers_frame_length; |
| 1801 AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, |
| 1802 &spdy_request_headers_frame_length)); |
| 1803 AddWrite(ConstructClientRstStreamErrorPacket(2, !kIncludeVersion)); |
| 1804 |
| 1805 Initialize(); |
| 1806 |
| 1807 ReadErrorUploadDataStream upload_data_stream( |
| 1808 ReadErrorUploadDataStream::FailureMode::ASYNC); |
| 1809 request_.method = "POST"; |
| 1810 request_.url = GURL("http://www.example.org/"); |
| 1811 request_.upload_data_stream = &upload_data_stream; |
| 1812 ASSERT_EQ(OK, request_.upload_data_stream->Init( |
| 1813 TestCompletionCallback().callback())); |
| 1814 |
| 1815 EXPECT_EQ(OK, |
| 1816 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1817 net_log_.bound(), callback_.callback())); |
| 1818 |
| 1819 int result = stream_->SendRequest(headers_, &response_, callback_.callback()); |
| 1820 |
| 1821 ProcessPacket(ConstructServerAckPacket(1, 0, 0)); |
| 1822 SetResponse("200 OK", string()); |
| 1823 |
| 1824 EXPECT_EQ(ERR_IO_PENDING, result); |
| 1825 EXPECT_EQ(ERR_FAILED, callback_.GetResult(result)); |
| 1826 |
| 1827 EXPECT_TRUE(AtEof()); |
| 1828 |
| 1829 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. |
| 1830 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
| 1831 stream_->GetTotalSentBytes()); |
| 1832 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
| 1833 } |
| 1834 |
1723 } // namespace test | 1835 } // namespace test |
1724 } // namespace net | 1836 } // namespace net |
OLD | NEW |