1 // Copyright 2013 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/quic_data_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_flow_controller_peer.h"
14 #include "net/quic/test_tools/quic_session_peer.h"
15 #include "net/quic/test_tools/quic_test_utils.h"
16 #include "net/quic/test_tools/reliable_quic_stream_peer.h"
17 #include "net/test/gtest_util.h"
18 #include "testing/gmock/include/gmock/gmock.h"
20 using base::StringPiece
;
22 using testing::AnyNumber
;
23 using testing::InSequence
;
24 using testing::Return
;
25 using testing::SaveArg
;
26 using testing::StrictMock
;
33 const bool kIsServer
= true;
34 const bool kShouldProcessData
= true;
36 class TestStream
: public QuicDataStream
{
38 TestStream(QuicStreamId id
,
40 bool should_process_data
)
41 : QuicDataStream(id
, session
),
42 should_process_data_(should_process_data
) {}
44 virtual uint32
ProcessData(const char* data
, uint32 data_len
) OVERRIDE
{
45 EXPECT_NE(0u, data_len
);
46 DVLOG(1) << "ProcessData data_len: " << data_len
;
47 data_
+= string(data
, data_len
);
48 return should_process_data_
? data_len
: 0;
51 using ReliableQuicStream::WriteOrBufferData
;
52 using ReliableQuicStream::CloseReadSide
;
53 using ReliableQuicStream::CloseWriteSide
;
55 const string
& data() const { return data_
; }
58 bool should_process_data_
;
62 class QuicDataStreamTest
: public ::testing::TestWithParam
<QuicVersion
> {
64 QuicDataStreamTest() {
65 headers_
[":host"] = "www.google.com";
66 headers_
[":path"] = "/index.hml";
67 headers_
[":scheme"] = "https";
69 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; "
71 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX"
72 "hoALMsy6HOdDad2Sz0flUByv7etmo3mLMidGrBoljqO9hSVA40SLqpG_iuKKSHX"
73 "RW3Np4bq0F0SDGDNsW0DSmTS9ufMRrlpARJDS7qAI6M3bghqJp4eABKZiRqebHT"
74 "pMU-RXvTI5D5oCF1vYxYofH_l1Kviuiy3oQ1kS1enqWgbhJ2t61_SNdv-1XJIS0"
75 "O3YeHLmVCs62O6zp89QwakfAWK9d3IDQvVSJzCQsvxvNIvaZFa567MawWlXg0Rh"
76 "1zFMi5vzcns38-8_Sns; "
77 "GA=v*2%2Fmem*57968640*47239936%2Fmem*57968640*47114716%2Fno-nm-"
78 "yj*15%2Fno-cc-yj*5%2Fpc-ch*133685%2Fpc-s-cr*133947%2Fpc-s-t*1339"
79 "47%2Fno-nm-yj*4%2Fno-cc-yj*1%2Fceft-as*1%2Fceft-nqas*0%2Fad-ra-c"
80 "v_p%2Fad-nr-cv_p-f*1%2Fad-v-cv_p*859%2Fad-ns-cv_p-f*1%2Ffn-v-ad%"
81 "2Fpc-t*250%2Fpc-cm*461%2Fpc-s-cr*722%2Fpc-s-t*722%2Fau_p*4"
82 "SICAID=AJKiYcHdKgxum7KMXG0ei2t1-W4OD1uW-ecNsCqC0wDuAXiDGIcT_HA2o1"
83 "3Rs1UKCuBAF9g8rWNOFbxt8PSNSHFuIhOo2t6bJAVpCsMU5Laa6lewuTMYI8MzdQP"
84 "ARHKyW-koxuhMZHUnGBJAM1gJODe0cATO_KGoX4pbbFxxJ5IicRxOrWK_5rU3cdy6"
85 "edlR9FsEdH6iujMcHkbE5l18ehJDwTWmBKBzVD87naobhMMrF6VvnDGxQVGp9Ir_b"
86 "Rgj3RWUoPumQVCxtSOBdX0GlJOEcDTNCzQIm9BSfetog_eP_TfYubKudt5eMsXmN6"
87 "QnyXHeGeK2UINUzJ-D30AFcpqYgH9_1BvYSpi7fc7_ydBU8TaD8ZRxvtnzXqj0RfG"
88 "tuHghmv3aD-uzSYJ75XDdzKdizZ86IG6Fbn1XFhYZM-fbHhm3mVEXnyRW4ZuNOLFk"
89 "Fas6LMcVC6Q8QLlHYbXBpdNFuGbuZGUnav5C-2I_-46lL0NGg3GewxGKGHvHEfoyn"
90 "EFFlEYHsBQ98rXImL8ySDycdLEFvBPdtctPmWCfTxwmoSMLHU2SCVDhbqMWU5b0yr"
91 "JBCScs_ejbKaqBDoB7ZGxTvqlrB__2ZmnHHjCr8RgMRtKNtIeuZAo ";
94 void Initialize(bool stream_should_process_data
) {
95 connection_
= new testing::StrictMock
<MockConnection
>(
96 kIsServer
, SupportedVersions(GetParam()));
97 session_
.reset(new testing::StrictMock
<MockSession
>(connection_
));
98 stream_
.reset(new TestStream(kClientDataStreamId1
, session_
.get(),
99 stream_should_process_data
));
100 stream2_
.reset(new TestStream(kClientDataStreamId2
, session_
.get(),
101 stream_should_process_data
));
102 write_blocked_list_
=
103 QuicSessionPeer::GetWriteBlockedStreams(session_
.get());
107 MockConnection
* connection_
;
108 scoped_ptr
<MockSession
> session_
;
109 scoped_ptr
<TestStream
> stream_
;
110 scoped_ptr
<TestStream
> stream2_
;
111 SpdyHeaderBlock headers_
;
112 QuicWriteBlockedList
* write_blocked_list_
;
115 INSTANTIATE_TEST_CASE_P(Tests
, QuicDataStreamTest
,
116 ::testing::ValuesIn(QuicSupportedVersions()));
118 TEST_P(QuicDataStreamTest
, ProcessHeaders
) {
119 Initialize(kShouldProcessData
);
121 string headers
= SpdyUtils::SerializeUncompressedHeaders(headers_
);
122 stream_
->OnStreamHeadersPriority(QuicUtils::HighestPriority());
123 stream_
->OnStreamHeaders(headers
);
124 EXPECT_EQ(headers
, stream_
->data());
125 stream_
->OnStreamHeadersComplete(false, headers
.size());
126 EXPECT_EQ(QuicUtils::HighestPriority(), stream_
->EffectivePriority());
127 EXPECT_EQ(headers
, stream_
->data());
128 EXPECT_FALSE(stream_
->IsDoneReading());
131 TEST_P(QuicDataStreamTest
, ProcessHeadersAndBody
) {
132 Initialize(kShouldProcessData
);
134 string headers
= SpdyUtils::SerializeUncompressedHeaders(headers_
);
135 string body
= "this is the body";
137 stream_
->OnStreamHeaders(headers
);
138 EXPECT_EQ(headers
, stream_
->data());
139 stream_
->OnStreamHeadersComplete(false, headers
.size());
140 QuicStreamFrame
frame(kClientDataStreamId1
, false, 0, MakeIOVector(body
));
141 stream_
->OnStreamFrame(frame
);
143 EXPECT_EQ(headers
+ body
, stream_
->data());
146 TEST_P(QuicDataStreamTest
, ProcessHeadersAndBodyFragments
) {
147 string headers
= SpdyUtils::SerializeUncompressedHeaders(headers_
);
148 string body
= "this is the body";
150 for (size_t fragment_size
= 1; fragment_size
< body
.size();
152 Initialize(kShouldProcessData
);
153 for (size_t offset
= 0; offset
< headers
.size();
154 offset
+= fragment_size
) {
155 size_t remaining_data
= headers
.size() - offset
;
156 StringPiece
fragment(headers
.data() + offset
,
157 min(fragment_size
, remaining_data
));
158 stream_
->OnStreamHeaders(fragment
);
160 stream_
->OnStreamHeadersComplete(false, headers
.size());
161 for (size_t offset
= 0; offset
< body
.size(); offset
+= fragment_size
) {
162 size_t remaining_data
= body
.size() - offset
;
163 StringPiece
fragment(body
.data() + offset
,
164 min(fragment_size
, remaining_data
));
165 QuicStreamFrame
frame(kClientDataStreamId1
, false, offset
,
166 MakeIOVector(fragment
));
167 stream_
->OnStreamFrame(frame
);
169 ASSERT_EQ(headers
+ body
,
170 stream_
->data()) << "fragment_size: " << fragment_size
;
174 TEST_P(QuicDataStreamTest
, ProcessHeadersAndBodyFragmentsSplit
) {
175 string headers
= SpdyUtils::SerializeUncompressedHeaders(headers_
);
176 string body
= "this is the body";
178 for (size_t split_point
= 1; split_point
< body
.size() - 1; ++split_point
) {
179 Initialize(kShouldProcessData
);
180 StringPiece
headers1(headers
.data(), split_point
);
181 stream_
->OnStreamHeaders(headers1
);
183 StringPiece
headers2(headers
.data() + split_point
,
184 headers
.size() - split_point
);
185 stream_
->OnStreamHeaders(headers2
);
186 stream_
->OnStreamHeadersComplete(false, headers
.size());
188 StringPiece
fragment1(body
.data(), split_point
);
189 QuicStreamFrame
frame1(kClientDataStreamId1
, false, 0,
190 MakeIOVector(fragment1
));
191 stream_
->OnStreamFrame(frame1
);
193 StringPiece
fragment2(body
.data() + split_point
,
194 body
.size() - split_point
);
195 QuicStreamFrame
frame2(kClientDataStreamId1
, false, split_point
,
196 MakeIOVector(fragment2
));
197 stream_
->OnStreamFrame(frame2
);
199 ASSERT_EQ(headers
+ body
,
200 stream_
->data()) << "split_point: " << split_point
;
204 TEST_P(QuicDataStreamTest
, ProcessHeadersAndBodyReadv
) {
205 Initialize(!kShouldProcessData
);
207 string headers
= SpdyUtils::SerializeUncompressedHeaders(headers_
);
208 string body
= "this is the body";
210 stream_
->OnStreamHeaders(headers
);
211 EXPECT_EQ(headers
, stream_
->data());
212 stream_
->OnStreamHeadersComplete(false, headers
.size());
213 QuicStreamFrame
frame(kClientDataStreamId1
, false, 0, MakeIOVector(body
));
214 stream_
->OnStreamFrame(frame
);
217 ASSERT_LT(headers
.length() + body
.length(), arraysize(buffer
));
219 vec
.iov_base
= buffer
;
220 vec
.iov_len
= arraysize(buffer
);
222 size_t bytes_read
= stream_
->Readv(&vec
, 1);
223 EXPECT_EQ(headers
.length(), bytes_read
);
224 EXPECT_EQ(headers
, string(buffer
, bytes_read
));
226 bytes_read
= stream_
->Readv(&vec
, 1);
227 EXPECT_EQ(body
.length(), bytes_read
);
228 EXPECT_EQ(body
, string(buffer
, bytes_read
));
231 TEST_P(QuicDataStreamTest
, ProcessHeadersAndBodyIncrementalReadv
) {
232 Initialize(!kShouldProcessData
);
234 string headers
= SpdyUtils::SerializeUncompressedHeaders(headers_
);
235 string body
= "this is the body";
236 stream_
->OnStreamHeaders(headers
);
237 EXPECT_EQ(headers
, stream_
->data());
238 stream_
->OnStreamHeadersComplete(false, headers
.size());
239 QuicStreamFrame
frame(kClientDataStreamId1
, false, 0, MakeIOVector(body
));
240 stream_
->OnStreamFrame(frame
);
244 vec
.iov_base
= buffer
;
245 vec
.iov_len
= arraysize(buffer
);
247 string data
= headers
+ body
;
248 for (size_t i
= 0; i
< data
.length(); ++i
) {
249 size_t bytes_read
= stream_
->Readv(&vec
, 1);
250 ASSERT_EQ(1u, bytes_read
);
251 EXPECT_EQ(data
.data()[i
], buffer
[0]);
255 TEST_P(QuicDataStreamTest
, ProcessHeadersUsingReadvWithMultipleIovecs
) {
256 Initialize(!kShouldProcessData
);
258 string headers
= SpdyUtils::SerializeUncompressedHeaders(headers_
);
259 string body
= "this is the body";
260 stream_
->OnStreamHeaders(headers
);
261 EXPECT_EQ(headers
, stream_
->data());
262 stream_
->OnStreamHeadersComplete(false, headers
.size());
263 QuicStreamFrame
frame(kClientDataStreamId1
, false, 0, MakeIOVector(body
));
264 stream_
->OnStreamFrame(frame
);
269 vec
[0].iov_base
= buffer1
;
270 vec
[0].iov_len
= arraysize(buffer1
);
271 vec
[1].iov_base
= buffer2
;
272 vec
[1].iov_len
= arraysize(buffer2
);
273 string data
= headers
+ body
;
274 for (size_t i
= 0; i
< data
.length(); i
+= 2) {
275 size_t bytes_read
= stream_
->Readv(vec
, 2);
276 ASSERT_EQ(2u, bytes_read
) << i
;
277 ASSERT_EQ(data
.data()[i
], buffer1
[0]) << i
;
278 ASSERT_EQ(data
.data()[i
+ 1], buffer2
[0]) << i
;
282 TEST_P(QuicDataStreamTest
, StreamFlowControlBlocked
) {
283 // Tests that we send a BLOCKED frame to the peer when we attempt to write,
284 // but are flow control blocked.
285 if (GetParam() <= QUIC_VERSION_16
) {
289 Initialize(kShouldProcessData
);
291 // Set a small flow control limit.
292 const uint64 kWindow
= 36;
293 QuicFlowControllerPeer::SetSendWindowOffset(stream_
->flow_controller(),
295 EXPECT_EQ(kWindow
, QuicFlowControllerPeer::SendWindowOffset(
296 stream_
->flow_controller()));
298 // Try to send more data than the flow control limit allows.
299 string headers
= SpdyUtils::SerializeUncompressedHeaders(headers_
);
301 const uint64 kOverflow
= 15;
302 GenerateBody(&body
, kWindow
+ kOverflow
);
304 EXPECT_CALL(*connection_
, SendBlocked(kClientDataStreamId1
));
305 EXPECT_CALL(*session_
, WritevData(kClientDataStreamId1
, _
, _
, _
, _
, _
))
306 .WillOnce(Return(QuicConsumedData(kWindow
, true)));
307 stream_
->WriteOrBufferData(body
, false, NULL
);
309 // Should have sent as much as possible, resulting in no send window left.
311 QuicFlowControllerPeer::SendWindowSize(stream_
->flow_controller()));
313 // And we should have queued the overflowed data.
315 ReliableQuicStreamPeer::SizeOfQueuedData(stream_
.get()));
318 TEST_P(QuicDataStreamTest
, StreamFlowControlNoWindowUpdateIfNotConsumed
) {
319 // The flow control receive window decreases whenever we add new bytes to the
320 // sequencer, whether they are consumed immediately or buffered. However we
321 // only send WINDOW_UPDATE frames based on increasing number of bytes
323 if (GetParam() <= QUIC_VERSION_16
) {
327 // Don't process data - it will be buffered instead.
328 Initialize(!kShouldProcessData
);
330 // Expect no WINDOW_UPDATE frames to be sent.
331 EXPECT_CALL(*connection_
, SendWindowUpdate(_
, _
)).Times(0);
333 // Set a small flow control receive window.
334 const uint64 kWindow
= 36;
335 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_
->flow_controller(),
337 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_
->flow_controller(),
339 EXPECT_EQ(kWindow
, QuicFlowControllerPeer::ReceiveWindowOffset(
340 stream_
->flow_controller()));
342 // Stream receives enough data to fill a fraction of the receive window.
343 string headers
= SpdyUtils::SerializeUncompressedHeaders(headers_
);
345 GenerateBody(&body
, kWindow
/ 3);
346 stream_
->OnStreamHeaders(headers
);
347 EXPECT_EQ(headers
, stream_
->data());
348 stream_
->OnStreamHeadersComplete(false, headers
.size());
350 QuicStreamFrame
frame1(kClientDataStreamId1
, false, 0, MakeIOVector(body
));
351 stream_
->OnStreamFrame(frame1
);
352 EXPECT_EQ(kWindow
- (kWindow
/ 3), QuicFlowControllerPeer::ReceiveWindowSize(
353 stream_
->flow_controller()));
355 // Now receive another frame which results in the receive window being over
356 // half full. This should all be buffered, decreasing the receive window but
357 // not sending WINDOW_UPDATE.
358 QuicStreamFrame
frame2(kClientDataStreamId1
, false, kWindow
/ 3,
360 stream_
->OnStreamFrame(frame2
);
362 kWindow
- (2 * kWindow
/ 3),
363 QuicFlowControllerPeer::ReceiveWindowSize(stream_
->flow_controller()));
366 TEST_P(QuicDataStreamTest
, StreamFlowControlWindowUpdate
) {
367 // Tests that on receipt of data, the stream updates its receive window offset
368 // appropriately, and sends WINDOW_UPDATE frames when its receive window drops
370 if (GetParam() <= QUIC_VERSION_16
) {
374 Initialize(kShouldProcessData
);
376 // Set a small flow control limit.
377 const uint64 kWindow
= 36;
378 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_
->flow_controller(),
380 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_
->flow_controller(),
382 EXPECT_EQ(kWindow
, QuicFlowControllerPeer::ReceiveWindowOffset(
383 stream_
->flow_controller()));
385 // Stream receives enough data to fill a fraction of the receive window.
386 string headers
= SpdyUtils::SerializeUncompressedHeaders(headers_
);
388 GenerateBody(&body
, kWindow
/ 3);
389 stream_
->OnStreamHeaders(headers
);
390 EXPECT_EQ(headers
, stream_
->data());
391 stream_
->OnStreamHeadersComplete(false, headers
.size());
393 QuicStreamFrame
frame1(kClientDataStreamId1
, false, 0, MakeIOVector(body
));
394 stream_
->OnStreamFrame(frame1
);
395 EXPECT_EQ(kWindow
- (kWindow
/ 3), QuicFlowControllerPeer::ReceiveWindowSize(
396 stream_
->flow_controller()));
398 // Now receive another frame which results in the receive window being over
399 // half full. This will trigger the stream to increase its receive window
400 // offset and send a WINDOW_UPDATE. The result will be again an available
401 // window of kWindow bytes.
402 QuicStreamFrame
frame2(kClientDataStreamId1
, false, kWindow
/ 3,
404 EXPECT_CALL(*connection_
,
405 SendWindowUpdate(kClientDataStreamId1
,
406 QuicFlowControllerPeer::ReceiveWindowOffset(
407 stream_
->flow_controller()) +
409 stream_
->OnStreamFrame(frame2
);
410 EXPECT_EQ(kWindow
, QuicFlowControllerPeer::ReceiveWindowSize(
411 stream_
->flow_controller()));
414 TEST_P(QuicDataStreamTest
, ConnectionFlowControlWindowUpdate
) {
415 // Tests that on receipt of data, the connection updates its receive window
416 // offset appropriately, and sends WINDOW_UPDATE frames when its receive
417 // window drops too low.
418 if (GetParam() < QUIC_VERSION_19
) {
421 ValueRestore
<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2
,
424 Initialize(kShouldProcessData
);
426 // Set a small flow control limit for streams and connection.
427 const uint64 kWindow
= 36;
428 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_
->flow_controller(),
430 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_
->flow_controller(),
432 QuicFlowControllerPeer::SetReceiveWindowOffset(stream2_
->flow_controller(),
434 QuicFlowControllerPeer::SetMaxReceiveWindow(stream2_
->flow_controller(),
436 QuicFlowControllerPeer::SetReceiveWindowOffset(session_
->flow_controller(),
438 QuicFlowControllerPeer::SetMaxReceiveWindow(session_
->flow_controller(),
441 // Supply headers to both streams so that they are happy to receive data.
442 string headers
= SpdyUtils::SerializeUncompressedHeaders(headers_
);
443 stream_
->OnStreamHeaders(headers
);
444 stream_
->OnStreamHeadersComplete(false, headers
.size());
445 stream2_
->OnStreamHeaders(headers
);
446 stream2_
->OnStreamHeadersComplete(false, headers
.size());
448 // Each stream gets a quarter window of data. This should not trigger a
449 // WINDOW_UPDATE for either stream, nor for the connection.
451 GenerateBody(&body
, kWindow
/ 4);
452 QuicStreamFrame
frame1(kClientDataStreamId1
, false, 0, MakeIOVector(body
));
453 stream_
->OnStreamFrame(frame1
);
454 QuicStreamFrame
frame2(kClientDataStreamId2
, false, 0, MakeIOVector(body
));
455 stream2_
->OnStreamFrame(frame2
);
457 // Now receive a further single byte on one stream - again this does not
458 // trigger a stream WINDOW_UPDATE, but now the connection flow control window
459 // is over half full and thus a connection WINDOW_UPDATE is sent.
460 EXPECT_CALL(*connection_
, SendWindowUpdate(kClientDataStreamId1
, _
)).Times(0);
461 EXPECT_CALL(*connection_
, SendWindowUpdate(kClientDataStreamId2
, _
)).Times(0);
462 EXPECT_CALL(*connection_
,
463 SendWindowUpdate(0, QuicFlowControllerPeer::ReceiveWindowOffset(
464 session_
->flow_controller()) +
466 QuicStreamFrame
frame3(kClientDataStreamId1
, false, (kWindow
/ 4),
468 stream_
->OnStreamFrame(frame3
);
471 TEST_P(QuicDataStreamTest
, StreamFlowControlViolation
) {
472 // Tests that on if the peer sends too much data (i.e. violates the flow
473 // control protocol), then we terminate the connection.
474 if (GetParam() <= QUIC_VERSION_16
) {
478 // Stream should not process data, so that data gets buffered in the
479 // sequencer, triggering flow control limits.
480 Initialize(!kShouldProcessData
);
482 // Set a small flow control limit.
483 const uint64 kWindow
= 50;
484 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_
->flow_controller(),
487 string headers
= SpdyUtils::SerializeUncompressedHeaders(headers_
);
488 stream_
->OnStreamHeaders(headers
);
489 EXPECT_EQ(headers
, stream_
->data());
490 stream_
->OnStreamHeadersComplete(false, headers
.size());
492 // Receive data to overflow the window, violating flow control.
494 GenerateBody(&body
, kWindow
+ 1);
495 QuicStreamFrame
frame(kClientDataStreamId1
, false, 0, MakeIOVector(body
));
496 EXPECT_CALL(*connection_
,
497 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA
));
498 stream_
->OnStreamFrame(frame
);
501 TEST_P(QuicDataStreamTest
, ConnectionFlowControlViolation
) {
502 // Tests that on if the peer sends too much data (i.e. violates the flow
503 // control protocol), at the connection level (rather than the stream level)
504 // then we terminate the connection.
505 if (GetParam() < QUIC_VERSION_19
) {
508 ValueRestore
<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2
,
511 // Stream should not process data, so that data gets buffered in the
512 // sequencer, triggering flow control limits.
513 Initialize(!kShouldProcessData
);
515 // Set a small flow control window on streams, and connection.
516 const uint64 kStreamWindow
= 50;
517 const uint64 kConnectionWindow
= 10;
518 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_
->flow_controller(),
520 QuicFlowControllerPeer::SetReceiveWindowOffset(session_
->flow_controller(),
523 string headers
= SpdyUtils::SerializeUncompressedHeaders(headers_
);
524 stream_
->OnStreamHeaders(headers
);
525 EXPECT_EQ(headers
, stream_
->data());
526 stream_
->OnStreamHeadersComplete(false, headers
.size());
528 // Send enough data to overflow the connection level flow control window.
530 GenerateBody(&body
, kConnectionWindow
+ 1);
531 EXPECT_LT(body
.size(), kStreamWindow
);
532 QuicStreamFrame
frame(kClientDataStreamId1
, false, 0, MakeIOVector(body
));
534 EXPECT_CALL(*connection_
,
535 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA
));
536 stream_
->OnStreamFrame(frame
);
539 TEST_P(QuicDataStreamTest
, StreamFlowControlFinNotBlocked
) {
540 // An attempt to write a FIN with no data should not be flow control blocked,
541 // even if the send window is 0.
542 if (GetParam() <= QUIC_VERSION_16
) {
546 Initialize(kShouldProcessData
);
548 // Set a flow control limit of zero.
549 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_
->flow_controller(), 0);
550 EXPECT_EQ(0u, QuicFlowControllerPeer::ReceiveWindowOffset(
551 stream_
->flow_controller()));
553 // Send a frame with a FIN but no data. This should not be blocked.
557 EXPECT_CALL(*connection_
, SendBlocked(kClientDataStreamId1
)).Times(0);
558 EXPECT_CALL(*session_
, WritevData(kClientDataStreamId1
, _
, _
, _
, _
, _
))
559 .WillOnce(Return(QuicConsumedData(0, fin
)));
561 stream_
->WriteOrBufferData(body
, fin
, NULL
);