| 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/quic/core/quic_server_session_base.h" | 5 #include "net/quic/core/quic_server_session_base.h" |
| 6 | 6 |
| 7 #include <cstdint> | 7 #include <cstdint> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 } | 68 } |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 namespace { | 71 namespace { |
| 72 | 72 |
| 73 class TestServerSession : public QuicServerSessionBase { | 73 class TestServerSession : public QuicServerSessionBase { |
| 74 public: | 74 public: |
| 75 TestServerSession(const QuicConfig& config, | 75 TestServerSession(const QuicConfig& config, |
| 76 QuicConnection* connection, | 76 QuicConnection* connection, |
| 77 QuicServerSessionBase::Visitor* visitor, | 77 QuicServerSessionBase::Visitor* visitor, |
| 78 QuicServerSessionBase::Helper* helper, | 78 QuicCryptoServerStream::Helper* helper, |
| 79 const QuicCryptoServerConfig* crypto_config, | 79 const QuicCryptoServerConfig* crypto_config, |
| 80 QuicCompressedCertsCache* compressed_certs_cache) | 80 QuicCompressedCertsCache* compressed_certs_cache) |
| 81 : QuicServerSessionBase(config, | 81 : QuicServerSessionBase(config, |
| 82 connection, | 82 connection, |
| 83 visitor, | 83 visitor, |
| 84 helper, | 84 helper, |
| 85 crypto_config, | 85 crypto_config, |
| 86 compressed_certs_cache) {} | 86 compressed_certs_cache) {} |
| 87 | 87 |
| 88 ~TestServerSession() override { delete connection(); }; | 88 ~TestServerSession() override { delete connection(); }; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 107 stream->SetPriority(priority); | 107 stream->SetPriority(priority); |
| 108 ActivateStream(stream); | 108 ActivateStream(stream); |
| 109 return stream; | 109 return stream; |
| 110 } | 110 } |
| 111 | 111 |
| 112 QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( | 112 QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( |
| 113 const QuicCryptoServerConfig* crypto_config, | 113 const QuicCryptoServerConfig* crypto_config, |
| 114 QuicCompressedCertsCache* compressed_certs_cache) override { | 114 QuicCompressedCertsCache* compressed_certs_cache) override { |
| 115 return new QuicCryptoServerStream( | 115 return new QuicCryptoServerStream( |
| 116 crypto_config, compressed_certs_cache, | 116 crypto_config, compressed_certs_cache, |
| 117 FLAGS_enable_quic_stateless_reject_support, this); | 117 FLAGS_enable_quic_stateless_reject_support, this, |
| 118 stream_helper()); |
| 118 } | 119 } |
| 119 }; | 120 }; |
| 120 | 121 |
| 121 const size_t kMaxStreamsForTest = 10; | 122 const size_t kMaxStreamsForTest = 10; |
| 122 | 123 |
| 123 class QuicServerSessionBaseTest : public ::testing::TestWithParam<QuicVersion> { | 124 class QuicServerSessionBaseTest : public ::testing::TestWithParam<QuicVersion> { |
| 124 protected: | 125 protected: |
| 125 QuicServerSessionBaseTest() | 126 QuicServerSessionBaseTest() |
| 126 : crypto_config_(QuicCryptoServerConfig::TESTING, | 127 : crypto_config_(QuicCryptoServerConfig::TESTING, |
| 127 QuicRandom::GetInstance(), | 128 QuicRandom::GetInstance(), |
| 128 CryptoTestUtils::ProofSourceForTesting()), | 129 CryptoTestUtils::ProofSourceForTesting()), |
| 129 compressed_certs_cache_( | 130 compressed_certs_cache_( |
| 130 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize) { | 131 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize) { |
| 131 config_.SetMaxStreamsPerConnection(kMaxStreamsForTest, kMaxStreamsForTest); | 132 config_.SetMaxStreamsPerConnection(kMaxStreamsForTest, kMaxStreamsForTest); |
| 132 config_.SetMaxIncomingDynamicStreamsToSend(kMaxStreamsForTest); | 133 config_.SetMaxIncomingDynamicStreamsToSend(kMaxStreamsForTest); |
| 133 QuicConfigPeer::SetReceivedMaxIncomingDynamicStreams(&config_, | 134 QuicConfigPeer::SetReceivedMaxIncomingDynamicStreams(&config_, |
| 134 kMaxStreamsForTest); | 135 kMaxStreamsForTest); |
| 135 config_.SetInitialStreamFlowControlWindowToSend( | 136 config_.SetInitialStreamFlowControlWindowToSend( |
| 136 kInitialStreamFlowControlWindowForTest); | 137 kInitialStreamFlowControlWindowForTest); |
| 137 config_.SetInitialSessionFlowControlWindowToSend( | 138 config_.SetInitialSessionFlowControlWindowToSend( |
| 138 kInitialSessionFlowControlWindowForTest); | 139 kInitialSessionFlowControlWindowForTest); |
| 139 | 140 |
| 140 connection_ = new StrictMock<MockQuicConnection>( | 141 connection_ = new StrictMock<MockQuicConnection>( |
| 141 &helper_, &alarm_factory_, Perspective::IS_SERVER, | 142 &helper_, &alarm_factory_, Perspective::IS_SERVER, |
| 142 SupportedVersions(GetParam())); | 143 SupportedVersions(GetParam())); |
| 143 session_.reset(new TestServerSession(config_, connection_, &owner_, | 144 session_.reset(new TestServerSession(config_, connection_, &owner_, |
| 144 &session_helper_, &crypto_config_, | 145 &stream_helper_, &crypto_config_, |
| 145 &compressed_certs_cache_)); | 146 &compressed_certs_cache_)); |
| 146 MockClock clock; | 147 MockClock clock; |
| 147 handshake_message_.reset(crypto_config_.AddDefaultConfig( | 148 handshake_message_.reset(crypto_config_.AddDefaultConfig( |
| 148 QuicRandom::GetInstance(), &clock, | 149 QuicRandom::GetInstance(), &clock, |
| 149 QuicCryptoServerConfig::ConfigOptions())); | 150 QuicCryptoServerConfig::ConfigOptions())); |
| 150 session_->Initialize(); | 151 session_->Initialize(); |
| 151 visitor_ = QuicConnectionPeer::GetVisitor(connection_); | 152 visitor_ = QuicConnectionPeer::GetVisitor(connection_); |
| 152 } | 153 } |
| 153 | 154 |
| 154 StrictMock<MockQuicServerSessionVisitor> owner_; | 155 StrictMock<MockQuicServerSessionVisitor> owner_; |
| 155 StrictMock<MockQuicServerSessionHelper> session_helper_; | 156 StrictMock<MockQuicCryptoServerStreamHelper> stream_helper_; |
| 156 MockQuicConnectionHelper helper_; | 157 MockQuicConnectionHelper helper_; |
| 157 MockAlarmFactory alarm_factory_; | 158 MockAlarmFactory alarm_factory_; |
| 158 StrictMock<MockQuicConnection>* connection_; | 159 StrictMock<MockQuicConnection>* connection_; |
| 159 QuicConfig config_; | 160 QuicConfig config_; |
| 160 QuicCryptoServerConfig crypto_config_; | 161 QuicCryptoServerConfig crypto_config_; |
| 161 QuicCompressedCertsCache compressed_certs_cache_; | 162 QuicCompressedCertsCache compressed_certs_cache_; |
| 162 std::unique_ptr<TestServerSession> session_; | 163 std::unique_ptr<TestServerSession> session_; |
| 163 std::unique_ptr<CryptoHandshakeMessage> handshake_message_; | 164 std::unique_ptr<CryptoHandshakeMessage> handshake_message_; |
| 164 QuicConnectionVisitorInterface* visitor_; | 165 QuicConnectionVisitorInterface* visitor_; |
| 165 }; | 166 }; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 EXPECT_QUIC_BUG( | 365 EXPECT_QUIC_BUG( |
| 365 QuicServerSessionBasePeer::GetOrCreateDynamicStream(session_.get(), 5), | 366 QuicServerSessionBasePeer::GetOrCreateDynamicStream(session_.get(), 5), |
| 366 "ShouldCreateIncomingDynamicStream called when disconnected"); | 367 "ShouldCreateIncomingDynamicStream called when disconnected"); |
| 367 } | 368 } |
| 368 | 369 |
| 369 class MockQuicCryptoServerStream : public QuicCryptoServerStream { | 370 class MockQuicCryptoServerStream : public QuicCryptoServerStream { |
| 370 public: | 371 public: |
| 371 explicit MockQuicCryptoServerStream( | 372 explicit MockQuicCryptoServerStream( |
| 372 const QuicCryptoServerConfig* crypto_config, | 373 const QuicCryptoServerConfig* crypto_config, |
| 373 QuicCompressedCertsCache* compressed_certs_cache, | 374 QuicCompressedCertsCache* compressed_certs_cache, |
| 374 QuicServerSessionBase* session) | 375 QuicServerSessionBase* session, |
| 376 QuicCryptoServerStream::Helper* helper) |
| 375 : QuicCryptoServerStream(crypto_config, | 377 : QuicCryptoServerStream(crypto_config, |
| 376 compressed_certs_cache, | 378 compressed_certs_cache, |
| 377 FLAGS_enable_quic_stateless_reject_support, | 379 FLAGS_enable_quic_stateless_reject_support, |
| 378 session) {} | 380 session, |
| 381 helper) {} |
| 379 ~MockQuicCryptoServerStream() override {} | 382 ~MockQuicCryptoServerStream() override {} |
| 380 | 383 |
| 381 MOCK_METHOD1(SendServerConfigUpdate, | 384 MOCK_METHOD1(SendServerConfigUpdate, |
| 382 void(const CachedNetworkParameters* cached_network_parameters)); | 385 void(const CachedNetworkParameters* cached_network_parameters)); |
| 383 | 386 |
| 384 void set_encryption_established(bool has_established) { | 387 void set_encryption_established(bool has_established) { |
| 385 encryption_established_ = has_established; | 388 encryption_established_ = has_established; |
| 386 } | 389 } |
| 387 | 390 |
| 388 private: | 391 private: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 404 session_->OnConfigNegotiated(); | 407 session_->OnConfigNegotiated(); |
| 405 EXPECT_TRUE( | 408 EXPECT_TRUE( |
| 406 QuicServerSessionBasePeer::IsBandwidthResumptionEnabled(session_.get())); | 409 QuicServerSessionBasePeer::IsBandwidthResumptionEnabled(session_.get())); |
| 407 | 410 |
| 408 int32_t bandwidth_estimate_kbytes_per_second = 123; | 411 int32_t bandwidth_estimate_kbytes_per_second = 123; |
| 409 int32_t max_bandwidth_estimate_kbytes_per_second = 134; | 412 int32_t max_bandwidth_estimate_kbytes_per_second = 134; |
| 410 int32_t max_bandwidth_estimate_timestamp = 1122334455; | 413 int32_t max_bandwidth_estimate_timestamp = 1122334455; |
| 411 const string serving_region = "not a real region"; | 414 const string serving_region = "not a real region"; |
| 412 session_->set_serving_region(serving_region); | 415 session_->set_serving_region(serving_region); |
| 413 | 416 |
| 414 MockQuicCryptoServerStream* crypto_stream = new MockQuicCryptoServerStream( | 417 MockQuicCryptoServerStream* crypto_stream = |
| 415 &crypto_config_, &compressed_certs_cache_, session_.get()); | 418 new MockQuicCryptoServerStream(&crypto_config_, &compressed_certs_cache_, |
| 419 session_.get(), &stream_helper_); |
| 416 QuicServerSessionBasePeer::SetCryptoStream(session_.get(), crypto_stream); | 420 QuicServerSessionBasePeer::SetCryptoStream(session_.get(), crypto_stream); |
| 417 | 421 |
| 418 // Set some initial bandwidth values. | 422 // Set some initial bandwidth values. |
| 419 QuicSentPacketManager* sent_packet_manager = | 423 QuicSentPacketManager* sent_packet_manager = |
| 420 QuicConnectionPeer::GetSentPacketManager(session_->connection(), | 424 QuicConnectionPeer::GetSentPacketManager(session_->connection(), |
| 421 kDefaultPathId); | 425 kDefaultPathId); |
| 422 QuicSustainedBandwidthRecorder& bandwidth_recorder = | 426 QuicSustainedBandwidthRecorder& bandwidth_recorder = |
| 423 QuicSentPacketManagerPeer::GetBandwidthRecorder(sent_packet_manager); | 427 QuicSentPacketManagerPeer::GetBandwidthRecorder(sent_packet_manager); |
| 424 // Seed an rtt measurement equal to the initial default rtt. | 428 // Seed an rtt measurement equal to the initial default rtt. |
| 425 RttStats* rtt_stats = | 429 RttStats* rtt_stats = |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 EXPECT_FALSE( | 559 EXPECT_FALSE( |
| 556 QuicServerSessionBasePeer::IsBandwidthResumptionEnabled(session_.get())); | 560 QuicServerSessionBasePeer::IsBandwidthResumptionEnabled(session_.get())); |
| 557 session_->OnConfigNegotiated(); | 561 session_->OnConfigNegotiated(); |
| 558 EXPECT_FALSE( | 562 EXPECT_FALSE( |
| 559 QuicServerSessionBasePeer::IsBandwidthResumptionEnabled(session_.get())); | 563 QuicServerSessionBasePeer::IsBandwidthResumptionEnabled(session_.get())); |
| 560 } | 564 } |
| 561 | 565 |
| 562 } // namespace | 566 } // namespace |
| 563 } // namespace test | 567 } // namespace test |
| 564 } // namespace net | 568 } // namespace net |
| OLD | NEW |