| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 bool fin, | 92 bool fin, |
| 93 SpdyPriority priority, | 93 SpdyPriority priority, |
| 94 QuicAckListenerInterface* ack_listener)); | 94 QuicAckListenerInterface* ack_listener)); |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 class MockQuicCryptoServerStream : public QuicCryptoServerStream { | 97 class MockQuicCryptoServerStream : public QuicCryptoServerStream { |
| 98 public: | 98 public: |
| 99 explicit MockQuicCryptoServerStream( | 99 explicit MockQuicCryptoServerStream( |
| 100 const QuicCryptoServerConfig* crypto_config, | 100 const QuicCryptoServerConfig* crypto_config, |
| 101 QuicCompressedCertsCache* compressed_certs_cache, | 101 QuicCompressedCertsCache* compressed_certs_cache, |
| 102 QuicServerSessionBase* session) | 102 QuicServerSessionBase* session, |
| 103 QuicCryptoServerStream::Helper* helper) |
| 103 : QuicCryptoServerStream(crypto_config, | 104 : QuicCryptoServerStream(crypto_config, |
| 104 compressed_certs_cache, | 105 compressed_certs_cache, |
| 105 FLAGS_enable_quic_stateless_reject_support, | 106 FLAGS_enable_quic_stateless_reject_support, |
| 106 session) {} | 107 session, |
| 108 helper) {} |
| 107 ~MockQuicCryptoServerStream() override {} | 109 ~MockQuicCryptoServerStream() override {} |
| 108 | 110 |
| 109 MOCK_METHOD1(SendServerConfigUpdate, | 111 MOCK_METHOD1(SendServerConfigUpdate, |
| 110 void(const CachedNetworkParameters* cached_network_parameters)); | 112 void(const CachedNetworkParameters* cached_network_parameters)); |
| 111 | 113 |
| 112 void set_encryption_established(bool has_established) { | 114 void set_encryption_established(bool has_established) { |
| 113 encryption_established_ = has_established; | 115 encryption_established_ = has_established; |
| 114 } | 116 } |
| 115 | 117 |
| 116 private: | 118 private: |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 QuicConfigPeer::SetReceivedMaxIncomingDynamicStreams(&config_, | 186 QuicConfigPeer::SetReceivedMaxIncomingDynamicStreams(&config_, |
| 185 kMaxStreamsForTest); | 187 kMaxStreamsForTest); |
| 186 config_.SetInitialStreamFlowControlWindowToSend( | 188 config_.SetInitialStreamFlowControlWindowToSend( |
| 187 kInitialStreamFlowControlWindowForTest); | 189 kInitialStreamFlowControlWindowForTest); |
| 188 config_.SetInitialSessionFlowControlWindowToSend( | 190 config_.SetInitialSessionFlowControlWindowToSend( |
| 189 kInitialSessionFlowControlWindowForTest); | 191 kInitialSessionFlowControlWindowForTest); |
| 190 | 192 |
| 191 connection_ = new StrictMock<MockQuicConnectionWithSendStreamData>( | 193 connection_ = new StrictMock<MockQuicConnectionWithSendStreamData>( |
| 192 &helper_, &alarm_factory_, Perspective::IS_SERVER, | 194 &helper_, &alarm_factory_, Perspective::IS_SERVER, |
| 193 SupportedVersions(GetParam())); | 195 SupportedVersions(GetParam())); |
| 194 session_.reset(new QuicSimpleServerSession( | 196 session_.reset(new QuicSimpleServerSession(config_, connection_, &owner_, |
| 195 config_, connection_, &owner_, &session_helper_, &crypto_config_, | 197 &stream_helper_, &crypto_config_, |
| 196 &compressed_certs_cache_)); | 198 &compressed_certs_cache_)); |
| 197 MockClock clock; | 199 MockClock clock; |
| 198 handshake_message_.reset(crypto_config_.AddDefaultConfig( | 200 handshake_message_.reset(crypto_config_.AddDefaultConfig( |
| 199 QuicRandom::GetInstance(), &clock, | 201 QuicRandom::GetInstance(), &clock, |
| 200 QuicCryptoServerConfig::ConfigOptions())); | 202 QuicCryptoServerConfig::ConfigOptions())); |
| 201 session_->Initialize(); | 203 session_->Initialize(); |
| 202 visitor_ = QuicConnectionPeer::GetVisitor(connection_); | 204 visitor_ = QuicConnectionPeer::GetVisitor(connection_); |
| 203 headers_stream_ = new MockQuicHeadersStream(session_.get()); | 205 headers_stream_ = new MockQuicHeadersStream(session_.get()); |
| 204 QuicSpdySessionPeer::SetHeadersStream(session_.get(), headers_stream_); | 206 QuicSpdySessionPeer::SetHeadersStream(session_.get(), headers_stream_); |
| 205 | 207 |
| 206 session_->OnConfigNegotiated(); | 208 session_->OnConfigNegotiated(); |
| 207 } | 209 } |
| 208 | 210 |
| 209 QuicFlagSaver flags_; // Save/restore all QUIC flag values. | 211 QuicFlagSaver flags_; // Save/restore all QUIC flag values. |
| 210 StrictMock<MockQuicServerSessionVisitor> owner_; | 212 StrictMock<MockQuicServerSessionVisitor> owner_; |
| 211 StrictMock<MockQuicServerSessionHelper> session_helper_; | 213 StrictMock<MockQuicCryptoServerStreamHelper> stream_helper_; |
| 212 MockQuicConnectionHelper helper_; | 214 MockQuicConnectionHelper helper_; |
| 213 MockAlarmFactory alarm_factory_; | 215 MockAlarmFactory alarm_factory_; |
| 214 StrictMock<MockQuicConnectionWithSendStreamData>* connection_; | 216 StrictMock<MockQuicConnectionWithSendStreamData>* connection_; |
| 215 QuicConfig config_; | 217 QuicConfig config_; |
| 216 QuicCryptoServerConfig crypto_config_; | 218 QuicCryptoServerConfig crypto_config_; |
| 217 QuicCompressedCertsCache compressed_certs_cache_; | 219 QuicCompressedCertsCache compressed_certs_cache_; |
| 218 std::unique_ptr<QuicSimpleServerSession> session_; | 220 std::unique_ptr<QuicSimpleServerSession> session_; |
| 219 std::unique_ptr<CryptoHandshakeMessage> handshake_message_; | 221 std::unique_ptr<CryptoHandshakeMessage> handshake_message_; |
| 220 QuicConnectionVisitorInterface* visitor_; | 222 QuicConnectionVisitorInterface* visitor_; |
| 221 MockQuicHeadersStream* headers_stream_; | 223 MockQuicHeadersStream* headers_stream_; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 // stream allowed, creation should fail. | 351 // stream allowed, creation should fail. |
| 350 | 352 |
| 351 // Receive some data to initiate a incoming stream which should not effect | 353 // Receive some data to initiate a incoming stream which should not effect |
| 352 // creating outgoing streams. | 354 // creating outgoing streams. |
| 353 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); | 355 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT")); |
| 354 session_->OnStreamFrame(data1); | 356 session_->OnStreamFrame(data1); |
| 355 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); | 357 EXPECT_EQ(1u, session_->GetNumOpenIncomingStreams()); |
| 356 EXPECT_EQ(0u, session_->GetNumOpenOutgoingStreams()); | 358 EXPECT_EQ(0u, session_->GetNumOpenOutgoingStreams()); |
| 357 | 359 |
| 358 // Assume encryption already established. | 360 // Assume encryption already established. |
| 359 MockQuicCryptoServerStream* crypto_stream = new MockQuicCryptoServerStream( | 361 MockQuicCryptoServerStream* crypto_stream = |
| 360 &crypto_config_, &compressed_certs_cache_, session_.get()); | 362 new MockQuicCryptoServerStream(&crypto_config_, &compressed_certs_cache_, |
| 363 session_.get(), &stream_helper_); |
| 361 crypto_stream->set_encryption_established(true); | 364 crypto_stream->set_encryption_established(true); |
| 362 QuicSimpleServerSessionPeer::SetCryptoStream(session_.get(), crypto_stream); | 365 QuicSimpleServerSessionPeer::SetCryptoStream(session_.get(), crypto_stream); |
| 363 | 366 |
| 364 // Create push streams till reaching the upper limit of allowed open streams. | 367 // Create push streams till reaching the upper limit of allowed open streams. |
| 365 for (size_t i = 0; i < kMaxStreamsForTest; ++i) { | 368 for (size_t i = 0; i < kMaxStreamsForTest; ++i) { |
| 366 QuicSpdyStream* created_stream = | 369 QuicSpdyStream* created_stream = |
| 367 QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( | 370 QuicSimpleServerSessionPeer::CreateOutgoingDynamicStream( |
| 368 session_.get(), kDefaultPriority); | 371 session_.get(), kDefaultPriority); |
| 369 EXPECT_EQ(2 * (i + 1), created_stream->id()); | 372 EXPECT_EQ(2 * (i + 1), created_stream->id()); |
| 370 EXPECT_EQ(i + 1, session_->GetNumOpenOutgoingStreams()); | 373 EXPECT_EQ(i + 1, session_->GetNumOpenOutgoingStreams()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow( | 426 QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow( |
| 424 &config_, kInitialSessionFlowControlWindowForTest); | 427 &config_, kInitialSessionFlowControlWindowForTest); |
| 425 // Enable server push. | 428 // Enable server push. |
| 426 QuicTagVector copt; | 429 QuicTagVector copt; |
| 427 copt.push_back(kSPSH); | 430 copt.push_back(kSPSH); |
| 428 QuicConfigPeer::SetReceivedConnectionOptions(&config_, copt); | 431 QuicConfigPeer::SetReceivedConnectionOptions(&config_, copt); |
| 429 | 432 |
| 430 connection_ = new StrictMock<MockQuicConnectionWithSendStreamData>( | 433 connection_ = new StrictMock<MockQuicConnectionWithSendStreamData>( |
| 431 &helper_, &alarm_factory_, Perspective::IS_SERVER, | 434 &helper_, &alarm_factory_, Perspective::IS_SERVER, |
| 432 SupportedVersions(GetParam())); | 435 SupportedVersions(GetParam())); |
| 433 session_.reset(new QuicSimpleServerSession( | 436 session_.reset(new QuicSimpleServerSession(config_, connection_, &owner_, |
| 434 config_, connection_, &owner_, &session_helper_, &crypto_config_, | 437 &stream_helper_, &crypto_config_, |
| 435 &compressed_certs_cache_)); | 438 &compressed_certs_cache_)); |
| 436 session_->Initialize(); | 439 session_->Initialize(); |
| 437 // 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. |
| 438 session_->OnConfigNegotiated(); | 441 session_->OnConfigNegotiated(); |
| 439 | 442 |
| 440 visitor_ = QuicConnectionPeer::GetVisitor(connection_); | 443 visitor_ = QuicConnectionPeer::GetVisitor(connection_); |
| 441 headers_stream_ = new MockQuicHeadersStream(session_.get()); | 444 headers_stream_ = new MockQuicHeadersStream(session_.get()); |
| 442 QuicSpdySessionPeer::SetHeadersStream(session_.get(), headers_stream_); | 445 QuicSpdySessionPeer::SetHeadersStream(session_.get(), headers_stream_); |
| 443 | 446 |
| 444 // Assume encryption already established. | 447 // Assume encryption already established. |
| 445 MockQuicCryptoServerStream* crypto_stream = new MockQuicCryptoServerStream( | 448 MockQuicCryptoServerStream* crypto_stream = new MockQuicCryptoServerStream( |
| 446 &crypto_config_, &compressed_certs_cache_, session_.get()); | 449 &crypto_config_, &compressed_certs_cache_, session_.get(), |
| 450 &stream_helper_); |
| 451 |
| 447 crypto_stream->set_encryption_established(true); | 452 crypto_stream->set_encryption_established(true); |
| 448 QuicSimpleServerSessionPeer::SetCryptoStream(session_.get(), crypto_stream); | 453 QuicSimpleServerSessionPeer::SetCryptoStream(session_.get(), crypto_stream); |
| 449 } | 454 } |
| 450 | 455 |
| 451 // Given |num_resources|, create this number of fake push resources and push | 456 // Given |num_resources|, create this number of fake push resources and push |
| 452 // them by sending PUSH_PROMISE for all and sending push responses for as much | 457 // them by sending PUSH_PROMISE for all and sending push responses for as much |
| 453 // as possible(limited by kMaxStreamsForTest). | 458 // as possible(limited by kMaxStreamsForTest). |
| 454 // If |num_resources| > kMaxStreamsForTest, the left over will be queued. | 459 // If |num_resources| > kMaxStreamsForTest, the left over will be queued. |
| 455 void PromisePushResources(size_t num_resources) { | 460 void PromisePushResources(size_t num_resources) { |
| 456 // To prevent push streams from being closed the response need to be larger | 461 // To prevent push streams from being closed the response need to be larger |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); | 625 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); |
| 621 | 626 |
| 622 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); | 627 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); |
| 623 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); | 628 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); |
| 624 visitor_->OnRstStream(rst); | 629 visitor_->OnRstStream(rst); |
| 625 } | 630 } |
| 626 | 631 |
| 627 } // namespace | 632 } // namespace |
| 628 } // namespace test | 633 } // namespace test |
| 629 } // namespace net | 634 } // namespace net |
| OLD | NEW |