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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 : QuicHttpStream(session) {} | 98 : QuicHttpStream(session) {} |
99 | 99 |
100 void OnHeadersAvailable(const SpdyHeaderBlock& headers, | 100 void OnHeadersAvailable(const SpdyHeaderBlock& headers, |
101 size_t frame_len) override { | 101 size_t frame_len) override { |
102 Close(false); | 102 Close(false); |
103 } | 103 } |
104 | 104 |
105 void OnDataAvailable() override { Close(false); } | 105 void OnDataAvailable() override { Close(false); } |
106 }; | 106 }; |
107 | 107 |
| 108 // UploadDataStream that always returns errors on data read. |
| 109 class ReadErrorUploadDataStream : public UploadDataStream { |
| 110 public: |
| 111 enum class FailureMode { SYNC, ASYNC }; |
| 112 |
| 113 explicit ReadErrorUploadDataStream(FailureMode mode) |
| 114 : UploadDataStream(true, 0), async_(mode), weak_factory_(this) {} |
| 115 ~ReadErrorUploadDataStream() override {} |
| 116 |
| 117 private: |
| 118 void CompleteRead() { UploadDataStream::OnReadCompleted(ERR_FAILED); } |
| 119 |
| 120 // UploadDataStream implementation: |
| 121 int InitInternal() override { return OK; } |
| 122 |
| 123 int ReadInternal(IOBuffer* buf, int buf_len) override { |
| 124 if (async_ == FailureMode::ASYNC) { |
| 125 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 126 FROM_HERE, base::Bind(&ReadErrorUploadDataStream::CompleteRead, |
| 127 weak_factory_.GetWeakPtr())); |
| 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 |
108 } // namespace | 142 } // namespace |
109 | 143 |
110 class QuicHttpStreamPeer { | 144 class QuicHttpStreamPeer { |
111 public: | 145 public: |
112 static QuicChromiumClientStream* GetQuicChromiumClientStream( | 146 static QuicChromiumClientStream* GetQuicChromiumClientStream( |
113 QuicHttpStream* stream) { | 147 QuicHttpStream* stream) { |
114 return stream->stream_; | 148 return stream->stream_; |
115 } | 149 } |
116 | 150 |
117 static bool WasHandshakeConfirmed(QuicHttpStream* stream) { | 151 static bool WasHandshakeConfirmed(QuicHttpStream* stream) { |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 QuicPacketNumber packet_number, | 453 QuicPacketNumber packet_number, |
420 QuicPacketNumber largest_received, | 454 QuicPacketNumber largest_received, |
421 QuicPacketNumber ack_least_unacked, | 455 QuicPacketNumber ack_least_unacked, |
422 QuicPacketNumber stop_least_unacked) { | 456 QuicPacketNumber stop_least_unacked) { |
423 return client_maker_.MakeAckAndRstPacket( | 457 return client_maker_.MakeAckAndRstPacket( |
424 packet_number, !kIncludeVersion, stream_id_, QUIC_STREAM_CANCELLED, | 458 packet_number, !kIncludeVersion, stream_id_, QUIC_STREAM_CANCELLED, |
425 largest_received, ack_least_unacked, stop_least_unacked, | 459 largest_received, ack_least_unacked, stop_least_unacked, |
426 !kIncludeCongestionFeedback); | 460 !kIncludeCongestionFeedback); |
427 } | 461 } |
428 | 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 |
429 std::unique_ptr<QuicReceivedPacket> ConstructAckAndRstStreamPacket( | 471 std::unique_ptr<QuicReceivedPacket> ConstructAckAndRstStreamPacket( |
430 QuicPacketNumber packet_number) { | 472 QuicPacketNumber packet_number) { |
431 return ConstructAckAndRstStreamPacket(packet_number, 2, 1, 1); | 473 return ConstructAckAndRstStreamPacket(packet_number, 2, 1, 1); |
432 } | 474 } |
433 | 475 |
434 std::unique_ptr<QuicReceivedPacket> ConstructClientAckPacket( | 476 std::unique_ptr<QuicReceivedPacket> ConstructClientAckPacket( |
435 QuicPacketNumber packet_number, | 477 QuicPacketNumber packet_number, |
436 QuicPacketNumber largest_received, | 478 QuicPacketNumber largest_received, |
437 QuicPacketNumber least_unacked) { | 479 QuicPacketNumber least_unacked) { |
438 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... |
1714 EXPECT_TRUE(AtEof()); | 1756 EXPECT_TRUE(AtEof()); |
1715 | 1757 |
1716 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the | 1758 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
1717 // headers and payload. | 1759 // headers and payload. |
1718 EXPECT_EQ(static_cast<int64_t>(spdy_request_header_frame_length), | 1760 EXPECT_EQ(static_cast<int64_t>(spdy_request_header_frame_length), |
1719 promised_stream_->GetTotalSentBytes()); | 1761 promised_stream_->GetTotalSentBytes()); |
1720 EXPECT_EQ(static_cast<int64_t>(spdy_response_header_frame_length), | 1762 EXPECT_EQ(static_cast<int64_t>(spdy_response_header_frame_length), |
1721 promised_stream_->GetTotalReceivedBytes()); | 1763 promised_stream_->GetTotalReceivedBytes()); |
1722 } | 1764 } |
1723 | 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 |
1724 } // namespace test | 1835 } // namespace test |
1725 } // namespace net | 1836 } // namespace net |
OLD | NEW |