| 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_flags.h" | 9 #include "net/quic/quic_flags.h" |
| 10 #include "net/quic/quic_utils.h" | 10 #include "net/quic/quic_utils.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 TEST_F(ReliableQuicStreamTest, WriteAllData) { | 151 TEST_F(ReliableQuicStreamTest, WriteAllData) { |
| 152 Initialize(kShouldProcessData); | 152 Initialize(kShouldProcessData); |
| 153 | 153 |
| 154 size_t length = 1 + QuicPacketCreator::StreamFramePacketOverhead( | 154 size_t length = 1 + QuicPacketCreator::StreamFramePacketOverhead( |
| 155 connection_->version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 155 connection_->version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
| 156 PACKET_6BYTE_SEQUENCE_NUMBER, 0u, NOT_IN_FEC_GROUP); | 156 PACKET_6BYTE_SEQUENCE_NUMBER, 0u, NOT_IN_FEC_GROUP); |
| 157 QuicConnectionPeer::GetPacketCreator(connection_)->set_max_packet_length( | 157 QuicConnectionPeer::GetPacketCreator(connection_)->set_max_packet_length( |
| 158 length); | 158 length); |
| 159 | 159 |
| 160 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _)).WillOnce( | 160 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)).WillOnce( |
| 161 Return(QuicConsumedData(kDataLen, true))); | 161 Return(QuicConsumedData(kDataLen, true))); |
| 162 stream_->WriteOrBufferData(kData1, false, NULL); | 162 stream_->WriteOrBufferData(kData1, false, NULL); |
| 163 EXPECT_FALSE(HasWriteBlockedStreams()); | 163 EXPECT_FALSE(HasWriteBlockedStreams()); |
| 164 } | 164 } |
| 165 | 165 |
| 166 TEST_F(ReliableQuicStreamTest, NoBlockingIfNoDataOrFin) { | 166 TEST_F(ReliableQuicStreamTest, NoBlockingIfNoDataOrFin) { |
| 167 Initialize(kShouldProcessData); | 167 Initialize(kShouldProcessData); |
| 168 | 168 |
| 169 // Write no data and no fin. If we consume nothing we should not be write | 169 // Write no data and no fin. If we consume nothing we should not be write |
| 170 // blocked. | 170 // blocked. |
| 171 EXPECT_DFATAL(stream_->WriteOrBufferData(StringPiece(), false, NULL), ""); | 171 EXPECT_DFATAL(stream_->WriteOrBufferData(StringPiece(), false, NULL), ""); |
| 172 EXPECT_FALSE(HasWriteBlockedStreams()); | 172 EXPECT_FALSE(HasWriteBlockedStreams()); |
| 173 } | 173 } |
| 174 | 174 |
| 175 TEST_F(ReliableQuicStreamTest, BlockIfOnlySomeDataConsumed) { | 175 TEST_F(ReliableQuicStreamTest, BlockIfOnlySomeDataConsumed) { |
| 176 Initialize(kShouldProcessData); | 176 Initialize(kShouldProcessData); |
| 177 | 177 |
| 178 // Write some data and no fin. If we consume some but not all of the data, | 178 // Write some data and no fin. If we consume some but not all of the data, |
| 179 // we should be write blocked a not all the data was consumed. | 179 // we should be write blocked a not all the data was consumed. |
| 180 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _)) | 180 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
| 181 .WillOnce(Return(QuicConsumedData(1, false))); | 181 .WillOnce(Return(QuicConsumedData(1, false))); |
| 182 stream_->WriteOrBufferData(StringPiece(kData1, 2), false, NULL); | 182 stream_->WriteOrBufferData(StringPiece(kData1, 2), false, NULL); |
| 183 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); | 183 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); |
| 184 } | 184 } |
| 185 | 185 |
| 186 TEST_F(ReliableQuicStreamTest, BlockIfFinNotConsumedWithData) { | 186 TEST_F(ReliableQuicStreamTest, BlockIfFinNotConsumedWithData) { |
| 187 Initialize(kShouldProcessData); | 187 Initialize(kShouldProcessData); |
| 188 | 188 |
| 189 // Write some data and no fin. If we consume all the data but not the fin, | 189 // Write some data and no fin. If we consume all the data but not the fin, |
| 190 // we should be write blocked because the fin was not consumed. | 190 // we should be write blocked because the fin was not consumed. |
| 191 // (This should never actually happen as the fin should be sent out with the | 191 // (This should never actually happen as the fin should be sent out with the |
| 192 // last data) | 192 // last data) |
| 193 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _)) | 193 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
| 194 .WillOnce(Return(QuicConsumedData(2, false))); | 194 .WillOnce(Return(QuicConsumedData(2, false))); |
| 195 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, NULL); | 195 stream_->WriteOrBufferData(StringPiece(kData1, 2), true, NULL); |
| 196 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); | 196 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); |
| 197 } | 197 } |
| 198 | 198 |
| 199 TEST_F(ReliableQuicStreamTest, BlockIfSoloFinNotConsumed) { | 199 TEST_F(ReliableQuicStreamTest, BlockIfSoloFinNotConsumed) { |
| 200 Initialize(kShouldProcessData); | 200 Initialize(kShouldProcessData); |
| 201 | 201 |
| 202 // Write no data and a fin. If we consume nothing we should be write blocked, | 202 // Write no data and a fin. If we consume nothing we should be write blocked, |
| 203 // as the fin was not consumed. | 203 // as the fin was not consumed. |
| 204 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _)) | 204 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
| 205 .WillOnce(Return(QuicConsumedData(0, false))); | 205 .WillOnce(Return(QuicConsumedData(0, false))); |
| 206 stream_->WriteOrBufferData(StringPiece(), true, NULL); | 206 stream_->WriteOrBufferData(StringPiece(), true, NULL); |
| 207 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); | 207 ASSERT_EQ(1u, write_blocked_list_->NumBlockedStreams()); |
| 208 } | 208 } |
| 209 | 209 |
| 210 TEST_F(ReliableQuicStreamTest, WriteOrBufferData) { | 210 TEST_F(ReliableQuicStreamTest, WriteOrBufferData) { |
| 211 Initialize(kShouldProcessData); | 211 Initialize(kShouldProcessData); |
| 212 | 212 |
| 213 EXPECT_FALSE(HasWriteBlockedStreams()); | 213 EXPECT_FALSE(HasWriteBlockedStreams()); |
| 214 size_t length = 1 + QuicPacketCreator::StreamFramePacketOverhead( | 214 size_t length = 1 + QuicPacketCreator::StreamFramePacketOverhead( |
| 215 connection_->version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 215 connection_->version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
| 216 PACKET_6BYTE_SEQUENCE_NUMBER, 0u, NOT_IN_FEC_GROUP); | 216 PACKET_6BYTE_SEQUENCE_NUMBER, 0u, NOT_IN_FEC_GROUP); |
| 217 QuicConnectionPeer::GetPacketCreator(connection_)->set_max_packet_length( | 217 QuicConnectionPeer::GetPacketCreator(connection_)->set_max_packet_length( |
| 218 length); | 218 length); |
| 219 | 219 |
| 220 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)).WillOnce( | 220 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)).WillOnce( |
| 221 Return(QuicConsumedData(kDataLen - 1, false))); | 221 Return(QuicConsumedData(kDataLen - 1, false))); |
| 222 stream_->WriteOrBufferData(kData1, false, NULL); | 222 stream_->WriteOrBufferData(kData1, false, NULL); |
| 223 EXPECT_TRUE(HasWriteBlockedStreams()); | 223 EXPECT_TRUE(HasWriteBlockedStreams()); |
| 224 | 224 |
| 225 // Queue a bytes_consumed write. | 225 // Queue a bytes_consumed write. |
| 226 stream_->WriteOrBufferData(kData2, false, NULL); | 226 stream_->WriteOrBufferData(kData2, false, NULL); |
| 227 | 227 |
| 228 // Make sure we get the tail of the first write followed by the bytes_consumed | 228 // Make sure we get the tail of the first write followed by the bytes_consumed |
| 229 InSequence s; | 229 InSequence s; |
| 230 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)). | 230 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)). |
| 231 WillOnce(Return(QuicConsumedData(1, false))); | 231 WillOnce(Return(QuicConsumedData(1, false))); |
| 232 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)). | 232 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)). |
| 233 WillOnce(Return(QuicConsumedData(kDataLen - 2, false))); | 233 WillOnce(Return(QuicConsumedData(kDataLen - 2, false))); |
| 234 stream_->OnCanWrite(); | 234 stream_->OnCanWrite(); |
| 235 | 235 |
| 236 // And finally the end of the bytes_consumed. | 236 // And finally the end of the bytes_consumed. |
| 237 EXPECT_CALL(*session_, WritevData(_, _, _, _, _)). | 237 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)). |
| 238 WillOnce(Return(QuicConsumedData(2, true))); | 238 WillOnce(Return(QuicConsumedData(2, true))); |
| 239 stream_->OnCanWrite(); | 239 stream_->OnCanWrite(); |
| 240 } | 240 } |
| 241 | 241 |
| 242 TEST_F(ReliableQuicStreamTest, ConnectionCloseAfterStreamClose) { | 242 TEST_F(ReliableQuicStreamTest, ConnectionCloseAfterStreamClose) { |
| 243 Initialize(kShouldProcessData); | 243 Initialize(kShouldProcessData); |
| 244 | 244 |
| 245 stream_->CloseReadSide(); | 245 stream_->CloseReadSide(); |
| 246 stream_->CloseWriteSide(); | 246 stream_->CloseWriteSide(); |
| 247 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); | 247 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); |
| 248 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error()); | 248 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error()); |
| 249 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR, false); | 249 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR, false); |
| 250 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); | 250 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error()); |
| 251 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error()); | 251 EXPECT_EQ(QUIC_NO_ERROR, stream_->connection_error()); |
| 252 } | 252 } |
| 253 | 253 |
| 254 TEST_F(ReliableQuicStreamTest, RstAlwaysSentIfNoFinSent) { | 254 TEST_F(ReliableQuicStreamTest, RstAlwaysSentIfNoFinSent) { |
| 255 // For flow control accounting, a stream must send either a FIN or a RST frame | 255 // For flow control accounting, a stream must send either a FIN or a RST frame |
| 256 // before termination. | 256 // before termination. |
| 257 // Test that if no FIN has been sent, we send a RST. | 257 // Test that if no FIN has been sent, we send a RST. |
| 258 | 258 |
| 259 Initialize(kShouldProcessData); | 259 Initialize(kShouldProcessData); |
| 260 EXPECT_FALSE(fin_sent()); | 260 EXPECT_FALSE(fin_sent()); |
| 261 EXPECT_FALSE(rst_sent()); | 261 EXPECT_FALSE(rst_sent()); |
| 262 | 262 |
| 263 // Write some data, with no FIN. | 263 // Write some data, with no FIN. |
| 264 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _)) | 264 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
| 265 .WillOnce(Return(QuicConsumedData(1, false))); | 265 .WillOnce(Return(QuicConsumedData(1, false))); |
| 266 stream_->WriteOrBufferData(StringPiece(kData1, 1), false, NULL); | 266 stream_->WriteOrBufferData(StringPiece(kData1, 1), false, NULL); |
| 267 EXPECT_FALSE(fin_sent()); | 267 EXPECT_FALSE(fin_sent()); |
| 268 EXPECT_FALSE(rst_sent()); | 268 EXPECT_FALSE(rst_sent()); |
| 269 | 269 |
| 270 // Now close the stream, and expect that we send a RST. | 270 // Now close the stream, and expect that we send a RST. |
| 271 EXPECT_CALL(*session_, SendRstStream(_, _, _)); | 271 EXPECT_CALL(*session_, SendRstStream(_, _, _)); |
| 272 stream_->OnClose(); | 272 stream_->OnClose(); |
| 273 EXPECT_FALSE(fin_sent()); | 273 EXPECT_FALSE(fin_sent()); |
| 274 EXPECT_TRUE(rst_sent()); | 274 EXPECT_TRUE(rst_sent()); |
| 275 } | 275 } |
| 276 | 276 |
| 277 TEST_F(ReliableQuicStreamTest, RstNotSentIfFinSent) { | 277 TEST_F(ReliableQuicStreamTest, RstNotSentIfFinSent) { |
| 278 // For flow control accounting, a stream must send either a FIN or a RST frame | 278 // For flow control accounting, a stream must send either a FIN or a RST frame |
| 279 // before termination. | 279 // before termination. |
| 280 // Test that if a FIN has been sent, we don't also send a RST. | 280 // Test that if a FIN has been sent, we don't also send a RST. |
| 281 | 281 |
| 282 Initialize(kShouldProcessData); | 282 Initialize(kShouldProcessData); |
| 283 EXPECT_FALSE(fin_sent()); | 283 EXPECT_FALSE(fin_sent()); |
| 284 EXPECT_FALSE(rst_sent()); | 284 EXPECT_FALSE(rst_sent()); |
| 285 | 285 |
| 286 // Write some data, with FIN. | 286 // Write some data, with FIN. |
| 287 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _)) | 287 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
| 288 .WillOnce(Return(QuicConsumedData(1, true))); | 288 .WillOnce(Return(QuicConsumedData(1, true))); |
| 289 stream_->WriteOrBufferData(StringPiece(kData1, 1), true, NULL); | 289 stream_->WriteOrBufferData(StringPiece(kData1, 1), true, NULL); |
| 290 EXPECT_TRUE(fin_sent()); | 290 EXPECT_TRUE(fin_sent()); |
| 291 EXPECT_FALSE(rst_sent()); | 291 EXPECT_FALSE(rst_sent()); |
| 292 | 292 |
| 293 // Now close the stream, and expect that we do not send a RST. | 293 // Now close the stream, and expect that we do not send a RST. |
| 294 stream_->OnClose(); | 294 stream_->OnClose(); |
| 295 EXPECT_TRUE(fin_sent()); | 295 EXPECT_TRUE(fin_sent()); |
| 296 EXPECT_FALSE(rst_sent()); | 296 EXPECT_FALSE(rst_sent()); |
| 297 } | 297 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 const int kLastWriteSize = kDataSize - kFirstWriteSize - kSecondWriteSize; | 398 const int kLastWriteSize = kDataSize - kFirstWriteSize - kSecondWriteSize; |
| 399 | 399 |
| 400 // Set a large flow control send window so this doesn't interfere with test. | 400 // Set a large flow control send window so this doesn't interfere with test. |
| 401 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); | 401 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); |
| 402 if (FLAGS_enable_quic_connection_flow_control) { | 402 if (FLAGS_enable_quic_connection_flow_control) { |
| 403 session_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); | 403 session_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); |
| 404 } | 404 } |
| 405 | 405 |
| 406 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 406 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
| 407 | 407 |
| 408 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _)) | 408 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
| 409 .WillOnce(DoAll(WithArgs<4>(Invoke(CreateFunctor( | 409 .WillOnce(DoAll(WithArgs<5>(Invoke(CreateFunctor( |
| 410 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 410 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
| 411 Return(QuicConsumedData(kFirstWriteSize, false)))); | 411 Return(QuicConsumedData(kFirstWriteSize, false)))); |
| 412 stream_->WriteOrBufferData(kData, false, delegate.get()); | 412 stream_->WriteOrBufferData(kData, false, delegate.get()); |
| 413 EXPECT_TRUE(HasWriteBlockedStreams()); | 413 EXPECT_TRUE(HasWriteBlockedStreams()); |
| 414 | 414 |
| 415 EXPECT_CALL(*session_, | 415 EXPECT_CALL(*session_, |
| 416 WritevData(kHeadersStreamId, _, _, _, proxy_delegate.get())) | 416 WritevData(kHeadersStreamId, _, _, _, _, proxy_delegate.get())) |
| 417 .WillOnce(Return(QuicConsumedData(kSecondWriteSize, false))); | 417 .WillOnce(Return(QuicConsumedData(kSecondWriteSize, false))); |
| 418 stream_->OnCanWrite(); | 418 stream_->OnCanWrite(); |
| 419 | 419 |
| 420 // No ack expected for an empty write. | 420 // No ack expected for an empty write. |
| 421 EXPECT_CALL(*session_, | 421 EXPECT_CALL(*session_, |
| 422 WritevData(kHeadersStreamId, _, _, _, proxy_delegate.get())) | 422 WritevData(kHeadersStreamId, _, _, _, _, proxy_delegate.get())) |
| 423 .WillOnce(Return(QuicConsumedData(0, false))); | 423 .WillOnce(Return(QuicConsumedData(0, false))); |
| 424 stream_->OnCanWrite(); | 424 stream_->OnCanWrite(); |
| 425 | 425 |
| 426 EXPECT_CALL(*session_, | 426 EXPECT_CALL(*session_, |
| 427 WritevData(kHeadersStreamId, _, _, _, proxy_delegate.get())) | 427 WritevData(kHeadersStreamId, _, _, _, _, proxy_delegate.get())) |
| 428 .WillOnce(Return(QuicConsumedData(kLastWriteSize, false))); | 428 .WillOnce(Return(QuicConsumedData(kLastWriteSize, false))); |
| 429 stream_->OnCanWrite(); | 429 stream_->OnCanWrite(); |
| 430 | 430 |
| 431 // There were two writes, so OnAckNotification is not propagated | 431 // There were two writes, so OnAckNotification is not propagated |
| 432 // until the third Ack arrives. | 432 // until the third Ack arrives. |
| 433 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); | 433 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); |
| 434 proxy_delegate->OnAckNotification(10, 20, 30, 40, zero_); | 434 proxy_delegate->OnAckNotification(10, 20, 30, 40, zero_); |
| 435 | 435 |
| 436 // The arguments to delegate->OnAckNotification are the sum of the | 436 // The arguments to delegate->OnAckNotification are the sum of the |
| 437 // arguments to proxy_delegate OnAckNotification calls. | 437 // arguments to proxy_delegate OnAckNotification calls. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 453 const int kInitialWriteSize = 100; | 453 const int kInitialWriteSize = 100; |
| 454 | 454 |
| 455 // Set a large flow control send window so this doesn't interfere with test. | 455 // Set a large flow control send window so this doesn't interfere with test. |
| 456 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); | 456 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); |
| 457 if (FLAGS_enable_quic_connection_flow_control) { | 457 if (FLAGS_enable_quic_connection_flow_control) { |
| 458 session_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); | 458 session_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); |
| 459 } | 459 } |
| 460 | 460 |
| 461 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 461 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
| 462 | 462 |
| 463 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _)) | 463 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
| 464 .WillOnce(DoAll(WithArgs<4>(Invoke(CreateFunctor( | 464 .WillOnce(DoAll(WithArgs<5>(Invoke(CreateFunctor( |
| 465 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 465 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
| 466 Return(QuicConsumedData(kInitialWriteSize, false)))); | 466 Return(QuicConsumedData(kInitialWriteSize, false)))); |
| 467 stream_->WriteOrBufferData(kData, false, delegate.get()); | 467 stream_->WriteOrBufferData(kData, false, delegate.get()); |
| 468 EXPECT_TRUE(HasWriteBlockedStreams()); | 468 EXPECT_TRUE(HasWriteBlockedStreams()); |
| 469 | 469 |
| 470 // Handle the ack of the first write. | 470 // Handle the ack of the first write. |
| 471 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); | 471 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); |
| 472 proxy_delegate = NULL; | 472 proxy_delegate = NULL; |
| 473 | 473 |
| 474 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _)).WillOnce( | 474 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)).WillOnce( |
| 475 DoAll(WithArgs<4>(Invoke(CreateFunctor( | 475 DoAll(WithArgs<5>(Invoke(CreateFunctor( |
| 476 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 476 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
| 477 Return(QuicConsumedData(kDataSize - kInitialWriteSize, false)))); | 477 Return(QuicConsumedData(kDataSize - kInitialWriteSize, false)))); |
| 478 stream_->OnCanWrite(); | 478 stream_->OnCanWrite(); |
| 479 | 479 |
| 480 // Handle the ack for the second write. | 480 // Handle the ack for the second write. |
| 481 EXPECT_CALL(*delegate, OnAckNotification(101, 202, 303, 404, zero_)); | 481 EXPECT_CALL(*delegate, OnAckNotification(101, 202, 303, 404, zero_)); |
| 482 proxy_delegate->OnAckNotification(100, 200, 300, 400, zero_); | 482 proxy_delegate->OnAckNotification(100, 200, 300, 400, zero_); |
| 483 } | 483 } |
| 484 | 484 |
| 485 // Verify delegate behavior when WriteOrBufferData does not buffer. | 485 // Verify delegate behavior when WriteOrBufferData does not buffer. |
| 486 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferNoBuffer) { | 486 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferNoBuffer) { |
| 487 Initialize(kShouldProcessData); | 487 Initialize(kShouldProcessData); |
| 488 | 488 |
| 489 scoped_refptr<MockAckNotifierDelegate> delegate( | 489 scoped_refptr<MockAckNotifierDelegate> delegate( |
| 490 new StrictMock<MockAckNotifierDelegate>); | 490 new StrictMock<MockAckNotifierDelegate>); |
| 491 | 491 |
| 492 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 492 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
| 493 | 493 |
| 494 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _)) | 494 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
| 495 .WillOnce(DoAll(WithArgs<4>(Invoke(CreateFunctor( | 495 .WillOnce(DoAll(WithArgs<5>(Invoke(CreateFunctor( |
| 496 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 496 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
| 497 Return(QuicConsumedData(kDataLen, true)))); | 497 Return(QuicConsumedData(kDataLen, true)))); |
| 498 stream_->WriteOrBufferData(kData1, true, delegate.get()); | 498 stream_->WriteOrBufferData(kData1, true, delegate.get()); |
| 499 EXPECT_FALSE(HasWriteBlockedStreams()); | 499 EXPECT_FALSE(HasWriteBlockedStreams()); |
| 500 | 500 |
| 501 // Handle the ack. | 501 // Handle the ack. |
| 502 EXPECT_CALL(*delegate, OnAckNotification(1, 2, 3, 4, zero_)); | 502 EXPECT_CALL(*delegate, OnAckNotification(1, 2, 3, 4, zero_)); |
| 503 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); | 503 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); |
| 504 } | 504 } |
| 505 | 505 |
| 506 // Verify delegate behavior when WriteOrBufferData buffers all the data. | 506 // Verify delegate behavior when WriteOrBufferData buffers all the data. |
| 507 TEST_F(ReliableQuicStreamTest, BufferOnWriteAndBufferDataWithAckNotifer) { | 507 TEST_F(ReliableQuicStreamTest, BufferOnWriteAndBufferDataWithAckNotifer) { |
| 508 Initialize(kShouldProcessData); | 508 Initialize(kShouldProcessData); |
| 509 | 509 |
| 510 scoped_refptr<MockAckNotifierDelegate> delegate( | 510 scoped_refptr<MockAckNotifierDelegate> delegate( |
| 511 new StrictMock<MockAckNotifierDelegate>); | 511 new StrictMock<MockAckNotifierDelegate>); |
| 512 | 512 |
| 513 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 513 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
| 514 | 514 |
| 515 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _)) | 515 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
| 516 .WillOnce(Return(QuicConsumedData(0, false))); | 516 .WillOnce(Return(QuicConsumedData(0, false))); |
| 517 stream_->WriteOrBufferData(kData1, true, delegate.get()); | 517 stream_->WriteOrBufferData(kData1, true, delegate.get()); |
| 518 EXPECT_TRUE(HasWriteBlockedStreams()); | 518 EXPECT_TRUE(HasWriteBlockedStreams()); |
| 519 | 519 |
| 520 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _)) | 520 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
| 521 .WillOnce(DoAll(WithArgs<4>(Invoke(CreateFunctor( | 521 .WillOnce(DoAll(WithArgs<5>(Invoke(CreateFunctor( |
| 522 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 522 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
| 523 Return(QuicConsumedData(kDataLen, true)))); | 523 Return(QuicConsumedData(kDataLen, true)))); |
| 524 stream_->OnCanWrite(); | 524 stream_->OnCanWrite(); |
| 525 | 525 |
| 526 // Handle the ack. | 526 // Handle the ack. |
| 527 EXPECT_CALL(*delegate, OnAckNotification(1, 2, 3, 4, zero_)); | 527 EXPECT_CALL(*delegate, OnAckNotification(1, 2, 3, 4, zero_)); |
| 528 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); | 528 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); |
| 529 } | 529 } |
| 530 | 530 |
| 531 // Verify delegate behavior when WriteOrBufferData when the FIN is | 531 // Verify delegate behavior when WriteOrBufferData when the FIN is |
| 532 // sent out in a different packet. | 532 // sent out in a different packet. |
| 533 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferOnlyFinRemains) { | 533 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferOnlyFinRemains) { |
| 534 Initialize(kShouldProcessData); | 534 Initialize(kShouldProcessData); |
| 535 | 535 |
| 536 scoped_refptr<MockAckNotifierDelegate> delegate( | 536 scoped_refptr<MockAckNotifierDelegate> delegate( |
| 537 new StrictMock<MockAckNotifierDelegate>); | 537 new StrictMock<MockAckNotifierDelegate>); |
| 538 | 538 |
| 539 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 539 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
| 540 | 540 |
| 541 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _)) | 541 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
| 542 .WillOnce(DoAll(WithArgs<4>(Invoke(CreateFunctor( | 542 .WillOnce(DoAll(WithArgs<5>(Invoke(CreateFunctor( |
| 543 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 543 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
| 544 Return(QuicConsumedData(kDataLen, false)))); | 544 Return(QuicConsumedData(kDataLen, false)))); |
| 545 stream_->WriteOrBufferData(kData1, true, delegate.get()); | 545 stream_->WriteOrBufferData(kData1, true, delegate.get()); |
| 546 EXPECT_TRUE(HasWriteBlockedStreams()); | 546 EXPECT_TRUE(HasWriteBlockedStreams()); |
| 547 | 547 |
| 548 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _)) | 548 EXPECT_CALL(*session_, WritevData(kHeadersStreamId, _, _, _, _, _)) |
| 549 .WillOnce(DoAll(WithArgs<4>(Invoke(CreateFunctor( | 549 .WillOnce(DoAll(WithArgs<5>(Invoke(CreateFunctor( |
| 550 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 550 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
| 551 Return(QuicConsumedData(0, true)))); | 551 Return(QuicConsumedData(0, true)))); |
| 552 stream_->OnCanWrite(); | 552 stream_->OnCanWrite(); |
| 553 | 553 |
| 554 // Handle the acks. | 554 // Handle the acks. |
| 555 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); | 555 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); |
| 556 EXPECT_CALL(*delegate, OnAckNotification(11, 22, 33, 44, zero_)); | 556 EXPECT_CALL(*delegate, OnAckNotification(11, 22, 33, 44, zero_)); |
| 557 proxy_delegate->OnAckNotification(10, 20, 30, 40, zero_); | 557 proxy_delegate->OnAckNotification(10, 20, 30, 40, zero_); |
| 558 } | 558 } |
| 559 | 559 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 | 604 |
| 605 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset()); | 605 EXPECT_FALSE(stream_->HasFinalReceivedByteOffset()); |
| 606 QuicRstStreamFrame rst_frame(stream_->id(), QUIC_STREAM_CANCELLED, 1234); | 606 QuicRstStreamFrame rst_frame(stream_->id(), QUIC_STREAM_CANCELLED, 1234); |
| 607 stream_->OnStreamReset(rst_frame); | 607 stream_->OnStreamReset(rst_frame); |
| 608 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); | 608 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); |
| 609 } | 609 } |
| 610 | 610 |
| 611 } // namespace | 611 } // namespace |
| 612 } // namespace test | 612 } // namespace test |
| 613 } // namespace net | 613 } // namespace net |
| OLD | NEW |