If there are no local credentials for a locked profile, show sign in button
[chromium-blink-merge.git] / net / quic / quic_data_stream_test.cc
blobab9ac12416e78e1b2cb82ebc01af13dcd862c9f5
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::Return;
23 using testing::StrictMock;
24 using testing::_;
26 namespace net {
27 namespace test {
28 namespace {
30 const bool kShouldProcessData = true;
32 class TestStream : public QuicDataStream {
33 public:
34 TestStream(QuicStreamId id,
35 QuicSpdySession* session,
36 bool should_process_data)
37 : QuicDataStream(id, session),
38 should_process_data_(should_process_data) {}
40 void OnDataAvailable() override {
41 if (!should_process_data_) {
42 return;
44 char buffer[2048];
45 struct iovec vec;
46 vec.iov_base = buffer;
47 vec.iov_len = arraysize(buffer);
48 size_t bytes_read = Readv(&vec, 1);
49 data_ += string(buffer, bytes_read);
52 using ReliableQuicStream::WriteOrBufferData;
53 using ReliableQuicStream::CloseReadSide;
54 using ReliableQuicStream::CloseWriteSide;
56 const string& data() const { return data_; }
58 private:
59 bool should_process_data_;
60 string data_;
63 class QuicDataStreamTest : public ::testing::TestWithParam<QuicVersion> {
64 public:
65 QuicDataStreamTest() {
66 headers_[":host"] = "www.google.com";
67 headers_[":path"] = "/index.hml";
68 headers_[":scheme"] = "https";
69 headers_["cookie"] =
70 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; "
71 "__utmc=160408618; "
72 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX"
73 "hoALMsy6HOdDad2Sz0flUByv7etmo3mLMidGrBoljqO9hSVA40SLqpG_iuKKSHX"
74 "RW3Np4bq0F0SDGDNsW0DSmTS9ufMRrlpARJDS7qAI6M3bghqJp4eABKZiRqebHT"
75 "pMU-RXvTI5D5oCF1vYxYofH_l1Kviuiy3oQ1kS1enqWgbhJ2t61_SNdv-1XJIS0"
76 "O3YeHLmVCs62O6zp89QwakfAWK9d3IDQvVSJzCQsvxvNIvaZFa567MawWlXg0Rh"
77 "1zFMi5vzcns38-8_Sns; "
78 "GA=v*2%2Fmem*57968640*47239936%2Fmem*57968640*47114716%2Fno-nm-"
79 "yj*15%2Fno-cc-yj*5%2Fpc-ch*133685%2Fpc-s-cr*133947%2Fpc-s-t*1339"
80 "47%2Fno-nm-yj*4%2Fno-cc-yj*1%2Fceft-as*1%2Fceft-nqas*0%2Fad-ra-c"
81 "v_p%2Fad-nr-cv_p-f*1%2Fad-v-cv_p*859%2Fad-ns-cv_p-f*1%2Ffn-v-ad%"
82 "2Fpc-t*250%2Fpc-cm*461%2Fpc-s-cr*722%2Fpc-s-t*722%2Fau_p*4"
83 "SICAID=AJKiYcHdKgxum7KMXG0ei2t1-W4OD1uW-ecNsCqC0wDuAXiDGIcT_HA2o1"
84 "3Rs1UKCuBAF9g8rWNOFbxt8PSNSHFuIhOo2t6bJAVpCsMU5Laa6lewuTMYI8MzdQP"
85 "ARHKyW-koxuhMZHUnGBJAM1gJODe0cATO_KGoX4pbbFxxJ5IicRxOrWK_5rU3cdy6"
86 "edlR9FsEdH6iujMcHkbE5l18ehJDwTWmBKBzVD87naobhMMrF6VvnDGxQVGp9Ir_b"
87 "Rgj3RWUoPumQVCxtSOBdX0GlJOEcDTNCzQIm9BSfetog_eP_TfYubKudt5eMsXmN6"
88 "QnyXHeGeK2UINUzJ-D30AFcpqYgH9_1BvYSpi7fc7_ydBU8TaD8ZRxvtnzXqj0RfG"
89 "tuHghmv3aD-uzSYJ75XDdzKdizZ86IG6Fbn1XFhYZM-fbHhm3mVEXnyRW4ZuNOLFk"
90 "Fas6LMcVC6Q8QLlHYbXBpdNFuGbuZGUnav5C-2I_-46lL0NGg3GewxGKGHvHEfoyn"
91 "EFFlEYHsBQ98rXImL8ySDycdLEFvBPdtctPmWCfTxwmoSMLHU2SCVDhbqMWU5b0yr"
92 "JBCScs_ejbKaqBDoB7ZGxTvqlrB__2ZmnHHjCr8RgMRtKNtIeuZAo ";
95 void Initialize(bool stream_should_process_data) {
96 connection_ = new testing::StrictMock<MockConnection>(
97 Perspective::IS_SERVER, SupportedVersions(GetParam()));
98 session_.reset(new testing::StrictMock<MockQuicSpdySession>(connection_));
99 stream_.reset(new TestStream(kClientDataStreamId1, session_.get(),
100 stream_should_process_data));
101 stream2_.reset(new TestStream(kClientDataStreamId2, session_.get(),
102 stream_should_process_data));
103 write_blocked_list_ =
104 QuicSessionPeer::GetWriteBlockedStreams(session_.get());
107 protected:
108 MockConnection* connection_;
109 scoped_ptr<MockQuicSpdySession> session_;
110 scoped_ptr<TestStream> stream_;
111 scoped_ptr<TestStream> stream2_;
112 SpdyHeaderBlock headers_;
113 QuicWriteBlockedList* write_blocked_list_;
116 INSTANTIATE_TEST_CASE_P(Tests, QuicDataStreamTest,
117 ::testing::ValuesIn(QuicSupportedVersions()));
119 TEST_P(QuicDataStreamTest, ProcessHeaders) {
120 Initialize(kShouldProcessData);
122 string headers =
123 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
124 stream_->OnStreamHeadersPriority(QuicUtils::HighestPriority());
125 stream_->OnStreamHeaders(headers);
126 EXPECT_EQ("", stream_->data());
127 EXPECT_EQ(headers, stream_->decompressed_headers());
128 stream_->OnStreamHeadersComplete(false, headers.size());
129 EXPECT_EQ(QuicUtils::HighestPriority(), stream_->EffectivePriority());
130 EXPECT_EQ("", stream_->data());
131 EXPECT_EQ(headers, stream_->decompressed_headers());
132 EXPECT_FALSE(stream_->IsDoneReading());
135 TEST_P(QuicDataStreamTest, ProcessHeadersWithFin) {
136 Initialize(kShouldProcessData);
138 string headers =
139 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
140 stream_->OnStreamHeadersPriority(QuicUtils::HighestPriority());
141 stream_->OnStreamHeaders(headers);
142 EXPECT_EQ("", stream_->data());
143 EXPECT_EQ(headers, stream_->decompressed_headers());
144 stream_->OnStreamHeadersComplete(true, headers.size());
145 EXPECT_EQ(QuicUtils::HighestPriority(), stream_->EffectivePriority());
146 EXPECT_EQ("", stream_->data());
147 EXPECT_EQ(headers, stream_->decompressed_headers());
148 EXPECT_FALSE(stream_->IsDoneReading());
149 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset());
152 TEST_P(QuicDataStreamTest, MarkHeadersConsumed) {
153 Initialize(kShouldProcessData);
155 string headers =
156 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
157 string body = "this is the body";
159 stream_->OnStreamHeaders(headers);
160 stream_->OnStreamHeadersComplete(false, headers.size());
161 EXPECT_EQ(headers, stream_->decompressed_headers());
163 headers.erase(0, 10);
164 stream_->MarkHeadersConsumed(10);
165 EXPECT_EQ(headers, stream_->decompressed_headers());
167 stream_->MarkHeadersConsumed(headers.length());
168 EXPECT_EQ("", stream_->decompressed_headers());
171 TEST_P(QuicDataStreamTest, ProcessHeadersAndBody) {
172 Initialize(kShouldProcessData);
174 string headers =
175 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
176 string body = "this is the body";
178 stream_->OnStreamHeaders(headers);
179 EXPECT_EQ("", stream_->data());
180 EXPECT_EQ(headers, stream_->decompressed_headers());
181 stream_->OnStreamHeadersComplete(false, headers.size());
182 EXPECT_EQ(headers, stream_->decompressed_headers());
183 stream_->MarkHeadersConsumed(headers.length());
184 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body));
185 stream_->OnStreamFrame(frame);
186 EXPECT_EQ("", stream_->decompressed_headers());
187 EXPECT_EQ(body, stream_->data());
190 TEST_P(QuicDataStreamTest, ProcessHeadersAndBodyFragments) {
191 string headers =
192 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
193 string body = "this is the body";
195 for (size_t fragment_size = 1; fragment_size < body.size();
196 ++fragment_size) {
197 Initialize(kShouldProcessData);
198 for (size_t offset = 0; offset < headers.size();
199 offset += fragment_size) {
200 size_t remaining_data = headers.size() - offset;
201 StringPiece fragment(headers.data() + offset,
202 min(fragment_size, remaining_data));
203 stream_->OnStreamHeaders(fragment);
205 stream_->OnStreamHeadersComplete(false, headers.size());
206 ASSERT_EQ(headers, stream_->decompressed_headers())
207 << "fragment_size: " << fragment_size;
208 stream_->MarkHeadersConsumed(headers.length());
209 for (size_t offset = 0; offset < body.size(); offset += fragment_size) {
210 size_t remaining_data = body.size() - offset;
211 StringPiece fragment(body.data() + offset,
212 min(fragment_size, remaining_data));
213 QuicStreamFrame frame(kClientDataStreamId1, false, offset,
214 StringPiece(fragment));
215 stream_->OnStreamFrame(frame);
217 ASSERT_EQ(body, stream_->data()) << "fragment_size: " << fragment_size;
221 TEST_P(QuicDataStreamTest, ProcessHeadersAndBodyFragmentsSplit) {
222 string headers =
223 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
224 string body = "this is the body";
226 for (size_t split_point = 1; split_point < body.size() - 1; ++split_point) {
227 Initialize(kShouldProcessData);
228 StringPiece headers1(headers.data(), split_point);
229 stream_->OnStreamHeaders(headers1);
231 StringPiece headers2(headers.data() + split_point,
232 headers.size() - split_point);
233 stream_->OnStreamHeaders(headers2);
234 stream_->OnStreamHeadersComplete(false, headers.size());
235 ASSERT_EQ(headers, stream_->decompressed_headers())
236 << "split_point: " << split_point;
237 stream_->MarkHeadersConsumed(headers.length());
239 StringPiece fragment1(body.data(), split_point);
240 QuicStreamFrame frame1(kClientDataStreamId1, false, 0,
241 StringPiece(fragment1));
242 stream_->OnStreamFrame(frame1);
244 StringPiece fragment2(body.data() + split_point,
245 body.size() - split_point);
246 QuicStreamFrame frame2(kClientDataStreamId1, false, split_point,
247 StringPiece(fragment2));
248 stream_->OnStreamFrame(frame2);
250 ASSERT_EQ(body, stream_->data()) << "split_point: " << split_point;
254 TEST_P(QuicDataStreamTest, ProcessHeadersAndBodyReadv) {
255 Initialize(!kShouldProcessData);
257 string headers =
258 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
259 string body = "this is the body";
261 stream_->OnStreamHeaders(headers);
262 stream_->OnStreamHeadersComplete(false, headers.size());
263 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body));
264 stream_->OnStreamFrame(frame);
265 stream_->MarkHeadersConsumed(headers.length());
267 char buffer[2048];
268 ASSERT_LT(body.length(), arraysize(buffer));
269 struct iovec vec;
270 vec.iov_base = buffer;
271 vec.iov_len = arraysize(buffer);
273 size_t bytes_read = stream_->Readv(&vec, 1);
274 EXPECT_EQ(body.length(), bytes_read);
275 EXPECT_EQ(body, string(buffer, bytes_read));
278 TEST_P(QuicDataStreamTest, ProcessHeadersAndBodyMarkConsumed) {
279 Initialize(!kShouldProcessData);
281 string headers =
282 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
283 string body = "this is the body";
285 stream_->OnStreamHeaders(headers);
286 stream_->OnStreamHeadersComplete(false, headers.size());
287 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body));
288 stream_->OnStreamFrame(frame);
289 stream_->MarkHeadersConsumed(headers.length());
291 struct iovec vec;
293 EXPECT_EQ(1, stream_->GetReadableRegions(&vec, 1));
294 EXPECT_EQ(body.length(), vec.iov_len);
295 EXPECT_EQ(body, string(static_cast<char*>(vec.iov_base), vec.iov_len));
297 stream_->MarkConsumed(body.length());
298 EXPECT_EQ(body.length(), stream_->flow_controller()->bytes_consumed());
301 TEST_P(QuicDataStreamTest, ProcessHeadersAndBodyIncrementalReadv) {
302 Initialize(!kShouldProcessData);
304 string headers =
305 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
306 string body = "this is the body";
307 stream_->OnStreamHeaders(headers);
308 stream_->OnStreamHeadersComplete(false, headers.size());
309 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body));
310 stream_->OnStreamFrame(frame);
311 stream_->MarkHeadersConsumed(headers.length());
313 char buffer[1];
314 struct iovec vec;
315 vec.iov_base = buffer;
316 vec.iov_len = arraysize(buffer);
318 for (size_t i = 0; i < body.length(); ++i) {
319 size_t bytes_read = stream_->Readv(&vec, 1);
320 ASSERT_EQ(1u, bytes_read);
321 EXPECT_EQ(body.data()[i], buffer[0]);
325 TEST_P(QuicDataStreamTest, ProcessHeadersUsingReadvWithMultipleIovecs) {
326 Initialize(!kShouldProcessData);
328 string headers =
329 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
330 string body = "this is the body";
331 stream_->OnStreamHeaders(headers);
332 stream_->OnStreamHeadersComplete(false, headers.size());
333 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body));
334 stream_->OnStreamFrame(frame);
335 stream_->MarkHeadersConsumed(headers.length());
337 char buffer1[1];
338 char buffer2[1];
339 struct iovec vec[2];
340 vec[0].iov_base = buffer1;
341 vec[0].iov_len = arraysize(buffer1);
342 vec[1].iov_base = buffer2;
343 vec[1].iov_len = arraysize(buffer2);
345 for (size_t i = 0; i < body.length(); i += 2) {
346 size_t bytes_read = stream_->Readv(vec, 2);
347 ASSERT_EQ(2u, bytes_read) << i;
348 ASSERT_EQ(body.data()[i], buffer1[0]) << i;
349 ASSERT_EQ(body.data()[i + 1], buffer2[0]) << i;
353 TEST_P(QuicDataStreamTest, StreamFlowControlBlocked) {
354 // Tests that we send a BLOCKED frame to the peer when we attempt to write,
355 // but are flow control blocked.
356 Initialize(kShouldProcessData);
358 // Set a small flow control limit.
359 const uint64 kWindow = 36;
360 QuicFlowControllerPeer::SetSendWindowOffset(stream_->flow_controller(),
361 kWindow);
362 EXPECT_EQ(kWindow, QuicFlowControllerPeer::SendWindowOffset(
363 stream_->flow_controller()));
365 // Try to send more data than the flow control limit allows.
366 string headers =
367 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
368 string body;
369 const uint64 kOverflow = 15;
370 GenerateBody(&body, kWindow + kOverflow);
372 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1));
373 EXPECT_CALL(*session_, WritevData(kClientDataStreamId1, _, _, _, _, _))
374 .WillOnce(Return(QuicConsumedData(kWindow, true)));
375 stream_->WriteOrBufferData(body, false, nullptr);
377 // Should have sent as much as possible, resulting in no send window left.
378 EXPECT_EQ(0u,
379 QuicFlowControllerPeer::SendWindowSize(stream_->flow_controller()));
381 // And we should have queued the overflowed data.
382 EXPECT_EQ(kOverflow,
383 ReliableQuicStreamPeer::SizeOfQueuedData(stream_.get()));
386 TEST_P(QuicDataStreamTest, StreamFlowControlNoWindowUpdateIfNotConsumed) {
387 // The flow control receive window decreases whenever we add new bytes to the
388 // sequencer, whether they are consumed immediately or buffered. However we
389 // only send WINDOW_UPDATE frames based on increasing number of bytes
390 // consumed.
392 // Don't process data - it will be buffered instead.
393 Initialize(!kShouldProcessData);
395 // Expect no WINDOW_UPDATE frames to be sent.
396 EXPECT_CALL(*connection_, SendWindowUpdate(_, _)).Times(0);
398 // Set a small flow control receive window.
399 const uint64 kWindow = 36;
400 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(),
401 kWindow);
402 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(),
403 kWindow);
404 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowOffset(
405 stream_->flow_controller()));
407 // Stream receives enough data to fill a fraction of the receive window.
408 string headers =
409 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
410 string body;
411 GenerateBody(&body, kWindow / 3);
412 stream_->OnStreamHeaders(headers);
413 stream_->OnStreamHeadersComplete(false, headers.size());
415 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, StringPiece(body));
416 stream_->OnStreamFrame(frame1);
417 EXPECT_EQ(kWindow - (kWindow / 3), QuicFlowControllerPeer::ReceiveWindowSize(
418 stream_->flow_controller()));
420 // Now receive another frame which results in the receive window being over
421 // half full. This should all be buffered, decreasing the receive window but
422 // not sending WINDOW_UPDATE.
423 QuicStreamFrame frame2(kClientDataStreamId1, false, kWindow / 3,
424 StringPiece(body));
425 stream_->OnStreamFrame(frame2);
426 EXPECT_EQ(
427 kWindow - (2 * kWindow / 3),
428 QuicFlowControllerPeer::ReceiveWindowSize(stream_->flow_controller()));
431 TEST_P(QuicDataStreamTest, StreamFlowControlWindowUpdate) {
432 // Tests that on receipt of data, the stream updates its receive window offset
433 // appropriately, and sends WINDOW_UPDATE frames when its receive window drops
434 // too low.
435 Initialize(kShouldProcessData);
437 // Set a small flow control limit.
438 const uint64 kWindow = 36;
439 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(),
440 kWindow);
441 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(),
442 kWindow);
443 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowOffset(
444 stream_->flow_controller()));
446 // Stream receives enough data to fill a fraction of the receive window.
447 string headers =
448 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
449 string body;
450 GenerateBody(&body, kWindow / 3);
451 stream_->OnStreamHeaders(headers);
452 stream_->OnStreamHeadersComplete(false, headers.size());
453 stream_->MarkHeadersConsumed(headers.length());
455 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, StringPiece(body));
456 stream_->OnStreamFrame(frame1);
457 EXPECT_EQ(kWindow - (kWindow / 3), QuicFlowControllerPeer::ReceiveWindowSize(
458 stream_->flow_controller()));
460 // Now receive another frame which results in the receive window being over
461 // half full. This will trigger the stream to increase its receive window
462 // offset and send a WINDOW_UPDATE. The result will be again an available
463 // window of kWindow bytes.
464 QuicStreamFrame frame2(kClientDataStreamId1, false, kWindow / 3,
465 StringPiece(body));
466 EXPECT_CALL(*connection_,
467 SendWindowUpdate(kClientDataStreamId1,
468 QuicFlowControllerPeer::ReceiveWindowOffset(
469 stream_->flow_controller()) +
470 2 * kWindow / 3));
471 stream_->OnStreamFrame(frame2);
472 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowSize(
473 stream_->flow_controller()));
476 TEST_P(QuicDataStreamTest, ConnectionFlowControlWindowUpdate) {
477 // Tests that on receipt of data, the connection updates its receive window
478 // offset appropriately, and sends WINDOW_UPDATE frames when its receive
479 // window drops too low.
480 Initialize(kShouldProcessData);
482 // Set a small flow control limit for streams and connection.
483 const uint64 kWindow = 36;
484 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(),
485 kWindow);
486 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(),
487 kWindow);
488 QuicFlowControllerPeer::SetReceiveWindowOffset(stream2_->flow_controller(),
489 kWindow);
490 QuicFlowControllerPeer::SetMaxReceiveWindow(stream2_->flow_controller(),
491 kWindow);
492 QuicFlowControllerPeer::SetReceiveWindowOffset(session_->flow_controller(),
493 kWindow);
494 QuicFlowControllerPeer::SetMaxReceiveWindow(session_->flow_controller(),
495 kWindow);
497 // Supply headers to both streams so that they are happy to receive data.
498 string headers =
499 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
500 stream_->OnStreamHeaders(headers);
501 stream_->OnStreamHeadersComplete(false, headers.size());
502 stream_->MarkHeadersConsumed(headers.length());
503 stream2_->OnStreamHeaders(headers);
504 stream2_->OnStreamHeadersComplete(false, headers.size());
505 stream2_->MarkHeadersConsumed(headers.length());
507 // Each stream gets a quarter window of data. This should not trigger a
508 // WINDOW_UPDATE for either stream, nor for the connection.
509 string body;
510 GenerateBody(&body, kWindow / 4);
511 QuicStreamFrame frame1(kClientDataStreamId1, false, 0, StringPiece(body));
512 stream_->OnStreamFrame(frame1);
513 QuicStreamFrame frame2(kClientDataStreamId2, false, 0, StringPiece(body));
514 stream2_->OnStreamFrame(frame2);
516 // Now receive a further single byte on one stream - again this does not
517 // trigger a stream WINDOW_UPDATE, but now the connection flow control window
518 // is over half full and thus a connection WINDOW_UPDATE is sent.
519 EXPECT_CALL(*connection_, SendWindowUpdate(kClientDataStreamId1, _)).Times(0);
520 EXPECT_CALL(*connection_, SendWindowUpdate(kClientDataStreamId2, _)).Times(0);
521 EXPECT_CALL(*connection_,
522 SendWindowUpdate(0, QuicFlowControllerPeer::ReceiveWindowOffset(
523 session_->flow_controller()) +
524 1 + kWindow / 2));
525 QuicStreamFrame frame3(kClientDataStreamId1, false, (kWindow / 4),
526 StringPiece("a"));
527 stream_->OnStreamFrame(frame3);
530 TEST_P(QuicDataStreamTest, StreamFlowControlViolation) {
531 // Tests that on if the peer sends too much data (i.e. violates the flow
532 // control protocol), then we terminate the connection.
534 // Stream should not process data, so that data gets buffered in the
535 // sequencer, triggering flow control limits.
536 Initialize(!kShouldProcessData);
538 // Set a small flow control limit.
539 const uint64 kWindow = 50;
540 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(),
541 kWindow);
543 string headers =
544 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
545 stream_->OnStreamHeaders(headers);
546 stream_->OnStreamHeadersComplete(false, headers.size());
548 // Receive data to overflow the window, violating flow control.
549 string body;
550 GenerateBody(&body, kWindow + 1);
551 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body));
552 EXPECT_CALL(*connection_,
553 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA));
554 stream_->OnStreamFrame(frame);
557 TEST_P(QuicDataStreamTest, ConnectionFlowControlViolation) {
558 // Tests that on if the peer sends too much data (i.e. violates the flow
559 // control protocol), at the connection level (rather than the stream level)
560 // then we terminate the connection.
562 // Stream should not process data, so that data gets buffered in the
563 // sequencer, triggering flow control limits.
564 Initialize(!kShouldProcessData);
566 // Set a small flow control window on streams, and connection.
567 const uint64 kStreamWindow = 50;
568 const uint64 kConnectionWindow = 10;
569 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(),
570 kStreamWindow);
571 QuicFlowControllerPeer::SetReceiveWindowOffset(session_->flow_controller(),
572 kConnectionWindow);
574 string headers =
575 SpdyUtils::SerializeUncompressedHeaders(headers_, GetParam());
576 stream_->OnStreamHeaders(headers);
577 stream_->OnStreamHeadersComplete(false, headers.size());
579 // Send enough data to overflow the connection level flow control window.
580 string body;
581 GenerateBody(&body, kConnectionWindow + 1);
582 EXPECT_LT(body.size(), kStreamWindow);
583 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body));
585 EXPECT_CALL(*connection_,
586 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA));
587 stream_->OnStreamFrame(frame);
590 TEST_P(QuicDataStreamTest, StreamFlowControlFinNotBlocked) {
591 // An attempt to write a FIN with no data should not be flow control blocked,
592 // even if the send window is 0.
594 Initialize(kShouldProcessData);
596 // Set a flow control limit of zero.
597 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), 0);
598 EXPECT_EQ(0u, QuicFlowControllerPeer::ReceiveWindowOffset(
599 stream_->flow_controller()));
601 // Send a frame with a FIN but no data. This should not be blocked.
602 string body = "";
603 bool fin = true;
605 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)).Times(0);
606 EXPECT_CALL(*session_, WritevData(kClientDataStreamId1, _, _, _, _, _))
607 .WillOnce(Return(QuicConsumedData(0, fin)));
609 stream_->WriteOrBufferData(body, fin, nullptr);
612 } // namespace
613 } // namespace test
614 } // namespace net