Snap pinch zoom gestures near the screen edge.
[chromium-blink-merge.git] / net / quic / quic_data_stream_test.cc
blob3cd89c49d22ac09684030f7edb3288307c8757ed
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 QuicSpdySession* 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<MockQuicSpdySession>(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<MockQuicSpdySession> 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 =
121 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
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 =
135 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
136 string body = "this is the body";
138 stream_->OnStreamHeaders(headers);
139 EXPECT_EQ(headers, stream_->data());
140 stream_->OnStreamHeadersComplete(false, headers.size());
141 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body));
142 stream_->OnStreamFrame(frame);
144 EXPECT_EQ(headers + body, stream_->data());
147 TEST_P(QuicDataStreamTest, ProcessHeadersAndBodyFragments) {
148 string headers =
149 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
150 string body = "this is the body";
152 for (size_t fragment_size = 1; fragment_size < body.size();
153 ++fragment_size) {
154 Initialize(kShouldProcessData);
155 for (size_t offset = 0; offset < headers.size();
156 offset += fragment_size) {
157 size_t remaining_data = headers.size() - offset;
158 StringPiece fragment(headers.data() + offset,
159 min(fragment_size, remaining_data));
160 stream_->OnStreamHeaders(fragment);
162 stream_->OnStreamHeadersComplete(false, headers.size());
163 for (size_t offset = 0; offset < body.size(); offset += fragment_size) {
164 size_t remaining_data = body.size() - offset;
165 StringPiece fragment(body.data() + offset,
166 min(fragment_size, remaining_data));
167 QuicStreamFrame frame(kClientDataStreamId1, false, offset,
168 StringPiece(fragment));
169 stream_->OnStreamFrame(frame);
171 ASSERT_EQ(headers + body,
172 stream_->data()) << "fragment_size: " << fragment_size;
176 TEST_P(QuicDataStreamTest, ProcessHeadersAndBodyFragmentsSplit) {
177 string headers =
178 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
179 string body = "this is the body";
181 for (size_t split_point = 1; split_point < body.size() - 1; ++split_point) {
182 Initialize(kShouldProcessData);
183 StringPiece headers1(headers.data(), split_point);
184 stream_->OnStreamHeaders(headers1);
186 StringPiece headers2(headers.data() + split_point,
187 headers.size() - split_point);
188 stream_->OnStreamHeaders(headers2);
189 stream_->OnStreamHeadersComplete(false, headers.size());
191 StringPiece fragment1(body.data(), split_point);
192 QuicStreamFrame frame1(kClientDataStreamId1, false, 0,
193 StringPiece(fragment1));
194 stream_->OnStreamFrame(frame1);
196 StringPiece fragment2(body.data() + split_point,
197 body.size() - split_point);
198 QuicStreamFrame frame2(kClientDataStreamId1, false, split_point,
199 StringPiece(fragment2));
200 stream_->OnStreamFrame(frame2);
202 ASSERT_EQ(headers + body,
203 stream_->data()) << "split_point: " << split_point;
207 TEST_P(QuicDataStreamTest, ProcessHeadersAndBodyReadv) {
208 Initialize(!kShouldProcessData);
210 string headers =
211 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
212 string body = "this is the body";
214 stream_->OnStreamHeaders(headers);
215 EXPECT_EQ(headers, stream_->data());
216 stream_->OnStreamHeadersComplete(false, headers.size());
217 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body));
218 stream_->OnStreamFrame(frame);
220 char buffer[2048];
221 ASSERT_LT(headers.length() + body.length(), arraysize(buffer));
222 struct iovec vec;
223 vec.iov_base = buffer;
224 vec.iov_len = arraysize(buffer);
226 size_t bytes_read = stream_->Readv(&vec, 1);
227 EXPECT_EQ(headers.length(), bytes_read);
228 EXPECT_EQ(headers, string(buffer, bytes_read));
230 bytes_read = stream_->Readv(&vec, 1);
231 EXPECT_EQ(body.length(), bytes_read);
232 EXPECT_EQ(body, string(buffer, bytes_read));
235 TEST_P(QuicDataStreamTest, ProcessHeadersAndBodyIncrementalReadv) {
236 Initialize(!kShouldProcessData);
238 string headers =
239 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
240 string body = "this is the body";
241 stream_->OnStreamHeaders(headers);
242 EXPECT_EQ(headers, stream_->data());
243 stream_->OnStreamHeadersComplete(false, headers.size());
244 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body));
245 stream_->OnStreamFrame(frame);
247 char buffer[1];
248 struct iovec vec;
249 vec.iov_base = buffer;
250 vec.iov_len = arraysize(buffer);
252 string data = headers + body;
253 for (size_t i = 0; i < data.length(); ++i) {
254 size_t bytes_read = stream_->Readv(&vec, 1);
255 ASSERT_EQ(1u, bytes_read);
256 EXPECT_EQ(data.data()[i], buffer[0]);
260 TEST_P(QuicDataStreamTest, ProcessHeadersUsingReadvWithMultipleIovecs) {
261 Initialize(!kShouldProcessData);
263 string headers =
264 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
265 string body = "this is the body";
266 stream_->OnStreamHeaders(headers);
267 EXPECT_EQ(headers, stream_->data());
268 stream_->OnStreamHeadersComplete(false, headers.size());
269 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body));
270 stream_->OnStreamFrame(frame);
272 char buffer1[1];
273 char buffer2[1];
274 struct iovec vec[2];
275 vec[0].iov_base = buffer1;
276 vec[0].iov_len = arraysize(buffer1);
277 vec[1].iov_base = buffer2;
278 vec[1].iov_len = arraysize(buffer2);
279 string data = headers + body;
280 for (size_t i = 0; i < data.length(); i += 2) {
281 size_t bytes_read = stream_->Readv(vec, 2);
282 ASSERT_EQ(2u, bytes_read) << i;
283 ASSERT_EQ(data.data()[i], buffer1[0]) << i;
284 ASSERT_EQ(data.data()[i + 1], buffer2[0]) << i;
288 TEST_P(QuicDataStreamTest, StreamFlowControlBlocked) {
289 // Tests that we send a BLOCKED frame to the peer when we attempt to write,
290 // but are flow control blocked.
291 Initialize(kShouldProcessData);
293 // Set a small flow control limit.
294 const uint64 kWindow = 36;
295 QuicFlowControllerPeer::SetSendWindowOffset(stream_->flow_controller(),
296 kWindow);
297 EXPECT_EQ(kWindow, QuicFlowControllerPeer::SendWindowOffset(
298 stream_->flow_controller()));
300 // Try to send more data than the flow control limit allows.
301 string headers =
302 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
303 string body;
304 const uint64 kOverflow = 15;
305 GenerateBody(&body, kWindow + kOverflow);
307 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1));
308 EXPECT_CALL(*session_, WritevData(kClientDataStreamId1, _, _, _, _, _))
309 .WillOnce(Return(QuicConsumedData(kWindow, true)));
310 stream_->WriteOrBufferData(body, false, nullptr);
312 // Should have sent as much as possible, resulting in no send window left.
313 EXPECT_EQ(0u,
314 QuicFlowControllerPeer::SendWindowSize(stream_->flow_controller()));
316 // And we should have queued the overflowed data.
317 EXPECT_EQ(kOverflow,
318 ReliableQuicStreamPeer::SizeOfQueuedData(stream_.get()));
321 TEST_P(QuicDataStreamTest, StreamFlowControlNoWindowUpdateIfNotConsumed) {
322 // The flow control receive window decreases whenever we add new bytes to the
323 // sequencer, whether they are consumed immediately or buffered. However we
324 // only send WINDOW_UPDATE frames based on increasing number of bytes
325 // consumed.
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(),
336 kWindow);
337 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(),
338 kWindow);
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 =
344 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
345 string body;
346 GenerateBody(&body, kWindow / 3);
347 stream_->OnStreamHeaders(headers);
348 EXPECT_EQ(headers, stream_->data());
349 stream_->OnStreamHeadersComplete(false, headers.size());
351 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, StringPiece(body));
352 stream_->OnStreamFrame(frame1);
353 EXPECT_EQ(kWindow - (kWindow / 3), QuicFlowControllerPeer::ReceiveWindowSize(
354 stream_->flow_controller()));
356 // Now receive another frame which results in the receive window being over
357 // half full. This should all be buffered, decreasing the receive window but
358 // not sending WINDOW_UPDATE.
359 QuicStreamFrame frame2(kClientDataStreamId1, false, kWindow / 3,
360 StringPiece(body));
361 stream_->OnStreamFrame(frame2);
362 EXPECT_EQ(
363 kWindow - (2 * kWindow / 3),
364 QuicFlowControllerPeer::ReceiveWindowSize(stream_->flow_controller()));
367 TEST_P(QuicDataStreamTest, StreamFlowControlWindowUpdate) {
368 // Tests that on receipt of data, the stream updates its receive window offset
369 // appropriately, and sends WINDOW_UPDATE frames when its receive window drops
370 // too low.
371 Initialize(kShouldProcessData);
373 // Set a small flow control limit.
374 const uint64 kWindow = 36;
375 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(),
376 kWindow);
377 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(),
378 kWindow);
379 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowOffset(
380 stream_->flow_controller()));
382 // Stream receives enough data to fill a fraction of the receive window.
383 string headers =
384 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
385 string body;
386 GenerateBody(&body, kWindow / 3);
387 stream_->OnStreamHeaders(headers);
388 EXPECT_EQ(headers, stream_->data());
389 stream_->OnStreamHeadersComplete(false, headers.size());
391 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, StringPiece(body));
392 stream_->OnStreamFrame(frame1);
393 EXPECT_EQ(kWindow - (kWindow / 3), QuicFlowControllerPeer::ReceiveWindowSize(
394 stream_->flow_controller()));
396 // Now receive another frame which results in the receive window being over
397 // half full. This will trigger the stream to increase its receive window
398 // offset and send a WINDOW_UPDATE. The result will be again an available
399 // window of kWindow bytes.
400 QuicStreamFrame frame2(kClientDataStreamId1, false, kWindow / 3,
401 StringPiece(body));
402 EXPECT_CALL(*connection_,
403 SendWindowUpdate(kClientDataStreamId1,
404 QuicFlowControllerPeer::ReceiveWindowOffset(
405 stream_->flow_controller()) +
406 2 * kWindow / 3));
407 stream_->OnStreamFrame(frame2);
408 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowSize(
409 stream_->flow_controller()));
412 TEST_P(QuicDataStreamTest, ConnectionFlowControlWindowUpdate) {
413 // Tests that on receipt of data, the connection updates its receive window
414 // offset appropriately, and sends WINDOW_UPDATE frames when its receive
415 // window drops too low.
416 Initialize(kShouldProcessData);
418 // Set a small flow control limit for streams and connection.
419 const uint64 kWindow = 36;
420 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(),
421 kWindow);
422 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(),
423 kWindow);
424 QuicFlowControllerPeer::SetReceiveWindowOffset(stream2_->flow_controller(),
425 kWindow);
426 QuicFlowControllerPeer::SetMaxReceiveWindow(stream2_->flow_controller(),
427 kWindow);
428 QuicFlowControllerPeer::SetReceiveWindowOffset(session_->flow_controller(),
429 kWindow);
430 QuicFlowControllerPeer::SetMaxReceiveWindow(session_->flow_controller(),
431 kWindow);
433 // Supply headers to both streams so that they are happy to receive data.
434 string headers =
435 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
436 stream_->OnStreamHeaders(headers);
437 stream_->OnStreamHeadersComplete(false, headers.size());
438 stream2_->OnStreamHeaders(headers);
439 stream2_->OnStreamHeadersComplete(false, headers.size());
441 // Each stream gets a quarter window of data. This should not trigger a
442 // WINDOW_UPDATE for either stream, nor for the connection.
443 string body;
444 GenerateBody(&body, kWindow / 4);
445 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, StringPiece(body));
446 stream_->OnStreamFrame(frame1);
447 QuicStreamFrame frame2(kClientDataStreamId2, false, 0, StringPiece(body));
448 stream2_->OnStreamFrame(frame2);
450 // Now receive a further single byte on one stream - again this does not
451 // trigger a stream WINDOW_UPDATE, but now the connection flow control window
452 // is over half full and thus a connection WINDOW_UPDATE is sent.
453 EXPECT_CALL(*connection_, SendWindowUpdate(kClientDataStreamId1, _)).Times(0);
454 EXPECT_CALL(*connection_, SendWindowUpdate(kClientDataStreamId2, _)).Times(0);
455 EXPECT_CALL(*connection_,
456 SendWindowUpdate(0, QuicFlowControllerPeer::ReceiveWindowOffset(
457 session_->flow_controller()) +
458 1 + kWindow / 2));
459 QuicStreamFrame frame3(kClientDataStreamId1, false, (kWindow / 4),
460 StringPiece("a"));
461 stream_->OnStreamFrame(frame3);
464 TEST_P(QuicDataStreamTest, StreamFlowControlViolation) {
465 // Tests that on if the peer sends too much data (i.e. violates the flow
466 // control protocol), then we terminate the connection.
468 // Stream should not process data, so that data gets buffered in the
469 // sequencer, triggering flow control limits.
470 Initialize(!kShouldProcessData);
472 // Set a small flow control limit.
473 const uint64 kWindow = 50;
474 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(),
475 kWindow);
477 string headers =
478 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
479 stream_->OnStreamHeaders(headers);
480 EXPECT_EQ(headers, stream_->data());
481 stream_->OnStreamHeadersComplete(false, headers.size());
483 // Receive data to overflow the window, violating flow control.
484 string body;
485 GenerateBody(&body, kWindow + 1);
486 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body));
487 EXPECT_CALL(*connection_,
488 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA));
489 stream_->OnStreamFrame(frame);
492 TEST_P(QuicDataStreamTest, ConnectionFlowControlViolation) {
493 // Tests that on if the peer sends too much data (i.e. violates the flow
494 // control protocol), at the connection level (rather than the stream level)
495 // then we terminate the connection.
497 // Stream should not process data, so that data gets buffered in the
498 // sequencer, triggering flow control limits.
499 Initialize(!kShouldProcessData);
501 // Set a small flow control window on streams, and connection.
502 const uint64 kStreamWindow = 50;
503 const uint64 kConnectionWindow = 10;
504 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(),
505 kStreamWindow);
506 QuicFlowControllerPeer::SetReceiveWindowOffset(session_->flow_controller(),
507 kConnectionWindow);
509 string headers =
510 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
511 stream_->OnStreamHeaders(headers);
512 EXPECT_EQ(headers, stream_->data());
513 stream_->OnStreamHeadersComplete(false, headers.size());
515 // Send enough data to overflow the connection level flow control window.
516 string body;
517 GenerateBody(&body, kConnectionWindow + 1);
518 EXPECT_LT(body.size(), kStreamWindow);
519 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body));
521 EXPECT_CALL(*connection_,
522 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA));
523 stream_->OnStreamFrame(frame);
526 TEST_P(QuicDataStreamTest, StreamFlowControlFinNotBlocked) {
527 // An attempt to write a FIN with no data should not be flow control blocked,
528 // even if the send window is 0.
530 Initialize(kShouldProcessData);
532 // Set a flow control limit of zero.
533 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), 0);
534 EXPECT_EQ(0u, QuicFlowControllerPeer::ReceiveWindowOffset(
535 stream_->flow_controller()));
537 // Send a frame with a FIN but no data. This should not be blocked.
538 string body = "";
539 bool fin = true;
541 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)).Times(0);
542 EXPECT_CALL(*session_, WritevData(kClientDataStreamId1, _, _, _, _, _))
543 .WillOnce(Return(QuicConsumedData(0, fin)));
545 stream_->WriteOrBufferData(body, fin, nullptr);
548 } // namespace
549 } // namespace test
550 } // namespace net