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