OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_spdy_stream.h" | 5 #include "net/quic/quic_spdy_stream.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 | 8 |
9 #include "net/quic/quic_connection.h" | 9 #include "net/quic/quic_connection.h" |
10 #include "net/quic/quic_utils.h" | 10 #include "net/quic/quic_utils.h" |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 ASSERT_EQ(body.data()[i + 1], buffer2[0]) << i; | 342 ASSERT_EQ(body.data()[i + 1], buffer2[0]) << i; |
343 } | 343 } |
344 } | 344 } |
345 | 345 |
346 TEST_P(QuicSpdyStreamTest, StreamFlowControlBlocked) { | 346 TEST_P(QuicSpdyStreamTest, StreamFlowControlBlocked) { |
347 // Tests that we send a BLOCKED frame to the peer when we attempt to write, | 347 // Tests that we send a BLOCKED frame to the peer when we attempt to write, |
348 // but are flow control blocked. | 348 // but are flow control blocked. |
349 Initialize(kShouldProcessData); | 349 Initialize(kShouldProcessData); |
350 | 350 |
351 // Set a small flow control limit. | 351 // Set a small flow control limit. |
352 const uint64 kWindow = 36; | 352 const uint64_t kWindow = 36; |
353 QuicFlowControllerPeer::SetSendWindowOffset(stream_->flow_controller(), | 353 QuicFlowControllerPeer::SetSendWindowOffset(stream_->flow_controller(), |
354 kWindow); | 354 kWindow); |
355 EXPECT_EQ(kWindow, QuicFlowControllerPeer::SendWindowOffset( | 355 EXPECT_EQ(kWindow, QuicFlowControllerPeer::SendWindowOffset( |
356 stream_->flow_controller())); | 356 stream_->flow_controller())); |
357 | 357 |
358 // Try to send more data than the flow control limit allows. | 358 // Try to send more data than the flow control limit allows. |
359 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); | 359 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
360 string body; | 360 string body; |
361 const uint64 kOverflow = 15; | 361 const uint64_t kOverflow = 15; |
362 GenerateBody(&body, kWindow + kOverflow); | 362 GenerateBody(&body, kWindow + kOverflow); |
363 | 363 |
364 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)); | 364 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)); |
365 EXPECT_CALL(*session_, WritevData(kClientDataStreamId1, _, _, _, _, _)) | 365 EXPECT_CALL(*session_, WritevData(kClientDataStreamId1, _, _, _, _, _)) |
366 .WillOnce(Return(QuicConsumedData(kWindow, true))); | 366 .WillOnce(Return(QuicConsumedData(kWindow, true))); |
367 stream_->WriteOrBufferData(body, false, nullptr); | 367 stream_->WriteOrBufferData(body, false, nullptr); |
368 | 368 |
369 // Should have sent as much as possible, resulting in no send window left. | 369 // Should have sent as much as possible, resulting in no send window left. |
370 EXPECT_EQ(0u, | 370 EXPECT_EQ(0u, |
371 QuicFlowControllerPeer::SendWindowSize(stream_->flow_controller())); | 371 QuicFlowControllerPeer::SendWindowSize(stream_->flow_controller())); |
372 | 372 |
373 // And we should have queued the overflowed data. | 373 // And we should have queued the overflowed data. |
374 EXPECT_EQ(kOverflow, ReliableQuicStreamPeer::SizeOfQueuedData(stream_)); | 374 EXPECT_EQ(kOverflow, ReliableQuicStreamPeer::SizeOfQueuedData(stream_)); |
375 } | 375 } |
376 | 376 |
377 TEST_P(QuicSpdyStreamTest, StreamFlowControlNoWindowUpdateIfNotConsumed) { | 377 TEST_P(QuicSpdyStreamTest, StreamFlowControlNoWindowUpdateIfNotConsumed) { |
378 // The flow control receive window decreases whenever we add new bytes to the | 378 // The flow control receive window decreases whenever we add new bytes to the |
379 // sequencer, whether they are consumed immediately or buffered. However we | 379 // sequencer, whether they are consumed immediately or buffered. However we |
380 // only send WINDOW_UPDATE frames based on increasing number of bytes | 380 // only send WINDOW_UPDATE frames based on increasing number of bytes |
381 // consumed. | 381 // consumed. |
382 | 382 |
383 // Don't process data - it will be buffered instead. | 383 // Don't process data - it will be buffered instead. |
384 Initialize(!kShouldProcessData); | 384 Initialize(!kShouldProcessData); |
385 | 385 |
386 // Expect no WINDOW_UPDATE frames to be sent. | 386 // Expect no WINDOW_UPDATE frames to be sent. |
387 EXPECT_CALL(*connection_, SendWindowUpdate(_, _)).Times(0); | 387 EXPECT_CALL(*connection_, SendWindowUpdate(_, _)).Times(0); |
388 | 388 |
389 // Set a small flow control receive window. | 389 // Set a small flow control receive window. |
390 const uint64 kWindow = 36; | 390 const uint64_t kWindow = 36; |
391 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), | 391 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), |
392 kWindow); | 392 kWindow); |
393 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(), | 393 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(), |
394 kWindow); | 394 kWindow); |
395 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowOffset( | 395 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowOffset( |
396 stream_->flow_controller())); | 396 stream_->flow_controller())); |
397 | 397 |
398 // Stream receives enough data to fill a fraction of the receive window. | 398 // Stream receives enough data to fill a fraction of the receive window. |
399 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); | 399 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
400 string body; | 400 string body; |
(...skipping 17 matching lines...) Expand all Loading... |
418 QuicFlowControllerPeer::ReceiveWindowSize(stream_->flow_controller())); | 418 QuicFlowControllerPeer::ReceiveWindowSize(stream_->flow_controller())); |
419 } | 419 } |
420 | 420 |
421 TEST_P(QuicSpdyStreamTest, StreamFlowControlWindowUpdate) { | 421 TEST_P(QuicSpdyStreamTest, StreamFlowControlWindowUpdate) { |
422 // Tests that on receipt of data, the stream updates its receive window offset | 422 // Tests that on receipt of data, the stream updates its receive window offset |
423 // appropriately, and sends WINDOW_UPDATE frames when its receive window drops | 423 // appropriately, and sends WINDOW_UPDATE frames when its receive window drops |
424 // too low. | 424 // too low. |
425 Initialize(kShouldProcessData); | 425 Initialize(kShouldProcessData); |
426 | 426 |
427 // Set a small flow control limit. | 427 // Set a small flow control limit. |
428 const uint64 kWindow = 36; | 428 const uint64_t kWindow = 36; |
429 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), | 429 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), |
430 kWindow); | 430 kWindow); |
431 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(), | 431 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(), |
432 kWindow); | 432 kWindow); |
433 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowOffset( | 433 EXPECT_EQ(kWindow, QuicFlowControllerPeer::ReceiveWindowOffset( |
434 stream_->flow_controller())); | 434 stream_->flow_controller())); |
435 | 435 |
436 // Stream receives enough data to fill a fraction of the receive window. | 436 // Stream receives enough data to fill a fraction of the receive window. |
437 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); | 437 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
438 string body; | 438 string body; |
(...skipping 23 matching lines...) Expand all Loading... |
462 stream_->flow_controller())); | 462 stream_->flow_controller())); |
463 } | 463 } |
464 | 464 |
465 TEST_P(QuicSpdyStreamTest, ConnectionFlowControlWindowUpdate) { | 465 TEST_P(QuicSpdyStreamTest, ConnectionFlowControlWindowUpdate) { |
466 // Tests that on receipt of data, the connection updates its receive window | 466 // Tests that on receipt of data, the connection updates its receive window |
467 // offset appropriately, and sends WINDOW_UPDATE frames when its receive | 467 // offset appropriately, and sends WINDOW_UPDATE frames when its receive |
468 // window drops too low. | 468 // window drops too low. |
469 Initialize(kShouldProcessData); | 469 Initialize(kShouldProcessData); |
470 | 470 |
471 // Set a small flow control limit for streams and connection. | 471 // Set a small flow control limit for streams and connection. |
472 const uint64 kWindow = 36; | 472 const uint64_t kWindow = 36; |
473 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), | 473 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), |
474 kWindow); | 474 kWindow); |
475 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(), | 475 QuicFlowControllerPeer::SetMaxReceiveWindow(stream_->flow_controller(), |
476 kWindow); | 476 kWindow); |
477 QuicFlowControllerPeer::SetReceiveWindowOffset(stream2_->flow_controller(), | 477 QuicFlowControllerPeer::SetReceiveWindowOffset(stream2_->flow_controller(), |
478 kWindow); | 478 kWindow); |
479 QuicFlowControllerPeer::SetMaxReceiveWindow(stream2_->flow_controller(), | 479 QuicFlowControllerPeer::SetMaxReceiveWindow(stream2_->flow_controller(), |
480 kWindow); | 480 kWindow); |
481 QuicFlowControllerPeer::SetReceiveWindowOffset(session_->flow_controller(), | 481 QuicFlowControllerPeer::SetReceiveWindowOffset(session_->flow_controller(), |
482 kWindow); | 482 kWindow); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 | 517 |
518 TEST_P(QuicSpdyStreamTest, StreamFlowControlViolation) { | 518 TEST_P(QuicSpdyStreamTest, StreamFlowControlViolation) { |
519 // Tests that on if the peer sends too much data (i.e. violates the flow | 519 // Tests that on if the peer sends too much data (i.e. violates the flow |
520 // control protocol), then we terminate the connection. | 520 // control protocol), then we terminate the connection. |
521 | 521 |
522 // Stream should not process data, so that data gets buffered in the | 522 // Stream should not process data, so that data gets buffered in the |
523 // sequencer, triggering flow control limits. | 523 // sequencer, triggering flow control limits. |
524 Initialize(!kShouldProcessData); | 524 Initialize(!kShouldProcessData); |
525 | 525 |
526 // Set a small flow control limit. | 526 // Set a small flow control limit. |
527 const uint64 kWindow = 50; | 527 const uint64_t kWindow = 50; |
528 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), | 528 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), |
529 kWindow); | 529 kWindow); |
530 | 530 |
531 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); | 531 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
532 stream_->OnStreamHeaders(headers); | 532 stream_->OnStreamHeaders(headers); |
533 stream_->OnStreamHeadersComplete(false, headers.size()); | 533 stream_->OnStreamHeadersComplete(false, headers.size()); |
534 | 534 |
535 // Receive data to overflow the window, violating flow control. | 535 // Receive data to overflow the window, violating flow control. |
536 string body; | 536 string body; |
537 GenerateBody(&body, kWindow + 1); | 537 GenerateBody(&body, kWindow + 1); |
(...skipping 25 matching lines...) Expand all Loading... |
563 TEST_P(QuicSpdyStreamTest, ConnectionFlowControlViolation) { | 563 TEST_P(QuicSpdyStreamTest, ConnectionFlowControlViolation) { |
564 // Tests that on if the peer sends too much data (i.e. violates the flow | 564 // Tests that on if the peer sends too much data (i.e. violates the flow |
565 // control protocol), at the connection level (rather than the stream level) | 565 // control protocol), at the connection level (rather than the stream level) |
566 // then we terminate the connection. | 566 // then we terminate the connection. |
567 | 567 |
568 // Stream should not process data, so that data gets buffered in the | 568 // Stream should not process data, so that data gets buffered in the |
569 // sequencer, triggering flow control limits. | 569 // sequencer, triggering flow control limits. |
570 Initialize(!kShouldProcessData); | 570 Initialize(!kShouldProcessData); |
571 | 571 |
572 // Set a small flow control window on streams, and connection. | 572 // Set a small flow control window on streams, and connection. |
573 const uint64 kStreamWindow = 50; | 573 const uint64_t kStreamWindow = 50; |
574 const uint64 kConnectionWindow = 10; | 574 const uint64_t kConnectionWindow = 10; |
575 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), | 575 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), |
576 kStreamWindow); | 576 kStreamWindow); |
577 QuicFlowControllerPeer::SetReceiveWindowOffset(session_->flow_controller(), | 577 QuicFlowControllerPeer::SetReceiveWindowOffset(session_->flow_controller(), |
578 kConnectionWindow); | 578 kConnectionWindow); |
579 | 579 |
580 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); | 580 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
581 stream_->OnStreamHeaders(headers); | 581 stream_->OnStreamHeaders(headers); |
582 stream_->OnStreamHeadersComplete(false, headers.size()); | 582 stream_->OnStreamHeadersComplete(false, headers.size()); |
583 | 583 |
584 // Send enough data to overflow the connection level flow control window. | 584 // Send enough data to overflow the connection level flow control window. |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 | 852 |
853 // Writing Trailers should fail, as the FIN has already been sent. | 853 // Writing Trailers should fail, as the FIN has already been sent. |
854 // populated with the number of body bytes written. | 854 // populated with the number of body bytes written. |
855 EXPECT_DFATAL(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), | 855 EXPECT_DFATAL(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), |
856 "Trailers cannot be sent after a FIN"); | 856 "Trailers cannot be sent after a FIN"); |
857 } | 857 } |
858 | 858 |
859 } // namespace | 859 } // namespace |
860 } // namespace test | 860 } // namespace test |
861 } // namespace net | 861 } // namespace net |
OLD | NEW |