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 <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
13 #include "net/base/chunked_upload_data_stream.h" | 13 #include "net/base/chunked_upload_data_stream.h" |
14 #include "net/base/elements_upload_data_stream.h" | 14 #include "net/base/elements_upload_data_stream.h" |
15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
16 #include "net/base/socket_performance_watcher.h" | 16 #include "net/base/socket_performance_watcher.h" |
17 #include "net/base/test_completion_callback.h" | 17 #include "net/base/test_completion_callback.h" |
18 #include "net/base/upload_bytes_element_reader.h" | 18 #include "net/base/upload_bytes_element_reader.h" |
19 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
20 #include "net/http/transport_security_state.h" | 20 #include "net/http/transport_security_state.h" |
21 #include "net/quic/congestion_control/send_algorithm_interface.h" | 21 #include "net/quic/congestion_control/send_algorithm_interface.h" |
22 #include "net/quic/crypto/crypto_protocol.h" | 22 #include "net/quic/crypto/crypto_protocol.h" |
23 #include "net/quic/crypto/quic_decrypter.h" | 23 #include "net/quic/crypto/quic_decrypter.h" |
24 #include "net/quic/crypto/quic_encrypter.h" | 24 #include "net/quic/crypto/quic_encrypter.h" |
25 #include "net/quic/crypto/quic_server_info.h" | 25 #include "net/quic/crypto/quic_server_info.h" |
26 #include "net/quic/quic_chromium_client_session.h" | 26 #include "net/quic/quic_chromium_client_session.h" |
| 27 #include "net/quic/quic_chromium_client_stream.h" |
| 28 #include "net/quic/quic_chromium_connection_helper.h" |
27 #include "net/quic/quic_connection.h" | 29 #include "net/quic/quic_connection.h" |
28 #include "net/quic/quic_connection_helper.h" | |
29 #include "net/quic/quic_default_packet_writer.h" | 30 #include "net/quic/quic_default_packet_writer.h" |
30 #include "net/quic/quic_http_utils.h" | 31 #include "net/quic/quic_http_utils.h" |
31 #include "net/quic/quic_packet_reader.h" | 32 #include "net/quic/quic_packet_reader.h" |
32 #include "net/quic/quic_reliable_client_stream.h" | |
33 #include "net/quic/quic_write_blocked_list.h" | 33 #include "net/quic/quic_write_blocked_list.h" |
34 #include "net/quic/spdy_utils.h" | 34 #include "net/quic/spdy_utils.h" |
35 #include "net/quic/test_tools/crypto_test_utils.h" | 35 #include "net/quic/test_tools/crypto_test_utils.h" |
36 #include "net/quic/test_tools/mock_clock.h" | 36 #include "net/quic/test_tools/mock_clock.h" |
37 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" | 37 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" |
38 #include "net/quic/test_tools/mock_random.h" | 38 #include "net/quic/test_tools/mock_random.h" |
39 #include "net/quic/test_tools/quic_connection_peer.h" | 39 #include "net/quic/test_tools/quic_connection_peer.h" |
40 #include "net/quic/test_tools/quic_test_packet_maker.h" | 40 #include "net/quic/test_tools/quic_test_packet_maker.h" |
41 #include "net/quic/test_tools/quic_test_utils.h" | 41 #include "net/quic/test_tools/quic_test_utils.h" |
42 #include "net/quic/test_tools/test_task_runner.h" | 42 #include "net/quic/test_tools/test_task_runner.h" |
(...skipping 15 matching lines...) Expand all Loading... |
58 | 58 |
59 const char kUploadData[] = "Really nifty data!"; | 59 const char kUploadData[] = "Really nifty data!"; |
60 const char kDefaultServerHostName[] = "www.google.com"; | 60 const char kDefaultServerHostName[] = "www.google.com"; |
61 const uint16_t kDefaultServerPort = 80; | 61 const uint16_t kDefaultServerPort = 80; |
62 | 62 |
63 class TestQuicConnection : public QuicConnection { | 63 class TestQuicConnection : public QuicConnection { |
64 public: | 64 public: |
65 TestQuicConnection(const QuicVersionVector& versions, | 65 TestQuicConnection(const QuicVersionVector& versions, |
66 QuicConnectionId connection_id, | 66 QuicConnectionId connection_id, |
67 IPEndPoint address, | 67 IPEndPoint address, |
68 QuicConnectionHelper* helper, | 68 QuicChromiumConnectionHelper* helper, |
69 QuicPacketWriter* writer) | 69 QuicPacketWriter* writer) |
70 : QuicConnection(connection_id, | 70 : QuicConnection(connection_id, |
71 address, | 71 address, |
72 helper, | 72 helper, |
73 writer, | 73 writer, |
74 true /* owns_writer */, | 74 true /* owns_writer */, |
75 Perspective::IS_CLIENT, | 75 Perspective::IS_CLIENT, |
76 versions) {} | 76 versions) {} |
77 | 77 |
78 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { | 78 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { |
(...skipping 14 matching lines...) Expand all Loading... |
93 Close(false); | 93 Close(false); |
94 } | 94 } |
95 | 95 |
96 void OnDataAvailable() override { Close(false); } | 96 void OnDataAvailable() override { Close(false); } |
97 }; | 97 }; |
98 | 98 |
99 } // namespace | 99 } // namespace |
100 | 100 |
101 class QuicHttpStreamPeer { | 101 class QuicHttpStreamPeer { |
102 public: | 102 public: |
103 static QuicReliableClientStream* GetQuicReliableClientStream( | 103 static QuicChromiumClientStream* GetQuicChromiumClientStream( |
104 QuicHttpStream* stream) { | 104 QuicHttpStream* stream) { |
105 return stream->stream_; | 105 return stream->stream_; |
106 } | 106 } |
107 | 107 |
108 static bool WasHandshakeConfirmed(QuicHttpStream* stream) { | 108 static bool WasHandshakeConfirmed(QuicHttpStream* stream) { |
109 return stream->was_handshake_confirmed_; | 109 return stream->was_handshake_confirmed_; |
110 } | 110 } |
111 | 111 |
112 static void SetHandshakeConfirmed(QuicHttpStream* stream, bool confirmed) { | 112 static void SetHandshakeConfirmed(QuicHttpStream* stream, bool confirmed) { |
113 stream->was_handshake_confirmed_ = confirmed; | 113 stream->was_handshake_confirmed_ = confirmed; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 .WillRepeatedly(Return(QuicTime::Delta::Zero())); | 193 .WillRepeatedly(Return(QuicTime::Delta::Zero())); |
194 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) | 194 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
195 .WillRepeatedly(Return(kMaxPacketSize)); | 195 .WillRepeatedly(Return(kMaxPacketSize)); |
196 EXPECT_CALL(*send_algorithm_, PacingRate()) | 196 EXPECT_CALL(*send_algorithm_, PacingRate()) |
197 .WillRepeatedly(Return(QuicBandwidth::Zero())); | 197 .WillRepeatedly(Return(QuicBandwidth::Zero())); |
198 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) | 198 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) |
199 .WillRepeatedly(Return(QuicTime::Delta::Zero())); | 199 .WillRepeatedly(Return(QuicTime::Delta::Zero())); |
200 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()) | 200 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()) |
201 .WillRepeatedly(Return(QuicBandwidth::Zero())); | 201 .WillRepeatedly(Return(QuicBandwidth::Zero())); |
202 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber()); | 202 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber()); |
203 helper_.reset( | 203 helper_.reset(new QuicChromiumConnectionHelper(runner_.get(), &clock_, |
204 new QuicConnectionHelper(runner_.get(), &clock_, &random_generator_)); | 204 &random_generator_)); |
205 connection_ = new TestQuicConnection( | 205 connection_ = new TestQuicConnection( |
206 SupportedVersions(GetParam()), connection_id_, peer_addr_, | 206 SupportedVersions(GetParam()), connection_id_, peer_addr_, |
207 helper_.get(), new QuicDefaultPacketWriter(socket)); | 207 helper_.get(), new QuicDefaultPacketWriter(socket)); |
208 connection_->set_visitor(&visitor_); | 208 connection_->set_visitor(&visitor_); |
209 connection_->SetSendAlgorithm(send_algorithm_); | 209 connection_->SetSendAlgorithm(send_algorithm_); |
210 session_.reset(new QuicChromiumClientSession( | 210 session_.reset(new QuicChromiumClientSession( |
211 connection_, scoped_ptr<DatagramClientSocket>(socket), | 211 connection_, scoped_ptr<DatagramClientSocket>(socket), |
212 /*stream_factory=*/nullptr, &crypto_client_stream_factory_, &clock_, | 212 /*stream_factory=*/nullptr, &crypto_client_stream_factory_, &clock_, |
213 &transport_security_state_, make_scoped_ptr((QuicServerInfo*)nullptr), | 213 &transport_security_state_, make_scoped_ptr((QuicServerInfo*)nullptr), |
214 QuicServerId(kDefaultServerHostName, kDefaultServerPort, | 214 QuicServerId(kDefaultServerHostName, kDefaultServerPort, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 !kIncludeCongestionFeedback); | 297 !kIncludeCongestionFeedback); |
298 } | 298 } |
299 | 299 |
300 BoundNetLog net_log_; | 300 BoundNetLog net_log_; |
301 bool use_closing_stream_; | 301 bool use_closing_stream_; |
302 MockSendAlgorithm* send_algorithm_; | 302 MockSendAlgorithm* send_algorithm_; |
303 scoped_refptr<TestTaskRunner> runner_; | 303 scoped_refptr<TestTaskRunner> runner_; |
304 scoped_ptr<MockWrite[]> mock_writes_; | 304 scoped_ptr<MockWrite[]> mock_writes_; |
305 MockClock clock_; | 305 MockClock clock_; |
306 TestQuicConnection* connection_; | 306 TestQuicConnection* connection_; |
307 scoped_ptr<QuicConnectionHelper> helper_; | 307 scoped_ptr<QuicChromiumConnectionHelper> helper_; |
308 testing::StrictMock<MockConnectionVisitor> visitor_; | 308 testing::StrictMock<MockConnectionVisitor> visitor_; |
309 scoped_ptr<QuicHttpStream> stream_; | 309 scoped_ptr<QuicHttpStream> stream_; |
310 TransportSecurityState transport_security_state_; | 310 TransportSecurityState transport_security_state_; |
311 scoped_ptr<QuicChromiumClientSession> session_; | 311 scoped_ptr<QuicChromiumClientSession> session_; |
312 QuicCryptoClientConfig crypto_config_; | 312 QuicCryptoClientConfig crypto_config_; |
313 TestCompletionCallback callback_; | 313 TestCompletionCallback callback_; |
314 HttpRequestInfo request_; | 314 HttpRequestInfo request_; |
315 HttpRequestHeaders headers_; | 315 HttpRequestHeaders headers_; |
316 HttpResponseInfo response_; | 316 HttpResponseInfo response_; |
317 scoped_refptr<IOBufferWithSize> read_buffer_; | 317 scoped_refptr<IOBufferWithSize> read_buffer_; |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 use_closing_stream_ = true; | 863 use_closing_stream_ = true; |
864 Initialize(); | 864 Initialize(); |
865 | 865 |
866 request_.method = "GET"; | 866 request_.method = "GET"; |
867 request_.url = GURL("http://www.google.com/"); | 867 request_.url = GURL("http://www.google.com/"); |
868 | 868 |
869 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_, | 869 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_, |
870 callback_.callback())); | 870 callback_.callback())); |
871 | 871 |
872 // Check that priority is highest. | 872 // Check that priority is highest. |
873 QuicReliableClientStream* reliable_stream = | 873 QuicChromiumClientStream* reliable_stream = |
874 QuicHttpStreamPeer::GetQuicReliableClientStream(stream_.get()); | 874 QuicHttpStreamPeer::GetQuicChromiumClientStream(stream_.get()); |
875 DCHECK(reliable_stream); | 875 DCHECK(reliable_stream); |
876 DCHECK_EQ(kV3HighestPriority, reliable_stream->Priority()); | 876 DCHECK_EQ(kV3HighestPriority, reliable_stream->Priority()); |
877 | 877 |
878 EXPECT_EQ(OK, | 878 EXPECT_EQ(OK, |
879 stream_->SendRequest(headers_, &response_, callback_.callback())); | 879 stream_->SendRequest(headers_, &response_, callback_.callback())); |
880 | 880 |
881 // Check that priority has now dropped back to MEDIUM. | 881 // Check that priority has now dropped back to MEDIUM. |
882 DCHECK_EQ(MEDIUM, | 882 DCHECK_EQ(MEDIUM, |
883 ConvertQuicPriorityToRequestPriority(reliable_stream->Priority())); | 883 ConvertQuicPriorityToRequestPriority(reliable_stream->Priority())); |
884 | 884 |
(...skipping 27 matching lines...) Expand all Loading... |
912 | 912 |
913 Initialize(); | 913 Initialize(); |
914 | 914 |
915 request_.method = "GET"; | 915 request_.method = "GET"; |
916 request_.url = GURL("http://www.google.com/"); | 916 request_.url = GURL("http://www.google.com/"); |
917 | 917 |
918 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_, | 918 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_, |
919 callback_.callback())); | 919 callback_.callback())); |
920 | 920 |
921 // Check that priority is highest. | 921 // Check that priority is highest. |
922 QuicReliableClientStream* reliable_stream = | 922 QuicChromiumClientStream* reliable_stream = |
923 QuicHttpStreamPeer::GetQuicReliableClientStream(stream_.get()); | 923 QuicHttpStreamPeer::GetQuicChromiumClientStream(stream_.get()); |
924 DCHECK(reliable_stream); | 924 DCHECK(reliable_stream); |
925 QuicReliableClientStream::Delegate* delegate = reliable_stream->GetDelegate(); | 925 QuicChromiumClientStream::Delegate* delegate = reliable_stream->GetDelegate(); |
926 DCHECK(delegate); | 926 DCHECK(delegate); |
927 DCHECK_EQ(kV3HighestPriority, reliable_stream->Priority()); | 927 DCHECK_EQ(kV3HighestPriority, reliable_stream->Priority()); |
928 | 928 |
929 // Set Delegate to nullptr and make sure Priority returns highest | 929 // Set Delegate to nullptr and make sure Priority returns highest |
930 // priority. | 930 // priority. |
931 reliable_stream->SetDelegate(nullptr); | 931 reliable_stream->SetDelegate(nullptr); |
932 DCHECK_EQ(kV3HighestPriority, reliable_stream->Priority()); | 932 DCHECK_EQ(kV3HighestPriority, reliable_stream->Priority()); |
933 reliable_stream->SetDelegate(delegate); | 933 reliable_stream->SetDelegate(delegate); |
934 | 934 |
935 EXPECT_EQ(0, stream_->GetTotalSentBytes()); | 935 EXPECT_EQ(0, stream_->GetTotalSentBytes()); |
936 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); | 936 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
937 } | 937 } |
938 | 938 |
939 } // namespace test | 939 } // namespace test |
940 } // namespace net | 940 } // namespace net |
OLD | NEW |