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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 using ReliableQuicStream::OnClose; | 68 using ReliableQuicStream::OnClose; |
69 | 69 |
70 private: | 70 private: |
71 bool should_process_data_; | 71 bool should_process_data_; |
72 string data_; | 72 string data_; |
73 }; | 73 }; |
74 | 74 |
75 class ReliableQuicStreamTest : public ::testing::TestWithParam<bool> { | 75 class ReliableQuicStreamTest : public ::testing::TestWithParam<bool> { |
76 public: | 76 public: |
77 ReliableQuicStreamTest() | 77 ReliableQuicStreamTest() |
78 : initial_flow_control_window_bytes_(kMaxPacketSize) { | 78 : initial_flow_control_window_bytes_(kMaxPacketSize), |
| 79 zero_(QuicTime::Delta::Zero()) { |
79 headers_[":host"] = "www.google.com"; | 80 headers_[":host"] = "www.google.com"; |
80 headers_[":path"] = "/index.hml"; | 81 headers_[":path"] = "/index.hml"; |
81 headers_[":scheme"] = "https"; | 82 headers_[":scheme"] = "https"; |
82 headers_["cookie"] = | 83 headers_["cookie"] = |
83 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; " | 84 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; " |
84 "__utmc=160408618; " | 85 "__utmc=160408618; " |
85 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX" | 86 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX" |
86 "hoALMsy6HOdDad2Sz0flUByv7etmo3mLMidGrBoljqO9hSVA40SLqpG_iuKKSHX" | 87 "hoALMsy6HOdDad2Sz0flUByv7etmo3mLMidGrBoljqO9hSVA40SLqpG_iuKKSHX" |
87 "RW3Np4bq0F0SDGDNsW0DSmTS9ufMRrlpARJDS7qAI6M3bghqJp4eABKZiRqebHT" | 88 "RW3Np4bq0F0SDGDNsW0DSmTS9ufMRrlpARJDS7qAI6M3bghqJp4eABKZiRqebHT" |
88 "pMU-RXvTI5D5oCF1vYxYofH_l1Kviuiy3oQ1kS1enqWgbhJ2t61_SNdv-1XJIS0" | 89 "pMU-RXvTI5D5oCF1vYxYofH_l1Kviuiy3oQ1kS1enqWgbhJ2t61_SNdv-1XJIS0" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 131 } |
131 | 132 |
132 protected: | 133 protected: |
133 MockConnection* connection_; | 134 MockConnection* connection_; |
134 scoped_ptr<MockSession> session_; | 135 scoped_ptr<MockSession> session_; |
135 scoped_ptr<TestStream> stream_; | 136 scoped_ptr<TestStream> stream_; |
136 scoped_ptr<TestStream> stream2_; | 137 scoped_ptr<TestStream> stream2_; |
137 SpdyHeaderBlock headers_; | 138 SpdyHeaderBlock headers_; |
138 QuicWriteBlockedList* write_blocked_list_; | 139 QuicWriteBlockedList* write_blocked_list_; |
139 uint32 initial_flow_control_window_bytes_; | 140 uint32 initial_flow_control_window_bytes_; |
| 141 QuicTime::Delta zero_; |
140 }; | 142 }; |
141 | 143 |
142 TEST_F(ReliableQuicStreamTest, WriteAllData) { | 144 TEST_F(ReliableQuicStreamTest, WriteAllData) { |
143 Initialize(kShouldProcessData); | 145 Initialize(kShouldProcessData); |
144 | 146 |
145 connection_->options()->max_packet_length = | 147 connection_->options()->max_packet_length = |
146 1 + QuicPacketCreator::StreamFramePacketOverhead( | 148 1 + QuicPacketCreator::StreamFramePacketOverhead( |
147 connection_->version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 149 connection_->version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
148 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); | 150 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); |
149 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce( | 151 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce( |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 Return(QuicConsumedData(0, false))); | 379 Return(QuicConsumedData(0, false))); |
378 stream_->OnCanWrite(); | 380 stream_->OnCanWrite(); |
379 | 381 |
380 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, proxy_delegate.get())). | 382 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, proxy_delegate.get())). |
381 WillOnce( | 383 WillOnce( |
382 Return(QuicConsumedData(kLastWriteSize, false))); | 384 Return(QuicConsumedData(kLastWriteSize, false))); |
383 stream_->OnCanWrite(); | 385 stream_->OnCanWrite(); |
384 | 386 |
385 // There were two writes, so OnAckNotification is not propagated | 387 // There were two writes, so OnAckNotification is not propagated |
386 // until the third Ack arrives. | 388 // until the third Ack arrives. |
387 proxy_delegate->OnAckNotification(1, 2, 3, 4); | 389 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); |
388 proxy_delegate->OnAckNotification(10, 20, 30, 40); | 390 proxy_delegate->OnAckNotification(10, 20, 30, 40, zero_); |
389 | 391 |
390 // The arguments to delegate->OnAckNotification are the sum of the | 392 // The arguments to delegate->OnAckNotification are the sum of the |
391 // arguments to proxy_delegate OnAckNotification calls. | 393 // arguments to proxy_delegate OnAckNotification calls. |
392 EXPECT_CALL(*delegate, OnAckNotification(111, 222, 333, 444)); | 394 EXPECT_CALL(*delegate, OnAckNotification(111, 222, 333, 444, zero_)); |
393 proxy_delegate->OnAckNotification(100, 200, 300, 400); | 395 proxy_delegate->OnAckNotification(100, 200, 300, 400, zero_); |
394 } | 396 } |
395 | 397 |
396 // Verify delegate behavior when packets are acked before the | 398 // Verify delegate behavior when packets are acked before the |
397 // WritevData call that sends out the last byte. | 399 // WritevData call that sends out the last byte. |
398 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataAckNotificationBeforeFlush) { | 400 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataAckNotificationBeforeFlush) { |
399 Initialize(kShouldProcessData); | 401 Initialize(kShouldProcessData); |
400 | 402 |
401 scoped_refptr<MockAckNotifierDelegate> delegate( | 403 scoped_refptr<MockAckNotifierDelegate> delegate( |
402 new StrictMock<MockAckNotifierDelegate>); | 404 new StrictMock<MockAckNotifierDelegate>); |
403 | 405 |
404 const int kDataSize = 16 * 1024; | 406 const int kDataSize = 16 * 1024; |
405 const string kData(kDataSize, 'a'); | 407 const string kData(kDataSize, 'a'); |
406 | 408 |
407 const int kInitialWriteSize = 100; | 409 const int kInitialWriteSize = 100; |
408 | 410 |
409 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 411 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
410 | 412 |
411 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( | 413 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( |
412 WithArgs<4>(Invoke(CreateFunctor( | 414 WithArgs<4>(Invoke(CreateFunctor( |
413 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 415 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
414 Return(QuicConsumedData(kInitialWriteSize, false)))); | 416 Return(QuicConsumedData(kInitialWriteSize, false)))); |
415 stream_->WriteOrBufferData(kData, false, delegate.get()); | 417 stream_->WriteOrBufferData(kData, false, delegate.get()); |
416 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); | 418 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); |
417 | 419 |
418 // Handle the ack of the first write. | 420 // Handle the ack of the first write. |
419 proxy_delegate->OnAckNotification(1, 2, 3, 4); | 421 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); |
420 proxy_delegate = NULL; | 422 proxy_delegate = NULL; |
421 | 423 |
422 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( | 424 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( |
423 WithArgs<4>(Invoke(CreateFunctor( | 425 WithArgs<4>(Invoke(CreateFunctor( |
424 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 426 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
425 Return(QuicConsumedData(kDataSize - kInitialWriteSize, false)))); | 427 Return(QuicConsumedData(kDataSize - kInitialWriteSize, false)))); |
426 stream_->OnCanWrite(); | 428 stream_->OnCanWrite(); |
427 | 429 |
428 // Handle the ack for the second write. | 430 // Handle the ack for the second write. |
429 EXPECT_CALL(*delegate, OnAckNotification(101, 202, 303, 404)); | 431 EXPECT_CALL(*delegate, OnAckNotification(101, 202, 303, 404, zero_)); |
430 proxy_delegate->OnAckNotification(100, 200, 300, 400); | 432 proxy_delegate->OnAckNotification(100, 200, 300, 400, zero_); |
431 } | 433 } |
432 | 434 |
433 // Verify delegate behavior when WriteOrBufferData does not buffer. | 435 // Verify delegate behavior when WriteOrBufferData does not buffer. |
434 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferNoBuffer) { | 436 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferNoBuffer) { |
435 Initialize(kShouldProcessData); | 437 Initialize(kShouldProcessData); |
436 | 438 |
437 scoped_refptr<MockAckNotifierDelegate> delegate( | 439 scoped_refptr<MockAckNotifierDelegate> delegate( |
438 new StrictMock<MockAckNotifierDelegate>); | 440 new StrictMock<MockAckNotifierDelegate>); |
439 | 441 |
440 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 442 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
441 | 443 |
442 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( | 444 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( |
443 WithArgs<4>(Invoke(CreateFunctor( | 445 WithArgs<4>(Invoke(CreateFunctor( |
444 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 446 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
445 Return(QuicConsumedData(kDataLen, true)))); | 447 Return(QuicConsumedData(kDataLen, true)))); |
446 stream_->WriteOrBufferData(kData1, true, delegate.get()); | 448 stream_->WriteOrBufferData(kData1, true, delegate.get()); |
447 EXPECT_FALSE(write_blocked_list_->HasWriteBlockedStreams()); | 449 EXPECT_FALSE(write_blocked_list_->HasWriteBlockedStreams()); |
448 | 450 |
449 // Handle the ack. | 451 // Handle the ack. |
450 EXPECT_CALL(*delegate, OnAckNotification(1, 2, 3, 4)); | 452 EXPECT_CALL(*delegate, OnAckNotification(1, 2, 3, 4, zero_)); |
451 proxy_delegate->OnAckNotification(1, 2, 3, 4); | 453 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); |
452 } | 454 } |
453 | 455 |
454 // Verify delegate behavior when WriteOrBufferData buffers all the data. | 456 // Verify delegate behavior when WriteOrBufferData buffers all the data. |
455 TEST_F(ReliableQuicStreamTest, BufferOnWriteAndBufferDataWithAckNotifer) { | 457 TEST_F(ReliableQuicStreamTest, BufferOnWriteAndBufferDataWithAckNotifer) { |
456 Initialize(kShouldProcessData); | 458 Initialize(kShouldProcessData); |
457 | 459 |
458 scoped_refptr<MockAckNotifierDelegate> delegate( | 460 scoped_refptr<MockAckNotifierDelegate> delegate( |
459 new StrictMock<MockAckNotifierDelegate>); | 461 new StrictMock<MockAckNotifierDelegate>); |
460 | 462 |
461 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 463 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
462 | 464 |
463 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce( | 465 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce( |
464 Return(QuicConsumedData(0, false))); | 466 Return(QuicConsumedData(0, false))); |
465 stream_->WriteOrBufferData(kData1, true, delegate.get()); | 467 stream_->WriteOrBufferData(kData1, true, delegate.get()); |
466 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); | 468 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); |
467 | 469 |
468 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( | 470 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( |
469 WithArgs<4>(Invoke(CreateFunctor( | 471 WithArgs<4>(Invoke(CreateFunctor( |
470 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 472 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
471 Return(QuicConsumedData(kDataLen, true)))); | 473 Return(QuicConsumedData(kDataLen, true)))); |
472 stream_->OnCanWrite(); | 474 stream_->OnCanWrite(); |
473 | 475 |
474 // Handle the ack. | 476 // Handle the ack. |
475 EXPECT_CALL(*delegate, OnAckNotification(1, 2, 3, 4)); | 477 EXPECT_CALL(*delegate, OnAckNotification(1, 2, 3, 4, zero_)); |
476 proxy_delegate->OnAckNotification(1, 2, 3, 4); | 478 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); |
477 } | 479 } |
478 | 480 |
479 // Verify delegate behavior when WriteOrBufferData when the FIN is | 481 // Verify delegate behavior when WriteOrBufferData when the FIN is |
480 // sent out in a different packet. | 482 // sent out in a different packet. |
481 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferOnlyFinRemains) { | 483 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferOnlyFinRemains) { |
482 Initialize(kShouldProcessData); | 484 Initialize(kShouldProcessData); |
483 | 485 |
484 scoped_refptr<MockAckNotifierDelegate> delegate( | 486 scoped_refptr<MockAckNotifierDelegate> delegate( |
485 new StrictMock<MockAckNotifierDelegate>); | 487 new StrictMock<MockAckNotifierDelegate>); |
486 | 488 |
487 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 489 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
488 | 490 |
489 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( | 491 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( |
490 WithArgs<4>(Invoke(CreateFunctor( | 492 WithArgs<4>(Invoke(CreateFunctor( |
491 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 493 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
492 Return(QuicConsumedData(kDataLen, false)))); | 494 Return(QuicConsumedData(kDataLen, false)))); |
493 stream_->WriteOrBufferData(kData1, true, delegate.get()); | 495 stream_->WriteOrBufferData(kData1, true, delegate.get()); |
494 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); | 496 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); |
495 | 497 |
496 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( | 498 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( |
497 WithArgs<4>(Invoke(CreateFunctor( | 499 WithArgs<4>(Invoke(CreateFunctor( |
498 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 500 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
499 Return(QuicConsumedData(0, true)))); | 501 Return(QuicConsumedData(0, true)))); |
500 stream_->OnCanWrite(); | 502 stream_->OnCanWrite(); |
501 | 503 |
502 // Handle the acks. | 504 // Handle the acks. |
503 proxy_delegate->OnAckNotification(1, 2, 3, 4); | 505 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); |
504 EXPECT_CALL(*delegate, OnAckNotification(11, 22, 33, 44)); | 506 EXPECT_CALL(*delegate, OnAckNotification(11, 22, 33, 44, zero_)); |
505 proxy_delegate->OnAckNotification(10, 20, 30, 40); | 507 proxy_delegate->OnAckNotification(10, 20, 30, 40, zero_); |
506 } | 508 } |
507 | 509 |
508 } // namespace | 510 } // namespace |
509 } // namespace test | 511 } // namespace test |
510 } // namespace net | 512 } // namespace net |
OLD | NEW |