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 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 protected: | 118 protected: |
119 static const bool kFin = true; | 119 static const bool kFin = true; |
120 static const bool kIncludeVersion = true; | 120 static const bool kIncludeVersion = true; |
121 static const bool kIncludeCongestionFeedback = true; | 121 static const bool kIncludeCongestionFeedback = true; |
122 | 122 |
123 // Holds a packet to be written to the wire, and the IO mode that should | 123 // Holds a packet to be written to the wire, and the IO mode that should |
124 // be used by the mock socket when performing the write. | 124 // be used by the mock socket when performing the write. |
125 struct PacketToWrite { | 125 struct PacketToWrite { |
126 PacketToWrite(IoMode mode, QuicEncryptedPacket* packet) | 126 PacketToWrite(IoMode mode, QuicEncryptedPacket* packet) |
127 : mode(mode), packet(packet) {} | 127 : mode(mode), packet(packet) {} |
| 128 PacketToWrite(IoMode mode, int rv) : mode(mode), packet(nullptr), rv(rv) {} |
128 IoMode mode; | 129 IoMode mode; |
129 QuicEncryptedPacket* packet; | 130 QuicEncryptedPacket* packet; |
| 131 int rv; |
130 }; | 132 }; |
131 | 133 |
132 QuicHttpStreamTest() | 134 QuicHttpStreamTest() |
133 : net_log_(BoundNetLog()), | 135 : net_log_(BoundNetLog()), |
134 use_closing_stream_(false), | 136 use_closing_stream_(false), |
135 crypto_config_(CryptoTestUtils::ProofVerifierForTesting()), | 137 crypto_config_(CryptoTestUtils::ProofVerifierForTesting()), |
136 read_buffer_(new IOBufferWithSize(4096)), | 138 read_buffer_(new IOBufferWithSize(4096)), |
137 connection_id_(2), | 139 connection_id_(2), |
138 stream_id_(kClientDataStreamId1), | 140 stream_id_(kClientDataStreamId1), |
139 maker_(GetParam(), connection_id_, &clock_, kDefaultServerHostName), | 141 maker_(GetParam(), connection_id_, &clock_, kDefaultServerHostName), |
(...skipping 10 matching lines...) Expand all Loading... |
150 for (size_t i = 0; i < writes_.size(); i++) { | 152 for (size_t i = 0; i < writes_.size(); i++) { |
151 delete writes_[i].packet; | 153 delete writes_[i].packet; |
152 } | 154 } |
153 } | 155 } |
154 | 156 |
155 // Adds a packet to the list of expected writes. | 157 // Adds a packet to the list of expected writes. |
156 void AddWrite(scoped_ptr<QuicEncryptedPacket> packet) { | 158 void AddWrite(scoped_ptr<QuicEncryptedPacket> packet) { |
157 writes_.push_back(PacketToWrite(SYNCHRONOUS, packet.release())); | 159 writes_.push_back(PacketToWrite(SYNCHRONOUS, packet.release())); |
158 } | 160 } |
159 | 161 |
| 162 void AddWrite(IoMode mode, int rv) { |
| 163 writes_.push_back(PacketToWrite(mode, rv)); |
| 164 } |
| 165 |
160 // Returns the packet to be written at position |pos|. | 166 // Returns the packet to be written at position |pos|. |
161 QuicEncryptedPacket* GetWrite(size_t pos) { return writes_[pos].packet; } | 167 QuicEncryptedPacket* GetWrite(size_t pos) { return writes_[pos].packet; } |
162 | 168 |
163 bool AtEof() { | 169 bool AtEof() { |
164 return socket_data_->AllReadDataConsumed() && | 170 return socket_data_->AllReadDataConsumed() && |
165 socket_data_->AllWriteDataConsumed(); | 171 socket_data_->AllWriteDataConsumed(); |
166 } | 172 } |
167 | 173 |
168 void ProcessPacket(scoped_ptr<QuicEncryptedPacket> packet) { | 174 void ProcessPacket(scoped_ptr<QuicEncryptedPacket> packet) { |
169 connection_->ProcessUdpPacket(self_addr_, peer_addr_, *packet); | 175 connection_->ProcessUdpPacket(self_addr_, peer_addr_, *packet); |
170 } | 176 } |
171 | 177 |
172 // Configures the test fixture to use the list of expected writes. | 178 // Configures the test fixture to use the list of expected writes. |
173 void Initialize() { | 179 void Initialize() { |
174 mock_writes_.reset(new MockWrite[writes_.size()]); | 180 mock_writes_.reset(new MockWrite[writes_.size()]); |
175 for (size_t i = 0; i < writes_.size(); i++) { | 181 for (size_t i = 0; i < writes_.size(); i++) { |
176 mock_writes_[i] = MockWrite(writes_[i].mode, writes_[i].packet->data(), | 182 if (writes_[i].packet == nullptr) { |
177 writes_[i].packet->length()); | 183 mock_writes_[i] = MockWrite(writes_[i].mode, writes_[i].rv, i); |
| 184 } else { |
| 185 mock_writes_[i] = MockWrite(writes_[i].mode, writes_[i].packet->data(), |
| 186 writes_[i].packet->length()); |
| 187 } |
178 }; | 188 }; |
179 | 189 |
180 socket_data_.reset(new StaticSocketDataProvider( | 190 socket_data_.reset(new StaticSocketDataProvider( |
181 nullptr, 0, mock_writes_.get(), writes_.size())); | 191 nullptr, 0, mock_writes_.get(), writes_.size())); |
182 | 192 |
183 MockUDPClientSocket* socket = | 193 MockUDPClientSocket* socket = |
184 new MockUDPClientSocket(socket_data_.get(), net_log_.net_log()); | 194 new MockUDPClientSocket(socket_data_.get(), net_log_.net_log()); |
185 socket->Connect(peer_addr_); | 195 socket->Connect(peer_addr_); |
186 runner_ = new TestTaskRunner(&clock_); | 196 runner_ = new TestTaskRunner(&clock_); |
187 send_algorithm_ = new MockSendAlgorithm(); | 197 send_algorithm_ = new MockSendAlgorithm(); |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 // Set Delegate to nullptr and make sure Priority returns highest | 939 // Set Delegate to nullptr and make sure Priority returns highest |
930 // priority. | 940 // priority. |
931 reliable_stream->SetDelegate(nullptr); | 941 reliable_stream->SetDelegate(nullptr); |
932 DCHECK_EQ(kV3HighestPriority, reliable_stream->Priority()); | 942 DCHECK_EQ(kV3HighestPriority, reliable_stream->Priority()); |
933 reliable_stream->SetDelegate(delegate); | 943 reliable_stream->SetDelegate(delegate); |
934 | 944 |
935 EXPECT_EQ(0, stream_->GetTotalSentBytes()); | 945 EXPECT_EQ(0, stream_->GetTotalSentBytes()); |
936 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); | 946 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
937 } | 947 } |
938 | 948 |
| 949 TEST_P(QuicHttpStreamTest, SessionClosedBeforeSendHeadersComplete) { |
| 950 SetRequest("POST", "/", DEFAULT_PRIORITY); |
| 951 AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 952 Initialize(); |
| 953 |
| 954 ChunkedUploadDataStream upload_data_stream(0); |
| 955 |
| 956 request_.method = "POST"; |
| 957 request_.url = GURL("http://www.google.com/"); |
| 958 request_.upload_data_stream = &upload_data_stream; |
| 959 ASSERT_EQ(OK, request_.upload_data_stream->Init( |
| 960 TestCompletionCallback().callback())); |
| 961 |
| 962 ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, net_log_, |
| 963 callback_.callback())); |
| 964 ASSERT_EQ(ERR_QUIC_PROTOCOL_ERROR, |
| 965 stream_->SendRequest(headers_, &response_, callback_.callback())); |
| 966 } |
| 967 |
| 968 TEST_P(QuicHttpStreamTest, SessionClosedBeforeSendBodyComplete) { |
| 969 SetRequest("POST", "/", DEFAULT_PRIORITY); |
| 970 size_t spdy_request_headers_frame_length; |
| 971 AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, |
| 972 &spdy_request_headers_frame_length)); |
| 973 AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 974 Initialize(); |
| 975 |
| 976 ChunkedUploadDataStream upload_data_stream(0); |
| 977 size_t chunk_size = strlen(kUploadData); |
| 978 upload_data_stream.AppendData(kUploadData, chunk_size, false); |
| 979 |
| 980 request_.method = "POST"; |
| 981 request_.url = GURL("http://www.google.com/"); |
| 982 request_.upload_data_stream = &upload_data_stream; |
| 983 ASSERT_EQ(OK, request_.upload_data_stream->Init( |
| 984 TestCompletionCallback().callback())); |
| 985 |
| 986 ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, net_log_, |
| 987 callback_.callback())); |
| 988 ASSERT_EQ(ERR_QUIC_PROTOCOL_ERROR, |
| 989 stream_->SendRequest(headers_, &response_, callback_.callback())); |
| 990 } |
| 991 |
939 } // namespace test | 992 } // namespace test |
940 } // namespace net | 993 } // namespace net |
OLD | NEW |