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/tools/quic/quic_simple_server_session.h" | 5 #include "net/tools/quic/quic_simple_server_session.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 using net::test::kClientDataStreamId1; | 47 using net::test::kClientDataStreamId1; |
48 using net::test::kClientDataStreamId2; | 48 using net::test::kClientDataStreamId2; |
49 using net::test::kClientDataStreamId3; | 49 using net::test::kClientDataStreamId3; |
50 using net::test::kInitialSessionFlowControlWindowForTest; | 50 using net::test::kInitialSessionFlowControlWindowForTest; |
51 using net::test::kInitialStreamFlowControlWindowForTest; | 51 using net::test::kInitialStreamFlowControlWindowForTest; |
52 using std::string; | 52 using std::string; |
53 using testing::StrictMock; | 53 using testing::StrictMock; |
54 using testing::_; | 54 using testing::_; |
55 using testing::InSequence; | 55 using testing::InSequence; |
56 using testing::Return; | 56 using testing::Return; |
| 57 using testing::AtLeast; |
57 | 58 |
58 namespace net { | 59 namespace net { |
59 namespace test { | 60 namespace test { |
60 namespace { | 61 namespace { |
61 typedef QuicSimpleServerSession::PromisedStreamInfo PromisedStreamInfo; | 62 typedef QuicSimpleServerSession::PromisedStreamInfo PromisedStreamInfo; |
62 } // namespace | 63 } // namespace |
63 | 64 |
64 class MockQuicHeadersStream : public QuicHeadersStream { | 65 class MockQuicHeadersStream : public QuicHeadersStream { |
65 public: | 66 public: |
66 explicit MockQuicHeadersStream(QuicSpdySession* session) | 67 explicit MockQuicHeadersStream(QuicSpdySession* session) |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 EXPECT_CALL( | 487 EXPECT_CALL( |
487 *headers_stream_, | 488 *headers_stream_, |
488 WritePushPromiseMock(kClientDataStreamId1, stream_id, _, nullptr)); | 489 WritePushPromiseMock(kClientDataStreamId1, stream_id, _, nullptr)); |
489 if (i <= kMaxStreamsForTest) { | 490 if (i <= kMaxStreamsForTest) { |
490 // |kMaxStreamsForTest| promised responses should be sent. | 491 // |kMaxStreamsForTest| promised responses should be sent. |
491 EXPECT_CALL( | 492 EXPECT_CALL( |
492 *headers_stream_, | 493 *headers_stream_, |
493 WriteHeadersMock(stream_id, _, false, kDefaultPriority, nullptr)); | 494 WriteHeadersMock(stream_id, _, false, kDefaultPriority, nullptr)); |
494 // Since flow control window is smaller than response body, not the | 495 // Since flow control window is smaller than response body, not the |
495 // whole body will be sent. | 496 // whole body will be sent. |
496 EXPECT_CALL(*connection_, | 497 if (!session_->force_hol_blocking()) { |
497 SendStreamData(stream_id, _, 0, false, nullptr)) | 498 EXPECT_CALL(*connection_, |
498 .WillOnce( | 499 SendStreamData(stream_id, _, 0, false, nullptr)) |
499 Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 500 .WillOnce(Return( |
500 EXPECT_CALL(*connection_, SendBlocked(stream_id)); | 501 QuicConsumedData(kStreamFlowControlWindowSize, false))); |
| 502 EXPECT_CALL(*connection_, SendBlocked(stream_id)); |
| 503 } else { |
| 504 // The forced HOL blocking encapsulates the stream data into |
| 505 // HTTP/2 DATA frames within the headers stream. HTTP/2 |
| 506 // DATA frames are limited to a max size of 16KB, so the |
| 507 // 64KB body will be fragemented into four DATA frames. |
| 508 EXPECT_CALL(*connection_, SendStreamData(_, _, _, false, nullptr)) |
| 509 .Times(body_size / 16384) |
| 510 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) |
| 511 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) |
| 512 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) |
| 513 .WillOnce(Return(QuicConsumedData(9 + 16394, false))); |
| 514 EXPECT_CALL(*connection_, SendBlocked(_)); |
| 515 } |
501 } | 516 } |
502 } | 517 } |
503 session_->PromisePushResources(request_url, push_resources, | 518 session_->PromisePushResources(request_url, push_resources, |
504 kClientDataStreamId1, request_headers); | 519 kClientDataStreamId1, request_headers); |
505 } | 520 } |
506 }; | 521 }; |
507 | 522 |
508 INSTANTIATE_TEST_CASE_P(Tests, | 523 INSTANTIATE_TEST_CASE_P(Tests, |
509 QuicSimpleServerSessionServerPushTest, | 524 QuicSimpleServerSessionServerPushTest, |
510 ::testing::ValuesIn(QuicSupportedVersions())); | 525 ::testing::ValuesIn(QuicSupportedVersions())); |
511 | 526 |
512 TEST_P(QuicSimpleServerSessionServerPushTest, TestPromisePushResources) { | 527 TEST_P(QuicSimpleServerSessionServerPushTest, TestPromisePushResources) { |
513 // Tests that given more than kMaxOpenStreamForTest resources, all their | 528 // Tests that given more than kMaxOpenStreamForTest resources, all their |
514 // PUSH_PROMISE's will be sent out and only |kMaxOpenStreamForTest| streams | 529 // PUSH_PROMISE's will be sent out and only |kMaxOpenStreamForTest| streams |
515 // will be opened and send push response. | 530 // will be opened and send push response. |
| 531 |
| 532 if (session_->force_hol_blocking()) { |
| 533 return; |
| 534 } |
516 size_t num_resources = kMaxStreamsForTest + 5; | 535 size_t num_resources = kMaxStreamsForTest + 5; |
517 PromisePushResources(num_resources); | 536 PromisePushResources(num_resources); |
518 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); | 537 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); |
519 } | 538 } |
520 | 539 |
521 TEST_P(QuicSimpleServerSessionServerPushTest, | 540 TEST_P(QuicSimpleServerSessionServerPushTest, |
522 HandlePromisedPushRequestsAfterStreamDraining) { | 541 HandlePromisedPushRequestsAfterStreamDraining) { |
| 542 if (session_->force_hol_blocking()) { |
| 543 return; |
| 544 } |
| 545 |
523 // Tests that after promised stream queued up, when an opened stream is marked | 546 // Tests that after promised stream queued up, when an opened stream is marked |
524 // draining, a queued promised stream will become open and send push response. | 547 // draining, a queued promised stream will become open and send push response. |
525 size_t num_resources = kMaxStreamsForTest + 1; | 548 size_t num_resources = kMaxStreamsForTest + 1; |
526 PromisePushResources(num_resources); | 549 PromisePushResources(num_resources); |
527 QuicStreamId next_out_going_stream_id = num_resources * 2; | 550 QuicStreamId next_out_going_stream_id = num_resources * 2; |
528 | 551 |
529 // After an open stream is marked draining, a new stream is expected to be | 552 // After an open stream is marked draining, a new stream is expected to be |
530 // created and a response sent on the stream. | 553 // created and a response sent on the stream. |
531 EXPECT_CALL(*headers_stream_, | 554 EXPECT_CALL(*headers_stream_, |
532 WriteHeadersMock(next_out_going_stream_id, _, false, | 555 WriteHeadersMock(next_out_going_stream_id, _, false, |
533 kDefaultPriority, nullptr)); | 556 kDefaultPriority, nullptr)); |
534 EXPECT_CALL(*connection_, | 557 EXPECT_CALL(*connection_, |
535 SendStreamData(next_out_going_stream_id, _, 0, false, nullptr)) | 558 SendStreamData(next_out_going_stream_id, _, 0, false, nullptr)) |
536 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 559 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
537 EXPECT_CALL(*connection_, SendBlocked(next_out_going_stream_id)); | 560 EXPECT_CALL(*connection_, SendBlocked(next_out_going_stream_id)); |
538 session_->StreamDraining(2); | 561 session_->StreamDraining(2); |
539 // Number of open outgoing streams should still be the same, because a new | 562 // Number of open outgoing streams should still be the same, because a new |
540 // stream is opened. And the queue should be empty. | 563 // stream is opened. And the queue should be empty. |
541 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); | 564 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); |
542 } | 565 } |
543 | 566 |
544 TEST_P(QuicSimpleServerSessionServerPushTest, | 567 TEST_P(QuicSimpleServerSessionServerPushTest, |
545 ResetPromisedStreamToCancelServerPush) { | 568 ResetPromisedStreamToCancelServerPush) { |
| 569 if (session_->force_hol_blocking()) { |
| 570 return; |
| 571 } |
546 // Tests that after all resources are promised, a RST frame from client can | 572 // Tests that after all resources are promised, a RST frame from client can |
547 // prevent a promised resource to be send out. | 573 // prevent a promised resource to be send out. |
548 | 574 |
549 // Having two extra resources to be send later. One of them will be reset, so | 575 // Having two extra resources to be send later. One of them will be reset, so |
550 // when opened stream become close, only one will become open. | 576 // when opened stream become close, only one will become open. |
551 size_t num_resources = kMaxStreamsForTest + 2; | 577 size_t num_resources = kMaxStreamsForTest + 2; |
552 PromisePushResources(num_resources); | 578 PromisePushResources(num_resources); |
553 | 579 |
554 // Reset the last stream in the queue. It should be marked cancelled. | 580 // Reset the last stream in the queue. It should be marked cancelled. |
555 QuicStreamId stream_got_reset = num_resources * 2; | 581 QuicStreamId stream_got_reset = num_resources * 2; |
(...skipping 16 matching lines...) Expand all Loading... |
572 EXPECT_CALL(*headers_stream_, WriteHeadersMock(stream_got_reset, _, false, | 598 EXPECT_CALL(*headers_stream_, WriteHeadersMock(stream_got_reset, _, false, |
573 kDefaultPriority, nullptr)) | 599 kDefaultPriority, nullptr)) |
574 .Times(0); | 600 .Times(0); |
575 | 601 |
576 session_->StreamDraining(2); | 602 session_->StreamDraining(2); |
577 session_->StreamDraining(4); | 603 session_->StreamDraining(4); |
578 } | 604 } |
579 | 605 |
580 TEST_P(QuicSimpleServerSessionServerPushTest, | 606 TEST_P(QuicSimpleServerSessionServerPushTest, |
581 CloseStreamToHandleMorePromisedStream) { | 607 CloseStreamToHandleMorePromisedStream) { |
| 608 if (session_->force_hol_blocking()) { |
| 609 return; |
| 610 } |
582 // Tests that closing a open outgoing stream can trigger a promised resource | 611 // Tests that closing a open outgoing stream can trigger a promised resource |
583 // in the queue to be send out. | 612 // in the queue to be send out. |
584 size_t num_resources = kMaxStreamsForTest + 1; | 613 size_t num_resources = kMaxStreamsForTest + 1; |
585 PromisePushResources(num_resources); | 614 PromisePushResources(num_resources); |
586 QuicStreamId stream_to_open = num_resources * 2; | 615 QuicStreamId stream_to_open = num_resources * 2; |
587 | 616 |
588 // Resetting 1st open stream will close the stream and give space for extra | 617 // Resetting 1st open stream will close the stream and give space for extra |
589 // stream to be opened. | 618 // stream to be opened. |
590 QuicStreamId stream_got_reset = 2; | 619 QuicStreamId stream_got_reset = 2; |
591 EXPECT_CALL(*connection_, | 620 EXPECT_CALL(*connection_, |
592 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, _)); | 621 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, _)); |
593 EXPECT_CALL(*headers_stream_, WriteHeadersMock(stream_to_open, _, false, | 622 EXPECT_CALL(*headers_stream_, WriteHeadersMock(stream_to_open, _, false, |
594 kDefaultPriority, nullptr)); | 623 kDefaultPriority, nullptr)); |
595 EXPECT_CALL(*connection_, | 624 EXPECT_CALL(*connection_, |
596 SendStreamData(stream_to_open, _, 0, false, nullptr)) | 625 SendStreamData(stream_to_open, _, 0, false, nullptr)) |
597 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 626 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
598 | 627 |
599 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); | 628 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); |
600 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); | 629 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); |
601 visitor_->OnRstStream(rst); | 630 visitor_->OnRstStream(rst); |
602 } | 631 } |
603 | 632 |
604 } // namespace | 633 } // namespace |
605 } // namespace test | 634 } // namespace test |
606 } // namespace net | 635 } // namespace net |
OLD | NEW |