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
3 // found in the LICENSE file.
5 #include "net/quic/reliable_quic_stream.h"
7 #include "net/quic/quic_ack_notifier.h"
8 #include "net/quic/quic_connection.h"
9 #include "net/quic/quic_flags.h"
10 #include "net/quic/quic_utils.h"
11 #include "net/quic/quic_write_blocked_list.h"
12 #include "net/quic/spdy_utils.h"
13 #include "net/quic/test_tools/quic_config_peer.h"
14 #include "net/quic/test_tools/quic_flow_controller_peer.h"
15 #include "net/quic/test_tools/quic_session_peer.h"
16 #include "net/quic/test_tools/quic_test_utils.h"
17 #include "net/quic/test_tools/reliable_quic_stream_peer.h"
18 #include "net/test/gtest_util.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gmock_mutant.h"
22 using base::StringPiece
;
24 using testing::CreateFunctor
;
25 using testing::InSequence
;
26 using testing::Invoke
;
27 using testing::Return
;
28 using testing::SaveArg
;
29 using testing::StrictMock
;
30 using testing::WithArgs
;
37 const char kData1
[] = "FooAndBar";
38 const char kData2
[] = "EepAndBaz";
39 const size_t kDataLen
= 9;
40 const QuicConnectionId kStreamId
= 3;
41 const bool kIsServer
= true;
42 const bool kShouldProcessData
= true;
44 class TestStream
: public ReliableQuicStream
{
46 TestStream(QuicStreamId id
,
48 bool should_process_data
)
49 : ReliableQuicStream(id
, session
),
50 should_process_data_(should_process_data
) {}
52 virtual uint32
ProcessRawData(const char* data
, uint32 data_len
) OVERRIDE
{
53 EXPECT_NE(0u, data_len
);
54 DVLOG(1) << "ProcessData data_len: " << data_len
;
55 data_
+= string(data
, data_len
);
56 return should_process_data_
? data_len
: 0;
59 virtual QuicPriority
EffectivePriority() const OVERRIDE
{
60 return QuicUtils::HighestPriority();
63 using ReliableQuicStream::WriteOrBufferData
;
64 using ReliableQuicStream::CloseReadSide
;
65 using ReliableQuicStream::CloseWriteSide
;
66 using ReliableQuicStream::OnClose
;
69 bool should_process_data_
;
73 class ReliableQuicStreamTest
: public ::testing::TestWithParam
<bool> {
75 ReliableQuicStreamTest()
76 : initial_flow_control_window_bytes_(kMaxPacketSize
),
77 zero_(QuicTime::Delta::Zero()),
78 supported_versions_(QuicSupportedVersions()) {
79 headers_
[":host"] = "www.google.com";
80 headers_
[":path"] = "/index.hml";
81 headers_
[":scheme"] = "https";
83 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; "
85 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX"
86 "hoALMsy6HOdDad2Sz0flUByv7etmo3mLMidGrBoljqO9hSVA40SLqpG_iuKKSHX"
87 "RW3Np4bq0F0SDGDNsW0DSmTS9ufMRrlpARJDS7qAI6M3bghqJp4eABKZiRqebHT"
88 "pMU-RXvTI5D5oCF1vYxYofH_l1Kviuiy3oQ1kS1enqWgbhJ2t61_SNdv-1XJIS0"
89 "O3YeHLmVCs62O6zp89QwakfAWK9d3IDQvVSJzCQsvxvNIvaZFa567MawWlXg0Rh"
90 "1zFMi5vzcns38-8_Sns; "
91 "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"
93 "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%"
95 "2Fpc-t*250%2Fpc-cm*461%2Fpc-s-cr*722%2Fpc-s-t*722%2Fau_p*4"
96 "SICAID=AJKiYcHdKgxum7KMXG0ei2t1-W4OD1uW-ecNsCqC0wDuAXiDGIcT_HA2o1"
97 "3Rs1UKCuBAF9g8rWNOFbxt8PSNSHFuIhOo2t6bJAVpCsMU5Laa6lewuTMYI8MzdQP"
98 "ARHKyW-koxuhMZHUnGBJAM1gJODe0cATO_KGoX4pbbFxxJ5IicRxOrWK_5rU3cdy6"
99 "edlR9FsEdH6iujMcHkbE5l18ehJDwTWmBKBzVD87naobhMMrF6VvnDGxQVGp9Ir_b"
100 "Rgj3RWUoPumQVCxtSOBdX0GlJOEcDTNCzQIm9BSfetog_eP_TfYubKudt5eMsXmN6"
101 "QnyXHeGeK2UINUzJ-D30AFcpqYgH9_1BvYSpi7fc7_ydBU8TaD8ZRxvtnzXqj0RfG"
102 "tuHghmv3aD-uzSYJ75XDdzKdizZ86IG6Fbn1XFhYZM-fbHhm3mVEXnyRW4ZuNOLFk"
103 "Fas6LMcVC6Q8QLlHYbXBpdNFuGbuZGUnav5C-2I_-46lL0NGg3GewxGKGHvHEfoyn"
104 "EFFlEYHsBQ98rXImL8ySDycdLEFvBPdtctPmWCfTxwmoSMLHU2SCVDhbqMWU5b0yr"
105 "JBCScs_ejbKaqBDoB7ZGxTvqlrB__2ZmnHHjCr8RgMRtKNtIeuZAo ";
108 void set_supported_versions(const QuicVersionVector
& versions
) {
109 supported_versions_
= versions
;
112 void Initialize(bool stream_should_process_data
) {
114 new StrictMock
<MockConnection
>(kIsServer
, supported_versions_
);
115 session_
.reset(new StrictMock
<MockSession
>(connection_
));
117 // New streams rely on having the peer's flow control receive window
118 // negotiated in the config.
119 QuicConfigPeer::SetReceivedInitialFlowControlWindow(
120 session_
->config(), initial_flow_control_window_bytes_
);
122 stream_
.reset(new TestStream(kStreamId
, session_
.get(),
123 stream_should_process_data
));
124 stream2_
.reset(new TestStream(kStreamId
+ 2, session_
.get(),
125 stream_should_process_data
));
126 write_blocked_list_
=
127 QuicSessionPeer::GetWriteblockedStreams(session_
.get());
130 bool fin_sent() { return ReliableQuicStreamPeer::FinSent(stream_
.get()); }
131 bool rst_sent() { return ReliableQuicStreamPeer::RstSent(stream_
.get()); }
133 void set_initial_flow_control_window_bytes(uint32 val
) {
134 initial_flow_control_window_bytes_
= val
;
138 MockConnection
* connection_
;
139 scoped_ptr
<MockSession
> session_
;
140 scoped_ptr
<TestStream
> stream_
;
141 scoped_ptr
<TestStream
> stream2_
;
142 SpdyHeaderBlock headers_
;
143 QuicWriteBlockedList
* write_blocked_list_
;
144 uint32 initial_flow_control_window_bytes_
;
145 QuicTime::Delta zero_
;
146 QuicVersionVector supported_versions_
;
149 TEST_F(ReliableQuicStreamTest
, WriteAllData
) {
150 Initialize(kShouldProcessData
);
152 connection_
->options()->max_packet_length
=
153 1 + QuicPacketCreator::StreamFramePacketOverhead(
154 connection_
->version(), PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
155 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
156 EXPECT_CALL(*session_
, WritevData(kStreamId
, _
, _
, _
, _
)).WillOnce(
157 Return(QuicConsumedData(kDataLen
, true)));
158 stream_
->WriteOrBufferData(kData1
, false, NULL
);
159 EXPECT_FALSE(write_blocked_list_
->HasWriteBlockedStreams());
162 TEST_F(ReliableQuicStreamTest
, NoBlockingIfNoDataOrFin
) {
163 Initialize(kShouldProcessData
);
165 // Write no data and no fin. If we consume nothing we should not be write
167 EXPECT_DFATAL(stream_
->WriteOrBufferData(StringPiece(), false, NULL
), "");
168 EXPECT_FALSE(write_blocked_list_
->HasWriteBlockedStreams());
171 TEST_F(ReliableQuicStreamTest
, BlockIfOnlySomeDataConsumed
) {
172 Initialize(kShouldProcessData
);
174 // Write some data and no fin. If we consume some but not all of the data,
175 // we should be write blocked a not all the data was consumed.
176 EXPECT_CALL(*session_
, WritevData(kStreamId
, _
, _
, _
, _
)).WillOnce(
177 Return(QuicConsumedData(1, false)));
178 stream_
->WriteOrBufferData(StringPiece(kData1
, 2), false, NULL
);
179 ASSERT_EQ(1u, write_blocked_list_
->NumBlockedStreams());
183 TEST_F(ReliableQuicStreamTest
, BlockIfFinNotConsumedWithData
) {
184 Initialize(kShouldProcessData
);
186 // Write some data and no fin. If we consume all the data but not the fin,
187 // we should be write blocked because the fin was not consumed.
188 // (This should never actually happen as the fin should be sent out with the
190 EXPECT_CALL(*session_
, WritevData(kStreamId
, _
, _
, _
, _
)).WillOnce(
191 Return(QuicConsumedData(2, false)));
192 stream_
->WriteOrBufferData(StringPiece(kData1
, 2), true, NULL
);
193 ASSERT_EQ(1u, write_blocked_list_
->NumBlockedStreams());
196 TEST_F(ReliableQuicStreamTest
, BlockIfSoloFinNotConsumed
) {
197 Initialize(kShouldProcessData
);
199 // Write no data and a fin. If we consume nothing we should be write blocked,
200 // as the fin was not consumed.
201 EXPECT_CALL(*session_
, WritevData(kStreamId
, _
, _
, _
, _
)).WillOnce(
202 Return(QuicConsumedData(0, false)));
203 stream_
->WriteOrBufferData(StringPiece(), true, NULL
);
204 ASSERT_EQ(1u, write_blocked_list_
->NumBlockedStreams());
207 TEST_F(ReliableQuicStreamTest
, WriteOrBufferData
) {
208 Initialize(kShouldProcessData
);
210 EXPECT_FALSE(write_blocked_list_
->HasWriteBlockedStreams());
211 connection_
->options()->max_packet_length
=
212 1 + QuicPacketCreator::StreamFramePacketOverhead(
213 connection_
->version(), PACKET_8BYTE_CONNECTION_ID
, !kIncludeVersion
,
214 PACKET_6BYTE_SEQUENCE_NUMBER
, NOT_IN_FEC_GROUP
);
215 EXPECT_CALL(*session_
, WritevData(_
, _
, _
, _
, _
)).WillOnce(
216 Return(QuicConsumedData(kDataLen
- 1, false)));
217 stream_
->WriteOrBufferData(kData1
, false, NULL
);
218 EXPECT_TRUE(write_blocked_list_
->HasWriteBlockedStreams());
220 // Queue a bytes_consumed write.
221 stream_
->WriteOrBufferData(kData2
, false, NULL
);
223 // Make sure we get the tail of the first write followed by the bytes_consumed
225 EXPECT_CALL(*session_
, WritevData(_
, _
, _
, _
, _
)).
226 WillOnce(Return(QuicConsumedData(1, false)));
227 EXPECT_CALL(*session_
, WritevData(_
, _
, _
, _
, _
)).
228 WillOnce(Return(QuicConsumedData(kDataLen
- 2, false)));
229 stream_
->OnCanWrite();
231 // And finally the end of the bytes_consumed.
232 EXPECT_CALL(*session_
, WritevData(_
, _
, _
, _
, _
)).
233 WillOnce(Return(QuicConsumedData(2, true)));
234 stream_
->OnCanWrite();
237 TEST_F(ReliableQuicStreamTest
, ConnectionCloseAfterStreamClose
) {
238 Initialize(kShouldProcessData
);
240 stream_
->CloseReadSide();
241 stream_
->CloseWriteSide();
242 EXPECT_EQ(QUIC_STREAM_NO_ERROR
, stream_
->stream_error());
243 EXPECT_EQ(QUIC_NO_ERROR
, stream_
->connection_error());
244 stream_
->OnConnectionClosed(QUIC_INTERNAL_ERROR
, false);
245 EXPECT_EQ(QUIC_STREAM_NO_ERROR
, stream_
->stream_error());
246 EXPECT_EQ(QUIC_NO_ERROR
, stream_
->connection_error());
249 TEST_F(ReliableQuicStreamTest
, RstAlwaysSentIfNoFinSent
) {
250 // For flow control accounting, a stream must send either a FIN or a RST frame
251 // before termination.
252 // Test that if no FIN has been sent, we send a RST.
254 Initialize(kShouldProcessData
);
255 EXPECT_FALSE(fin_sent());
256 EXPECT_FALSE(rst_sent());
258 // Write some data, with no FIN.
259 EXPECT_CALL(*session_
, WritevData(kStreamId
, _
, _
, _
, _
)).WillOnce(
260 Return(QuicConsumedData(1, false)));
261 stream_
->WriteOrBufferData(StringPiece(kData1
, 1), false, NULL
);
262 EXPECT_FALSE(fin_sent());
263 EXPECT_FALSE(rst_sent());
265 // Now close the stream, and expect that we send a RST.
266 EXPECT_CALL(*session_
, SendRstStream(_
, _
, _
));
268 EXPECT_FALSE(fin_sent());
269 EXPECT_TRUE(rst_sent());
272 TEST_F(ReliableQuicStreamTest
, RstNotSentIfFinSent
) {
273 // For flow control accounting, a stream must send either a FIN or a RST frame
274 // before termination.
275 // Test that if a FIN has been sent, we don't also send a RST.
277 Initialize(kShouldProcessData
);
278 EXPECT_FALSE(fin_sent());
279 EXPECT_FALSE(rst_sent());
281 // Write some data, with FIN.
282 EXPECT_CALL(*session_
, WritevData(kStreamId
, _
, _
, _
, _
)).WillOnce(
283 Return(QuicConsumedData(1, true)));
284 stream_
->WriteOrBufferData(StringPiece(kData1
, 1), true, NULL
);
285 EXPECT_TRUE(fin_sent());
286 EXPECT_FALSE(rst_sent());
288 // Now close the stream, and expect that we do not send a RST.
290 EXPECT_TRUE(fin_sent());
291 EXPECT_FALSE(rst_sent());
294 TEST_F(ReliableQuicStreamTest
, OnlySendOneRst
) {
295 // For flow control accounting, a stream must send either a FIN or a RST frame
296 // before termination.
297 // Test that if a stream sends a RST, it doesn't send an additional RST during
298 // OnClose() (this shouldn't be harmful, but we shouldn't do it anyway...)
300 Initialize(kShouldProcessData
);
301 EXPECT_FALSE(fin_sent());
302 EXPECT_FALSE(rst_sent());
305 const int expected_resets
= 1;
306 EXPECT_CALL(*session_
, SendRstStream(_
, _
, _
)).Times(expected_resets
);
307 stream_
->Reset(QUIC_STREAM_CANCELLED
);
308 EXPECT_FALSE(fin_sent());
309 EXPECT_TRUE(rst_sent());
311 // Now close the stream (any further resets being sent would break the
312 // expectation above).
314 EXPECT_FALSE(fin_sent());
315 EXPECT_TRUE(rst_sent());
318 TEST_F(ReliableQuicStreamTest
, StreamFlowControlMultipleWindowUpdates
) {
319 ValueRestore
<bool> old_flag(&FLAGS_enable_quic_stream_flow_control_2
, true);
320 set_initial_flow_control_window_bytes(1000);
322 Initialize(kShouldProcessData
);
324 // If we receive multiple WINDOW_UPDATES (potentially out of order), then we
325 // want to make sure we latch the largest offset we see.
327 // Initially should be default.
328 EXPECT_EQ(initial_flow_control_window_bytes_
,
329 QuicFlowControllerPeer::SendWindowOffset(
330 stream_
.get()->flow_controller()));
332 // Check a single WINDOW_UPDATE results in correct offset.
333 QuicWindowUpdateFrame
window_update_1(stream_
->id(), 1234);
334 stream_
->OnWindowUpdateFrame(window_update_1
);
335 EXPECT_EQ(window_update_1
.byte_offset
,
336 QuicFlowControllerPeer::SendWindowOffset(
337 stream_
.get()->flow_controller()));
339 // Now send a few more WINDOW_UPDATES and make sure that only the largest is
341 QuicWindowUpdateFrame
window_update_2(stream_
->id(), 1);
342 QuicWindowUpdateFrame
window_update_3(stream_
->id(), 9999);
343 QuicWindowUpdateFrame
window_update_4(stream_
->id(), 5678);
344 stream_
->OnWindowUpdateFrame(window_update_2
);
345 stream_
->OnWindowUpdateFrame(window_update_3
);
346 stream_
->OnWindowUpdateFrame(window_update_4
);
347 EXPECT_EQ(window_update_3
.byte_offset
,
348 QuicFlowControllerPeer::SendWindowOffset(
349 stream_
.get()->flow_controller()));
352 TEST_F(ReliableQuicStreamTest
, StreamFlowControlShouldNotBlockInLessThanQ017
) {
353 // TODO(rjshade): Remove this test when we no longer have any versions <
355 ValueRestore
<bool> old_flag(&FLAGS_enable_quic_stream_flow_control_2
, true);
357 // Make sure we are using a version which does not support flow control.
358 QuicVersion kTestQuicVersions
[] = {QUIC_VERSION_16
};
359 QuicVersionVector versions
;
360 for (size_t i
= 0; i
< arraysize(kTestQuicVersions
); ++i
) {
361 versions
.push_back(kTestQuicVersions
[i
]);
363 set_supported_versions(versions
);
365 // Peer is not talking QUIC_VERSION_17 so assumes that it can send a zero
366 // length flow control receive window with no consequences.
367 set_initial_flow_control_window_bytes(0);
369 Initialize(kShouldProcessData
);
371 // The stream should _not_ be flow control blocked, because we are not talking
372 // a version which has flow control enabled.
373 EXPECT_FALSE(stream_
->flow_controller()->IsBlocked());
376 void SaveProxyAckNotifierDelegate(
377 scoped_refptr
<QuicAckNotifier::DelegateInterface
>* delegate_out
,
378 QuicAckNotifier::DelegateInterface
* delegate
) {
379 *delegate_out
= delegate
;
382 TEST_F(ReliableQuicStreamTest
, WriteOrBufferDataWithQuicAckNotifier
) {
383 Initialize(kShouldProcessData
);
385 scoped_refptr
<MockAckNotifierDelegate
> delegate(
386 new StrictMock
<MockAckNotifierDelegate
>);
388 const int kDataSize
= 16 * 1024;
389 const string
kData(kDataSize
, 'a');
391 const int kFirstWriteSize
= 100;
392 const int kSecondWriteSize
= 50;
393 const int kLastWriteSize
= kDataSize
- kFirstWriteSize
- kSecondWriteSize
;
395 // Set a large flow control send window so this doesn't interfere with test.
396 stream_
->flow_controller()->UpdateSendWindowOffset(kDataSize
+ 1);
398 scoped_refptr
<QuicAckNotifier::DelegateInterface
> proxy_delegate
;
400 EXPECT_CALL(*session_
, WritevData(kStreamId
, _
, _
, _
, _
)).WillOnce(DoAll(
401 WithArgs
<4>(Invoke(CreateFunctor(
402 &SaveProxyAckNotifierDelegate
, &proxy_delegate
))),
403 Return(QuicConsumedData(kFirstWriteSize
, false))));
404 stream_
->WriteOrBufferData(kData
, false, delegate
.get());
405 EXPECT_TRUE(write_blocked_list_
->HasWriteBlockedStreams());
407 EXPECT_CALL(*session_
, WritevData(kStreamId
, _
, _
, _
, proxy_delegate
.get())).
409 Return(QuicConsumedData(kSecondWriteSize
, false)));
410 stream_
->OnCanWrite();
412 // No ack expected for an empty write.
413 EXPECT_CALL(*session_
, WritevData(kStreamId
, _
, _
, _
, proxy_delegate
.get())).
415 Return(QuicConsumedData(0, false)));
416 stream_
->OnCanWrite();
418 EXPECT_CALL(*session_
, WritevData(kStreamId
, _
, _
, _
, proxy_delegate
.get())).
420 Return(QuicConsumedData(kLastWriteSize
, false)));
421 stream_
->OnCanWrite();
423 // There were two writes, so OnAckNotification is not propagated
424 // until the third Ack arrives.
425 proxy_delegate
->OnAckNotification(1, 2, 3, 4, zero_
);
426 proxy_delegate
->OnAckNotification(10, 20, 30, 40, zero_
);
428 // The arguments to delegate->OnAckNotification are the sum of the
429 // arguments to proxy_delegate OnAckNotification calls.
430 EXPECT_CALL(*delegate
, OnAckNotification(111, 222, 333, 444, zero_
));
431 proxy_delegate
->OnAckNotification(100, 200, 300, 400, zero_
);
434 // Verify delegate behavior when packets are acked before the
435 // WritevData call that sends out the last byte.
436 TEST_F(ReliableQuicStreamTest
, WriteOrBufferDataAckNotificationBeforeFlush
) {
437 Initialize(kShouldProcessData
);
439 scoped_refptr
<MockAckNotifierDelegate
> delegate(
440 new StrictMock
<MockAckNotifierDelegate
>);
442 const int kDataSize
= 16 * 1024;
443 const string
kData(kDataSize
, 'a');
445 const int kInitialWriteSize
= 100;
447 // Set a large flow control send window so this doesn't interfere with test.
448 stream_
->flow_controller()->UpdateSendWindowOffset(kDataSize
+ 1);
450 scoped_refptr
<QuicAckNotifier::DelegateInterface
> proxy_delegate
;
452 EXPECT_CALL(*session_
, WritevData(kStreamId
, _
, _
, _
, _
)).WillOnce(DoAll(
453 WithArgs
<4>(Invoke(CreateFunctor(
454 &SaveProxyAckNotifierDelegate
, &proxy_delegate
))),
455 Return(QuicConsumedData(kInitialWriteSize
, false))));
456 stream_
->WriteOrBufferData(kData
, false, delegate
.get());
457 EXPECT_TRUE(write_blocked_list_
->HasWriteBlockedStreams());
459 // Handle the ack of the first write.
460 proxy_delegate
->OnAckNotification(1, 2, 3, 4, zero_
);
461 proxy_delegate
= NULL
;
463 EXPECT_CALL(*session_
, WritevData(kStreamId
, _
, _
, _
, _
)).WillOnce(DoAll(
464 WithArgs
<4>(Invoke(CreateFunctor(
465 &SaveProxyAckNotifierDelegate
, &proxy_delegate
))),
466 Return(QuicConsumedData(kDataSize
- kInitialWriteSize
, false))));
467 stream_
->OnCanWrite();
469 // Handle the ack for the second write.
470 EXPECT_CALL(*delegate
, OnAckNotification(101, 202, 303, 404, zero_
));
471 proxy_delegate
->OnAckNotification(100, 200, 300, 400, zero_
);
474 // Verify delegate behavior when WriteOrBufferData does not buffer.
475 TEST_F(ReliableQuicStreamTest
, WriteAndBufferDataWithAckNotiferNoBuffer
) {
476 Initialize(kShouldProcessData
);
478 scoped_refptr
<MockAckNotifierDelegate
> delegate(
479 new StrictMock
<MockAckNotifierDelegate
>);
481 scoped_refptr
<QuicAckNotifier::DelegateInterface
> proxy_delegate
;
483 EXPECT_CALL(*session_
, WritevData(kStreamId
, _
, _
, _
, _
)).WillOnce(DoAll(
484 WithArgs
<4>(Invoke(CreateFunctor(
485 &SaveProxyAckNotifierDelegate
, &proxy_delegate
))),
486 Return(QuicConsumedData(kDataLen
, true))));
487 stream_
->WriteOrBufferData(kData1
, true, delegate
.get());
488 EXPECT_FALSE(write_blocked_list_
->HasWriteBlockedStreams());
491 EXPECT_CALL(*delegate
, OnAckNotification(1, 2, 3, 4, zero_
));
492 proxy_delegate
->OnAckNotification(1, 2, 3, 4, zero_
);
495 // Verify delegate behavior when WriteOrBufferData buffers all the data.
496 TEST_F(ReliableQuicStreamTest
, BufferOnWriteAndBufferDataWithAckNotifer
) {
497 Initialize(kShouldProcessData
);
499 scoped_refptr
<MockAckNotifierDelegate
> delegate(
500 new StrictMock
<MockAckNotifierDelegate
>);
502 scoped_refptr
<QuicAckNotifier::DelegateInterface
> proxy_delegate
;
504 EXPECT_CALL(*session_
, WritevData(kStreamId
, _
, _
, _
, _
)).WillOnce(
505 Return(QuicConsumedData(0, false)));
506 stream_
->WriteOrBufferData(kData1
, true, delegate
.get());
507 EXPECT_TRUE(write_blocked_list_
->HasWriteBlockedStreams());
509 EXPECT_CALL(*session_
, WritevData(kStreamId
, _
, _
, _
, _
)).WillOnce(DoAll(
510 WithArgs
<4>(Invoke(CreateFunctor(
511 &SaveProxyAckNotifierDelegate
, &proxy_delegate
))),
512 Return(QuicConsumedData(kDataLen
, true))));
513 stream_
->OnCanWrite();
516 EXPECT_CALL(*delegate
, OnAckNotification(1, 2, 3, 4, zero_
));
517 proxy_delegate
->OnAckNotification(1, 2, 3, 4, zero_
);
520 // Verify delegate behavior when WriteOrBufferData when the FIN is
521 // sent out in a different packet.
522 TEST_F(ReliableQuicStreamTest
, WriteAndBufferDataWithAckNotiferOnlyFinRemains
) {
523 Initialize(kShouldProcessData
);
525 scoped_refptr
<MockAckNotifierDelegate
> delegate(
526 new StrictMock
<MockAckNotifierDelegate
>);
528 scoped_refptr
<QuicAckNotifier::DelegateInterface
> proxy_delegate
;
530 EXPECT_CALL(*session_
, WritevData(kStreamId
, _
, _
, _
, _
)).WillOnce(DoAll(
531 WithArgs
<4>(Invoke(CreateFunctor(
532 &SaveProxyAckNotifierDelegate
, &proxy_delegate
))),
533 Return(QuicConsumedData(kDataLen
, false))));
534 stream_
->WriteOrBufferData(kData1
, true, delegate
.get());
535 EXPECT_TRUE(write_blocked_list_
->HasWriteBlockedStreams());
537 EXPECT_CALL(*session_
, WritevData(kStreamId
, _
, _
, _
, _
)).WillOnce(DoAll(
538 WithArgs
<4>(Invoke(CreateFunctor(
539 &SaveProxyAckNotifierDelegate
, &proxy_delegate
))),
540 Return(QuicConsumedData(0, true))));
541 stream_
->OnCanWrite();
544 proxy_delegate
->OnAckNotification(1, 2, 3, 4, zero_
);
545 EXPECT_CALL(*delegate
, OnAckNotification(11, 22, 33, 44, zero_
));
546 proxy_delegate
->OnAckNotification(10, 20, 30, 40, zero_
);