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

Side by Side Diff: net/quic/chromium/quic_end_to_end_unittest.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
« no previous file with comments | « net/net.gypi ('k') | net/quic/core/quic_server_session_base_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory> 5 #include <memory>
6 #include <ostream> 6 #include <ostream>
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 20 matching lines...) Expand all
31 #include "net/proxy/proxy_service.h" 31 #include "net/proxy/proxy_service.h"
32 #include "net/quic/test_tools/crypto_test_utils.h" 32 #include "net/quic/test_tools/crypto_test_utils.h"
33 #include "net/quic/test_tools/quic_test_utils.h" 33 #include "net/quic/test_tools/quic_test_utils.h"
34 #include "net/ssl/default_channel_id_store.h" 34 #include "net/ssl/default_channel_id_store.h"
35 #include "net/ssl/ssl_config_service_defaults.h" 35 #include "net/ssl/ssl_config_service_defaults.h"
36 #include "net/test/cert_test_util.h" 36 #include "net/test/cert_test_util.h"
37 #include "net/test/gtest_util.h" 37 #include "net/test/gtest_util.h"
38 #include "net/test/test_data_directory.h" 38 #include "net/test/test_data_directory.h"
39 #include "net/tools/quic/quic_in_memory_cache.h" 39 #include "net/tools/quic/quic_in_memory_cache.h"
40 #include "net/tools/quic/quic_simple_server.h" 40 #include "net/tools/quic/quic_simple_server.h"
41 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h"
42 #include "testing/gmock/include/gmock/gmock.h" 41 #include "testing/gmock/include/gmock/gmock.h"
43 #include "testing/gtest/include/gtest/gtest.h" 42 #include "testing/gtest/include/gtest/gtest.h"
44 #include "testing/platform_test.h" 43 #include "testing/platform_test.h"
45 44
46 using base::StringPiece; 45 using base::StringPiece;
47 46
48 namespace net { 47 namespace net {
49 48
50 using test::IsOk; 49 using test::IsOk;
51 using test::QuicInMemoryCachePeer;
52 50
53 namespace test { 51 namespace test {
54 52
55 namespace { 53 namespace {
56 54
57 const char kResponseBody[] = "some arbitrary response body"; 55 const char kResponseBody[] = "some arbitrary response body";
58 56
59 // Factory for creating HttpTransactions, used by TestTransactionConsumer. 57 // Factory for creating HttpTransactions, used by TestTransactionConsumer.
60 class TestTransactionFactory : public HttpTransactionFactory { 58 class TestTransactionFactory : public HttpTransactionFactory {
61 public: 59 public:
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 144
147 // Creates a mock host resolver in which test.example.com 145 // Creates a mock host resolver in which test.example.com
148 // resolves to localhost. 146 // resolves to localhost.
149 static MockHostResolver* CreateResolverImpl() { 147 static MockHostResolver* CreateResolverImpl() {
150 MockHostResolver* resolver = new MockHostResolver(); 148 MockHostResolver* resolver = new MockHostResolver();
151 resolver->rules()->AddRule("test.example.com", "127.0.0.1"); 149 resolver->rules()->AddRule("test.example.com", "127.0.0.1");
152 return resolver; 150 return resolver;
153 } 151 }
154 152
155 void SetUp() override { 153 void SetUp() override {
156 QuicInMemoryCachePeer::ResetForTests();
157 StartServer(); 154 StartServer();
158 155
159 // Use a mapped host resolver so that request for test.example.com (port 80) 156 // Use a mapped host resolver so that request for test.example.com (port 80)
160 // reach the server running on localhost. 157 // reach the server running on localhost.
161 std::string map_rule = "MAP test.example.com test.example.com:" + 158 std::string map_rule = "MAP test.example.com test.example.com:" +
162 base::IntToString(server_->server_address().port()); 159 base::IntToString(server_->server_address().port());
163 EXPECT_TRUE(host_resolver_.AddRuleFromString(map_rule)); 160 EXPECT_TRUE(host_resolver_.AddRuleFromString(map_rule));
164 161
165 // To simplify the test, and avoid the race with the HTTP request, we force 162 // To simplify the test, and avoid the race with the HTTP request, we force
166 // QUIC for these requests. 163 // QUIC for these requests.
167 params_.origins_to_force_quic_on.insert( 164 params_.origins_to_force_quic_on.insert(
168 HostPortPair::FromString("test.example.com:443")); 165 HostPortPair::FromString("test.example.com:443"));
169 166
170 transaction_factory_.reset(new TestTransactionFactory(params_)); 167 transaction_factory_.reset(new TestTransactionFactory(params_));
171 } 168 }
172 169
173 void TearDown() override { QuicInMemoryCachePeer::ResetForTests(); } 170 void TearDown() override {}
174 171
175 // Starts the QUIC server listening on a random port. 172 // Starts the QUIC server listening on a random port.
176 void StartServer() { 173 void StartServer() {
177 server_address_ = IPEndPoint(IPAddress(127, 0, 0, 1), 0); 174 server_address_ = IPEndPoint(IPAddress(127, 0, 0, 1), 0);
178 server_config_.SetInitialStreamFlowControlWindowToSend( 175 server_config_.SetInitialStreamFlowControlWindowToSend(
179 kInitialStreamFlowControlWindowForTest); 176 kInitialStreamFlowControlWindowForTest);
180 server_config_.SetInitialSessionFlowControlWindowToSend( 177 server_config_.SetInitialSessionFlowControlWindowToSend(
181 kInitialSessionFlowControlWindowForTest); 178 kInitialSessionFlowControlWindowForTest);
182 server_config_options_.token_binding_params = QuicTagVector{kTB10, kP256}; 179 server_config_options_.token_binding_params = QuicTagVector{kTB10, kP256};
183 server_.reset(new QuicSimpleServer(CryptoTestUtils::ProofSourceForTesting(), 180 server_.reset(new QuicSimpleServer(
184 server_config_, server_config_options_, 181 CryptoTestUtils::ProofSourceForTesting(), server_config_,
185 AllSupportedVersions())); 182 server_config_options_, AllSupportedVersions(), &in_memory_cache_));
186 server_->Listen(server_address_); 183 server_->Listen(server_address_);
187 server_address_ = server_->server_address(); 184 server_address_ = server_->server_address();
188 server_->StartReading(); 185 server_->StartReading();
189 server_started_ = true; 186 server_started_ = true;
190 } 187 }
191 188
192 // Adds an entry to the cache used by the QUIC server to serve 189 // Adds an entry to the cache used by the QUIC server to serve
193 // responses. 190 // responses.
194 void AddToCache(StringPiece path, 191 void AddToCache(StringPiece path,
195 int response_code, 192 int response_code,
196 StringPiece response_detail, 193 StringPiece response_detail,
197 StringPiece body) { 194 StringPiece body) {
198 QuicInMemoryCache::GetInstance()->AddSimpleResponse( 195 in_memory_cache_.AddSimpleResponse("test.example.com", path, response_code,
199 "test.example.com", path, response_code, body); 196 body);
200 } 197 }
201 198
202 // Populates |request_body_| with |length_| ASCII bytes. 199 // Populates |request_body_| with |length_| ASCII bytes.
203 void GenerateBody(size_t length) { 200 void GenerateBody(size_t length) {
204 request_body_.clear(); 201 request_body_.clear();
205 request_body_.reserve(length); 202 request_body_.reserve(length);
206 for (size_t i = 0; i < length; ++i) { 203 for (size_t i = 0; i < length; ++i) {
207 request_body_.append(1, static_cast<char>(32 + i % (126 - 32))); 204 request_body_.append(1, static_cast<char>(32 + i % (126 - 32)));
208 } 205 }
209 } 206 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; 241 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_;
245 std::unique_ptr<ProxyService> proxy_service_; 242 std::unique_ptr<ProxyService> proxy_service_;
246 std::unique_ptr<HttpAuthHandlerFactory> auth_handler_factory_; 243 std::unique_ptr<HttpAuthHandlerFactory> auth_handler_factory_;
247 HttpServerPropertiesImpl http_server_properties_; 244 HttpServerPropertiesImpl http_server_properties_;
248 HttpNetworkSession::Params params_; 245 HttpNetworkSession::Params params_;
249 std::unique_ptr<TestTransactionFactory> transaction_factory_; 246 std::unique_ptr<TestTransactionFactory> transaction_factory_;
250 HttpRequestInfo request_; 247 HttpRequestInfo request_;
251 std::string request_body_; 248 std::string request_body_;
252 std::unique_ptr<UploadDataStream> upload_data_stream_; 249 std::unique_ptr<UploadDataStream> upload_data_stream_;
253 std::unique_ptr<QuicSimpleServer> server_; 250 std::unique_ptr<QuicSimpleServer> server_;
251 QuicInMemoryCache in_memory_cache_;
254 IPEndPoint server_address_; 252 IPEndPoint server_address_;
255 std::string server_hostname_; 253 std::string server_hostname_;
256 QuicConfig server_config_; 254 QuicConfig server_config_;
257 QuicCryptoServerConfig::ConfigOptions server_config_options_; 255 QuicCryptoServerConfig::ConfigOptions server_config_options_;
258 bool server_started_; 256 bool server_started_;
259 bool strike_register_no_startup_period_; 257 bool strike_register_no_startup_period_;
260 }; 258 };
261 259
262 INSTANTIATE_TEST_CASE_P(Tests, 260 INSTANTIATE_TEST_CASE_P(Tests,
263 QuicEndToEndTest, 261 QuicEndToEndTest,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 359
362 // Will terminate when the last consumer completes. 360 // Will terminate when the last consumer completes.
363 base::RunLoop().Run(); 361 base::RunLoop().Run();
364 362
365 for (const auto& consumer : consumers) 363 for (const auto& consumer : consumers)
366 CheckResponse(*consumer.get(), "HTTP/1.1 200", kResponseBody); 364 CheckResponse(*consumer.get(), "HTTP/1.1 200", kResponseBody);
367 } 365 }
368 366
369 } // namespace test 367 } // namespace test
370 } // namespace net 368 } // namespace net
OLDNEW
« no previous file with comments | « net/net.gypi ('k') | net/quic/core/quic_server_session_base_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698