OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/http/bidirectional_stream.h" | 5 #include "net/http/bidirectional_stream.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "base/timer/mock_timer.h" | 16 #include "base/timer/mock_timer.h" |
17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
18 #include "net/http/bidirectional_stream_request_info.h" | 18 #include "net/http/bidirectional_stream_request_info.h" |
19 #include "net/http/http_network_session.h" | 19 #include "net/http/http_network_session.h" |
20 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
21 #include "net/http/http_server_properties.h" | 21 #include "net/http/http_server_properties.h" |
22 #include "net/log/net_log.h" | 22 #include "net/log/net_log.h" |
| 23 #include "net/log/net_log_event_type.h" |
| 24 #include "net/log/net_log_source_type.h" |
23 #include "net/log/test_net_log.h" | 25 #include "net/log/test_net_log.h" |
24 #include "net/log/test_net_log_util.h" | 26 #include "net/log/test_net_log_util.h" |
25 #include "net/socket/socket_test_util.h" | 27 #include "net/socket/socket_test_util.h" |
26 #include "net/spdy/spdy_session.h" | 28 #include "net/spdy/spdy_session.h" |
27 #include "net/spdy/spdy_test_util_common.h" | 29 #include "net/spdy/spdy_test_util_common.h" |
28 #include "net/test/cert_test_util.h" | 30 #include "net/test/cert_test_util.h" |
29 #include "net/test/gtest_util.h" | 31 #include "net/test/gtest_util.h" |
30 #include "net/test/test_data_directory.h" | 32 #include "net/test/test_data_directory.h" |
31 #include "net/url_request/url_request_test_util.h" | 33 #include "net/url_request/url_request_test_util.h" |
32 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 597 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
596 delegate->GetTotalReceivedBytes()); | 598 delegate->GetTotalReceivedBytes()); |
597 | 599 |
598 // Destroy the delegate will destroy the stream, so we can get an end event | 600 // Destroy the delegate will destroy the stream, so we can get an end event |
599 // for BIDIRECTIONAL_STREAM_ALIVE. | 601 // for BIDIRECTIONAL_STREAM_ALIVE. |
600 delegate.reset(); | 602 delegate.reset(); |
601 TestNetLogEntry::List entries; | 603 TestNetLogEntry::List entries; |
602 net_log_.GetEntries(&entries); | 604 net_log_.GetEntries(&entries); |
603 | 605 |
604 size_t index = ExpectLogContainsSomewhere( | 606 size_t index = ExpectLogContainsSomewhere( |
605 entries, 0, NetLog::TYPE_BIDIRECTIONAL_STREAM_ALIVE, NetLog::PHASE_BEGIN); | 607 entries, 0, NetLogEventType::BIDIRECTIONAL_STREAM_ALIVE, |
| 608 NetLogEventPhase::BEGIN); |
606 // HTTP_STREAM_REQUEST is nested inside in BIDIRECTIONAL_STREAM_ALIVE. | 609 // HTTP_STREAM_REQUEST is nested inside in BIDIRECTIONAL_STREAM_ALIVE. |
607 index = ExpectLogContainsSomewhere( | 610 index = ExpectLogContainsSomewhere(entries, index, |
608 entries, index, NetLog::TYPE_HTTP_STREAM_REQUEST, NetLog::PHASE_BEGIN); | 611 NetLogEventType::HTTP_STREAM_REQUEST, |
609 index = ExpectLogContainsSomewhere( | 612 NetLogEventPhase::BEGIN); |
610 entries, index, NetLog::TYPE_HTTP_STREAM_REQUEST, NetLog::PHASE_END); | 613 index = ExpectLogContainsSomewhere(entries, index, |
| 614 NetLogEventType::HTTP_STREAM_REQUEST, |
| 615 NetLogEventPhase::END); |
611 // Headers received should happen after HTTP_STREAM_REQUEST. | 616 // Headers received should happen after HTTP_STREAM_REQUEST. |
612 index = ExpectLogContainsSomewhere( | 617 index = ExpectLogContainsSomewhere( |
613 entries, index, NetLog::TYPE_BIDIRECTIONAL_STREAM_RECV_HEADERS, | 618 entries, index, NetLogEventType::BIDIRECTIONAL_STREAM_RECV_HEADERS, |
614 NetLog::PHASE_NONE); | 619 NetLogEventPhase::NONE); |
615 // Trailers received should happen after headers received. It might happen | 620 // Trailers received should happen after headers received. It might happen |
616 // before the reads complete. | 621 // before the reads complete. |
617 ExpectLogContainsSomewhere(entries, index, | 622 ExpectLogContainsSomewhere( |
618 NetLog::TYPE_BIDIRECTIONAL_STREAM_RECV_TRAILERS, | 623 entries, index, NetLogEventType::BIDIRECTIONAL_STREAM_RECV_TRAILERS, |
619 NetLog::PHASE_NONE); | 624 NetLogEventPhase::NONE); |
620 index = ExpectLogContainsSomewhere( | 625 index = ExpectLogContainsSomewhere( |
621 entries, index, NetLog::TYPE_BIDIRECTIONAL_STREAM_SEND_DATA, | 626 entries, index, NetLogEventType::BIDIRECTIONAL_STREAM_SEND_DATA, |
622 NetLog::PHASE_NONE); | 627 NetLogEventPhase::NONE); |
623 index = ExpectLogContainsSomewhere( | 628 index = ExpectLogContainsSomewhere( |
624 entries, index, NetLog::TYPE_BIDIRECTIONAL_STREAM_READ_DATA, | 629 entries, index, NetLogEventType::BIDIRECTIONAL_STREAM_READ_DATA, |
625 NetLog::PHASE_NONE); | 630 NetLogEventPhase::NONE); |
626 TestNetLogEntry entry = entries[index]; | 631 TestNetLogEntry entry = entries[index]; |
627 int read_result = 0; | 632 int read_result = 0; |
628 EXPECT_TRUE(entry.params->GetInteger("rv", &read_result)); | 633 EXPECT_TRUE(entry.params->GetInteger("rv", &read_result)); |
629 EXPECT_EQ(ERR_IO_PENDING, read_result); | 634 EXPECT_EQ(ERR_IO_PENDING, read_result); |
630 | 635 |
631 // Sent bytes. Sending data is always asynchronous. | 636 // Sent bytes. Sending data is always asynchronous. |
632 index = ExpectLogContainsSomewhere( | 637 index = ExpectLogContainsSomewhere( |
633 entries, index, NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_SENT, | 638 entries, index, NetLogEventType::BIDIRECTIONAL_STREAM_BYTES_SENT, |
634 NetLog::PHASE_NONE); | 639 NetLogEventPhase::NONE); |
635 entry = entries[index]; | 640 entry = entries[index]; |
636 EXPECT_EQ(NetLog::SOURCE_BIDIRECTIONAL_STREAM, entry.source.type); | 641 EXPECT_EQ(NetLogSourceType::BIDIRECTIONAL_STREAM, entry.source.type); |
637 // Received bytes for asynchronous read. | 642 // Received bytes for asynchronous read. |
638 index = ExpectLogContainsSomewhere( | 643 index = ExpectLogContainsSomewhere( |
639 entries, index, NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, | 644 entries, index, NetLogEventType::BIDIRECTIONAL_STREAM_BYTES_RECEIVED, |
640 NetLog::PHASE_NONE); | 645 NetLogEventPhase::NONE); |
641 entry = entries[index]; | 646 entry = entries[index]; |
642 EXPECT_EQ(NetLog::SOURCE_BIDIRECTIONAL_STREAM, entry.source.type); | 647 EXPECT_EQ(NetLogSourceType::BIDIRECTIONAL_STREAM, entry.source.type); |
643 // Received bytes for synchronous read. | 648 // Received bytes for synchronous read. |
644 index = ExpectLogContainsSomewhere( | 649 index = ExpectLogContainsSomewhere( |
645 entries, index, NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, | 650 entries, index, NetLogEventType::BIDIRECTIONAL_STREAM_BYTES_RECEIVED, |
646 NetLog::PHASE_NONE); | 651 NetLogEventPhase::NONE); |
647 entry = entries[index]; | 652 entry = entries[index]; |
648 EXPECT_EQ(NetLog::SOURCE_BIDIRECTIONAL_STREAM, entry.source.type); | 653 EXPECT_EQ(NetLogSourceType::BIDIRECTIONAL_STREAM, entry.source.type); |
649 ExpectLogContainsSomewhere(entries, index, | 654 ExpectLogContainsSomewhere(entries, index, |
650 NetLog::TYPE_BIDIRECTIONAL_STREAM_ALIVE, | 655 NetLogEventType::BIDIRECTIONAL_STREAM_ALIVE, |
651 NetLog::PHASE_END); | 656 NetLogEventPhase::END); |
652 } | 657 } |
653 | 658 |
654 TEST_F(BidirectionalStreamTest, TestInterleaveReadDataAndSendData) { | 659 TEST_F(BidirectionalStreamTest, TestInterleaveReadDataAndSendData) { |
655 SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( | 660 SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( |
656 kDefaultUrl, 1, kBodyDataSize * 3, LOWEST, nullptr, 0)); | 661 kDefaultUrl, 1, kBodyDataSize * 3, LOWEST, nullptr, 0)); |
657 SpdySerializedFrame data_frame1(spdy_util_.ConstructSpdyDataFrame( | 662 SpdySerializedFrame data_frame1(spdy_util_.ConstructSpdyDataFrame( |
658 1, kBodyData, kBodyDataSize, /*fin=*/false)); | 663 1, kBodyData, kBodyDataSize, /*fin=*/false)); |
659 SpdySerializedFrame data_frame2(spdy_util_.ConstructSpdyDataFrame( | 664 SpdySerializedFrame data_frame2(spdy_util_.ConstructSpdyDataFrame( |
660 1, kBodyData, kBodyDataSize, /*fin=*/false)); | 665 1, kBodyData, kBodyDataSize, /*fin=*/false)); |
661 SpdySerializedFrame data_frame3(spdy_util_.ConstructSpdyDataFrame( | 666 SpdySerializedFrame data_frame3(spdy_util_.ConstructSpdyDataFrame( |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 EXPECT_EQ(1, delegate->on_data_sent_count()); | 814 EXPECT_EQ(1, delegate->on_data_sent_count()); |
810 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol()); | 815 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol()); |
811 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), | 816 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), |
812 delegate->GetTotalSentBytes()); | 817 delegate->GetTotalSentBytes()); |
813 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 818 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
814 delegate->GetTotalReceivedBytes()); | 819 delegate->GetTotalReceivedBytes()); |
815 | 820 |
816 TestNetLogEntry::List entries; | 821 TestNetLogEntry::List entries; |
817 net_log_.GetEntries(&entries); | 822 net_log_.GetEntries(&entries); |
818 size_t index = ExpectLogContainsSomewhere( | 823 size_t index = ExpectLogContainsSomewhere( |
819 entries, 0, NetLog::TYPE_BIDIRECTIONAL_STREAM_SENDV_DATA, | 824 entries, 0, NetLogEventType::BIDIRECTIONAL_STREAM_SENDV_DATA, |
820 NetLog::PHASE_NONE); | 825 NetLogEventPhase::NONE); |
821 TestNetLogEntry entry = entries[index]; | 826 TestNetLogEntry entry = entries[index]; |
822 int num_buffers = 0; | 827 int num_buffers = 0; |
823 EXPECT_TRUE(entry.params->GetInteger("num_buffers", &num_buffers)); | 828 EXPECT_TRUE(entry.params->GetInteger("num_buffers", &num_buffers)); |
824 EXPECT_EQ(2, num_buffers); | 829 EXPECT_EQ(2, num_buffers); |
825 | 830 |
826 index = ExpectLogContainsSomewhereAfter( | 831 index = ExpectLogContainsSomewhereAfter( |
827 entries, index, NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_SENT_COALESCED, | 832 entries, index, |
828 NetLog::PHASE_BEGIN); | 833 NetLogEventType::BIDIRECTIONAL_STREAM_BYTES_SENT_COALESCED, |
| 834 NetLogEventPhase::BEGIN); |
829 entry = entries[index]; | 835 entry = entries[index]; |
830 int num_buffers_coalesced = 0; | 836 int num_buffers_coalesced = 0; |
831 EXPECT_TRUE(entry.params->GetInteger("num_buffers_coalesced", | 837 EXPECT_TRUE(entry.params->GetInteger("num_buffers_coalesced", |
832 &num_buffers_coalesced)); | 838 &num_buffers_coalesced)); |
833 EXPECT_EQ(2, num_buffers_coalesced); | 839 EXPECT_EQ(2, num_buffers_coalesced); |
834 | 840 |
835 index = ExpectLogContainsSomewhereAfter( | 841 index = ExpectLogContainsSomewhereAfter( |
836 entries, index, NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_SENT, | 842 entries, index, NetLogEventType::BIDIRECTIONAL_STREAM_BYTES_SENT, |
837 NetLog::PHASE_NONE); | 843 NetLogEventPhase::NONE); |
838 entry = entries[index]; | 844 entry = entries[index]; |
839 int byte_count = 0; | 845 int byte_count = 0; |
840 EXPECT_TRUE(entry.params->GetInteger("byte_count", &byte_count)); | 846 EXPECT_TRUE(entry.params->GetInteger("byte_count", &byte_count)); |
841 EXPECT_EQ(buf->size(), byte_count); | 847 EXPECT_EQ(buf->size(), byte_count); |
842 | 848 |
843 index = ExpectLogContainsSomewhereAfter( | 849 index = ExpectLogContainsSomewhereAfter( |
844 entries, index + 1, NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_SENT, | 850 entries, index + 1, NetLogEventType::BIDIRECTIONAL_STREAM_BYTES_SENT, |
845 NetLog::PHASE_NONE); | 851 NetLogEventPhase::NONE); |
846 entry = entries[index]; | 852 entry = entries[index]; |
847 byte_count = 0; | 853 byte_count = 0; |
848 EXPECT_TRUE(entry.params->GetInteger("byte_count", &byte_count)); | 854 EXPECT_TRUE(entry.params->GetInteger("byte_count", &byte_count)); |
849 EXPECT_EQ(buf2->size(), byte_count); | 855 EXPECT_EQ(buf2->size(), byte_count); |
850 | 856 |
851 ExpectLogContainsSomewhere( | 857 ExpectLogContainsSomewhere( |
852 entries, index, NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_SENT_COALESCED, | 858 entries, index, |
853 NetLog::PHASE_END); | 859 NetLogEventType::BIDIRECTIONAL_STREAM_BYTES_SENT_COALESCED, |
| 860 NetLogEventPhase::END); |
854 } | 861 } |
855 | 862 |
856 // Tests that BidirectionalStreamSpdyImpl::OnClose will complete any remaining | 863 // Tests that BidirectionalStreamSpdyImpl::OnClose will complete any remaining |
857 // read even if the read queue is empty. | 864 // read even if the read queue is empty. |
858 TEST_F(BidirectionalStreamTest, TestCompleteAsyncRead) { | 865 TEST_F(BidirectionalStreamTest, TestCompleteAsyncRead) { |
859 SpdySerializedFrame req(spdy_util_.ConstructSpdyGet(kDefaultUrl, 1, LOWEST)); | 866 SpdySerializedFrame req(spdy_util_.ConstructSpdyGet(kDefaultUrl, 1, LOWEST)); |
860 // Empty DATA frame with an END_STREAM flag. | 867 // Empty DATA frame with an END_STREAM flag. |
861 SpdySerializedFrame end_stream( | 868 SpdySerializedFrame end_stream( |
862 spdy_util_.ConstructSpdyDataFrame(1, nullptr, 0, true)); | 869 spdy_util_.ConstructSpdyDataFrame(1, nullptr, 0, true)); |
863 | 870 |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1238 // BidirectionalStreamSpdyStreamJob does not count the bytes sent for |rst| | 1245 // BidirectionalStreamSpdyStreamJob does not count the bytes sent for |rst| |
1239 // because it is sent after SpdyStream::Delegate::OnClose is called. | 1246 // because it is sent after SpdyStream::Delegate::OnClose is called. |
1240 EXPECT_EQ(CountWriteBytes(writes, 1), delegate->GetTotalSentBytes()); | 1247 EXPECT_EQ(CountWriteBytes(writes, 1), delegate->GetTotalSentBytes()); |
1241 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), | 1248 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), |
1242 delegate->GetTotalReceivedBytes()); | 1249 delegate->GetTotalReceivedBytes()); |
1243 | 1250 |
1244 TestNetLogEntry::List entries; | 1251 TestNetLogEntry::List entries; |
1245 net_log_.GetEntries(&entries); | 1252 net_log_.GetEntries(&entries); |
1246 | 1253 |
1247 size_t index = ExpectLogContainsSomewhere( | 1254 size_t index = ExpectLogContainsSomewhere( |
1248 entries, 0, NetLog::TYPE_BIDIRECTIONAL_STREAM_READY, NetLog::PHASE_NONE); | 1255 entries, 0, NetLogEventType::BIDIRECTIONAL_STREAM_READY, |
| 1256 NetLogEventPhase::NONE); |
1249 TestNetLogEntry entry = entries[index]; | 1257 TestNetLogEntry entry = entries[index]; |
1250 bool request_headers_sent = false; | 1258 bool request_headers_sent = false; |
1251 EXPECT_TRUE( | 1259 EXPECT_TRUE( |
1252 entry.params->GetBoolean("request_headers_sent", &request_headers_sent)); | 1260 entry.params->GetBoolean("request_headers_sent", &request_headers_sent)); |
1253 EXPECT_TRUE(request_headers_sent); | 1261 EXPECT_TRUE(request_headers_sent); |
1254 | 1262 |
1255 index = ExpectLogContainsSomewhere(entries, index, | 1263 index = ExpectLogContainsSomewhere( |
1256 NetLog::TYPE_BIDIRECTIONAL_STREAM_FAILED, | 1264 entries, index, NetLogEventType::BIDIRECTIONAL_STREAM_FAILED, |
1257 NetLog::PHASE_NONE); | 1265 NetLogEventPhase::NONE); |
1258 entry = entries[index]; | 1266 entry = entries[index]; |
1259 int net_error = OK; | 1267 int net_error = OK; |
1260 EXPECT_TRUE(entry.params->GetInteger("net_error", &net_error)); | 1268 EXPECT_TRUE(entry.params->GetInteger("net_error", &net_error)); |
1261 EXPECT_THAT(net_error, IsError(ERR_SPDY_PROTOCOL_ERROR)); | 1269 EXPECT_THAT(net_error, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
1262 } | 1270 } |
1263 | 1271 |
1264 TEST_F(BidirectionalStreamTest, DeleteStreamDuringOnHeadersReceived) { | 1272 TEST_F(BidirectionalStreamTest, DeleteStreamDuringOnHeadersReceived) { |
1265 SpdySerializedFrame req(spdy_util_.ConstructSpdyGet(kDefaultUrl, 1, LOWEST)); | 1273 SpdySerializedFrame req(spdy_util_.ConstructSpdyGet(kDefaultUrl, 1, LOWEST)); |
1266 | 1274 |
1267 SpdySerializedFrame rst( | 1275 SpdySerializedFrame rst( |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 http_session_->http_server_properties()->GetAlternativeServices( | 1537 http_session_->http_server_properties()->GetAlternativeServices( |
1530 url::SchemeHostPort(default_url_)); | 1538 url::SchemeHostPort(default_url_)); |
1531 ASSERT_EQ(1u, alternative_service_vector.size()); | 1539 ASSERT_EQ(1u, alternative_service_vector.size()); |
1532 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3), | 1540 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3), |
1533 alternative_service_vector[0].protocol); | 1541 alternative_service_vector[0].protocol); |
1534 EXPECT_EQ("www.example.org", alternative_service_vector[0].host); | 1542 EXPECT_EQ("www.example.org", alternative_service_vector[0].host); |
1535 EXPECT_EQ(443, alternative_service_vector[0].port); | 1543 EXPECT_EQ(443, alternative_service_vector[0].port); |
1536 } | 1544 } |
1537 | 1545 |
1538 } // namespace net | 1546 } // namespace net |
OLD | NEW |