Re-land: C++ readability review
[chromium-blink-merge.git] / net / quic / quic_data_stream_test.cc
blob246edc926308af762eb95737fd1a89a3b93fb8f1
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_utils.h"
10 #include "net/quic/quic_write_blocked_list.h"
11 #include "net/quic/spdy_utils.h"
12 #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_test_utils.h"
15 #include "net/quic/test_tools/reliable_quic_stream_peer.h"
16 #include "net/test/gtest_util.h"
17 #include "testing/gmock/include/gmock/gmock.h"
19 using base::StringPiece;
20 using std::min;
21 using std::string;
22 using testing::AnyNumber;
23 using testing::InSequence;
24 using testing::Return;
25 using testing::SaveArg;
26 using testing::StrictMock;
27 using testing::_;
29 namespace net {
30 namespace test {
31 namespace {
33 const bool kShouldProcessData = true;
35 class TestStream : public QuicDataStream {
36 public:
37 TestStream(QuicStreamId id,
38 QuicSession* session,
39 bool should_process_data)
40 : QuicDataStream(id, session),
41 should_process_data_(should_process_data) {}
43 uint32 ProcessData(const char* data, uint32 data_len) override {
44 EXPECT_NE(0u, data_len);
45 DVLOG(1) << "ProcessData data_len: " << data_len;
46 data_ += string(data, data_len);
47 return should_process_data_ ? data_len : 0;
50 using ReliableQuicStream::WriteOrBufferData;
51 using ReliableQuicStream::CloseReadSide;
52 using ReliableQuicStream::CloseWriteSide;
54 const string& data() const { return data_; }
56 private:
57 bool should_process_data_;
58 string data_;
61 class QuicDataStreamTest : public ::testing::TestWithParam<QuicVersion> {
62 public:
63 QuicDataStreamTest() {
64 headers_[":host"] = "www.google.com";
65 headers_[":path"] = "/index.hml";
66 headers_[":scheme"] = "https";
67 headers_["cookie"] =
68 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; "
69 "__utmc=160408618; "
70 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX"
71 "hoALMsy6HOdDad2Sz0flUByv7etmo3mLMidGrBoljqO9hSVA40SLqpG_iuKKSHX"
72 "RW3Np4bq0F0SDGDNsW0DSmTS9ufMRrlpARJDS7qAI6M3bghqJp4eABKZiRqebHT"
73 "pMU-RXvTI5D5oCF1vYxYofH_l1Kviuiy3oQ1kS1enqWgbhJ2t61_SNdv-1XJIS0"
74 "O3YeHLmVCs62O6zp89QwakfAWK9d3IDQvVSJzCQsvxvNIvaZFa567MawWlXg0Rh"
75 "1zFMi5vzcns38-8_Sns; "
76 "GA=v*2%2Fmem*57968640*47239936%2Fmem*57968640*47114716%2Fno-nm-"
77 "yj*15%2Fno-cc-yj*5%2Fpc-ch*133685%2Fpc-s-cr*133947%2Fpc-s-t*1339"
78 "47%2Fno-nm-yj*4%2Fno-cc-yj*1%2Fceft-as*1%2Fceft-nqas*0%2Fad-ra-c"
79 "v_p%2Fad-nr-cv_p-f*1%2Fad-v-cv_p*859%2Fad-ns-cv_p-f*1%2Ffn-v-ad%"
80 "2Fpc-t*250%2Fpc-cm*461%2Fpc-s-cr*722%2Fpc-s-t*722%2Fau_p*4"
81 "SICAID=AJKiYcHdKgxum7KMXG0ei2t1-W4OD1uW-ecNsCqC0wDuAXiDGIcT_HA2o1"
82 "3Rs1UKCuBAF9g8rWNOFbxt8PSNSHFuIhOo2t6bJAVpCsMU5Laa6lewuTMYI8MzdQP"
83 "ARHKyW-koxuhMZHUnGBJAM1gJODe0cATO_KGoX4pbbFxxJ5IicRxOrWK_5rU3cdy6"
84 "edlR9FsEdH6iujMcHkbE5l18ehJDwTWmBKBzVD87naobhMMrF6VvnDGxQVGp9Ir_b"
85 "Rgj3RWUoPumQVCxtSOBdX0GlJOEcDTNCzQIm9BSfetog_eP_TfYubKudt5eMsXmN6"
86 "QnyXHeGeK2UINUzJ-D30AFcpqYgH9_1BvYSpi7fc7_ydBU8TaD8ZRxvtnzXqj0RfG"
87 "tuHghmv3aD-uzSYJ75XDdzKdizZ86IG6Fbn1XFhYZM-fbHhm3mVEXnyRW4ZuNOLFk"
88 "Fas6LMcVC6Q8QLlHYbXBpdNFuGbuZGUnav5C-2I_-46lL0NGg3GewxGKGHvHEfoyn"
89 "EFFlEYHsBQ98rXImL8ySDycdLEFvBPdtctPmWCfTxwmoSMLHU2SCVDhbqMWU5b0yr"
90 "JBCScs_ejbKaqBDoB7ZGxTvqlrB__2ZmnHHjCr8RgMRtKNtIeuZAo ";
93 void Initialize(bool stream_should_process_data) {
94 connection_ = new testing::StrictMock<MockConnection>(
95 Perspective::IS_SERVER, SupportedVersions(GetParam()));
96 session_.reset(new testing::StrictMock<MockSession>(connection_));
97 stream_.reset(new TestStream(kClientDataStreamId1, session_.get(),
98 stream_should_process_data));
99 stream2_.reset(new TestStream(kClientDataStreamId2, session_.get(),
100 stream_should_process_data));
101 write_blocked_list_ =
102 QuicSessionPeer::GetWriteBlockedStreams(session_.get());
105 protected:
106 MockConnection* connection_;
107 scoped_ptr<MockSession> session_;
108 scoped_ptr<TestStream> stream_;
109 scoped_ptr<TestStream> stream2_;
110 SpdyHeaderBlock headers_;
111 QuicWriteBlockedList* write_blocked_list_;
114 INSTANTIATE_TEST_CASE_P(Tests, QuicDataStreamTest,
115 ::testing::ValuesIn(QuicSupportedVersions()));
117 TEST_P(QuicDataStreamTest, ProcessHeaders) {
118 Initialize(kShouldProcessData);
120 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_);
121 stream_->OnStreamHeadersPriority(QuicUtils::HighestPriority());
122 stream_->OnStreamHeaders(headers);
123 EXPECT_EQ(headers, stream_->data());
124 stream_->OnStreamHeadersComplete(false, headers.size());
125 EXPECT_EQ(QuicUtils::HighestPriority(), stream_->EffectivePriority());
126 EXPECT_EQ(headers, stream_->data());
127 EXPECT_FALSE(stream_->IsDoneReading());
130 TEST_P(QuicDataStreamTest, ProcessHeadersAndBody) {
131 Initialize(kShouldProcessData);
133 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_);
134 string body = "this is the body";
136 stream_->OnStreamHeaders(headers);
137 EXPECT_EQ(headers, stream_->data());
138 stream_->OnStreamHeadersComplete(false, headers.size());
139 QuicStreamFrame frame(kClientDataStreamId1, false, 0, MakeIOVector(body));
140 stream_->OnStreamFrame(frame);
142 EXPECT_EQ(headers + body, stream_->data());
145 TEST_P(QuicDataStreamTest, ProcessHeadersAndBodyFragments) {
146 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_);
147 string body = "this is the body";
149 for (size_t fragment_size = 1; fragment_size < body.size();
150 ++fragment_size) {
151 Initialize(kShouldProcessData);
152 for (size_t offset = 0; offset < headers.size();
153 offset += fragment_size) {
154 size_t remaining_data = headers.size() - offset;
155 StringPiece fragment(headers.data() + offset,
156 min(fragment_size, remaining_data));
157 stream_->OnStreamHeaders(fragment);
159 stream_->OnStreamHeadersComplete(false, headers.size());
160 for (size_t offset = 0; offset < body.size(); offset += fragment_size) {
161 size_t remaining_data = body.size() - offset;
162 StringPiece fragment(body.data() + offset,
163 min(fragment_size, remaining_data));
164 QuicStreamFrame frame(kClientDataStreamId1, false, offset,
165 MakeIOVector(fragment));
166 stream_->OnStreamFrame(frame);
168 ASSERT_EQ(headers + body,
169 stream_->data()) << "fragment_size: " << fragment_size;
173 TEST_P(QuicDataStreamTest, ProcessHeadersAndBodyFragmentsSplit) {
174 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_);
175 string body = "this is the body";
177 for (size_t split_point = 1; split_point < body.size() - 1; ++split_point) {
178 Initialize(kShouldProcessData);
179 StringPiece headers1(headers.data(), split_point);
180 stream_->OnStreamHeaders(headers1);
182 StringPiece headers2(headers.data() + split_point,
183 headers.size() - split_point);
184 stream_->OnStreamHeaders(headers2);
185 stream_->OnStreamHeadersComplete(false, headers.size());
187 StringPiece fragment1(body.data(), split_point);
188 QuicStreamFrame frame1(kClientDataStreamId1, false, 0,
189 MakeIOVector(fragment1));
190 stream_->OnStreamFrame(frame1);
192 StringPiece fragment2(body.data() + split_point,
193 body.size() - split_point);
194 QuicStreamFrame frame2(kClientDataStreamId1, false, split_point,
195 MakeIOVector(fragment2));
196 stream_->OnStreamFrame(frame2);
198 ASSERT_EQ(headers + body,
199 stream_->data()) << "split_point: " << split_point;
203 TEST_P(QuicDataStreamTest, ProcessHeadersAndBodyReadv) {
204 Initialize(!kShouldProcessData);
206 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_);
207 string body = "this is the body";
209 stream_->OnStreamHeaders(headers);
210 EXPECT_EQ(headers, stream_->data());
211 stream_->OnStreamHeadersComplete(false, headers.size());
212 QuicStreamFrame frame(kClientDataStreamId1, false, 0, MakeIOVector(body));
213 stream_->OnStreamFrame(frame);
215 char buffer[2048];
216 ASSERT_LT(headers.length() + body.length(), arraysize(buffer));
217 struct iovec vec;
218 vec.iov_base = buffer;
219 vec.iov_len = arraysize(buffer);
221 size_t bytes_read = stream_->Readv(&vec, 1);
222 EXPECT_EQ(headers.length(), bytes_read);
223 EXPECT_EQ(headers, string(buffer, bytes_read));
225 bytes_read = stream_->Readv(&vec, 1);
226 EXPECT_EQ(body.length(), bytes_read);
227 EXPECT_EQ(body, string(buffer, bytes_read));
230 TEST_P(QuicDataStreamTest, ProcessHeadersAndBodyIncrementalReadv) {
231 Initialize(!kShouldProcessData);
233 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_);
234 string body = "this is the body";
235 stream_->OnStreamHeaders(headers);
236 EXPECT_EQ(headers, stream_->data());
237 stream_->OnStreamHeadersComplete(false, headers.size());
238 QuicStreamFrame frame(kClientDataStreamId1, false, 0, MakeIOVector(body));
239 stream_->OnStreamFrame(frame);
241 char buffer[1];
242 struct iovec vec;
243 vec.iov_base = buffer;
244 vec.iov_len = arraysize(buffer);
246 string data = headers + body;
247 for (size_t i = 0; i < data.length(); ++i) {
248 size_t bytes_read = stream_->Readv(&vec, 1);
249 ASSERT_EQ(1u, bytes_read);
250 EXPECT_EQ(data.data()[i], buffer[0]);
254 TEST_P(QuicDataStreamTest, ProcessHeadersUsingReadvWithMultipleIovecs) {
255 Initialize(!kShouldProcessData);
257 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_);
258 string body = "this is the body";
259 stream_->OnStreamHeaders(headers);
260 EXPECT_EQ(headers, stream_->data());
261 stream_->OnStreamHeadersComplete(false, headers.size());
262 QuicStreamFrame frame(kClientDataStreamId1, false, 0, MakeIOVector(body));
263 stream_->OnStreamFrame(frame);
265 char buffer1[1];
266 char buffer2[1];
267 struct iovec vec[2];
268 vec[0].iov_base = buffer1;
269 vec[0].iov_len = arraysize(buffer1);
270 vec[1].iov_base = buffer2;
271 vec[1].iov_len = arraysize(buffer2);
272 string data = headers + body;
273 for (size_t i = 0; i < data.length(); i += 2) {
274 size_t bytes_read = stream_->Readv(vec, 2);
275 ASSERT_EQ(2u, bytes_read) << i;
276 ASSERT_EQ(data.data()[i], buffer1[0]) << i;
277 ASSERT_EQ(data.data()[i + 1], buffer2[0]) << i;
281 TEST_P(QuicDataStreamTest, StreamFlowControlBlocked) {
282 // Tests that we send a BLOCKED frame to the peer when we attempt to write,
283 // but are flow control blocked.
284 Initialize(kShouldProcessData);
286 // Set a small flow control limit.
287 const uint64 kWindow = 36;
288 QuicFlowControllerPeer::SetSendWindowOffset(stream_->flow_controller(),
289 kWindow);
290 EXPECT_EQ(kWindow, QuicFlowControllerPeer::SendWindowOffset(
291 stream_->flow_controller()));
293 // Try to send more data than the flow control limit allows.
294 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_);
295 string body;
296 const uint64 kOverflow = 15;
297 GenerateBody(&body, kWindow + kOverflow);
299 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1));
300 EXPECT_CALL(*session_, WritevData(kClientDataStreamId1, _, _, _, _, _))
301 .WillOnce(Return(QuicConsumedData(kWindow, true)));
302 stream_->WriteOrBufferData(body, false, nullptr);
304 // Should have sent as much as possible, resulting in no send window left.
305 EXPECT_EQ(0u,
306 QuicFlowControllerPeer::SendWindowSize(stream_->flow_controller()));
308 // And we should have queued the overflowed data.
309 EXPECT_EQ(kOverflow,
310 ReliableQuicStreamPeer::SizeOfQueuedData(stream_.get()));
313 TEST_P(QuicDataStreamTest, StreamFlowControlNoWindowUpdateIfNotConsumed) {
314 // The flow control receive window decreases whenever we add new bytes to the
315 // sequencer, whether they are consumed immediately or buffered. However we
316 // only send WINDOW_UPDATE frames based on increasing number of bytes
317 // consumed.
319 // Don't process data - it will be buffered instead.
320 Initialize(!kShouldProcessData);
322 // Expect no WINDOW_UPDATE frames to be sent.
323 EXPECT_CALL(*connection_, SendWindowUpdate(_, _)).Times(0);
325 // Set a small flow control receive window.
326 const uint64 kWindow = 36;
327 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(),
328 kWindow);
329 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(),
330 kWindow);
331 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowOffset(
332 stream_->flow_controller()));
334 // Stream receives enough data to fill a fraction of the receive window.
335 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_);
336 string body;
337 GenerateBody(&body, kWindow / 3);
338 stream_->OnStreamHeaders(headers);
339 EXPECT_EQ(headers, stream_->data());
340 stream_->OnStreamHeadersComplete(false, headers.size());
342 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, MakeIOVector(body));
343 stream_->OnStreamFrame(frame1);
344 EXPECT_EQ(kWindow - (kWindow / 3), QuicFlowControllerPeer::ReceiveWindowSize(
345 stream_->flow_controller()));
347 // Now receive another frame which results in the receive window being over
348 // half full. This should all be buffered, decreasing the receive window but
349 // not sending WINDOW_UPDATE.
350 QuicStreamFrame frame2(kClientDataStreamId1, false, kWindow / 3,
351 MakeIOVector(body));
352 stream_->OnStreamFrame(frame2);
353 EXPECT_EQ(
354 kWindow - (2 * kWindow / 3),
355 QuicFlowControllerPeer::ReceiveWindowSize(stream_->flow_controller()));
358 TEST_P(QuicDataStreamTest, StreamFlowControlWindowUpdate) {
359 // Tests that on receipt of data, the stream updates its receive window offset
360 // appropriately, and sends WINDOW_UPDATE frames when its receive window drops
361 // too low.
362 Initialize(kShouldProcessData);
364 // Set a small flow control limit.
365 const uint64 kWindow = 36;
366 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(),
367 kWindow);
368 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(),
369 kWindow);
370 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowOffset(
371 stream_->flow_controller()));
373 // Stream receives enough data to fill a fraction of the receive window.
374 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_);
375 string body;
376 GenerateBody(&body, kWindow / 3);
377 stream_->OnStreamHeaders(headers);
378 EXPECT_EQ(headers, stream_->data());
379 stream_->OnStreamHeadersComplete(false, headers.size());
381 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, MakeIOVector(body));
382 stream_->OnStreamFrame(frame1);
383 EXPECT_EQ(kWindow - (kWindow / 3), QuicFlowControllerPeer::ReceiveWindowSize(
384 stream_->flow_controller()));
386 // Now receive another frame which results in the receive window being over
387 // half full. This will trigger the stream to increase its receive window
388 // offset and send a WINDOW_UPDATE. The result will be again an available
389 // window of kWindow bytes.
390 QuicStreamFrame frame2(kClientDataStreamId1, false, kWindow / 3,
391 MakeIOVector(body));
392 EXPECT_CALL(*connection_,
393 SendWindowUpdate(kClientDataStreamId1,
394 QuicFlowControllerPeer::ReceiveWindowOffset(
395 stream_->flow_controller()) +
396 2 * kWindow / 3));
397 stream_->OnStreamFrame(frame2);
398 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowSize(
399 stream_->flow_controller()));
402 TEST_P(QuicDataStreamTest, ConnectionFlowControlWindowUpdate) {
403 // Tests that on receipt of data, the connection updates its receive window
404 // offset appropriately, and sends WINDOW_UPDATE frames when its receive
405 // window drops too low.
406 Initialize(kShouldProcessData);
408 // Set a small flow control limit for streams and connection.
409 const uint64 kWindow = 36;
410 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(),
411 kWindow);
412 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(),
413 kWindow);
414 QuicFlowControllerPeer::SetReceiveWindowOffset(stream2_->flow_controller(),
415 kWindow);
416 QuicFlowControllerPeer::SetMaxReceiveWindow(stream2_->flow_controller(),
417 kWindow);
418 QuicFlowControllerPeer::SetReceiveWindowOffset(session_->flow_controller(),
419 kWindow);
420 QuicFlowControllerPeer::SetMaxReceiveWindow(session_->flow_controller(),
421 kWindow);
423 // Supply headers to both streams so that they are happy to receive data.
424 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_);
425 stream_->OnStreamHeaders(headers);
426 stream_->OnStreamHeadersComplete(false, headers.size());
427 stream2_->OnStreamHeaders(headers);
428 stream2_->OnStreamHeadersComplete(false, headers.size());
430 // Each stream gets a quarter window of data. This should not trigger a
431 // WINDOW_UPDATE for either stream, nor for the connection.
432 string body;
433 GenerateBody(&body, kWindow / 4);
434 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, MakeIOVector(body));
435 stream_->OnStreamFrame(frame1);
436 QuicStreamFrame frame2(kClientDataStreamId2, false, 0, MakeIOVector(body));
437 stream2_->OnStreamFrame(frame2);
439 // Now receive a further single byte on one stream - again this does not
440 // trigger a stream WINDOW_UPDATE, but now the connection flow control window
441 // is over half full and thus a connection WINDOW_UPDATE is sent.
442 EXPECT_CALL(*connection_, SendWindowUpdate(kClientDataStreamId1, _)).Times(0);
443 EXPECT_CALL(*connection_, SendWindowUpdate(kClientDataStreamId2, _)).Times(0);
444 EXPECT_CALL(*connection_,
445 SendWindowUpdate(0, QuicFlowControllerPeer::ReceiveWindowOffset(
446 session_->flow_controller()) +
447 1 + kWindow / 2));
448 QuicStreamFrame frame3(kClientDataStreamId1, false, (kWindow / 4),
449 MakeIOVector("a"));
450 stream_->OnStreamFrame(frame3);
453 TEST_P(QuicDataStreamTest, StreamFlowControlViolation) {
454 // Tests that on if the peer sends too much data (i.e. violates the flow
455 // control protocol), then we terminate the connection.
457 // Stream should not process data, so that data gets buffered in the
458 // sequencer, triggering flow control limits.
459 Initialize(!kShouldProcessData);
461 // Set a small flow control limit.
462 const uint64 kWindow = 50;
463 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(),
464 kWindow);
466 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_);
467 stream_->OnStreamHeaders(headers);
468 EXPECT_EQ(headers, stream_->data());
469 stream_->OnStreamHeadersComplete(false, headers.size());
471 // Receive data to overflow the window, violating flow control.
472 string body;
473 GenerateBody(&body, kWindow + 1);
474 QuicStreamFrame frame(kClientDataStreamId1, false, 0, MakeIOVector(body));
475 EXPECT_CALL(*connection_,
476 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA));
477 stream_->OnStreamFrame(frame);
480 TEST_P(QuicDataStreamTest, ConnectionFlowControlViolation) {
481 // Tests that on if the peer sends too much data (i.e. violates the flow
482 // control protocol), at the connection level (rather than the stream level)
483 // then we terminate the connection.
485 // Stream should not process data, so that data gets buffered in the
486 // sequencer, triggering flow control limits.
487 Initialize(!kShouldProcessData);
489 // Set a small flow control window on streams, and connection.
490 const uint64 kStreamWindow = 50;
491 const uint64 kConnectionWindow = 10;
492 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(),
493 kStreamWindow);
494 QuicFlowControllerPeer::SetReceiveWindowOffset(session_->flow_controller(),
495 kConnectionWindow);
497 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_);
498 stream_->OnStreamHeaders(headers);
499 EXPECT_EQ(headers, stream_->data());
500 stream_->OnStreamHeadersComplete(false, headers.size());
502 // Send enough data to overflow the connection level flow control window.
503 string body;
504 GenerateBody(&body, kConnectionWindow + 1);
505 EXPECT_LT(body.size(), kStreamWindow);
506 QuicStreamFrame frame(kClientDataStreamId1, false, 0, MakeIOVector(body));
508 EXPECT_CALL(*connection_,
509 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA));
510 stream_->OnStreamFrame(frame);
513 TEST_P(QuicDataStreamTest, StreamFlowControlFinNotBlocked) {
514 // An attempt to write a FIN with no data should not be flow control blocked,
515 // even if the send window is 0.
517 Initialize(kShouldProcessData);
519 // Set a flow control limit of zero.
520 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), 0);
521 EXPECT_EQ(0u, QuicFlowControllerPeer::ReceiveWindowOffset(
522 stream_->flow_controller()));
524 // Send a frame with a FIN but no data. This should not be blocked.
525 string body = "";
526 bool fin = true;
528 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)).Times(0);
529 EXPECT_CALL(*session_, WritevData(kClientDataStreamId1, _, _, _, _, _))
530 .WillOnce(Return(QuicConsumedData(0, fin)));
532 stream_->WriteOrBufferData(body, fin, nullptr);
535 } // namespace
536 } // namespace test
537 } // namespace net