Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(920)

Side by Side Diff: net/quic/core/quic_server_session_base_test.cc

Issue 2518063007: Pass QuicInMemoryCache directly instead of using a singleton. (Closed)
Patch Set: Fix Cronet compile error Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 namespace { 77 namespace {
78 78
79 class TestServerSession : public QuicServerSessionBase { 79 class TestServerSession : public QuicServerSessionBase {
80 public: 80 public:
81 TestServerSession(const QuicConfig& config, 81 TestServerSession(const QuicConfig& config,
82 QuicConnection* connection, 82 QuicConnection* connection,
83 QuicSession::Visitor* visitor, 83 QuicSession::Visitor* visitor,
84 QuicCryptoServerStream::Helper* helper, 84 QuicCryptoServerStream::Helper* helper,
85 const QuicCryptoServerConfig* crypto_config, 85 const QuicCryptoServerConfig* crypto_config,
86 QuicCompressedCertsCache* compressed_certs_cache) 86 QuicCompressedCertsCache* compressed_certs_cache,
87 QuicInMemoryCache* in_memory_cache)
87 : QuicServerSessionBase(config, 88 : QuicServerSessionBase(config,
88 connection, 89 connection,
89 visitor, 90 visitor,
90 helper, 91 helper,
91 crypto_config, 92 crypto_config,
92 compressed_certs_cache) {} 93 compressed_certs_cache),
94 in_memory_cache_(in_memory_cache) {}
93 95
94 ~TestServerSession() override { delete connection(); }; 96 ~TestServerSession() override { delete connection(); };
95 97
96 protected: 98 protected:
97 QuicSpdyStream* CreateIncomingDynamicStream(QuicStreamId id) override { 99 QuicSpdyStream* CreateIncomingDynamicStream(QuicStreamId id) override {
98 if (!ShouldCreateIncomingDynamicStream(id)) { 100 if (!ShouldCreateIncomingDynamicStream(id)) {
99 return nullptr; 101 return nullptr;
100 } 102 }
101 QuicSpdyStream* stream = new QuicSimpleServerStream(id, this); 103 QuicSpdyStream* stream =
104 new QuicSimpleServerStream(id, this, in_memory_cache_);
102 ActivateStream(base::WrapUnique(stream)); 105 ActivateStream(base::WrapUnique(stream));
103 return stream; 106 return stream;
104 } 107 }
105 108
106 QuicSpdyStream* CreateOutgoingDynamicStream(SpdyPriority priority) override { 109 QuicSpdyStream* CreateOutgoingDynamicStream(SpdyPriority priority) override {
107 if (!ShouldCreateOutgoingDynamicStream()) { 110 if (!ShouldCreateOutgoingDynamicStream()) {
108 return nullptr; 111 return nullptr;
109 } 112 }
110 113
111 QuicSpdyStream* stream = 114 QuicSpdyStream* stream = new QuicSimpleServerStream(
112 new QuicSimpleServerStream(GetNextOutgoingStreamId(), this); 115 GetNextOutgoingStreamId(), this, in_memory_cache_);
113 stream->SetPriority(priority); 116 stream->SetPriority(priority);
114 ActivateStream(base::WrapUnique(stream)); 117 ActivateStream(base::WrapUnique(stream));
115 return stream; 118 return stream;
116 } 119 }
117 120
118 QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( 121 QuicCryptoServerStreamBase* CreateQuicCryptoServerStream(
119 const QuicCryptoServerConfig* crypto_config, 122 const QuicCryptoServerConfig* crypto_config,
120 QuicCompressedCertsCache* compressed_certs_cache) override { 123 QuicCompressedCertsCache* compressed_certs_cache) override {
121 return new QuicCryptoServerStream( 124 return new QuicCryptoServerStream(
122 crypto_config, compressed_certs_cache, 125 crypto_config, compressed_certs_cache,
123 FLAGS_enable_quic_stateless_reject_support, this, stream_helper()); 126 FLAGS_enable_quic_stateless_reject_support, this, stream_helper());
124 } 127 }
128
129 private:
130 QuicInMemoryCache* in_memory_cache_; // Owned by QuicServerSessionBaseTest.
125 }; 131 };
126 132
127 const size_t kMaxStreamsForTest = 10; 133 const size_t kMaxStreamsForTest = 10;
128 134
129 class QuicServerSessionBaseTest : public ::testing::TestWithParam<QuicVersion> { 135 class QuicServerSessionBaseTest : public ::testing::TestWithParam<QuicVersion> {
130 protected: 136 protected:
131 QuicServerSessionBaseTest() 137 QuicServerSessionBaseTest()
132 : QuicServerSessionBaseTest(CryptoTestUtils::ProofSourceForTesting()) {} 138 : QuicServerSessionBaseTest(CryptoTestUtils::ProofSourceForTesting()) {}
133 139
134 explicit QuicServerSessionBaseTest(std::unique_ptr<ProofSource> proof_source) 140 explicit QuicServerSessionBaseTest(std::unique_ptr<ProofSource> proof_source)
135 : crypto_config_(QuicCryptoServerConfig::TESTING, 141 : crypto_config_(QuicCryptoServerConfig::TESTING,
136 QuicRandom::GetInstance(), 142 QuicRandom::GetInstance(),
137 std::move(proof_source)), 143 std::move(proof_source)),
138 compressed_certs_cache_( 144 compressed_certs_cache_(
139 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize) { 145 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize) {
140 config_.SetMaxStreamsPerConnection(kMaxStreamsForTest, kMaxStreamsForTest); 146 config_.SetMaxStreamsPerConnection(kMaxStreamsForTest, kMaxStreamsForTest);
141 config_.SetMaxIncomingDynamicStreamsToSend(kMaxStreamsForTest); 147 config_.SetMaxIncomingDynamicStreamsToSend(kMaxStreamsForTest);
142 QuicConfigPeer::SetReceivedMaxIncomingDynamicStreams(&config_, 148 QuicConfigPeer::SetReceivedMaxIncomingDynamicStreams(&config_,
143 kMaxStreamsForTest); 149 kMaxStreamsForTest);
144 config_.SetInitialStreamFlowControlWindowToSend( 150 config_.SetInitialStreamFlowControlWindowToSend(
145 kInitialStreamFlowControlWindowForTest); 151 kInitialStreamFlowControlWindowForTest);
146 config_.SetInitialSessionFlowControlWindowToSend( 152 config_.SetInitialSessionFlowControlWindowToSend(
147 kInitialSessionFlowControlWindowForTest); 153 kInitialSessionFlowControlWindowForTest);
148 154
149 connection_ = new StrictMock<MockQuicConnection>( 155 connection_ = new StrictMock<MockQuicConnection>(
150 &helper_, &alarm_factory_, Perspective::IS_SERVER, 156 &helper_, &alarm_factory_, Perspective::IS_SERVER,
151 SupportedVersions(GetParam())); 157 SupportedVersions(GetParam()));
152 session_.reset(new TestServerSession(config_, connection_, &owner_, 158 session_.reset(new TestServerSession(
153 &stream_helper_, &crypto_config_, 159 config_, connection_, &owner_, &stream_helper_, &crypto_config_,
154 &compressed_certs_cache_)); 160 &compressed_certs_cache_, &in_memory_cache_));
155 MockClock clock; 161 MockClock clock;
156 handshake_message_.reset(crypto_config_.AddDefaultConfig( 162 handshake_message_.reset(crypto_config_.AddDefaultConfig(
157 QuicRandom::GetInstance(), &clock, 163 QuicRandom::GetInstance(), &clock,
158 QuicCryptoServerConfig::ConfigOptions())); 164 QuicCryptoServerConfig::ConfigOptions()));
159 session_->Initialize(); 165 session_->Initialize();
160 visitor_ = QuicConnectionPeer::GetVisitor(connection_); 166 visitor_ = QuicConnectionPeer::GetVisitor(connection_);
161 } 167 }
162 168
163 StrictMock<MockQuicSessionVisitor> owner_; 169 StrictMock<MockQuicSessionVisitor> owner_;
164 StrictMock<MockQuicCryptoServerStreamHelper> stream_helper_; 170 StrictMock<MockQuicCryptoServerStreamHelper> stream_helper_;
165 MockQuicConnectionHelper helper_; 171 MockQuicConnectionHelper helper_;
166 MockAlarmFactory alarm_factory_; 172 MockAlarmFactory alarm_factory_;
167 StrictMock<MockQuicConnection>* connection_; 173 StrictMock<MockQuicConnection>* connection_;
168 QuicConfig config_; 174 QuicConfig config_;
169 QuicCryptoServerConfig crypto_config_; 175 QuicCryptoServerConfig crypto_config_;
170 QuicCompressedCertsCache compressed_certs_cache_; 176 QuicCompressedCertsCache compressed_certs_cache_;
177 QuicInMemoryCache in_memory_cache_;
171 std::unique_ptr<TestServerSession> session_; 178 std::unique_ptr<TestServerSession> session_;
172 std::unique_ptr<CryptoHandshakeMessage> handshake_message_; 179 std::unique_ptr<CryptoHandshakeMessage> handshake_message_;
173 QuicConnectionVisitorInterface* visitor_; 180 QuicConnectionVisitorInterface* visitor_;
174 QuicFlagSaver flags_; // Save/restore all QUIC flag values. 181 QuicFlagSaver flags_; // Save/restore all QUIC flag values.
175 }; 182 };
176 183
177 // Compares CachedNetworkParameters. 184 // Compares CachedNetworkParameters.
178 MATCHER_P(EqualsProto, network_params, "") { 185 MATCHER_P(EqualsProto, network_params, "") {
179 CachedNetworkParameters reference(network_params); 186 CachedNetworkParameters reference(network_params);
180 return (arg->bandwidth_estimate_bytes_per_second() == 187 return (arg->bandwidth_estimate_bytes_per_second() ==
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 655
649 // Allow the async ProofSource::GetProof call to complete. Verify (under 656 // Allow the async ProofSource::GetProof call to complete. Verify (under
650 // asan) that this does not result in accesses to any freed memory from the 657 // asan) that this does not result in accesses to any freed memory from the
651 // session or its subobjects. 658 // session or its subobjects.
652 GetFakeProofSource()->InvokePendingCallback(0); 659 GetFakeProofSource()->InvokePendingCallback(0);
653 } 660 }
654 661
655 } // namespace 662 } // namespace
656 } // namespace test 663 } // namespace test
657 } // namespace net 664 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/chromium/quic_end_to_end_unittest.cc ('k') | net/quic/test_tools/mock_quic_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698