| 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 18 matching lines...) Expand all Loading... |
| 29 #include "net/quic/test_tools/quic_test_utils.h" | 29 #include "net/quic/test_tools/quic_test_utils.h" |
| 30 #include "net/test/gtest_util.h" | 30 #include "net/test/gtest_util.h" |
| 31 #include "net/tools/quic/quic_simple_server_stream.h" | 31 #include "net/tools/quic/quic_simple_server_stream.h" |
| 32 #include "net/tools/quic/test_tools/mock_quic_server_session_visitor.h" | 32 #include "net/tools/quic/test_tools/mock_quic_server_session_visitor.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 35 | 35 |
| 36 using std::string; | 36 using std::string; |
| 37 using testing::StrictMock; | 37 using testing::StrictMock; |
| 38 using testing::_; | 38 using testing::_; |
| 39 using testing::AtLeast; |
| 39 using testing::InSequence; | 40 using testing::InSequence; |
| 40 using testing::Return; | 41 using testing::Return; |
| 41 using testing::AtLeast; | 42 using testing::StrictMock; |
| 42 | 43 |
| 43 namespace net { | 44 namespace net { |
| 44 namespace test { | 45 namespace test { |
| 45 namespace { | 46 namespace { |
| 46 typedef QuicSimpleServerSession::PromisedStreamInfo PromisedStreamInfo; | 47 typedef QuicSimpleServerSession::PromisedStreamInfo PromisedStreamInfo; |
| 47 } // namespace | 48 } // namespace |
| 48 | 49 |
| 49 class MockQuicHeadersStream : public QuicHeadersStream { | 50 class QuicSimpleServerSessionPeer { |
| 50 public: | 51 public: |
| 51 explicit MockQuicHeadersStream(QuicSpdySession* session) | 52 static void SetCryptoStream(QuicSimpleServerSession* s, |
| 52 : QuicHeadersStream(session) {} | 53 QuicCryptoServerStream* crypto_stream) { |
| 54 s->crypto_stream_.reset(crypto_stream); |
| 55 s->static_streams()[kCryptoStreamId] = crypto_stream; |
| 56 } |
| 53 | 57 |
| 54 // Methods taking non-copyable types like SpdyHeaderBlock by value cannot be | 58 static QuicSpdyStream* CreateIncomingDynamicStream(QuicSimpleServerSession* s, |
| 55 // mocked directly. | 59 QuicStreamId id) { |
| 56 size_t WritePushPromise(QuicStreamId original_stream_id, | 60 return s->CreateIncomingDynamicStream(id); |
| 57 QuicStreamId promised_stream_id, | |
| 58 SpdyHeaderBlock headers) override { | |
| 59 return WritePushPromiseMock(original_stream_id, promised_stream_id, | |
| 60 headers); | |
| 61 } | 61 } |
| 62 MOCK_METHOD3(WritePushPromiseMock, | |
| 63 size_t(QuicStreamId original_stream_id, | |
| 64 QuicStreamId promised_stream_id, | |
| 65 const SpdyHeaderBlock& headers)); | |
| 66 | 62 |
| 67 size_t WriteHeaders(QuicStreamId stream_id, | 63 static QuicSimpleServerStream* CreateOutgoingDynamicStream( |
| 68 SpdyHeaderBlock headers, | 64 QuicSimpleServerSession* s, |
| 69 bool fin, | 65 SpdyPriority priority) { |
| 70 SpdyPriority priority, | 66 return s->CreateOutgoingDynamicStream(priority); |
| 71 QuicReferenceCountedPointer<QuicAckListenerInterface> | |
| 72 ack_listener) override { | |
| 73 return WriteHeadersMock(stream_id, headers, fin, priority, ack_listener); | |
| 74 } | 67 } |
| 75 MOCK_METHOD5( | 68 |
| 76 WriteHeadersMock, | 69 static std::deque<PromisedStreamInfo>* promised_streams( |
| 77 size_t(QuicStreamId stream_id, | 70 QuicSimpleServerSession* s) { |
| 78 const SpdyHeaderBlock& headers, | 71 return &(s->promised_streams_); |
| 79 bool fin, | 72 } |
| 80 SpdyPriority priority, | 73 |
| 81 const QuicReferenceCountedPointer<QuicAckListenerInterface>& | 74 static QuicStreamId hightest_promised_stream_id(QuicSimpleServerSession* s) { |
| 82 ack_listener)); | 75 return s->highest_promised_stream_id_; |
| 76 } |
| 83 }; | 77 }; |
| 84 | 78 |
| 79 namespace { |
| 80 |
| 81 const size_t kMaxStreamsForTest = 10; |
| 82 |
| 85 class MockQuicCryptoServerStream : public QuicCryptoServerStream { | 83 class MockQuicCryptoServerStream : public QuicCryptoServerStream { |
| 86 public: | 84 public: |
| 87 explicit MockQuicCryptoServerStream( | 85 explicit MockQuicCryptoServerStream( |
| 88 const QuicCryptoServerConfig* crypto_config, | 86 const QuicCryptoServerConfig* crypto_config, |
| 89 QuicCompressedCertsCache* compressed_certs_cache, | 87 QuicCompressedCertsCache* compressed_certs_cache, |
| 90 QuicServerSessionBase* session, | 88 QuicServerSessionBase* session, |
| 91 QuicCryptoServerStream::Helper* helper) | 89 QuicCryptoServerStream::Helper* helper) |
| 92 : QuicCryptoServerStream( | 90 : QuicCryptoServerStream( |
| 93 crypto_config, | 91 crypto_config, |
| 94 compressed_certs_cache, | 92 compressed_certs_cache, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 123 MOCK_METHOD5( | 121 MOCK_METHOD5( |
| 124 SendStreamData, | 122 SendStreamData, |
| 125 QuicConsumedData( | 123 QuicConsumedData( |
| 126 QuicStreamId id, | 124 QuicStreamId id, |
| 127 QuicIOVector iov, | 125 QuicIOVector iov, |
| 128 QuicStreamOffset offset, | 126 QuicStreamOffset offset, |
| 129 bool fin, | 127 bool fin, |
| 130 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener)); | 128 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener)); |
| 131 }; | 129 }; |
| 132 | 130 |
| 133 class QuicSimpleServerSessionPeer { | 131 class MockQuicSimpleServerSession : public QuicSimpleServerSession { |
| 134 public: | 132 public: |
| 135 static void SetCryptoStream(QuicSimpleServerSession* s, | 133 MockQuicSimpleServerSession(const QuicConfig& config, |
| 136 QuicCryptoServerStream* crypto_stream) { | 134 QuicConnection* connection, |
| 137 s->crypto_stream_.reset(crypto_stream); | 135 QuicSession::Visitor* visitor, |
| 138 s->static_streams()[kCryptoStreamId] = crypto_stream; | 136 QuicCryptoServerStream::Helper* helper, |
| 137 const QuicCryptoServerConfig* crypto_config, |
| 138 QuicCompressedCertsCache* compressed_certs_cache, |
| 139 QuicHttpResponseCache* response_cache) |
| 140 : QuicSimpleServerSession(config, |
| 141 connection, |
| 142 visitor, |
| 143 helper, |
| 144 crypto_config, |
| 145 compressed_certs_cache, |
| 146 response_cache) {} |
| 147 // Methods taking non-copyable types like SpdyHeaderBlock by value cannot be |
| 148 // mocked directly. |
| 149 size_t WritePushPromise(QuicStreamId original_stream_id, |
| 150 QuicStreamId promised_stream_id, |
| 151 SpdyHeaderBlock headers) override { |
| 152 return WritePushPromiseMock(original_stream_id, promised_stream_id, |
| 153 headers); |
| 139 } | 154 } |
| 155 MOCK_METHOD3(WritePushPromiseMock, |
| 156 size_t(QuicStreamId original_stream_id, |
| 157 QuicStreamId promised_stream_id, |
| 158 const SpdyHeaderBlock& headers)); |
| 140 | 159 |
| 141 static QuicSpdyStream* CreateIncomingDynamicStream(QuicSimpleServerSession* s, | 160 size_t WriteHeaders(QuicStreamId stream_id, |
| 142 QuicStreamId id) { | 161 SpdyHeaderBlock headers, |
| 143 return s->CreateIncomingDynamicStream(id); | 162 bool fin, |
| 163 SpdyPriority priority, |
| 164 QuicReferenceCountedPointer<QuicAckListenerInterface> |
| 165 ack_listener) override { |
| 166 return WriteHeadersMock(stream_id, headers, fin, priority, ack_listener); |
| 144 } | 167 } |
| 145 | 168 MOCK_METHOD5( |
| 146 static QuicSimpleServerStream* CreateOutgoingDynamicStream( | 169 WriteHeadersMock, |
| 147 QuicSimpleServerSession* s, | 170 size_t(QuicStreamId stream_id, |
| 148 SpdyPriority priority) { | 171 const SpdyHeaderBlock& headers, |
| 149 return s->CreateOutgoingDynamicStream(priority); | 172 bool fin, |
| 150 } | 173 SpdyPriority priority, |
| 151 | 174 const QuicReferenceCountedPointer<QuicAckListenerInterface>& |
| 152 static std::deque<PromisedStreamInfo>* promised_streams( | 175 ack_listener)); |
| 153 QuicSimpleServerSession* s) { | |
| 154 return &(s->promised_streams_); | |
| 155 } | |
| 156 | |
| 157 static QuicStreamId hightest_promised_stream_id(QuicSimpleServerSession* s) { | |
| 158 return s->highest_promised_stream_id_; | |
| 159 } | |
| 160 }; | 176 }; |
| 161 | 177 |
| 162 namespace { | |
| 163 | |
| 164 const size_t kMaxStreamsForTest = 10; | |
| 165 | |
| 166 class QuicSimpleServerSessionTest | 178 class QuicSimpleServerSessionTest |
| 167 : public ::testing::TestWithParam<QuicVersion> { | 179 : public ::testing::TestWithParam<QuicVersion> { |
| 168 protected: | 180 protected: |
| 169 QuicSimpleServerSessionTest() | 181 QuicSimpleServerSessionTest() |
| 170 : crypto_config_(QuicCryptoServerConfig::TESTING, | 182 : crypto_config_(QuicCryptoServerConfig::TESTING, |
| 171 QuicRandom::GetInstance(), | 183 QuicRandom::GetInstance(), |
| 172 CryptoTestUtils::ProofSourceForTesting()), | 184 CryptoTestUtils::ProofSourceForTesting()), |
| 173 compressed_certs_cache_( | 185 compressed_certs_cache_( |
| 174 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize) { | 186 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize) { |
| 175 config_.SetMaxStreamsPerConnection(kMaxStreamsForTest, kMaxStreamsForTest); | 187 config_.SetMaxStreamsPerConnection(kMaxStreamsForTest, kMaxStreamsForTest); |
| 176 config_.SetMaxIncomingDynamicStreamsToSend(kMaxStreamsForTest); | 188 config_.SetMaxIncomingDynamicStreamsToSend(kMaxStreamsForTest); |
| 177 QuicConfigPeer::SetReceivedMaxIncomingDynamicStreams(&config_, | 189 QuicConfigPeer::SetReceivedMaxIncomingDynamicStreams(&config_, |
| 178 kMaxStreamsForTest); | 190 kMaxStreamsForTest); |
| 179 config_.SetInitialStreamFlowControlWindowToSend( | 191 config_.SetInitialStreamFlowControlWindowToSend( |
| 180 kInitialStreamFlowControlWindowForTest); | 192 kInitialStreamFlowControlWindowForTest); |
| 181 config_.SetInitialSessionFlowControlWindowToSend( | 193 config_.SetInitialSessionFlowControlWindowToSend( |
| 182 kInitialSessionFlowControlWindowForTest); | 194 kInitialSessionFlowControlWindowForTest); |
| 183 | 195 |
| 184 connection_ = new StrictMock<MockQuicConnectionWithSendStreamData>( | 196 connection_ = new StrictMock<MockQuicConnectionWithSendStreamData>( |
| 185 &helper_, &alarm_factory_, Perspective::IS_SERVER, | 197 &helper_, &alarm_factory_, Perspective::IS_SERVER, |
| 186 SupportedVersions(GetParam())); | 198 SupportedVersions(GetParam())); |
| 187 session_.reset(new QuicSimpleServerSession( | 199 session_.reset(new MockQuicSimpleServerSession( |
| 188 config_, connection_, &owner_, &stream_helper_, &crypto_config_, | 200 config_, connection_, &owner_, &stream_helper_, &crypto_config_, |
| 189 &compressed_certs_cache_, &response_cache_)); | 201 &compressed_certs_cache_, &response_cache_)); |
| 190 MockClock clock; | 202 MockClock clock; |
| 191 handshake_message_.reset(crypto_config_.AddDefaultConfig( | 203 handshake_message_.reset(crypto_config_.AddDefaultConfig( |
| 192 QuicRandom::GetInstance(), &clock, | 204 QuicRandom::GetInstance(), &clock, |
| 193 QuicCryptoServerConfig::ConfigOptions())); | 205 QuicCryptoServerConfig::ConfigOptions())); |
| 194 session_->Initialize(); | 206 session_->Initialize(); |
| 195 visitor_ = QuicConnectionPeer::GetVisitor(connection_); | 207 visitor_ = QuicConnectionPeer::GetVisitor(connection_); |
| 196 headers_stream_ = new MockQuicHeadersStream(session_.get()); | |
| 197 QuicSpdySessionPeer::SetHeadersStream(session_.get(), headers_stream_); | |
| 198 | 208 |
| 199 session_->OnConfigNegotiated(); | 209 session_->OnConfigNegotiated(); |
| 200 } | 210 } |
| 201 | 211 |
| 202 StrictMock<MockQuicSessionVisitor> owner_; | 212 StrictMock<MockQuicSessionVisitor> owner_; |
| 203 StrictMock<MockQuicCryptoServerStreamHelper> stream_helper_; | 213 StrictMock<MockQuicCryptoServerStreamHelper> stream_helper_; |
| 204 MockQuicConnectionHelper helper_; | 214 MockQuicConnectionHelper helper_; |
| 205 MockAlarmFactory alarm_factory_; | 215 MockAlarmFactory alarm_factory_; |
| 206 StrictMock<MockQuicConnectionWithSendStreamData>* connection_; | 216 StrictMock<MockQuicConnectionWithSendStreamData>* connection_; |
| 207 QuicConfig config_; | 217 QuicConfig config_; |
| 208 QuicCryptoServerConfig crypto_config_; | 218 QuicCryptoServerConfig crypto_config_; |
| 209 QuicCompressedCertsCache compressed_certs_cache_; | 219 QuicCompressedCertsCache compressed_certs_cache_; |
| 210 QuicHttpResponseCache response_cache_; | 220 QuicHttpResponseCache response_cache_; |
| 211 std::unique_ptr<QuicSimpleServerSession> session_; | 221 std::unique_ptr<MockQuicSimpleServerSession> session_; |
| 212 std::unique_ptr<CryptoHandshakeMessage> handshake_message_; | 222 std::unique_ptr<CryptoHandshakeMessage> handshake_message_; |
| 213 QuicConnectionVisitorInterface* visitor_; | 223 QuicConnectionVisitorInterface* visitor_; |
| 214 MockQuicHeadersStream* headers_stream_; | |
| 215 }; | 224 }; |
| 216 | 225 |
| 217 INSTANTIATE_TEST_CASE_P(Tests, | 226 INSTANTIATE_TEST_CASE_P(Tests, |
| 218 QuicSimpleServerSessionTest, | 227 QuicSimpleServerSessionTest, |
| 219 ::testing::ValuesIn(AllSupportedVersions())); | 228 ::testing::ValuesIn(AllSupportedVersions())); |
| 220 | 229 |
| 221 TEST_P(QuicSimpleServerSessionTest, CloseStreamDueToReset) { | 230 TEST_P(QuicSimpleServerSessionTest, CloseStreamDueToReset) { |
| 222 // Open a stream, then reset it. | 231 // Open a stream, then reset it. |
| 223 // Send two bytes of payload to open it. | 232 // Send two bytes of payload to open it. |
| 224 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); | 233 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow( | 426 QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow( |
| 418 &config_, kInitialSessionFlowControlWindowForTest); | 427 &config_, kInitialSessionFlowControlWindowForTest); |
| 419 // Enable server push. | 428 // Enable server push. |
| 420 QuicTagVector copt; | 429 QuicTagVector copt; |
| 421 copt.push_back(kSPSH); | 430 copt.push_back(kSPSH); |
| 422 QuicConfigPeer::SetReceivedConnectionOptions(&config_, copt); | 431 QuicConfigPeer::SetReceivedConnectionOptions(&config_, copt); |
| 423 | 432 |
| 424 connection_ = new StrictMock<MockQuicConnectionWithSendStreamData>( | 433 connection_ = new StrictMock<MockQuicConnectionWithSendStreamData>( |
| 425 &helper_, &alarm_factory_, Perspective::IS_SERVER, | 434 &helper_, &alarm_factory_, Perspective::IS_SERVER, |
| 426 SupportedVersions(GetParam())); | 435 SupportedVersions(GetParam())); |
| 427 session_.reset(new QuicSimpleServerSession( | 436 session_.reset(new MockQuicSimpleServerSession( |
| 428 config_, connection_, &owner_, &stream_helper_, &crypto_config_, | 437 config_, connection_, &owner_, &stream_helper_, &crypto_config_, |
| 429 &compressed_certs_cache_, &response_cache_)); | 438 &compressed_certs_cache_, &response_cache_)); |
| 430 session_->Initialize(); | 439 session_->Initialize(); |
| 431 // Needed to make new session flow control window and server push work. | 440 // Needed to make new session flow control window and server push work. |
| 432 session_->OnConfigNegotiated(); | 441 session_->OnConfigNegotiated(); |
| 433 | 442 |
| 434 visitor_ = QuicConnectionPeer::GetVisitor(connection_); | 443 visitor_ = QuicConnectionPeer::GetVisitor(connection_); |
| 435 headers_stream_ = new MockQuicHeadersStream(session_.get()); | |
| 436 QuicSpdySessionPeer::SetHeadersStream(session_.get(), headers_stream_); | |
| 437 | 444 |
| 438 // Assume encryption already established. | 445 // Assume encryption already established. |
| 439 MockQuicCryptoServerStream* crypto_stream = new MockQuicCryptoServerStream( | 446 MockQuicCryptoServerStream* crypto_stream = new MockQuicCryptoServerStream( |
| 440 &crypto_config_, &compressed_certs_cache_, session_.get(), | 447 &crypto_config_, &compressed_certs_cache_, session_.get(), |
| 441 &stream_helper_); | 448 &stream_helper_); |
| 442 | 449 |
| 443 crypto_stream->set_encryption_established(true); | 450 crypto_stream->set_encryption_established(true); |
| 444 QuicSimpleServerSessionPeer::SetCryptoStream(session_.get(), crypto_stream); | 451 QuicSimpleServerSessionPeer::SetCryptoStream(session_.get(), crypto_stream); |
| 445 } | 452 } |
| 446 | 453 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 465 QuicStreamId stream_id = i * 2; | 472 QuicStreamId stream_id = i * 2; |
| 466 string path = | 473 string path = |
| 467 partial_push_resource_path + QuicTextUtils::Uint64ToString(i); | 474 partial_push_resource_path + QuicTextUtils::Uint64ToString(i); |
| 468 string url = scheme + "://" + resource_host + path; | 475 string url = scheme + "://" + resource_host + path; |
| 469 GURL resource_url = GURL(url); | 476 GURL resource_url = GURL(url); |
| 470 string body(body_size, 'a'); | 477 string body(body_size, 'a'); |
| 471 response_cache_.AddSimpleResponse(resource_host, path, 200, body); | 478 response_cache_.AddSimpleResponse(resource_host, path, 200, body); |
| 472 push_resources.push_back(QuicHttpResponseCache::ServerPushInfo( | 479 push_resources.push_back(QuicHttpResponseCache::ServerPushInfo( |
| 473 resource_url, SpdyHeaderBlock(), kDefaultPriority, body)); | 480 resource_url, SpdyHeaderBlock(), kDefaultPriority, body)); |
| 474 // PUSH_PROMISED are sent for all the resources. | 481 // PUSH_PROMISED are sent for all the resources. |
| 475 EXPECT_CALL(*headers_stream_, | 482 EXPECT_CALL(*session_, |
| 476 WritePushPromiseMock(kClientDataStreamId1, stream_id, _)); | 483 WritePushPromiseMock(kClientDataStreamId1, stream_id, _)); |
| 477 if (i <= kMaxStreamsForTest) { | 484 if (i <= kMaxStreamsForTest) { |
| 478 // |kMaxStreamsForTest| promised responses should be sent. | 485 // |kMaxStreamsForTest| promised responses should be sent. |
| 479 EXPECT_CALL(*headers_stream_, | 486 EXPECT_CALL(*session_, |
| 480 WriteHeadersMock(stream_id, _, false, kDefaultPriority, _)); | 487 WriteHeadersMock(stream_id, _, false, kDefaultPriority, _)); |
| 481 // Since flow control window is smaller than response body, not the | 488 // Since flow control window is smaller than response body, not the |
| 482 // whole body will be sent. | 489 // whole body will be sent. |
| 483 if (!session_->force_hol_blocking()) { | 490 if (!session_->force_hol_blocking()) { |
| 484 EXPECT_CALL(*connection_, SendStreamData(stream_id, _, 0, false, _)) | 491 EXPECT_CALL(*connection_, SendStreamData(stream_id, _, 0, false, _)) |
| 485 .WillOnce(Return( | 492 .WillOnce(Return( |
| 486 QuicConsumedData(kStreamFlowControlWindowSize, false))); | 493 QuicConsumedData(kStreamFlowControlWindowSize, false))); |
| 487 EXPECT_CALL(*connection_, SendBlocked(stream_id)); | 494 EXPECT_CALL(*connection_, SendBlocked(stream_id)); |
| 488 } else { | 495 } else { |
| 489 // The forced HOL blocking encapsulates the stream data into | 496 // The forced HOL blocking encapsulates the stream data into |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 } | 536 } |
| 530 | 537 |
| 531 // Tests that after promised stream queued up, when an opened stream is marked | 538 // Tests that after promised stream queued up, when an opened stream is marked |
| 532 // draining, a queued promised stream will become open and send push response. | 539 // draining, a queued promised stream will become open and send push response. |
| 533 size_t num_resources = kMaxStreamsForTest + 1; | 540 size_t num_resources = kMaxStreamsForTest + 1; |
| 534 PromisePushResources(num_resources); | 541 PromisePushResources(num_resources); |
| 535 QuicStreamId next_out_going_stream_id = num_resources * 2; | 542 QuicStreamId next_out_going_stream_id = num_resources * 2; |
| 536 | 543 |
| 537 // After an open stream is marked draining, a new stream is expected to be | 544 // After an open stream is marked draining, a new stream is expected to be |
| 538 // created and a response sent on the stream. | 545 // created and a response sent on the stream. |
| 539 EXPECT_CALL(*headers_stream_, WriteHeadersMock(next_out_going_stream_id, _, | 546 EXPECT_CALL(*session_, WriteHeadersMock(next_out_going_stream_id, _, false, |
| 540 false, kDefaultPriority, _)); | 547 kDefaultPriority, _)); |
| 541 EXPECT_CALL(*connection_, | 548 EXPECT_CALL(*connection_, |
| 542 SendStreamData(next_out_going_stream_id, _, 0, false, _)) | 549 SendStreamData(next_out_going_stream_id, _, 0, false, _)) |
| 543 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 550 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
| 544 EXPECT_CALL(*connection_, SendBlocked(next_out_going_stream_id)); | 551 EXPECT_CALL(*connection_, SendBlocked(next_out_going_stream_id)); |
| 545 session_->StreamDraining(2); | 552 session_->StreamDraining(2); |
| 546 // Number of open outgoing streams should still be the same, because a new | 553 // Number of open outgoing streams should still be the same, because a new |
| 547 // stream is opened. And the queue should be empty. | 554 // stream is opened. And the queue should be empty. |
| 548 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); | 555 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); |
| 549 } | 556 } |
| 550 | 557 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 566 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); | 573 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); |
| 567 EXPECT_CALL(*connection_, | 574 EXPECT_CALL(*connection_, |
| 568 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 575 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, 0)); |
| 569 visitor_->OnRstStream(rst); | 576 visitor_->OnRstStream(rst); |
| 570 | 577 |
| 571 // When the first 2 streams becomes draining, the two queued up stream could | 578 // When the first 2 streams becomes draining, the two queued up stream could |
| 572 // be created. But since one of them was marked cancelled due to RST frame, | 579 // be created. But since one of them was marked cancelled due to RST frame, |
| 573 // only one queued resource will be sent out. | 580 // only one queued resource will be sent out. |
| 574 QuicStreamId stream_not_reset = (kMaxStreamsForTest + 1) * 2; | 581 QuicStreamId stream_not_reset = (kMaxStreamsForTest + 1) * 2; |
| 575 InSequence s; | 582 InSequence s; |
| 576 EXPECT_CALL(*headers_stream_, WriteHeadersMock(stream_not_reset, _, false, | 583 EXPECT_CALL(*session_, WriteHeadersMock(stream_not_reset, _, false, |
| 577 kDefaultPriority, _)); | 584 kDefaultPriority, _)); |
| 578 EXPECT_CALL(*connection_, SendStreamData(stream_not_reset, _, 0, false, _)) | 585 EXPECT_CALL(*connection_, SendStreamData(stream_not_reset, _, 0, false, _)) |
| 579 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 586 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
| 580 EXPECT_CALL(*connection_, SendBlocked(stream_not_reset)); | 587 EXPECT_CALL(*connection_, SendBlocked(stream_not_reset)); |
| 581 EXPECT_CALL(*headers_stream_, | 588 EXPECT_CALL(*session_, |
| 582 WriteHeadersMock(stream_got_reset, _, false, kDefaultPriority, _)) | 589 WriteHeadersMock(stream_got_reset, _, false, kDefaultPriority, _)) |
| 583 .Times(0); | 590 .Times(0); |
| 584 | 591 |
| 585 session_->StreamDraining(2); | 592 session_->StreamDraining(2); |
| 586 session_->StreamDraining(4); | 593 session_->StreamDraining(4); |
| 587 } | 594 } |
| 588 | 595 |
| 589 TEST_P(QuicSimpleServerSessionServerPushTest, | 596 TEST_P(QuicSimpleServerSessionServerPushTest, |
| 590 CloseStreamToHandleMorePromisedStream) { | 597 CloseStreamToHandleMorePromisedStream) { |
| 591 if (session_->force_hol_blocking()) { | 598 if (session_->force_hol_blocking()) { |
| 592 return; | 599 return; |
| 593 } | 600 } |
| 594 // Tests that closing a open outgoing stream can trigger a promised resource | 601 // Tests that closing a open outgoing stream can trigger a promised resource |
| 595 // in the queue to be send out. | 602 // in the queue to be send out. |
| 596 size_t num_resources = kMaxStreamsForTest + 1; | 603 size_t num_resources = kMaxStreamsForTest + 1; |
| 597 PromisePushResources(num_resources); | 604 PromisePushResources(num_resources); |
| 598 QuicStreamId stream_to_open = num_resources * 2; | 605 QuicStreamId stream_to_open = num_resources * 2; |
| 599 | 606 |
| 600 // Resetting 1st open stream will close the stream and give space for extra | 607 // Resetting 1st open stream will close the stream and give space for extra |
| 601 // stream to be opened. | 608 // stream to be opened. |
| 602 QuicStreamId stream_got_reset = 2; | 609 QuicStreamId stream_got_reset = 2; |
| 603 EXPECT_CALL(*connection_, | 610 EXPECT_CALL(*connection_, |
| 604 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, _)); | 611 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, _)); |
| 605 EXPECT_CALL(*headers_stream_, | 612 EXPECT_CALL(*session_, |
| 606 WriteHeadersMock(stream_to_open, _, false, kDefaultPriority, _)); | 613 WriteHeadersMock(stream_to_open, _, false, kDefaultPriority, _)); |
| 607 EXPECT_CALL(*connection_, SendStreamData(stream_to_open, _, 0, false, _)) | 614 EXPECT_CALL(*connection_, SendStreamData(stream_to_open, _, 0, false, _)) |
| 608 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 615 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
| 609 | 616 |
| 610 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); | 617 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); |
| 611 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); | 618 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); |
| 612 visitor_->OnRstStream(rst); | 619 visitor_->OnRstStream(rst); |
| 613 } | 620 } |
| 614 | 621 |
| 615 } // namespace | 622 } // namespace |
| 616 } // namespace test | 623 } // namespace test |
| 617 } // namespace net | 624 } // namespace net |
| OLD | NEW |