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/bidirectional_stream_quic_impl.h" | 5 #include "net/quic/bidirectional_stream_quic_impl.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/message_loop/message_loop.h" | |
10 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
11 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
12 #include "net/base/ip_address.h" | 11 #include "net/base/ip_address.h" |
13 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
14 #include "net/http/bidirectional_stream_request_info.h" | 13 #include "net/http/bidirectional_stream_request_info.h" |
15 #include "net/http/transport_security_state.h" | 14 #include "net/http/transport_security_state.h" |
16 #include "net/log/test_net_log.h" | 15 #include "net/log/test_net_log.h" |
17 #include "net/log/test_net_log_util.h" | 16 #include "net/log/test_net_log_util.h" |
18 #include "net/quic/crypto/crypto_protocol.h" | 17 #include "net/quic/crypto/crypto_protocol.h" |
19 #include "net/quic/crypto/quic_decrypter.h" | 18 #include "net/quic/crypto/quic_decrypter.h" |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 // Server sends trailers. | 646 // Server sends trailers. |
648 ProcessPacket(ConstructResponseTrailersPacket( | 647 ProcessPacket(ConstructResponseTrailersPacket( |
649 4, kFin, trailers, &spdy_trailers_frame_length, &offset)); | 648 4, kFin, trailers, &spdy_trailers_frame_length, &offset)); |
650 | 649 |
651 delegate->WaitUntilNextCallback(); // OnTrailersReceived | 650 delegate->WaitUntilNextCallback(); // OnTrailersReceived |
652 EXPECT_EQ(OK, cb2.WaitForResult()); | 651 EXPECT_EQ(OK, cb2.WaitForResult()); |
653 trailers.erase(kFinalOffsetHeaderKey); | 652 trailers.erase(kFinalOffsetHeaderKey); |
654 EXPECT_EQ(trailers, delegate->trailers()); | 653 EXPECT_EQ(trailers, delegate->trailers()); |
655 | 654 |
656 EXPECT_EQ(OK, delegate->ReadData(cb2.callback())); | 655 EXPECT_EQ(OK, delegate->ReadData(cb2.callback())); |
657 base::MessageLoop::current()->RunUntilIdle(); | 656 base::RunLoop().RunUntilIdle(); |
658 | 657 |
659 EXPECT_EQ(2, delegate->on_data_read_count()); | 658 EXPECT_EQ(2, delegate->on_data_read_count()); |
660 EXPECT_EQ(0, delegate->on_data_sent_count()); | 659 EXPECT_EQ(0, delegate->on_data_sent_count()); |
661 EXPECT_EQ(kProtoQUIC1SPDY3, delegate->GetProtocol()); | 660 EXPECT_EQ(kProtoQUIC1SPDY3, delegate->GetProtocol()); |
662 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), | 661 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
663 delegate->GetTotalSentBytes()); | 662 delegate->GetTotalSentBytes()); |
664 EXPECT_EQ( | 663 EXPECT_EQ( |
665 static_cast<int64_t>(spdy_response_headers_frame_length + | 664 static_cast<int64_t>(spdy_response_headers_frame_length + |
666 strlen(kResponseBody) + spdy_trailers_frame_length), | 665 strlen(kResponseBody) + spdy_trailers_frame_length), |
667 delegate->GetTotalReceivedBytes()); | 666 delegate->GetTotalReceivedBytes()); |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 delegate->Start(&request, net_log().bound(), session()->GetWeakPtr()); | 1164 delegate->Start(&request, net_log().bound(), session()->GetWeakPtr()); |
1166 delegate->WaitUntilNextCallback(); // OnStreamReady | 1165 delegate->WaitUntilNextCallback(); // OnStreamReady |
1167 | 1166 |
1168 // Server sends a Rst. | 1167 // Server sends a Rst. |
1169 ProcessPacket(ConstructServerRstStreamPacket(1)); | 1168 ProcessPacket(ConstructServerRstStreamPacket(1)); |
1170 | 1169 |
1171 delegate->WaitUntilNextCallback(); // OnFailed | 1170 delegate->WaitUntilNextCallback(); // OnFailed |
1172 TestCompletionCallback cb; | 1171 TestCompletionCallback cb; |
1173 EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, delegate->ReadData(cb.callback())); | 1172 EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, delegate->ReadData(cb.callback())); |
1174 | 1173 |
1175 base::MessageLoop::current()->RunUntilIdle(); | 1174 base::RunLoop().RunUntilIdle(); |
1176 | 1175 |
1177 EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, delegate->error()); | 1176 EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, delegate->error()); |
1178 EXPECT_EQ(0, delegate->on_data_read_count()); | 1177 EXPECT_EQ(0, delegate->on_data_read_count()); |
1179 EXPECT_EQ(0, delegate->on_data_sent_count()); | 1178 EXPECT_EQ(0, delegate->on_data_sent_count()); |
1180 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), | 1179 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
1181 delegate->GetTotalSentBytes()); | 1180 delegate->GetTotalSentBytes()); |
1182 EXPECT_EQ(0, delegate->GetTotalReceivedBytes()); | 1181 EXPECT_EQ(0, delegate->GetTotalReceivedBytes()); |
1183 } | 1182 } |
1184 | 1183 |
1185 TEST_P(BidirectionalStreamQuicImplTest, ServerSendsRstAfterReadData) { | 1184 TEST_P(BidirectionalStreamQuicImplTest, ServerSendsRstAfterReadData) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1274 delegate->WaitUntilNextCallback(); // OnHeadersReceived | 1273 delegate->WaitUntilNextCallback(); // OnHeadersReceived |
1275 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); | 1274 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); |
1276 | 1275 |
1277 // Send a DATA frame. | 1276 // Send a DATA frame. |
1278 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(kUploadData)); | 1277 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(kUploadData)); |
1279 | 1278 |
1280 delegate->SendData(buf, buf->size(), false); | 1279 delegate->SendData(buf, buf->size(), false); |
1281 delegate->WaitUntilNextCallback(); // OnDataSent | 1280 delegate->WaitUntilNextCallback(); // OnDataSent |
1282 | 1281 |
1283 delegate->CancelStream(); | 1282 delegate->CancelStream(); |
1284 base::MessageLoop::current()->RunUntilIdle(); | 1283 base::RunLoop().RunUntilIdle(); |
1285 | 1284 |
1286 // Try to send data after Cancel(), should not get called back. | 1285 // Try to send data after Cancel(), should not get called back. |
1287 delegate->SendData(buf, buf->size(), false); | 1286 delegate->SendData(buf, buf->size(), false); |
1288 base::MessageLoop::current()->RunUntilIdle(); | 1287 base::RunLoop().RunUntilIdle(); |
1289 EXPECT_FALSE(delegate->on_failed_called()); | 1288 EXPECT_FALSE(delegate->on_failed_called()); |
1290 | 1289 |
1291 EXPECT_EQ(0, delegate->on_data_read_count()); | 1290 EXPECT_EQ(0, delegate->on_data_read_count()); |
1292 EXPECT_EQ(1, delegate->on_data_sent_count()); | 1291 EXPECT_EQ(1, delegate->on_data_sent_count()); |
1293 EXPECT_EQ(kProtoQUIC1SPDY3, delegate->GetProtocol()); | 1292 EXPECT_EQ(kProtoQUIC1SPDY3, delegate->GetProtocol()); |
1294 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length + | 1293 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length + |
1295 strlen(kUploadData)), | 1294 strlen(kUploadData)), |
1296 delegate->GetTotalSentBytes()); | 1295 delegate->GetTotalSentBytes()); |
1297 EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length), | 1296 EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length), |
1298 delegate->GetTotalReceivedBytes()); | 1297 delegate->GetTotalReceivedBytes()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1334 int rv = delegate->ReadData(cb.callback()); | 1333 int rv = delegate->ReadData(cb.callback()); |
1335 EXPECT_EQ(ERR_IO_PENDING, rv); | 1334 EXPECT_EQ(ERR_IO_PENDING, rv); |
1336 session()->connection()->CloseConnection( | 1335 session()->connection()->CloseConnection( |
1337 QUIC_NO_ERROR, "test", ConnectionCloseBehavior::SILENT_CLOSE); | 1336 QUIC_NO_ERROR, "test", ConnectionCloseBehavior::SILENT_CLOSE); |
1338 delegate->WaitUntilNextCallback(); // OnFailed | 1337 delegate->WaitUntilNextCallback(); // OnFailed |
1339 EXPECT_TRUE(delegate->on_failed_called()); | 1338 EXPECT_TRUE(delegate->on_failed_called()); |
1340 | 1339 |
1341 // Try to send data after OnFailed(), should not get called back. | 1340 // Try to send data after OnFailed(), should not get called back. |
1342 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(kUploadData)); | 1341 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(kUploadData)); |
1343 delegate->SendData(buf, buf->size(), false); | 1342 delegate->SendData(buf, buf->size(), false); |
1344 base::MessageLoop::current()->RunUntilIdle(); | 1343 base::RunLoop().RunUntilIdle(); |
1345 | 1344 |
1346 EXPECT_EQ(ERR_UNEXPECTED, delegate->ReadData(cb.callback())); | 1345 EXPECT_EQ(ERR_UNEXPECTED, delegate->ReadData(cb.callback())); |
1347 EXPECT_EQ(ERR_UNEXPECTED, delegate->error()); | 1346 EXPECT_EQ(ERR_UNEXPECTED, delegate->error()); |
1348 EXPECT_EQ(0, delegate->on_data_read_count()); | 1347 EXPECT_EQ(0, delegate->on_data_read_count()); |
1349 EXPECT_EQ(0, delegate->on_data_sent_count()); | 1348 EXPECT_EQ(0, delegate->on_data_sent_count()); |
1350 EXPECT_EQ(kProtoQUIC1SPDY3, delegate->GetProtocol()); | 1349 EXPECT_EQ(kProtoQUIC1SPDY3, delegate->GetProtocol()); |
1351 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), | 1350 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
1352 delegate->GetTotalSentBytes()); | 1351 delegate->GetTotalSentBytes()); |
1353 EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length), | 1352 EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length), |
1354 delegate->GetTotalReceivedBytes()); | 1353 delegate->GetTotalReceivedBytes()); |
(...skipping 30 matching lines...) Expand all Loading... |
1385 2, !kFin, response_headers, &spdy_response_headers_frame_length, 0)); | 1384 2, !kFin, response_headers, &spdy_response_headers_frame_length, 0)); |
1386 | 1385 |
1387 delegate->WaitUntilNextCallback(); // OnHeadersReceived | 1386 delegate->WaitUntilNextCallback(); // OnHeadersReceived |
1388 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); | 1387 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); |
1389 | 1388 |
1390 // Cancel the stream after ReadData returns ERR_IO_PENDING. | 1389 // Cancel the stream after ReadData returns ERR_IO_PENDING. |
1391 TestCompletionCallback cb; | 1390 TestCompletionCallback cb; |
1392 EXPECT_EQ(ERR_IO_PENDING, delegate->ReadData(cb.callback())); | 1391 EXPECT_EQ(ERR_IO_PENDING, delegate->ReadData(cb.callback())); |
1393 delegate->CancelStream(); | 1392 delegate->CancelStream(); |
1394 | 1393 |
1395 base::MessageLoop::current()->RunUntilIdle(); | 1394 base::RunLoop().RunUntilIdle(); |
1396 | 1395 |
1397 EXPECT_EQ(0, delegate->on_data_read_count()); | 1396 EXPECT_EQ(0, delegate->on_data_read_count()); |
1398 EXPECT_EQ(0, delegate->on_data_sent_count()); | 1397 EXPECT_EQ(0, delegate->on_data_sent_count()); |
1399 EXPECT_EQ(kProtoQUIC1SPDY3, delegate->GetProtocol()); | 1398 EXPECT_EQ(kProtoQUIC1SPDY3, delegate->GetProtocol()); |
1400 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), | 1399 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
1401 delegate->GetTotalSentBytes()); | 1400 delegate->GetTotalSentBytes()); |
1402 EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length), | 1401 EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length), |
1403 delegate->GetTotalReceivedBytes()); | 1402 delegate->GetTotalReceivedBytes()); |
1404 } | 1403 } |
1405 | 1404 |
(...skipping 26 matching lines...) Expand all Loading... |
1432 SpdyHeaderBlock response_headers = ConstructResponseHeaders("200"); | 1431 SpdyHeaderBlock response_headers = ConstructResponseHeaders("200"); |
1433 | 1432 |
1434 size_t spdy_response_headers_frame_length; | 1433 size_t spdy_response_headers_frame_length; |
1435 ProcessPacket(ConstructResponseHeadersPacket( | 1434 ProcessPacket(ConstructResponseHeadersPacket( |
1436 2, !kFin, response_headers, &spdy_response_headers_frame_length, | 1435 2, !kFin, response_headers, &spdy_response_headers_frame_length, |
1437 nullptr)); | 1436 nullptr)); |
1438 | 1437 |
1439 delegate->WaitUntilNextCallback(); // OnHeadersReceived | 1438 delegate->WaitUntilNextCallback(); // OnHeadersReceived |
1440 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); | 1439 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); |
1441 | 1440 |
1442 base::MessageLoop::current()->RunUntilIdle(); | 1441 base::RunLoop().RunUntilIdle(); |
1443 | 1442 |
1444 EXPECT_EQ(0, delegate->on_data_read_count()); | 1443 EXPECT_EQ(0, delegate->on_data_read_count()); |
1445 EXPECT_EQ(0, delegate->on_data_sent_count()); | 1444 EXPECT_EQ(0, delegate->on_data_sent_count()); |
1446 } | 1445 } |
1447 | 1446 |
1448 TEST_P(BidirectionalStreamQuicImplTest, DeleteStreamDuringOnDataRead) { | 1447 TEST_P(BidirectionalStreamQuicImplTest, DeleteStreamDuringOnDataRead) { |
1449 SetRequest("POST", "/", DEFAULT_PRIORITY); | 1448 SetRequest("POST", "/", DEFAULT_PRIORITY); |
1450 size_t spdy_request_headers_frame_length; | 1449 size_t spdy_request_headers_frame_length; |
1451 AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, | 1450 AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, |
1452 &spdy_request_headers_frame_length)); | 1451 &spdy_request_headers_frame_length)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1484 | 1483 |
1485 TestCompletionCallback cb; | 1484 TestCompletionCallback cb; |
1486 int rv = delegate->ReadData(cb.callback()); | 1485 int rv = delegate->ReadData(cb.callback()); |
1487 EXPECT_EQ(ERR_IO_PENDING, rv); | 1486 EXPECT_EQ(ERR_IO_PENDING, rv); |
1488 const char kResponseBody[] = "Hello world!"; | 1487 const char kResponseBody[] = "Hello world!"; |
1489 // Server sends data. | 1488 // Server sends data. |
1490 ProcessPacket( | 1489 ProcessPacket( |
1491 ConstructServerDataPacket(3, !kIncludeVersion, !kFin, 0, kResponseBody)); | 1490 ConstructServerDataPacket(3, !kIncludeVersion, !kFin, 0, kResponseBody)); |
1492 EXPECT_EQ(static_cast<int64_t>(strlen(kResponseBody)), cb.WaitForResult()); | 1491 EXPECT_EQ(static_cast<int64_t>(strlen(kResponseBody)), cb.WaitForResult()); |
1493 | 1492 |
1494 base::MessageLoop::current()->RunUntilIdle(); | 1493 base::RunLoop().RunUntilIdle(); |
1495 | 1494 |
1496 EXPECT_EQ(1, delegate->on_data_read_count()); | 1495 EXPECT_EQ(1, delegate->on_data_read_count()); |
1497 EXPECT_EQ(0, delegate->on_data_sent_count()); | 1496 EXPECT_EQ(0, delegate->on_data_sent_count()); |
1498 } | 1497 } |
1499 | 1498 |
1500 TEST_P(BidirectionalStreamQuicImplTest, DeleteStreamDuringOnTrailersReceived) { | 1499 TEST_P(BidirectionalStreamQuicImplTest, DeleteStreamDuringOnTrailersReceived) { |
1501 SetRequest("GET", "/", DEFAULT_PRIORITY); | 1500 SetRequest("GET", "/", DEFAULT_PRIORITY); |
1502 size_t spdy_request_headers_frame_length; | 1501 size_t spdy_request_headers_frame_length; |
1503 AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY, | 1502 AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY, |
1504 &spdy_request_headers_frame_length)); | 1503 &spdy_request_headers_frame_length)); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1551 trailers["foo"] = "bar"; | 1550 trailers["foo"] = "bar"; |
1552 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(kResponseBody)); | 1551 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(kResponseBody)); |
1553 // Server sends trailers. | 1552 // Server sends trailers. |
1554 ProcessPacket(ConstructResponseTrailersPacket( | 1553 ProcessPacket(ConstructResponseTrailersPacket( |
1555 4, kFin, trailers, &spdy_trailers_frame_length, &offset)); | 1554 4, kFin, trailers, &spdy_trailers_frame_length, &offset)); |
1556 | 1555 |
1557 delegate->WaitUntilNextCallback(); // OnTrailersReceived | 1556 delegate->WaitUntilNextCallback(); // OnTrailersReceived |
1558 trailers.erase(kFinalOffsetHeaderKey); | 1557 trailers.erase(kFinalOffsetHeaderKey); |
1559 EXPECT_EQ(trailers, delegate->trailers()); | 1558 EXPECT_EQ(trailers, delegate->trailers()); |
1560 | 1559 |
1561 base::MessageLoop::current()->RunUntilIdle(); | 1560 base::RunLoop().RunUntilIdle(); |
1562 | 1561 |
1563 EXPECT_EQ(1, delegate->on_data_read_count()); | 1562 EXPECT_EQ(1, delegate->on_data_read_count()); |
1564 EXPECT_EQ(0, delegate->on_data_sent_count()); | 1563 EXPECT_EQ(0, delegate->on_data_sent_count()); |
1565 } | 1564 } |
1566 | 1565 |
1567 } // namespace test | 1566 } // namespace test |
1568 | 1567 |
1569 } // namespace net | 1568 } // namespace net |
OLD | NEW |