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 1744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1755 ProcessPacket( | 1755 ProcessPacket( |
1756 ConstructServerDataPacket(3, !kIncludeVersion, !kFin, 0, kResponseBody)); | 1756 ConstructServerDataPacket(3, !kIncludeVersion, !kFin, 0, kResponseBody)); |
1757 EXPECT_EQ(static_cast<int64_t>(strlen(kResponseBody)), cb.WaitForResult()); | 1757 EXPECT_EQ(static_cast<int64_t>(strlen(kResponseBody)), cb.WaitForResult()); |
1758 | 1758 |
1759 base::RunLoop().RunUntilIdle(); | 1759 base::RunLoop().RunUntilIdle(); |
1760 | 1760 |
1761 EXPECT_EQ(1, delegate->on_data_read_count()); | 1761 EXPECT_EQ(1, delegate->on_data_read_count()); |
1762 EXPECT_EQ(0, delegate->on_data_sent_count()); | 1762 EXPECT_EQ(0, delegate->on_data_sent_count()); |
1763 } | 1763 } |
1764 | 1764 |
| 1765 TEST_P(BidirectionalStreamQuicImplTest, AsyncFinRead) { |
| 1766 const char kBody[] = "here is some data"; |
| 1767 SetRequest("POST", "/", DEFAULT_PRIORITY); |
| 1768 size_t spdy_request_headers_frame_length; |
| 1769 QuicStreamOffset header_stream_offset = 0; |
| 1770 AddWrite(ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 1771 AddWrite(ConstructRequestHeadersPacketInner( |
| 1772 2, GetNthClientInitiatedStreamId(0), !kFin, DEFAULT_PRIORITY, |
| 1773 &spdy_request_headers_frame_length, &header_stream_offset)); |
| 1774 AddWrite(ConstructClientMultipleDataFramesPacket(3, kIncludeVersion, kFin, 0, |
| 1775 {kBody})); |
| 1776 AddWrite(ConstructClientAckPacket(4, 3, 1, 1)); |
| 1777 |
| 1778 Initialize(); |
| 1779 |
| 1780 BidirectionalStreamRequestInfo request; |
| 1781 request.method = "POST"; |
| 1782 request.url = GURL("http://www.google.com/"); |
| 1783 request.end_stream_on_headers = false; |
| 1784 request.priority = DEFAULT_PRIORITY; |
| 1785 |
| 1786 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); |
| 1787 std::unique_ptr<TestDelegateBase> delegate( |
| 1788 new TestDelegateBase(read_buffer.get(), kReadBufferSize)); |
| 1789 |
| 1790 delegate->Start(&request, net_log().bound(), session()->CreateHandle()); |
| 1791 ConfirmHandshake(); |
| 1792 delegate->WaitUntilNextCallback(); // OnStreamReady |
| 1793 |
| 1794 // Send a Data packet with fin set. |
| 1795 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer(kBody)); |
| 1796 delegate->SendData(buf1, buf1->size(), /*fin*/ true); |
| 1797 delegate->WaitUntilNextCallback(); // OnDataSent |
| 1798 |
| 1799 // Server acks the request. |
| 1800 ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0)); |
| 1801 |
| 1802 // Server sends the response headers. |
| 1803 SpdyHeaderBlock response_headers = ConstructResponseHeaders("200"); |
| 1804 |
| 1805 size_t spdy_response_headers_frame_length; |
| 1806 ProcessPacket(ConstructResponseHeadersPacket( |
| 1807 2, !kFin, std::move(response_headers), |
| 1808 &spdy_response_headers_frame_length, nullptr)); |
| 1809 |
| 1810 delegate->WaitUntilNextCallback(); // OnHeadersReceived |
| 1811 |
| 1812 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); |
| 1813 |
| 1814 // Read the body, which will complete asynchronously. |
| 1815 TestCompletionCallback cb; |
| 1816 int rv = delegate->ReadData(cb.callback()); |
| 1817 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1818 const char kResponseBody[] = "Hello world!"; |
| 1819 |
| 1820 // Server sends data with the fin set, which should result in the stream |
| 1821 // being closed and hence no RST_STREAM will be sent. |
| 1822 ProcessPacket( |
| 1823 ConstructServerDataPacket(3, !kIncludeVersion, kFin, 0, kResponseBody)); |
| 1824 EXPECT_EQ(static_cast<int64_t>(strlen(kResponseBody)), cb.WaitForResult()); |
| 1825 |
| 1826 base::RunLoop().RunUntilIdle(); |
| 1827 |
| 1828 EXPECT_EQ(1, delegate->on_data_read_count()); |
| 1829 EXPECT_EQ(1, delegate->on_data_sent_count()); |
| 1830 } |
| 1831 |
1765 TEST_P(BidirectionalStreamQuicImplTest, DeleteStreamDuringOnTrailersReceived) { | 1832 TEST_P(BidirectionalStreamQuicImplTest, DeleteStreamDuringOnTrailersReceived) { |
1766 SetRequest("GET", "/", DEFAULT_PRIORITY); | 1833 SetRequest("GET", "/", DEFAULT_PRIORITY); |
1767 size_t spdy_request_headers_frame_length; | 1834 size_t spdy_request_headers_frame_length; |
1768 AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY, | 1835 AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY, |
1769 &spdy_request_headers_frame_length)); | 1836 &spdy_request_headers_frame_length)); |
1770 AddWrite(ConstructClientAckPacket(2, 3, 1, 1)); // Ack the data packet | 1837 AddWrite(ConstructClientAckPacket(2, 3, 1, 1)); // Ack the data packet |
1771 AddWrite(ConstructClientAckAndRstStreamPacket(3, 4, 4, 1)); | 1838 AddWrite(ConstructClientAckAndRstStreamPacket(3, 4, 4, 1)); |
1772 | 1839 |
1773 Initialize(); | 1840 Initialize(); |
1774 | 1841 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1826 | 1893 |
1827 base::RunLoop().RunUntilIdle(); | 1894 base::RunLoop().RunUntilIdle(); |
1828 | 1895 |
1829 EXPECT_EQ(1, delegate->on_data_read_count()); | 1896 EXPECT_EQ(1, delegate->on_data_read_count()); |
1830 EXPECT_EQ(0, delegate->on_data_sent_count()); | 1897 EXPECT_EQ(0, delegate->on_data_sent_count()); |
1831 } | 1898 } |
1832 | 1899 |
1833 } // namespace test | 1900 } // namespace test |
1834 | 1901 |
1835 } // namespace net | 1902 } // namespace net |
OLD | NEW |