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" |
11 #include "net/quic/quic_write_blocked_list.h" | 11 #include "net/quic/quic_write_blocked_list.h" |
12 #include "net/quic/spdy_utils.h" | 12 #include "net/quic/spdy_utils.h" |
| 13 #include "net/quic/test_tools/quic_flow_controller_peer.h" |
13 #include "net/quic/test_tools/quic_session_peer.h" | 14 #include "net/quic/test_tools/quic_session_peer.h" |
14 #include "net/quic/test_tools/quic_test_utils.h" | 15 #include "net/quic/test_tools/quic_test_utils.h" |
15 #include "net/quic/test_tools/reliable_quic_stream_peer.h" | 16 #include "net/quic/test_tools/reliable_quic_stream_peer.h" |
16 #include "net/test/gtest_util.h" | 17 #include "net/test/gtest_util.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gmock_mutant.h" | 19 #include "testing/gmock_mutant.h" |
19 | 20 |
20 using base::StringPiece; | 21 using base::StringPiece; |
21 using std::min; | 22 using std::min; |
22 using testing::_; | 23 using testing::_; |
(...skipping 28 matching lines...) Expand all Loading... |
51 EXPECT_NE(0u, data_len); | 52 EXPECT_NE(0u, data_len); |
52 DVLOG(1) << "ProcessData data_len: " << data_len; | 53 DVLOG(1) << "ProcessData data_len: " << data_len; |
53 data_ += string(data, data_len); | 54 data_ += string(data, data_len); |
54 return should_process_data_ ? data_len : 0; | 55 return should_process_data_ ? data_len : 0; |
55 } | 56 } |
56 | 57 |
57 virtual QuicPriority EffectivePriority() const OVERRIDE { | 58 virtual QuicPriority EffectivePriority() const OVERRIDE { |
58 return QuicUtils::HighestPriority(); | 59 return QuicUtils::HighestPriority(); |
59 } | 60 } |
60 | 61 |
61 virtual bool IsFlowControlEnabled() const OVERRIDE { | |
62 return true; | |
63 } | |
64 | |
65 using ReliableQuicStream::WriteOrBufferData; | 62 using ReliableQuicStream::WriteOrBufferData; |
66 using ReliableQuicStream::CloseReadSide; | 63 using ReliableQuicStream::CloseReadSide; |
67 using ReliableQuicStream::CloseWriteSide; | 64 using ReliableQuicStream::CloseWriteSide; |
68 using ReliableQuicStream::OnClose; | 65 using ReliableQuicStream::OnClose; |
69 | 66 |
70 private: | 67 private: |
71 bool should_process_data_; | 68 bool should_process_data_; |
72 string data_; | 69 string data_; |
73 }; | 70 }; |
74 | 71 |
75 class ReliableQuicStreamTest : public ::testing::TestWithParam<bool> { | 72 class ReliableQuicStreamTest : public ::testing::TestWithParam<bool> { |
76 public: | 73 public: |
77 ReliableQuicStreamTest() | 74 ReliableQuicStreamTest() |
78 : initial_flow_control_window_bytes_(kMaxPacketSize) { | 75 : initial_flow_control_window_bytes_(kMaxPacketSize), |
| 76 zero_(QuicTime::Delta::Zero()), |
| 77 supported_versions_(QuicSupportedVersions()) { |
79 headers_[":host"] = "www.google.com"; | 78 headers_[":host"] = "www.google.com"; |
80 headers_[":path"] = "/index.hml"; | 79 headers_[":path"] = "/index.hml"; |
81 headers_[":scheme"] = "https"; | 80 headers_[":scheme"] = "https"; |
82 headers_["cookie"] = | 81 headers_["cookie"] = |
83 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; " | 82 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; " |
84 "__utmc=160408618; " | 83 "__utmc=160408618; " |
85 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX" | 84 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX" |
86 "hoALMsy6HOdDad2Sz0flUByv7etmo3mLMidGrBoljqO9hSVA40SLqpG_iuKKSHX" | 85 "hoALMsy6HOdDad2Sz0flUByv7etmo3mLMidGrBoljqO9hSVA40SLqpG_iuKKSHX" |
87 "RW3Np4bq0F0SDGDNsW0DSmTS9ufMRrlpARJDS7qAI6M3bghqJp4eABKZiRqebHT" | 86 "RW3Np4bq0F0SDGDNsW0DSmTS9ufMRrlpARJDS7qAI6M3bghqJp4eABKZiRqebHT" |
88 "pMU-RXvTI5D5oCF1vYxYofH_l1Kviuiy3oQ1kS1enqWgbhJ2t61_SNdv-1XJIS0" | 87 "pMU-RXvTI5D5oCF1vYxYofH_l1Kviuiy3oQ1kS1enqWgbhJ2t61_SNdv-1XJIS0" |
89 "O3YeHLmVCs62O6zp89QwakfAWK9d3IDQvVSJzCQsvxvNIvaZFa567MawWlXg0Rh" | 88 "O3YeHLmVCs62O6zp89QwakfAWK9d3IDQvVSJzCQsvxvNIvaZFa567MawWlXg0Rh" |
90 "1zFMi5vzcns38-8_Sns; " | 89 "1zFMi5vzcns38-8_Sns; " |
91 "GA=v*2%2Fmem*57968640*47239936%2Fmem*57968640*47114716%2Fno-nm-" | 90 "GA=v*2%2Fmem*57968640*47239936%2Fmem*57968640*47114716%2Fno-nm-" |
92 "yj*15%2Fno-cc-yj*5%2Fpc-ch*133685%2Fpc-s-cr*133947%2Fpc-s-t*1339" | 91 "yj*15%2Fno-cc-yj*5%2Fpc-ch*133685%2Fpc-s-cr*133947%2Fpc-s-t*1339" |
93 "47%2Fno-nm-yj*4%2Fno-cc-yj*1%2Fceft-as*1%2Fceft-nqas*0%2Fad-ra-c" | 92 "47%2Fno-nm-yj*4%2Fno-cc-yj*1%2Fceft-as*1%2Fceft-nqas*0%2Fad-ra-c" |
94 "v_p%2Fad-nr-cv_p-f*1%2Fad-v-cv_p*859%2Fad-ns-cv_p-f*1%2Ffn-v-ad%" | 93 "v_p%2Fad-nr-cv_p-f*1%2Fad-v-cv_p*859%2Fad-ns-cv_p-f*1%2Ffn-v-ad%" |
95 "2Fpc-t*250%2Fpc-cm*461%2Fpc-s-cr*722%2Fpc-s-t*722%2Fau_p*4" | 94 "2Fpc-t*250%2Fpc-cm*461%2Fpc-s-cr*722%2Fpc-s-t*722%2Fau_p*4" |
96 "SICAID=AJKiYcHdKgxum7KMXG0ei2t1-W4OD1uW-ecNsCqC0wDuAXiDGIcT_HA2o1" | 95 "SICAID=AJKiYcHdKgxum7KMXG0ei2t1-W4OD1uW-ecNsCqC0wDuAXiDGIcT_HA2o1" |
97 "3Rs1UKCuBAF9g8rWNOFbxt8PSNSHFuIhOo2t6bJAVpCsMU5Laa6lewuTMYI8MzdQP" | 96 "3Rs1UKCuBAF9g8rWNOFbxt8PSNSHFuIhOo2t6bJAVpCsMU5Laa6lewuTMYI8MzdQP" |
98 "ARHKyW-koxuhMZHUnGBJAM1gJODe0cATO_KGoX4pbbFxxJ5IicRxOrWK_5rU3cdy6" | 97 "ARHKyW-koxuhMZHUnGBJAM1gJODe0cATO_KGoX4pbbFxxJ5IicRxOrWK_5rU3cdy6" |
99 "edlR9FsEdH6iujMcHkbE5l18ehJDwTWmBKBzVD87naobhMMrF6VvnDGxQVGp9Ir_b" | 98 "edlR9FsEdH6iujMcHkbE5l18ehJDwTWmBKBzVD87naobhMMrF6VvnDGxQVGp9Ir_b" |
100 "Rgj3RWUoPumQVCxtSOBdX0GlJOEcDTNCzQIm9BSfetog_eP_TfYubKudt5eMsXmN6" | 99 "Rgj3RWUoPumQVCxtSOBdX0GlJOEcDTNCzQIm9BSfetog_eP_TfYubKudt5eMsXmN6" |
101 "QnyXHeGeK2UINUzJ-D30AFcpqYgH9_1BvYSpi7fc7_ydBU8TaD8ZRxvtnzXqj0RfG" | 100 "QnyXHeGeK2UINUzJ-D30AFcpqYgH9_1BvYSpi7fc7_ydBU8TaD8ZRxvtnzXqj0RfG" |
102 "tuHghmv3aD-uzSYJ75XDdzKdizZ86IG6Fbn1XFhYZM-fbHhm3mVEXnyRW4ZuNOLFk" | 101 "tuHghmv3aD-uzSYJ75XDdzKdizZ86IG6Fbn1XFhYZM-fbHhm3mVEXnyRW4ZuNOLFk" |
103 "Fas6LMcVC6Q8QLlHYbXBpdNFuGbuZGUnav5C-2I_-46lL0NGg3GewxGKGHvHEfoyn" | 102 "Fas6LMcVC6Q8QLlHYbXBpdNFuGbuZGUnav5C-2I_-46lL0NGg3GewxGKGHvHEfoyn" |
104 "EFFlEYHsBQ98rXImL8ySDycdLEFvBPdtctPmWCfTxwmoSMLHU2SCVDhbqMWU5b0yr" | 103 "EFFlEYHsBQ98rXImL8ySDycdLEFvBPdtctPmWCfTxwmoSMLHU2SCVDhbqMWU5b0yr" |
105 "JBCScs_ejbKaqBDoB7ZGxTvqlrB__2ZmnHHjCr8RgMRtKNtIeuZAo "; | 104 "JBCScs_ejbKaqBDoB7ZGxTvqlrB__2ZmnHHjCr8RgMRtKNtIeuZAo "; |
106 } | 105 } |
107 | 106 |
| 107 void set_supported_versions(const QuicVersionVector& versions) { |
| 108 supported_versions_ = versions; |
| 109 } |
| 110 |
108 void Initialize(bool stream_should_process_data) { | 111 void Initialize(bool stream_should_process_data) { |
109 connection_ = new StrictMock<MockConnection>(kIsServer); | 112 connection_ = |
| 113 new StrictMock<MockConnection>(kIsServer, supported_versions_); |
110 session_.reset(new StrictMock<MockSession>(connection_)); | 114 session_.reset(new StrictMock<MockSession>(connection_)); |
111 | 115 |
112 // New streams rely on having the peer's flow control receive window | 116 // New streams rely on having the peer's flow control receive window |
113 // negotiated in the config. | 117 // negotiated in the config. |
114 session_->config()->set_peer_initial_flow_control_window_bytes( | 118 session_->config()->set_peer_initial_flow_control_window_bytes( |
115 initial_flow_control_window_bytes_); | 119 initial_flow_control_window_bytes_); |
116 | 120 |
117 stream_.reset(new TestStream(kStreamId, session_.get(), | 121 stream_.reset(new TestStream(kStreamId, session_.get(), |
118 stream_should_process_data)); | 122 stream_should_process_data)); |
119 stream2_.reset(new TestStream(kStreamId + 2, session_.get(), | 123 stream2_.reset(new TestStream(kStreamId + 2, session_.get(), |
(...skipping 10 matching lines...) Expand all Loading... |
130 } | 134 } |
131 | 135 |
132 protected: | 136 protected: |
133 MockConnection* connection_; | 137 MockConnection* connection_; |
134 scoped_ptr<MockSession> session_; | 138 scoped_ptr<MockSession> session_; |
135 scoped_ptr<TestStream> stream_; | 139 scoped_ptr<TestStream> stream_; |
136 scoped_ptr<TestStream> stream2_; | 140 scoped_ptr<TestStream> stream2_; |
137 SpdyHeaderBlock headers_; | 141 SpdyHeaderBlock headers_; |
138 QuicWriteBlockedList* write_blocked_list_; | 142 QuicWriteBlockedList* write_blocked_list_; |
139 uint32 initial_flow_control_window_bytes_; | 143 uint32 initial_flow_control_window_bytes_; |
| 144 QuicTime::Delta zero_; |
| 145 QuicVersionVector supported_versions_; |
140 }; | 146 }; |
141 | 147 |
142 TEST_F(ReliableQuicStreamTest, WriteAllData) { | 148 TEST_F(ReliableQuicStreamTest, WriteAllData) { |
143 Initialize(kShouldProcessData); | 149 Initialize(kShouldProcessData); |
144 | 150 |
145 connection_->options()->max_packet_length = | 151 connection_->options()->max_packet_length = |
146 1 + QuicPacketCreator::StreamFramePacketOverhead( | 152 1 + QuicPacketCreator::StreamFramePacketOverhead( |
147 connection_->version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 153 connection_->version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
148 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); | 154 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); |
149 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce( | 155 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce( |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control, true); | 318 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control, true); |
313 set_initial_flow_control_window_bytes(1000); | 319 set_initial_flow_control_window_bytes(1000); |
314 | 320 |
315 Initialize(kShouldProcessData); | 321 Initialize(kShouldProcessData); |
316 | 322 |
317 // If we receive multiple WINDOW_UPDATES (potentially out of order), then we | 323 // If we receive multiple WINDOW_UPDATES (potentially out of order), then we |
318 // want to make sure we latch the largest offset we see. | 324 // want to make sure we latch the largest offset we see. |
319 | 325 |
320 // Initially should be default. | 326 // Initially should be default. |
321 EXPECT_EQ(initial_flow_control_window_bytes_, | 327 EXPECT_EQ(initial_flow_control_window_bytes_, |
322 ReliableQuicStreamPeer::SendWindowOffset(stream_.get())); | 328 QuicFlowControllerPeer::SendWindowOffset( |
| 329 stream_.get()->flow_controller())); |
323 | 330 |
324 // Check a single WINDOW_UPDATE results in correct offset. | 331 // Check a single WINDOW_UPDATE results in correct offset. |
325 QuicWindowUpdateFrame window_update_1(stream_->id(), 1234); | 332 QuicWindowUpdateFrame window_update_1(stream_->id(), 1234); |
326 stream_->OnWindowUpdateFrame(window_update_1); | 333 stream_->OnWindowUpdateFrame(window_update_1); |
327 EXPECT_EQ(window_update_1.byte_offset, | 334 EXPECT_EQ(window_update_1.byte_offset, |
328 ReliableQuicStreamPeer::SendWindowOffset(stream_.get())); | 335 QuicFlowControllerPeer::SendWindowOffset( |
| 336 stream_.get()->flow_controller())); |
329 | 337 |
330 // Now send a few more WINDOW_UPDATES and make sure that only the largest is | 338 // Now send a few more WINDOW_UPDATES and make sure that only the largest is |
331 // remembered. | 339 // remembered. |
332 QuicWindowUpdateFrame window_update_2(stream_->id(), 1); | 340 QuicWindowUpdateFrame window_update_2(stream_->id(), 1); |
333 QuicWindowUpdateFrame window_update_3(stream_->id(), 9999); | 341 QuicWindowUpdateFrame window_update_3(stream_->id(), 9999); |
334 QuicWindowUpdateFrame window_update_4(stream_->id(), 5678); | 342 QuicWindowUpdateFrame window_update_4(stream_->id(), 5678); |
335 stream_->OnWindowUpdateFrame(window_update_2); | 343 stream_->OnWindowUpdateFrame(window_update_2); |
336 stream_->OnWindowUpdateFrame(window_update_3); | 344 stream_->OnWindowUpdateFrame(window_update_3); |
337 stream_->OnWindowUpdateFrame(window_update_4); | 345 stream_->OnWindowUpdateFrame(window_update_4); |
338 EXPECT_EQ(window_update_3.byte_offset, | 346 EXPECT_EQ(window_update_3.byte_offset, |
339 ReliableQuicStreamPeer::SendWindowOffset(stream_.get())); | 347 QuicFlowControllerPeer::SendWindowOffset( |
| 348 stream_.get()->flow_controller())); |
| 349 } |
| 350 |
| 351 TEST_F(ReliableQuicStreamTest, StreamFlowControlShouldNotBlockInLessThanQ017) { |
| 352 // TODO(rjshade): Remove this test when we no longer have any versions < |
| 353 // QUIC_VERSION_17. |
| 354 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control, true); |
| 355 |
| 356 // Make sure we are using a version which does not support flow control. |
| 357 QuicVersion kTestQuicVersions[] = {QUIC_VERSION_16}; |
| 358 QuicVersionVector versions; |
| 359 for (size_t i = 0; i < arraysize(kTestQuicVersions); ++i) { |
| 360 versions.push_back(kTestQuicVersions[i]); |
| 361 } |
| 362 set_supported_versions(versions); |
| 363 |
| 364 // Peer is not talking QUIC_VERSION_17 so assumes that it can send a zero |
| 365 // length flow control receive window with no consequences. |
| 366 set_initial_flow_control_window_bytes(0); |
| 367 |
| 368 Initialize(kShouldProcessData); |
| 369 |
| 370 // The stream should _not_ be flow control blocked, because we are not talking |
| 371 // a version which has flow control enabled. |
| 372 EXPECT_FALSE(stream_->flow_controller()->IsBlocked()); |
340 } | 373 } |
341 | 374 |
342 void SaveProxyAckNotifierDelegate( | 375 void SaveProxyAckNotifierDelegate( |
343 scoped_refptr<QuicAckNotifier::DelegateInterface>* delegate_out, | 376 scoped_refptr<QuicAckNotifier::DelegateInterface>* delegate_out, |
344 QuicAckNotifier::DelegateInterface* delegate) { | 377 QuicAckNotifier::DelegateInterface* delegate) { |
345 *delegate_out = delegate; | 378 *delegate_out = delegate; |
346 } | 379 } |
347 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataWithQuicAckNotifier) { | 380 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataWithQuicAckNotifier) { |
348 Initialize(kShouldProcessData); | 381 Initialize(kShouldProcessData); |
349 | 382 |
350 scoped_refptr<MockAckNotifierDelegate> delegate( | 383 scoped_refptr<MockAckNotifierDelegate> delegate( |
351 new StrictMock<MockAckNotifierDelegate>); | 384 new StrictMock<MockAckNotifierDelegate>); |
352 | 385 |
353 const int kDataSize = 16 * 1024; | 386 const int kDataSize = 16 * 1024; |
354 const string kData(kDataSize, 'a'); | 387 const string kData(kDataSize, 'a'); |
355 | 388 |
356 const int kFirstWriteSize = 100; | 389 const int kFirstWriteSize = 100; |
357 const int kSecondWriteSize = 50; | 390 const int kSecondWriteSize = 50; |
358 const int kLastWriteSize = kDataSize - kFirstWriteSize - kSecondWriteSize; | 391 const int kLastWriteSize = kDataSize - kFirstWriteSize - kSecondWriteSize; |
359 | 392 |
| 393 // Set a large flow control send window so this doesn't interfere with test. |
| 394 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); |
| 395 |
360 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 396 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
361 | 397 |
362 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( | 398 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( |
363 WithArgs<4>(Invoke(CreateFunctor( | 399 WithArgs<4>(Invoke(CreateFunctor( |
364 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 400 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
365 Return(QuicConsumedData(kFirstWriteSize, false)))); | 401 Return(QuicConsumedData(kFirstWriteSize, false)))); |
366 stream_->WriteOrBufferData(kData, false, delegate.get()); | 402 stream_->WriteOrBufferData(kData, false, delegate.get()); |
367 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); | 403 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); |
368 | 404 |
369 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, proxy_delegate.get())). | 405 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, proxy_delegate.get())). |
370 WillOnce( | 406 WillOnce( |
371 Return(QuicConsumedData(kSecondWriteSize, false))); | 407 Return(QuicConsumedData(kSecondWriteSize, false))); |
372 stream_->OnCanWrite(); | 408 stream_->OnCanWrite(); |
373 | 409 |
374 // No ack expected for an empty write. | 410 // No ack expected for an empty write. |
375 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, proxy_delegate.get())). | 411 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, proxy_delegate.get())). |
376 WillOnce( | 412 WillOnce( |
377 Return(QuicConsumedData(0, false))); | 413 Return(QuicConsumedData(0, false))); |
378 stream_->OnCanWrite(); | 414 stream_->OnCanWrite(); |
379 | 415 |
380 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, proxy_delegate.get())). | 416 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, proxy_delegate.get())). |
381 WillOnce( | 417 WillOnce( |
382 Return(QuicConsumedData(kLastWriteSize, false))); | 418 Return(QuicConsumedData(kLastWriteSize, false))); |
383 stream_->OnCanWrite(); | 419 stream_->OnCanWrite(); |
384 | 420 |
385 // There were two writes, so OnAckNotification is not propagated | 421 // There were two writes, so OnAckNotification is not propagated |
386 // until the third Ack arrives. | 422 // until the third Ack arrives. |
387 proxy_delegate->OnAckNotification(1, 2, 3, 4); | 423 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); |
388 proxy_delegate->OnAckNotification(10, 20, 30, 40); | 424 proxy_delegate->OnAckNotification(10, 20, 30, 40, zero_); |
389 | 425 |
390 // The arguments to delegate->OnAckNotification are the sum of the | 426 // The arguments to delegate->OnAckNotification are the sum of the |
391 // arguments to proxy_delegate OnAckNotification calls. | 427 // arguments to proxy_delegate OnAckNotification calls. |
392 EXPECT_CALL(*delegate, OnAckNotification(111, 222, 333, 444)); | 428 EXPECT_CALL(*delegate, OnAckNotification(111, 222, 333, 444, zero_)); |
393 proxy_delegate->OnAckNotification(100, 200, 300, 400); | 429 proxy_delegate->OnAckNotification(100, 200, 300, 400, zero_); |
394 } | 430 } |
395 | 431 |
396 // Verify delegate behavior when packets are acked before the | 432 // Verify delegate behavior when packets are acked before the |
397 // WritevData call that sends out the last byte. | 433 // WritevData call that sends out the last byte. |
398 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataAckNotificationBeforeFlush) { | 434 TEST_F(ReliableQuicStreamTest, WriteOrBufferDataAckNotificationBeforeFlush) { |
399 Initialize(kShouldProcessData); | 435 Initialize(kShouldProcessData); |
400 | 436 |
401 scoped_refptr<MockAckNotifierDelegate> delegate( | 437 scoped_refptr<MockAckNotifierDelegate> delegate( |
402 new StrictMock<MockAckNotifierDelegate>); | 438 new StrictMock<MockAckNotifierDelegate>); |
403 | 439 |
404 const int kDataSize = 16 * 1024; | 440 const int kDataSize = 16 * 1024; |
405 const string kData(kDataSize, 'a'); | 441 const string kData(kDataSize, 'a'); |
406 | 442 |
407 const int kInitialWriteSize = 100; | 443 const int kInitialWriteSize = 100; |
408 | 444 |
| 445 // Set a large flow control send window so this doesn't interfere with test. |
| 446 stream_->flow_controller()->UpdateSendWindowOffset(kDataSize + 1); |
| 447 |
409 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 448 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
410 | 449 |
411 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( | 450 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( |
412 WithArgs<4>(Invoke(CreateFunctor( | 451 WithArgs<4>(Invoke(CreateFunctor( |
413 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 452 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
414 Return(QuicConsumedData(kInitialWriteSize, false)))); | 453 Return(QuicConsumedData(kInitialWriteSize, false)))); |
415 stream_->WriteOrBufferData(kData, false, delegate.get()); | 454 stream_->WriteOrBufferData(kData, false, delegate.get()); |
416 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); | 455 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); |
417 | 456 |
418 // Handle the ack of the first write. | 457 // Handle the ack of the first write. |
419 proxy_delegate->OnAckNotification(1, 2, 3, 4); | 458 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); |
420 proxy_delegate = NULL; | 459 proxy_delegate = NULL; |
421 | 460 |
422 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( | 461 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( |
423 WithArgs<4>(Invoke(CreateFunctor( | 462 WithArgs<4>(Invoke(CreateFunctor( |
424 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 463 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
425 Return(QuicConsumedData(kDataSize - kInitialWriteSize, false)))); | 464 Return(QuicConsumedData(kDataSize - kInitialWriteSize, false)))); |
426 stream_->OnCanWrite(); | 465 stream_->OnCanWrite(); |
427 | 466 |
428 // Handle the ack for the second write. | 467 // Handle the ack for the second write. |
429 EXPECT_CALL(*delegate, OnAckNotification(101, 202, 303, 404)); | 468 EXPECT_CALL(*delegate, OnAckNotification(101, 202, 303, 404, zero_)); |
430 proxy_delegate->OnAckNotification(100, 200, 300, 400); | 469 proxy_delegate->OnAckNotification(100, 200, 300, 400, zero_); |
431 } | 470 } |
432 | 471 |
433 // Verify delegate behavior when WriteOrBufferData does not buffer. | 472 // Verify delegate behavior when WriteOrBufferData does not buffer. |
434 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferNoBuffer) { | 473 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferNoBuffer) { |
435 Initialize(kShouldProcessData); | 474 Initialize(kShouldProcessData); |
436 | 475 |
437 scoped_refptr<MockAckNotifierDelegate> delegate( | 476 scoped_refptr<MockAckNotifierDelegate> delegate( |
438 new StrictMock<MockAckNotifierDelegate>); | 477 new StrictMock<MockAckNotifierDelegate>); |
439 | 478 |
440 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 479 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
441 | 480 |
442 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( | 481 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( |
443 WithArgs<4>(Invoke(CreateFunctor( | 482 WithArgs<4>(Invoke(CreateFunctor( |
444 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 483 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
445 Return(QuicConsumedData(kDataLen, true)))); | 484 Return(QuicConsumedData(kDataLen, true)))); |
446 stream_->WriteOrBufferData(kData1, true, delegate.get()); | 485 stream_->WriteOrBufferData(kData1, true, delegate.get()); |
447 EXPECT_FALSE(write_blocked_list_->HasWriteBlockedStreams()); | 486 EXPECT_FALSE(write_blocked_list_->HasWriteBlockedStreams()); |
448 | 487 |
449 // Handle the ack. | 488 // Handle the ack. |
450 EXPECT_CALL(*delegate, OnAckNotification(1, 2, 3, 4)); | 489 EXPECT_CALL(*delegate, OnAckNotification(1, 2, 3, 4, zero_)); |
451 proxy_delegate->OnAckNotification(1, 2, 3, 4); | 490 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); |
452 } | 491 } |
453 | 492 |
454 // Verify delegate behavior when WriteOrBufferData buffers all the data. | 493 // Verify delegate behavior when WriteOrBufferData buffers all the data. |
455 TEST_F(ReliableQuicStreamTest, BufferOnWriteAndBufferDataWithAckNotifer) { | 494 TEST_F(ReliableQuicStreamTest, BufferOnWriteAndBufferDataWithAckNotifer) { |
456 Initialize(kShouldProcessData); | 495 Initialize(kShouldProcessData); |
457 | 496 |
458 scoped_refptr<MockAckNotifierDelegate> delegate( | 497 scoped_refptr<MockAckNotifierDelegate> delegate( |
459 new StrictMock<MockAckNotifierDelegate>); | 498 new StrictMock<MockAckNotifierDelegate>); |
460 | 499 |
461 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 500 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
462 | 501 |
463 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce( | 502 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce( |
464 Return(QuicConsumedData(0, false))); | 503 Return(QuicConsumedData(0, false))); |
465 stream_->WriteOrBufferData(kData1, true, delegate.get()); | 504 stream_->WriteOrBufferData(kData1, true, delegate.get()); |
466 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); | 505 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); |
467 | 506 |
468 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( | 507 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( |
469 WithArgs<4>(Invoke(CreateFunctor( | 508 WithArgs<4>(Invoke(CreateFunctor( |
470 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 509 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
471 Return(QuicConsumedData(kDataLen, true)))); | 510 Return(QuicConsumedData(kDataLen, true)))); |
472 stream_->OnCanWrite(); | 511 stream_->OnCanWrite(); |
473 | 512 |
474 // Handle the ack. | 513 // Handle the ack. |
475 EXPECT_CALL(*delegate, OnAckNotification(1, 2, 3, 4)); | 514 EXPECT_CALL(*delegate, OnAckNotification(1, 2, 3, 4, zero_)); |
476 proxy_delegate->OnAckNotification(1, 2, 3, 4); | 515 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); |
477 } | 516 } |
478 | 517 |
479 // Verify delegate behavior when WriteOrBufferData when the FIN is | 518 // Verify delegate behavior when WriteOrBufferData when the FIN is |
480 // sent out in a different packet. | 519 // sent out in a different packet. |
481 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferOnlyFinRemains) { | 520 TEST_F(ReliableQuicStreamTest, WriteAndBufferDataWithAckNotiferOnlyFinRemains) { |
482 Initialize(kShouldProcessData); | 521 Initialize(kShouldProcessData); |
483 | 522 |
484 scoped_refptr<MockAckNotifierDelegate> delegate( | 523 scoped_refptr<MockAckNotifierDelegate> delegate( |
485 new StrictMock<MockAckNotifierDelegate>); | 524 new StrictMock<MockAckNotifierDelegate>); |
486 | 525 |
487 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; | 526 scoped_refptr<QuicAckNotifier::DelegateInterface> proxy_delegate; |
488 | 527 |
489 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( | 528 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( |
490 WithArgs<4>(Invoke(CreateFunctor( | 529 WithArgs<4>(Invoke(CreateFunctor( |
491 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 530 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
492 Return(QuicConsumedData(kDataLen, false)))); | 531 Return(QuicConsumedData(kDataLen, false)))); |
493 stream_->WriteOrBufferData(kData1, true, delegate.get()); | 532 stream_->WriteOrBufferData(kData1, true, delegate.get()); |
494 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); | 533 EXPECT_TRUE(write_blocked_list_->HasWriteBlockedStreams()); |
495 | 534 |
496 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( | 535 EXPECT_CALL(*session_, WritevData(kStreamId, _, _, _, _)).WillOnce(DoAll( |
497 WithArgs<4>(Invoke(CreateFunctor( | 536 WithArgs<4>(Invoke(CreateFunctor( |
498 &SaveProxyAckNotifierDelegate, &proxy_delegate))), | 537 &SaveProxyAckNotifierDelegate, &proxy_delegate))), |
499 Return(QuicConsumedData(0, true)))); | 538 Return(QuicConsumedData(0, true)))); |
500 stream_->OnCanWrite(); | 539 stream_->OnCanWrite(); |
501 | 540 |
502 // Handle the acks. | 541 // Handle the acks. |
503 proxy_delegate->OnAckNotification(1, 2, 3, 4); | 542 proxy_delegate->OnAckNotification(1, 2, 3, 4, zero_); |
504 EXPECT_CALL(*delegate, OnAckNotification(11, 22, 33, 44)); | 543 EXPECT_CALL(*delegate, OnAckNotification(11, 22, 33, 44, zero_)); |
505 proxy_delegate->OnAckNotification(10, 20, 30, 40); | 544 proxy_delegate->OnAckNotification(10, 20, 30, 40, zero_); |
506 } | 545 } |
507 | 546 |
508 } // namespace | 547 } // namespace |
509 } // namespace test | 548 } // namespace test |
510 } // namespace net | 549 } // namespace net |
OLD | NEW |