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/reliable_quic_stream.h" | 5 #include "net/quic/reliable_quic_stream.h" |
6 | 6 |
7 #include "net/quic/quic_ack_notifier.h" | 7 #include "net/quic/quic_ack_notifier.h" |
8 #include "net/quic/quic_connection.h" | 8 #include "net/quic/quic_connection.h" |
9 #include "net/quic/quic_spdy_compressor.h" | 9 #include "net/quic/quic_spdy_compressor.h" |
10 #include "net/quic/quic_spdy_decompressor.h" | 10 #include "net/quic/quic_spdy_decompressor.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 QuicWriteBlockedList* write_blocked_list_; | 127 QuicWriteBlockedList* write_blocked_list_; |
128 }; | 128 }; |
129 | 129 |
130 TEST_F(ReliableQuicStreamTest, WriteAllData) { | 130 TEST_F(ReliableQuicStreamTest, WriteAllData) { |
131 Initialize(kShouldProcessData); | 131 Initialize(kShouldProcessData); |
132 | 132 |
133 connection_->options()->max_packet_length = | 133 connection_->options()->max_packet_length = |
134 1 + QuicPacketCreator::StreamFramePacketOverhead( | 134 1 + QuicPacketCreator::StreamFramePacketOverhead( |
135 connection_->version(), PACKET_8BYTE_GUID, !kIncludeVersion, | 135 connection_->version(), PACKET_8BYTE_GUID, !kIncludeVersion, |
136 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); | 136 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); |
137 EXPECT_CALL(*session_, WritevData(kStreamId, _, 1, _, _, _)).WillOnce( | 137 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce( |
138 Return(QuicConsumedData(kDataLen, true))); | 138 Return(QuicConsumedData(kDataLen, true))); |
139 stream_->WriteOrBufferData(kData1, false); | 139 stream_->WriteOrBufferData(kData1, false); |
140 EXPECT_FALSE(write_blocked_list_->HasWriteBlockedStreams()); | 140 EXPECT_FALSE(write_blocked_list_->HasWriteBlockedStreams()); |
141 } | 141 } |
142 | 142 |
143 TEST_F(ReliableQuicStreamTest, NoBlockingIfNoDataOrFin) { | 143 TEST_F(ReliableQuicStreamTest, NoBlockingIfNoDataOrFin) { |
144 Initialize(kShouldProcessData); | 144 Initialize(kShouldProcessData); |
145 | 145 |
146 // Write no data and no fin. If we consume nothing we should not be write | 146 // Write no data and no fin. If we consume nothing we should not be write |
147 // blocked. | 147 // blocked. |
148 EXPECT_DFATAL(stream_->WriteOrBufferData(StringPiece(), false), ""); | 148 EXPECT_DFATAL(stream_->WriteOrBufferData(StringPiece(), false), ""); |
149 EXPECT_FALSE(write_blocked_list_->HasWriteBlockedStreams()); | 149 EXPECT_FALSE(write_blocked_list_->HasWriteBlockedStreams()); |
150 } | 150 } |
151 | 151 |
152 TEST_F(ReliableQuicStreamTest, BlockIfOnlySomeDataConsumed) { | 152 TEST_F(ReliableQuicStreamTest, BlockIfOnlySomeDataConsumed) { |
153 Initialize(kShouldProcessData); | 153 Initialize(kShouldProcessData); |
154 | 154 |
155 // Write some data and no fin. If we consume some but not all of the data, | 155 // Write some data and no fin. If we consume some but not all of the data, |
156 // we should be write blocked a not all the data was consumed. | 156 // we should be write blocked a not all the data was consumed. |
157 EXPECT_CALL(*session_, WritevData(kStreamId, _, 1, _, _, _)).WillOnce( | 157 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce( |
158 Return(QuicConsumedData(1, false))); | 158 Return(QuicConsumedData(1, false))); |
159 stream_->WriteOrBufferData(StringPiece(kData1, 2), false); | 159 stream_->WriteOrBufferData(StringPiece(kData1, 2), false); |
160 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); | 160 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); |
161 } | 161 } |
162 | 162 |
163 | 163 |
164 TEST_F(ReliableQuicStreamTest, BlockIfFinNotConsumedWithData) { | 164 TEST_F(ReliableQuicStreamTest, BlockIfFinNotConsumedWithData) { |
165 Initialize(kShouldProcessData); | 165 Initialize(kShouldProcessData); |
166 | 166 |
167 // Write some data and no fin. If we consume all the data but not the fin, | 167 // Write some data and no fin. If we consume all the data but not the fin, |
168 // we should be write blocked because the fin was not consumed. | 168 // we should be write blocked because the fin was not consumed. |
169 // (This should never actually happen as the fin should be sent out with the | 169 // (This should never actually happen as the fin should be sent out with the |
170 // last data) | 170 // last data) |
171 EXPECT_CALL(*session_, WritevData(kStreamId, _, 1, _, _, _)).WillOnce( | 171 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce( |
172 Return(QuicConsumedData(2, false))); | 172 Return(QuicConsumedData(2, false))); |
173 stream_->WriteOrBufferData(StringPiece(kData1, 2), true); | 173 stream_->WriteOrBufferData(StringPiece(kData1, 2), true); |
174 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); | 174 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); |
175 } | 175 } |
176 | 176 |
177 TEST_F(ReliableQuicStreamTest, BlockIfSoloFinNotConsumed) { | 177 TEST_F(ReliableQuicStreamTest, BlockIfSoloFinNotConsumed) { |
178 Initialize(kShouldProcessData); | 178 Initialize(kShouldProcessData); |
179 | 179 |
180 // Write no data and a fin. If we consume nothing we should be write blocked, | 180 // Write no data and a fin. If we consume nothing we should be write blocked, |
181 // as the fin was not consumed. | 181 // as the fin was not consumed. |
182 EXPECT_CALL(*session_, WritevData(kStreamId, _, 1, _, _, _)).WillOnce( | 182 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce( |
183 Return(QuicConsumedData(0, false))); | 183 Return(QuicConsumedData(0, false))); |
184 stream_->WriteOrBufferData(StringPiece(), true); | 184 stream_->WriteOrBufferData(StringPiece(), true); |
185 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); | 185 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); |
186 } | 186 } |
187 | 187 |
188 TEST_F(ReliableQuicStreamTest, WriteOrBufferData) { | 188 TEST_F(ReliableQuicStreamTest, WriteOrBufferData) { |
189 Initialize(kShouldProcessData); | 189 Initialize(kShouldProcessData); |
190 | 190 |
191 EXPECT_FALSE(write_blocked_list_->HasWriteBlockedStreams()); | 191 EXPECT_FALSE(write_blocked_list_->HasWriteBlockedStreams()); |
192 connection_->options()->max_packet_length = | 192 connection_->options()->max_packet_length = |
193 1 + QuicPacketCreator::StreamFramePacketOverhead( | 193 1 + QuicPacketCreator::StreamFramePacketOverhead( |
194 connection_->version(), PACKET_8BYTE_GUID, !kIncludeVersion, | 194 connection_->version(), PACKET_8BYTE_GUID, !kIncludeVersion, |
195 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); | 195 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); |
196 EXPECT_CALL(*session_, WritevData(_, _, 1, _, _, _)).WillOnce( | 196 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)).WillOnce( |
197 Return(QuicConsumedData(kDataLen - 1, false))); | 197 Return(QuicConsumedData(kDataLen - 1, false))); |
198 stream_->WriteOrBufferData(kData1, false); | 198 stream_->WriteOrBufferData(kData1, false); |
199 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); | 199 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); |
200 | 200 |
201 // Queue a bytes_consumed write. | 201 // Queue a bytes_consumed write. |
202 stream_->WriteOrBufferData(kData2, false); | 202 stream_->WriteOrBufferData(kData2, false); |
203 | 203 |
204 // Make sure we get the tail of the first write followed by the bytes_consumed | 204 // Make sure we get the tail of the first write followed by the bytes_consumed |
205 InSequence s; | 205 InSequence s; |
206 EXPECT_CALL(*session_, WritevData(_, _, 1, _, _, _)). | 206 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)). |
207 WillOnce(Return(QuicConsumedData(1, false))); | 207 WillOnce(Return(QuicConsumedData(1, false))); |
208 EXPECT_CALL(*session_, WritevData(_, _, 1, _, _, _)). | 208 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)). |
209 WillOnce(Return(QuicConsumedData(kDataLen - 2, false))); | 209 WillOnce(Return(QuicConsumedData(kDataLen - 2, false))); |
210 stream_->OnCanWrite(); | 210 stream_->OnCanWrite(); |
211 | 211 |
212 // And finally the end of the bytes_consumed. | 212 // And finally the end of the bytes_consumed. |
213 EXPECT_CALL(*session_, WritevData(_, _, 1, _, _, _)). | 213 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)). |
214 WillOnce(Return(QuicConsumedData(2, true))); | 214 WillOnce(Return(QuicConsumedData(2, true))); |
215 stream_->OnCanWrite(); | 215 stream_->OnCanWrite(); |
216 } | 216 } |
217 | 217 |
218 TEST_F(ReliableQuicStreamTest, ConnectionCloseAfterStreamClose) { | 218 TEST_F(ReliableQuicStreamTest, ConnectionCloseAfterStreamClose) { |
219 Initialize(kShouldProcessData); | 219 Initialize(kShouldProcessData); |
220 | 220 |
221 stream_->CloseReadSide(); | 221 stream_->CloseReadSide(); |
222 stream_->CloseWriteSide(); | 222 stream_->CloseWriteSide(); |
223 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); | 223 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); |
224 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error()); | 224 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error()); |
225 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR, false); | 225 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR, false); |
226 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); | 226 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); |
227 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error()); | 227 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error()); |
228 } | 228 } |
229 | 229 |
230 TEST_F(ReliableQuicStreamTest, RstAlwaysSentIfNoFinSent) { | 230 TEST_F(ReliableQuicStreamTest, RstAlwaysSentIfNoFinSent) { |
231 // For flow control accounting, a stream must send either a FIN or a RST frame | 231 // For flow control accounting, a stream must send either a FIN or a RST frame |
232 // before termination. | 232 // before termination. |
233 // Test that if no FIN has been sent, we send a RST. | 233 // Test that if no FIN has been sent, we send a RST. |
234 | 234 |
235 Initialize(kShouldProcessData); | 235 Initialize(kShouldProcessData); |
236 EXPECT_FALSE(fin_sent()); | 236 EXPECT_FALSE(fin_sent()); |
237 EXPECT_FALSE(rst_sent()); | 237 EXPECT_FALSE(rst_sent()); |
238 | 238 |
239 // Write some data, with no FIN. | 239 // Write some data, with no FIN. |
240 EXPECT_CALL(*session_, WritevData(kStreamId, _, 1, _, _, _)).WillOnce( | 240 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce( |
241 Return(QuicConsumedData(1, false))); | 241 Return(QuicConsumedData(1, false))); |
242 stream_->WriteOrBufferData(StringPiece(kData1, 1), false); | 242 stream_->WriteOrBufferData(StringPiece(kData1, 1), false); |
243 EXPECT_FALSE(fin_sent()); | 243 EXPECT_FALSE(fin_sent()); |
244 EXPECT_FALSE(rst_sent()); | 244 EXPECT_FALSE(rst_sent()); |
245 | 245 |
246 // Now close the stream, and expect that we send a RST. | 246 // Now close the stream, and expect that we send a RST. |
247 EXPECT_CALL(*session_, SendRstStream(_, _, _)); | 247 EXPECT_CALL(*session_, SendRstStream(_, _, _)); |
248 stream_->OnClose(); | 248 stream_->OnClose(); |
249 EXPECT_FALSE(fin_sent()); | 249 EXPECT_FALSE(fin_sent()); |
250 EXPECT_TRUE(rst_sent()); | 250 EXPECT_TRUE(rst_sent()); |
251 } | 251 } |
252 | 252 |
253 TEST_F(ReliableQuicStreamTest, RstNotSentIfFinSent) { | 253 TEST_F(ReliableQuicStreamTest, RstNotSentIfFinSent) { |
254 // For flow control accounting, a stream must send either a FIN or a RST frame | 254 // For flow control accounting, a stream must send either a FIN or a RST frame |
255 // before termination. | 255 // before termination. |
256 // Test that if a FIN has been sent, we don't also send a RST. | 256 // Test that if a FIN has been sent, we don't also send a RST. |
257 | 257 |
258 Initialize(kShouldProcessData); | 258 Initialize(kShouldProcessData); |
259 EXPECT_FALSE(fin_sent()); | 259 EXPECT_FALSE(fin_sent()); |
260 EXPECT_FALSE(rst_sent()); | 260 EXPECT_FALSE(rst_sent()); |
261 | 261 |
262 // Write some data, with FIN. | 262 // Write some data, with FIN. |
263 EXPECT_CALL(*session_, WritevData(kStreamId, _, 1, _, _, _)).WillOnce( | 263 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce( |
264 Return(QuicConsumedData(1, true))); | 264 Return(QuicConsumedData(1, true))); |
265 stream_->WriteOrBufferData(StringPiece(kData1, 1), true); | 265 stream_->WriteOrBufferData(StringPiece(kData1, 1), true); |
266 EXPECT_TRUE(fin_sent()); | 266 EXPECT_TRUE(fin_sent()); |
267 EXPECT_FALSE(rst_sent()); | 267 EXPECT_FALSE(rst_sent()); |
268 | 268 |
269 // Now close the stream, and expect that we do not send a RST. | 269 // Now close the stream, and expect that we do not send a RST. |
270 stream_->OnClose(); | 270 stream_->OnClose(); |
271 EXPECT_TRUE(fin_sent()); | 271 EXPECT_TRUE(fin_sent()); |
272 EXPECT_FALSE(rst_sent()); | 272 EXPECT_FALSE(rst_sent()); |
273 } | 273 } |
(...skipping 18 matching lines...) Expand all Loading... |
292 // Now close the stream (any further resets being sent would break the | 292 // Now close the stream (any further resets being sent would break the |
293 // expectation above). | 293 // expectation above). |
294 stream_->OnClose(); | 294 stream_->OnClose(); |
295 EXPECT_FALSE(fin_sent()); | 295 EXPECT_FALSE(fin_sent()); |
296 EXPECT_TRUE(rst_sent()); | 296 EXPECT_TRUE(rst_sent()); |
297 } | 297 } |
298 | 298 |
299 } // namespace | 299 } // namespace |
300 } // namespace test | 300 } // namespace test |
301 } // namespace net | 301 } // namespace net |
OLD | NEW |