| 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 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoServerStream); | 100 DISALLOW_COPY_AND_ASSIGN(MockQuicCryptoServerStream); |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 class MockConnectionWithSendStreamData : public MockConnection { | 103 class MockConnectionWithSendStreamData : public MockConnection { |
| 104 public: | 104 public: |
| 105 MockConnectionWithSendStreamData(MockConnectionHelper* helper, | 105 MockConnectionWithSendStreamData(MockConnectionHelper* helper, |
| 106 Perspective perspective, | 106 Perspective perspective, |
| 107 const QuicVersionVector& supported_versions) | 107 const QuicVersionVector& supported_versions) |
| 108 : MockConnection(helper, perspective, supported_versions) {} | 108 : MockConnection(helper, perspective, supported_versions) {} |
| 109 | 109 |
| 110 MOCK_METHOD6(SendStreamData, | 110 MOCK_METHOD5(SendStreamData, |
| 111 QuicConsumedData(QuicStreamId id, | 111 QuicConsumedData(QuicStreamId id, |
| 112 QuicIOVector iov, | 112 QuicIOVector iov, |
| 113 QuicStreamOffset offset, | 113 QuicStreamOffset offset, |
| 114 bool fin, | 114 bool fin, |
| 115 FecProtection fec_protection, | |
| 116 QuicAckListenerInterface* listern)); | 115 QuicAckListenerInterface* listern)); |
| 117 }; | 116 }; |
| 118 | 117 |
| 119 class QuicSimpleServerSessionPeer { | 118 class QuicSimpleServerSessionPeer { |
| 120 public: | 119 public: |
| 121 static void SetCryptoStream(QuicSimpleServerSession* s, | 120 static void SetCryptoStream(QuicSimpleServerSession* s, |
| 122 QuicCryptoServerStream* crypto_stream) { | 121 QuicCryptoServerStream* crypto_stream) { |
| 123 s->crypto_stream_.reset(crypto_stream); | 122 s->crypto_stream_.reset(crypto_stream); |
| 124 s->static_streams()[kCryptoStreamId] = crypto_stream; | 123 s->static_streams()[kCryptoStreamId] = crypto_stream; |
| 125 } | 124 } |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 // PUSH_PROMISED are sent for all the resources. | 449 // PUSH_PROMISED are sent for all the resources. |
| 451 EXPECT_CALL(*headers_stream_, WritePushPromise(kClientDataStreamId1, | 450 EXPECT_CALL(*headers_stream_, WritePushPromise(kClientDataStreamId1, |
| 452 stream_id, _, nullptr)); | 451 stream_id, _, nullptr)); |
| 453 if (i <= kMaxStreamsForTest) { | 452 if (i <= kMaxStreamsForTest) { |
| 454 // |kMaxStreamsForTest| promised responses should be sent. | 453 // |kMaxStreamsForTest| promised responses should be sent. |
| 455 EXPECT_CALL(*headers_stream_, WriteHeaders(stream_id, _, false, | 454 EXPECT_CALL(*headers_stream_, WriteHeaders(stream_id, _, false, |
| 456 kDefaultPriority, nullptr)); | 455 kDefaultPriority, nullptr)); |
| 457 // Since flow control window is smaller than response body, not the | 456 // Since flow control window is smaller than response body, not the |
| 458 // whole body will be sent. | 457 // whole body will be sent. |
| 459 EXPECT_CALL(*connection_, | 458 EXPECT_CALL(*connection_, |
| 460 SendStreamData(stream_id, _, 0, false, _, nullptr)) | 459 SendStreamData(stream_id, _, 0, false, nullptr)) |
| 461 .WillOnce( | 460 .WillOnce( |
| 462 Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 461 Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
| 463 EXPECT_CALL(*connection_, SendBlocked(stream_id)); | 462 EXPECT_CALL(*connection_, SendBlocked(stream_id)); |
| 464 } | 463 } |
| 465 } | 464 } |
| 466 session_->PromisePushResources(request_url, push_resources, | 465 session_->PromisePushResources(request_url, push_resources, |
| 467 kClientDataStreamId1, request_headers); | 466 kClientDataStreamId1, request_headers); |
| 468 } | 467 } |
| 469 }; | 468 }; |
| 470 | 469 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 487 // draining, a queued promised stream will become open and send push response. | 486 // draining, a queued promised stream will become open and send push response. |
| 488 size_t num_resources = kMaxStreamsForTest + 1; | 487 size_t num_resources = kMaxStreamsForTest + 1; |
| 489 PromisePushResources(num_resources); | 488 PromisePushResources(num_resources); |
| 490 QuicStreamId next_out_going_stream_id = num_resources * 2; | 489 QuicStreamId next_out_going_stream_id = num_resources * 2; |
| 491 | 490 |
| 492 // After an open stream is marked draining, a new stream is expected to be | 491 // After an open stream is marked draining, a new stream is expected to be |
| 493 // created and a response sent on the stream. | 492 // created and a response sent on the stream. |
| 494 EXPECT_CALL(*headers_stream_, WriteHeaders(next_out_going_stream_id, _, false, | 493 EXPECT_CALL(*headers_stream_, WriteHeaders(next_out_going_stream_id, _, false, |
| 495 kDefaultPriority, nullptr)); | 494 kDefaultPriority, nullptr)); |
| 496 EXPECT_CALL(*connection_, | 495 EXPECT_CALL(*connection_, |
| 497 SendStreamData(next_out_going_stream_id, _, 0, false, _, nullptr)) | 496 SendStreamData(next_out_going_stream_id, _, 0, false, nullptr)) |
| 498 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 497 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
| 499 EXPECT_CALL(*connection_, SendBlocked(next_out_going_stream_id)); | 498 EXPECT_CALL(*connection_, SendBlocked(next_out_going_stream_id)); |
| 500 session_->StreamDraining(2); | 499 session_->StreamDraining(2); |
| 501 // Number of open outgoing streams should still be the same, because a new | 500 // Number of open outgoing streams should still be the same, because a new |
| 502 // stream is opened. And the queue should be empty. | 501 // stream is opened. And the queue should be empty. |
| 503 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); | 502 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); |
| 504 } | 503 } |
| 505 | 504 |
| 506 TEST_P(QuicSimpleServerSessionServerPushTest, | 505 TEST_P(QuicSimpleServerSessionServerPushTest, |
| 507 ResetPromisedStreamToCancelServerPush) { | 506 ResetPromisedStreamToCancelServerPush) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 521 visitor_->OnRstStream(rst); | 520 visitor_->OnRstStream(rst); |
| 522 | 521 |
| 523 // When the first 2 streams becomes draining, the two queued up stream could | 522 // When the first 2 streams becomes draining, the two queued up stream could |
| 524 // be created. But since one of them was marked cancelled due to RST frame, | 523 // be created. But since one of them was marked cancelled due to RST frame, |
| 525 // only one queued resource will be sent out. | 524 // only one queued resource will be sent out. |
| 526 QuicStreamId stream_not_reset = (kMaxStreamsForTest + 1) * 2; | 525 QuicStreamId stream_not_reset = (kMaxStreamsForTest + 1) * 2; |
| 527 InSequence s; | 526 InSequence s; |
| 528 EXPECT_CALL(*headers_stream_, WriteHeaders(stream_not_reset, _, false, | 527 EXPECT_CALL(*headers_stream_, WriteHeaders(stream_not_reset, _, false, |
| 529 kDefaultPriority, nullptr)); | 528 kDefaultPriority, nullptr)); |
| 530 EXPECT_CALL(*connection_, | 529 EXPECT_CALL(*connection_, |
| 531 SendStreamData(stream_not_reset, _, 0, false, _, nullptr)) | 530 SendStreamData(stream_not_reset, _, 0, false, nullptr)) |
| 532 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 531 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
| 533 EXPECT_CALL(*connection_, SendBlocked(stream_not_reset)); | 532 EXPECT_CALL(*connection_, SendBlocked(stream_not_reset)); |
| 534 EXPECT_CALL(*headers_stream_, WriteHeaders(stream_got_reset, _, false, | 533 EXPECT_CALL(*headers_stream_, WriteHeaders(stream_got_reset, _, false, |
| 535 kDefaultPriority, nullptr)) | 534 kDefaultPriority, nullptr)) |
| 536 .Times(0); | 535 .Times(0); |
| 537 | 536 |
| 538 session_->StreamDraining(2); | 537 session_->StreamDraining(2); |
| 539 session_->StreamDraining(4); | 538 session_->StreamDraining(4); |
| 540 } | 539 } |
| 541 | 540 |
| 542 TEST_P(QuicSimpleServerSessionServerPushTest, | 541 TEST_P(QuicSimpleServerSessionServerPushTest, |
| 543 CloseStreamToHandleMorePromisedStream) { | 542 CloseStreamToHandleMorePromisedStream) { |
| 544 // Tests that closing a open outgoing stream can trigger a promised resource | 543 // Tests that closing a open outgoing stream can trigger a promised resource |
| 545 // in the queue to be send out. | 544 // in the queue to be send out. |
| 546 size_t num_resources = kMaxStreamsForTest + 1; | 545 size_t num_resources = kMaxStreamsForTest + 1; |
| 547 PromisePushResources(num_resources); | 546 PromisePushResources(num_resources); |
| 548 QuicStreamId stream_to_open = num_resources * 2; | 547 QuicStreamId stream_to_open = num_resources * 2; |
| 549 | 548 |
| 550 // Resetting 1st open stream will close the stream and give space for extra | 549 // Resetting 1st open stream will close the stream and give space for extra |
| 551 // stream to be opened. | 550 // stream to be opened. |
| 552 QuicStreamId stream_got_reset = 2; | 551 QuicStreamId stream_got_reset = 2; |
| 553 EXPECT_CALL(*connection_, | 552 EXPECT_CALL(*connection_, |
| 554 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, _)); | 553 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, _)); |
| 555 EXPECT_CALL(*headers_stream_, WriteHeaders(stream_to_open, _, false, | 554 EXPECT_CALL(*headers_stream_, WriteHeaders(stream_to_open, _, false, |
| 556 kDefaultPriority, nullptr)); | 555 kDefaultPriority, nullptr)); |
| 557 EXPECT_CALL(*connection_, | 556 EXPECT_CALL(*connection_, |
| 558 SendStreamData(stream_to_open, _, 0, false, _, nullptr)) | 557 SendStreamData(stream_to_open, _, 0, false, nullptr)) |
| 559 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 558 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
| 560 | 559 |
| 561 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); | 560 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); |
| 562 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); | 561 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); |
| 563 visitor_->OnRstStream(rst); | 562 visitor_->OnRstStream(rst); |
| 564 } | 563 } |
| 565 | 564 |
| 566 } // namespace | 565 } // namespace |
| 567 } // namespace test | 566 } // namespace test |
| 568 } // namespace net | 567 } // namespace net |
| OLD | NEW |