Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: net/quic/chromium/bidirectional_stream_quic_impl_unittest.cc

Issue 2915973002: Fix potential crash bug with BidirectionalStreamQuicImpl::SendRequestHeaders (Closed)
Patch Set: More comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/chromium/bidirectional_stream_quic_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 static_cast<int64_t>(spdy_request_headers_frame_length + strlen(kBody1) + 1241 static_cast<int64_t>(spdy_request_headers_frame_length + strlen(kBody1) +
1242 strlen(kBody2) + strlen(kBody3) + strlen(kBody4) + 1242 strlen(kBody2) + strlen(kBody3) + strlen(kBody4) +
1243 strlen(kBody5)), 1243 strlen(kBody5)),
1244 delegate->GetTotalSentBytes()); 1244 delegate->GetTotalSentBytes());
1245 EXPECT_EQ( 1245 EXPECT_EQ(
1246 static_cast<int64_t>(spdy_response_headers_frame_length + 1246 static_cast<int64_t>(spdy_response_headers_frame_length +
1247 strlen(kResponseBody) + spdy_trailers_frame_length), 1247 strlen(kResponseBody) + spdy_trailers_frame_length),
1248 delegate->GetTotalReceivedBytes()); 1248 delegate->GetTotalReceivedBytes());
1249 } 1249 }
1250 1250
1251 // Tests that when request headers are delayed and SendData triggers the
1252 // headers to be sent, if that write fails the stream does not crash.
1253 TEST_P(BidirectionalStreamQuicImplTest,
1254 SendDataWriteErrorCoalesceDataBufferAndHeaderFrame) {
1255 QuicStreamOffset header_stream_offset = 0;
1256 AddWrite(ConstructInitialSettingsPacket(1, &header_stream_offset));
1257 AddWriteError(SYNCHRONOUS, ERR_CONNECTION_REFUSED);
1258
1259 Initialize();
1260
1261 BidirectionalStreamRequestInfo request;
1262 request.method = "POST";
1263 request.url = GURL("http://www.google.com/");
1264 request.end_stream_on_headers = false;
1265 request.priority = DEFAULT_PRIORITY;
1266 request.extra_headers.SetHeader("cookie", std::string(2048, 'A'));
1267
1268 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize));
1269 std::unique_ptr<DeleteStreamDelegate> delegate(new DeleteStreamDelegate(
1270 read_buffer.get(), kReadBufferSize, DeleteStreamDelegate::ON_FAILED));
1271 delegate->DoNotSendRequestHeadersAutomatically();
1272 delegate->Start(&request, net_log().bound(), session()->CreateHandle());
1273 ConfirmHandshake();
1274 delegate->WaitUntilNextCallback(kOnStreamReady);
1275
1276 // Attempt to send the headers and data.
1277 const char kBody1[] = "here are some data";
1278 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer(kBody1));
1279 delegate->SendData(buf1, buf1->size(), !kFin);
1280
1281 delegate->WaitUntilNextCallback(kOnFailed);
1282 }
1283
1284 // Tests that when request headers are delayed and SendvData triggers the
1285 // headers to be sent, if that write fails the stream does not crash.
1286 TEST_P(BidirectionalStreamQuicImplTest,
1287 SendvDataWriteErrorCoalesceDataBufferAndHeaderFrame) {
1288 QuicStreamOffset header_stream_offset = 0;
1289 AddWrite(ConstructInitialSettingsPacket(1, &header_stream_offset));
1290 AddWriteError(SYNCHRONOUS, ERR_CONNECTION_REFUSED);
1291
1292 Initialize();
1293
1294 BidirectionalStreamRequestInfo request;
1295 request.method = "POST";
1296 request.url = GURL("http://www.google.com/");
1297 request.end_stream_on_headers = false;
1298 request.priority = DEFAULT_PRIORITY;
1299 request.extra_headers.SetHeader("cookie", std::string(2048, 'A'));
1300
1301 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize));
1302 std::unique_ptr<DeleteStreamDelegate> delegate(new DeleteStreamDelegate(
1303 read_buffer.get(), kReadBufferSize, DeleteStreamDelegate::ON_FAILED));
1304 delegate->DoNotSendRequestHeadersAutomatically();
1305 delegate->Start(&request, net_log().bound(), session()->CreateHandle());
1306 ConfirmHandshake();
1307 delegate->WaitUntilNextCallback(kOnStreamReady);
1308
1309 // Attempt to send the headers and data.
1310 const char kBody1[] = "here are some data";
1311 const char kBody2[] = "data keep coming";
1312 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer(kBody1));
1313 scoped_refptr<StringIOBuffer> buf2(new StringIOBuffer(kBody2));
1314 std::vector<int> lengths = {buf1->size(), buf2->size()};
1315 delegate->SendvData({buf1, buf2}, lengths, !kFin);
1316
1317 delegate->WaitUntilNextCallback(kOnFailed);
1318 }
1319
1251 TEST_P(BidirectionalStreamQuicImplTest, PostRequest) { 1320 TEST_P(BidirectionalStreamQuicImplTest, PostRequest) {
1252 SetRequest("POST", "/", DEFAULT_PRIORITY); 1321 SetRequest("POST", "/", DEFAULT_PRIORITY);
1253 size_t spdy_request_headers_frame_length; 1322 size_t spdy_request_headers_frame_length;
1254 QuicStreamOffset header_stream_offset = 0; 1323 QuicStreamOffset header_stream_offset = 0;
1255 AddWrite(ConstructInitialSettingsPacket(1, &header_stream_offset)); 1324 AddWrite(ConstructInitialSettingsPacket(1, &header_stream_offset));
1256 AddWrite(ConstructRequestHeadersPacketInner( 1325 AddWrite(ConstructRequestHeadersPacketInner(
1257 2, GetNthClientInitiatedStreamId(0), !kFin, DEFAULT_PRIORITY, 1326 2, GetNthClientInitiatedStreamId(0), !kFin, DEFAULT_PRIORITY,
1258 &spdy_request_headers_frame_length, &header_stream_offset)); 1327 &spdy_request_headers_frame_length, &header_stream_offset));
1259 AddWrite(ConstructDataPacket(3, kIncludeVersion, kFin, 0, kUploadData, 1328 AddWrite(ConstructDataPacket(3, kIncludeVersion, kFin, 0, kUploadData,
1260 &client_maker_)); 1329 &client_maker_));
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); 1582 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize));
1514 std::unique_ptr<TestDelegateBase> delegate( 1583 std::unique_ptr<TestDelegateBase> delegate(
1515 new TestDelegateBase(read_buffer.get(), kReadBufferSize)); 1584 new TestDelegateBase(read_buffer.get(), kReadBufferSize));
1516 delegate->Start(&request, net_log().bound(), session()->CreateHandle()); 1585 delegate->Start(&request, net_log().bound(), session()->CreateHandle());
1517 delegate->WaitUntilNextCallback(kOnStreamReady); 1586 delegate->WaitUntilNextCallback(kOnStreamReady);
1518 ConfirmHandshake(); 1587 ConfirmHandshake();
1519 1588
1520 // Server sends a Rst. 1589 // Server sends a Rst.
1521 ProcessPacket(ConstructServerRstStreamPacket(1)); 1590 ProcessPacket(ConstructServerRstStreamPacket(1));
1522 1591
1523 EXPECT_TRUE(delegate->on_failed_called()); 1592 delegate->WaitUntilNextCallback(kOnFailed);
1524 1593
1525 TestCompletionCallback cb; 1594 TestCompletionCallback cb;
1526 EXPECT_THAT(delegate->ReadData(cb.callback()), 1595 EXPECT_THAT(delegate->ReadData(cb.callback()),
1527 IsError(ERR_QUIC_PROTOCOL_ERROR)); 1596 IsError(ERR_QUIC_PROTOCOL_ERROR));
1528 1597
1529 base::RunLoop().RunUntilIdle(); 1598 base::RunLoop().RunUntilIdle();
1530 1599
1531 EXPECT_THAT(delegate->error(), IsError(ERR_QUIC_PROTOCOL_ERROR)); 1600 EXPECT_THAT(delegate->error(), IsError(ERR_QUIC_PROTOCOL_ERROR));
1532 EXPECT_EQ(0, delegate->on_data_read_count()); 1601 EXPECT_EQ(0, delegate->on_data_read_count());
1533 EXPECT_EQ(0, delegate->on_data_sent_count()); 1602 EXPECT_EQ(0, delegate->on_data_sent_count());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 delegate->WaitUntilNextCallback(kOnHeadersReceived); 1646 delegate->WaitUntilNextCallback(kOnHeadersReceived);
1578 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); 1647 EXPECT_EQ("200", delegate->response_headers().find(":status")->second);
1579 1648
1580 TestCompletionCallback cb; 1649 TestCompletionCallback cb;
1581 int rv = delegate->ReadData(cb.callback()); 1650 int rv = delegate->ReadData(cb.callback());
1582 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 1651 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1583 1652
1584 // Server sends a Rst. 1653 // Server sends a Rst.
1585 ProcessPacket(ConstructServerRstStreamPacket(3)); 1654 ProcessPacket(ConstructServerRstStreamPacket(3));
1586 1655
1587 EXPECT_TRUE(delegate->on_failed_called()); 1656 delegate->WaitUntilNextCallback(kOnFailed);
1588 1657
1589 EXPECT_THAT(delegate->ReadData(cb.callback()), 1658 EXPECT_THAT(delegate->ReadData(cb.callback()),
1590 IsError(ERR_QUIC_PROTOCOL_ERROR)); 1659 IsError(ERR_QUIC_PROTOCOL_ERROR));
1591 EXPECT_THAT(delegate->error(), IsError(ERR_QUIC_PROTOCOL_ERROR)); 1660 EXPECT_THAT(delegate->error(), IsError(ERR_QUIC_PROTOCOL_ERROR));
1592 EXPECT_EQ(0, delegate->on_data_read_count()); 1661 EXPECT_EQ(0, delegate->on_data_read_count());
1593 EXPECT_EQ(0, delegate->on_data_sent_count()); 1662 EXPECT_EQ(0, delegate->on_data_sent_count());
1594 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), 1663 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length),
1595 delegate->GetTotalSentBytes()); 1664 delegate->GetTotalSentBytes());
1596 EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length), 1665 EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length),
1597 delegate->GetTotalReceivedBytes()); 1666 delegate->GetTotalReceivedBytes());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 ProcessPacket(ConstructResponseHeadersPacket( 1700 ProcessPacket(ConstructResponseHeadersPacket(
1632 2, !kFin, std::move(response_headers), 1701 2, !kFin, std::move(response_headers),
1633 &spdy_response_headers_frame_length, &offset)); 1702 &spdy_response_headers_frame_length, &offset));
1634 1703
1635 delegate->WaitUntilNextCallback(kOnHeadersReceived); 1704 delegate->WaitUntilNextCallback(kOnHeadersReceived);
1636 TestCompletionCallback cb; 1705 TestCompletionCallback cb;
1637 int rv = delegate->ReadData(cb.callback()); 1706 int rv = delegate->ReadData(cb.callback());
1638 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 1707 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1639 session()->connection()->CloseConnection( 1708 session()->connection()->CloseConnection(
1640 QUIC_NO_ERROR, "test", ConnectionCloseBehavior::SILENT_CLOSE); 1709 QUIC_NO_ERROR, "test", ConnectionCloseBehavior::SILENT_CLOSE);
1641 EXPECT_TRUE(delegate->on_failed_called()); 1710 delegate->WaitUntilNextCallback(kOnFailed);
1642 1711
1643 // Try to send data after OnFailed(), should not get called back. 1712 // Try to send data after OnFailed(), should not get called back.
1644 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(kUploadData)); 1713 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(kUploadData));
1645 delegate->SendData(buf, buf->size(), false); 1714 delegate->SendData(buf, buf->size(), false);
1646 base::RunLoop().RunUntilIdle(); 1715 base::RunLoop().RunUntilIdle();
1647 1716
1648 EXPECT_THAT(delegate->ReadData(cb.callback()), IsError(ERR_UNEXPECTED)); 1717 EXPECT_THAT(delegate->ReadData(cb.callback()), IsError(ERR_UNEXPECTED));
1649 EXPECT_THAT(delegate->error(), IsError(ERR_UNEXPECTED)); 1718 EXPECT_THAT(delegate->error(), IsError(ERR_UNEXPECTED));
1650 EXPECT_EQ(0, delegate->on_data_read_count()); 1719 EXPECT_EQ(0, delegate->on_data_read_count());
1651 EXPECT_EQ(0, delegate->on_data_sent_count()); 1720 EXPECT_EQ(0, delegate->on_data_sent_count());
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
2043 2112
2044 base::RunLoop().RunUntilIdle(); 2113 base::RunLoop().RunUntilIdle();
2045 2114
2046 EXPECT_EQ(1, delegate->on_data_read_count()); 2115 EXPECT_EQ(1, delegate->on_data_read_count());
2047 EXPECT_EQ(0, delegate->on_data_sent_count()); 2116 EXPECT_EQ(0, delegate->on_data_sent_count());
2048 } 2117 }
2049 2118
2050 } // namespace test 2119 } // namespace test
2051 2120
2052 } // namespace net 2121 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/chromium/bidirectional_stream_quic_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698