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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 alarm_factory, | 116 alarm_factory, |
117 perspective, | 117 perspective, |
118 supported_versions) {} | 118 supported_versions) {} |
119 | 119 |
120 MOCK_METHOD5( | 120 MOCK_METHOD5( |
121 SendStreamData, | 121 SendStreamData, |
122 QuicConsumedData( | 122 QuicConsumedData( |
123 QuicStreamId id, | 123 QuicStreamId id, |
124 QuicIOVector iov, | 124 QuicIOVector iov, |
125 QuicStreamOffset offset, | 125 QuicStreamOffset offset, |
126 bool fin, | 126 StreamSendingState state, |
127 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener)); | 127 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener)); |
128 }; | 128 }; |
129 | 129 |
130 class MockQuicSimpleServerSession : public QuicSimpleServerSession { | 130 class MockQuicSimpleServerSession : public QuicSimpleServerSession { |
131 public: | 131 public: |
132 MockQuicSimpleServerSession(const QuicConfig& config, | 132 MockQuicSimpleServerSession(const QuicConfig& config, |
133 QuicConnection* connection, | 133 QuicConnection* connection, |
134 QuicSession::Visitor* visitor, | 134 QuicSession::Visitor* visitor, |
135 QuicCryptoServerStream::Helper* helper, | 135 QuicCryptoServerStream::Helper* helper, |
136 const QuicCryptoServerConfig* crypto_config, | 136 const QuicCryptoServerConfig* crypto_config, |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 // PUSH_PROMISED are sent for all the resources. | 483 // PUSH_PROMISED are sent for all the resources. |
484 EXPECT_CALL(*session_, | 484 EXPECT_CALL(*session_, |
485 WritePushPromiseMock(kClientDataStreamId1, stream_id, _)); | 485 WritePushPromiseMock(kClientDataStreamId1, stream_id, _)); |
486 if (i <= kMaxStreamsForTest) { | 486 if (i <= kMaxStreamsForTest) { |
487 // |kMaxStreamsForTest| promised responses should be sent. | 487 // |kMaxStreamsForTest| promised responses should be sent. |
488 EXPECT_CALL(*session_, | 488 EXPECT_CALL(*session_, |
489 WriteHeadersMock(stream_id, _, false, kDefaultPriority, _)); | 489 WriteHeadersMock(stream_id, _, false, kDefaultPriority, _)); |
490 // Since flow control window is smaller than response body, not the | 490 // Since flow control window is smaller than response body, not the |
491 // whole body will be sent. | 491 // whole body will be sent. |
492 if (!session_->force_hol_blocking()) { | 492 if (!session_->force_hol_blocking()) { |
493 EXPECT_CALL(*connection_, SendStreamData(stream_id, _, 0, false, _)) | 493 EXPECT_CALL(*connection_, SendStreamData(stream_id, _, 0, NO_FIN, _)) |
494 .WillOnce(Return( | 494 .WillOnce(Return( |
495 QuicConsumedData(kStreamFlowControlWindowSize, false))); | 495 QuicConsumedData(kStreamFlowControlWindowSize, false))); |
496 EXPECT_CALL(*connection_, SendBlocked(stream_id)); | 496 EXPECT_CALL(*connection_, SendBlocked(stream_id)); |
497 } else { | 497 } else { |
498 // The forced HOL blocking encapsulates the stream data into | 498 // The forced HOL blocking encapsulates the stream data into |
499 // HTTP/2 DATA frames within the headers stream. HTTP/2 | 499 // HTTP/2 DATA frames within the headers stream. HTTP/2 |
500 // DATA frames are limited to a max size of 16KB, so the | 500 // DATA frames are limited to a max size of 16KB, so the |
501 // 64KB body will be fragemented into four DATA frames. | 501 // 64KB body will be fragemented into four DATA frames. |
502 EXPECT_CALL(*connection_, SendStreamData(_, _, _, false, _)) | 502 EXPECT_CALL(*connection_, SendStreamData(_, _, _, NO_FIN, _)) |
503 .Times(body_size / 16384) | 503 .Times(body_size / 16384) |
504 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) | 504 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) |
505 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) | 505 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) |
506 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) | 506 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) |
507 .WillOnce(Return(QuicConsumedData(9 + 16394, false))); | 507 .WillOnce(Return(QuicConsumedData(9 + 16394, false))); |
508 EXPECT_CALL(*connection_, SendBlocked(_)); | 508 EXPECT_CALL(*connection_, SendBlocked(_)); |
509 } | 509 } |
510 } | 510 } |
511 } | 511 } |
512 session_->PromisePushResources(request_url, push_resources, | 512 session_->PromisePushResources(request_url, push_resources, |
(...skipping 28 matching lines...) Expand all Loading... |
541 // draining, a queued promised stream will become open and send push response. | 541 // draining, a queued promised stream will become open and send push response. |
542 size_t num_resources = kMaxStreamsForTest + 1; | 542 size_t num_resources = kMaxStreamsForTest + 1; |
543 PromisePushResources(num_resources); | 543 PromisePushResources(num_resources); |
544 QuicStreamId next_out_going_stream_id = num_resources * 2; | 544 QuicStreamId next_out_going_stream_id = num_resources * 2; |
545 | 545 |
546 // After an open stream is marked draining, a new stream is expected to be | 546 // After an open stream is marked draining, a new stream is expected to be |
547 // created and a response sent on the stream. | 547 // created and a response sent on the stream. |
548 EXPECT_CALL(*session_, WriteHeadersMock(next_out_going_stream_id, _, false, | 548 EXPECT_CALL(*session_, WriteHeadersMock(next_out_going_stream_id, _, false, |
549 kDefaultPriority, _)); | 549 kDefaultPriority, _)); |
550 EXPECT_CALL(*connection_, | 550 EXPECT_CALL(*connection_, |
551 SendStreamData(next_out_going_stream_id, _, 0, false, _)) | 551 SendStreamData(next_out_going_stream_id, _, 0, NO_FIN, _)) |
552 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 552 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
553 EXPECT_CALL(*connection_, SendBlocked(next_out_going_stream_id)); | 553 EXPECT_CALL(*connection_, SendBlocked(next_out_going_stream_id)); |
554 session_->StreamDraining(2); | 554 session_->StreamDraining(2); |
555 // Number of open outgoing streams should still be the same, because a new | 555 // Number of open outgoing streams should still be the same, because a new |
556 // stream is opened. And the queue should be empty. | 556 // stream is opened. And the queue should be empty. |
557 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); | 557 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); |
558 } | 558 } |
559 | 559 |
560 TEST_P(QuicSimpleServerSessionServerPushTest, | 560 TEST_P(QuicSimpleServerSessionServerPushTest, |
561 ResetPromisedStreamToCancelServerPush) { | 561 ResetPromisedStreamToCancelServerPush) { |
(...skipping 16 matching lines...) Expand all Loading... |
578 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 578 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, 0)); |
579 visitor_->OnRstStream(rst); | 579 visitor_->OnRstStream(rst); |
580 | 580 |
581 // When the first 2 streams becomes draining, the two queued up stream could | 581 // When the first 2 streams becomes draining, the two queued up stream could |
582 // be created. But since one of them was marked cancelled due to RST frame, | 582 // be created. But since one of them was marked cancelled due to RST frame, |
583 // only one queued resource will be sent out. | 583 // only one queued resource will be sent out. |
584 QuicStreamId stream_not_reset = (kMaxStreamsForTest + 1) * 2; | 584 QuicStreamId stream_not_reset = (kMaxStreamsForTest + 1) * 2; |
585 InSequence s; | 585 InSequence s; |
586 EXPECT_CALL(*session_, WriteHeadersMock(stream_not_reset, _, false, | 586 EXPECT_CALL(*session_, WriteHeadersMock(stream_not_reset, _, false, |
587 kDefaultPriority, _)); | 587 kDefaultPriority, _)); |
588 EXPECT_CALL(*connection_, SendStreamData(stream_not_reset, _, 0, false, _)) | 588 EXPECT_CALL(*connection_, SendStreamData(stream_not_reset, _, 0, NO_FIN, _)) |
589 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 589 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
590 EXPECT_CALL(*connection_, SendBlocked(stream_not_reset)); | 590 EXPECT_CALL(*connection_, SendBlocked(stream_not_reset)); |
591 EXPECT_CALL(*session_, | 591 EXPECT_CALL(*session_, |
592 WriteHeadersMock(stream_got_reset, _, false, kDefaultPriority, _)) | 592 WriteHeadersMock(stream_got_reset, _, false, kDefaultPriority, _)) |
593 .Times(0); | 593 .Times(0); |
594 | 594 |
595 session_->StreamDraining(2); | 595 session_->StreamDraining(2); |
596 session_->StreamDraining(4); | 596 session_->StreamDraining(4); |
597 } | 597 } |
598 | 598 |
599 TEST_P(QuicSimpleServerSessionServerPushTest, | 599 TEST_P(QuicSimpleServerSessionServerPushTest, |
600 CloseStreamToHandleMorePromisedStream) { | 600 CloseStreamToHandleMorePromisedStream) { |
601 if (session_->force_hol_blocking()) { | 601 if (session_->force_hol_blocking()) { |
602 return; | 602 return; |
603 } | 603 } |
604 // Tests that closing a open outgoing stream can trigger a promised resource | 604 // Tests that closing a open outgoing stream can trigger a promised resource |
605 // in the queue to be send out. | 605 // in the queue to be send out. |
606 size_t num_resources = kMaxStreamsForTest + 1; | 606 size_t num_resources = kMaxStreamsForTest + 1; |
607 PromisePushResources(num_resources); | 607 PromisePushResources(num_resources); |
608 QuicStreamId stream_to_open = num_resources * 2; | 608 QuicStreamId stream_to_open = num_resources * 2; |
609 | 609 |
610 // Resetting 1st open stream will close the stream and give space for extra | 610 // Resetting 1st open stream will close the stream and give space for extra |
611 // stream to be opened. | 611 // stream to be opened. |
612 QuicStreamId stream_got_reset = 2; | 612 QuicStreamId stream_got_reset = 2; |
613 EXPECT_CALL(*connection_, | 613 EXPECT_CALL(*connection_, |
614 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, _)); | 614 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, _)); |
615 EXPECT_CALL(*session_, | 615 EXPECT_CALL(*session_, |
616 WriteHeadersMock(stream_to_open, _, false, kDefaultPriority, _)); | 616 WriteHeadersMock(stream_to_open, _, false, kDefaultPriority, _)); |
617 EXPECT_CALL(*connection_, SendStreamData(stream_to_open, _, 0, false, _)) | 617 EXPECT_CALL(*connection_, SendStreamData(stream_to_open, _, 0, NO_FIN, _)) |
618 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 618 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
619 | 619 |
620 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); | 620 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); |
621 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); | 621 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); |
622 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); | 622 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); |
623 visitor_->OnRstStream(rst); | 623 visitor_->OnRstStream(rst); |
624 } | 624 } |
625 | 625 |
626 } // namespace | 626 } // namespace |
627 } // namespace test | 627 } // namespace test |
628 } // namespace net | 628 } // namespace net |
OLD | NEW |