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

Side by Side Diff: net/quic/chromium/quic_end_to_end_unittest.cc

Issue 2295473002: Move the chromium specific QUIC end-to-end tests from net/quic/core (Closed)
Patch Set: cronet iOS Created 4 years, 3 months 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_end_to_end_unittest.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 19 matching lines...) Expand all
30 #include "net/http/transport_security_state.h" 30 #include "net/http/transport_security_state.h"
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_server.h" 40 #include "net/tools/quic/quic_simple_server.h"
41 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" 41 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h"
42 #include "net/tools/quic/test_tools/server_thread.h"
43 #include "testing/gmock/include/gmock/gmock.h" 42 #include "testing/gmock/include/gmock/gmock.h"
44 #include "testing/gtest/include/gtest/gtest.h" 43 #include "testing/gtest/include/gtest/gtest.h"
45 #include "testing/platform_test.h" 44 #include "testing/platform_test.h"
46 45
47 using base::StringPiece; 46 using base::StringPiece;
48 47
49 namespace net { 48 namespace net {
50 49
51 using test::IsOk; 50 using test::IsOk;
52 using test::QuicInMemoryCachePeer; 51 using test::QuicInMemoryCachePeer;
53 using test::ServerThread;
54 52
55 namespace test { 53 namespace test {
56 54
57 namespace { 55 namespace {
58 56
59 const char kResponseBody[] = "some arbitrary response body"; 57 const char kResponseBody[] = "some arbitrary response body";
60 58
61 // Factory for creating HttpTransactions, used by TestTransactionConsumer. 59 // Factory for creating HttpTransactions, used by TestTransactionConsumer.
62 class TestTransactionFactory : public HttpTransactionFactory { 60 class TestTransactionFactory : public HttpTransactionFactory {
63 public: 61 public:
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 return resolver; 152 return resolver;
155 } 153 }
156 154
157 void SetUp() override { 155 void SetUp() override {
158 QuicInMemoryCachePeer::ResetForTests(); 156 QuicInMemoryCachePeer::ResetForTests();
159 StartServer(); 157 StartServer();
160 158
161 // Use a mapped host resolver so that request for test.example.com (port 80) 159 // Use a mapped host resolver so that request for test.example.com (port 80)
162 // reach the server running on localhost. 160 // reach the server running on localhost.
163 std::string map_rule = "MAP test.example.com test.example.com:" + 161 std::string map_rule = "MAP test.example.com test.example.com:" +
164 base::IntToString(server_thread_->GetPort()); 162 base::IntToString(server_->server_address().port());
165 EXPECT_TRUE(host_resolver_.AddRuleFromString(map_rule)); 163 EXPECT_TRUE(host_resolver_.AddRuleFromString(map_rule));
166 164
167 // To simplify the test, and avoid the race with the HTTP request, we force 165 // To simplify the test, and avoid the race with the HTTP request, we force
168 // QUIC for these requests. 166 // QUIC for these requests.
169 params_.origins_to_force_quic_on.insert( 167 params_.origins_to_force_quic_on.insert(
170 HostPortPair::FromString("test.example.com:443")); 168 HostPortPair::FromString("test.example.com:443"));
171 169
172 transaction_factory_.reset(new TestTransactionFactory(params_)); 170 transaction_factory_.reset(new TestTransactionFactory(params_));
173 } 171 }
174 172
175 void TearDown() override { 173 void TearDown() override { QuicInMemoryCachePeer::ResetForTests(); }
176 StopServer();
177 QuicInMemoryCachePeer::ResetForTests();
178 }
179 174
180 // Starts the QUIC server listening on a random port. 175 // Starts the QUIC server listening on a random port.
181 void StartServer() { 176 void StartServer() {
182 server_address_ = IPEndPoint(IPAddress(127, 0, 0, 1), 0); 177 server_address_ = IPEndPoint(IPAddress(127, 0, 0, 1), 0);
183 server_config_.SetInitialStreamFlowControlWindowToSend( 178 server_config_.SetInitialStreamFlowControlWindowToSend(
184 kInitialStreamFlowControlWindowForTest); 179 kInitialStreamFlowControlWindowForTest);
185 server_config_.SetInitialSessionFlowControlWindowToSend( 180 server_config_.SetInitialSessionFlowControlWindowToSend(
186 kInitialSessionFlowControlWindowForTest); 181 kInitialSessionFlowControlWindowForTest);
187 server_config_options_.token_binding_enabled = true; 182 server_config_options_.token_binding_enabled = true;
188 QuicServer* server = 183 server_.reset(new QuicSimpleServer(CryptoTestUtils::ProofSourceForTesting(),
189 new QuicServer(CryptoTestUtils::ProofSourceForTesting(), server_config_, 184 server_config_, server_config_options_,
190 server_config_options_, AllSupportedVersions()); 185 AllSupportedVersions()));
191 server_thread_.reset(new ServerThread(server, server_address_, 186 server_->Listen(server_address_);
192 strike_register_no_startup_period_)); 187 server_address_ = server_->server_address();
193 server_thread_->Initialize(); 188 server_->StartReading();
194 server_address_ =
195 IPEndPoint(server_address_.address(), server_thread_->GetPort());
196 server_thread_->Start();
197 server_started_ = true; 189 server_started_ = true;
198 } 190 }
199 191
200 // Stops the QUIC server.
201 void StopServer() {
202 if (!server_started_) {
203 return;
204 }
205 if (server_thread_.get()) {
206 server_thread_->Quit();
207 server_thread_->Join();
208 }
209 }
210
211 // Adds an entry to the cache used by the QUIC server to serve 192 // Adds an entry to the cache used by the QUIC server to serve
212 // responses. 193 // responses.
213 void AddToCache(StringPiece path, 194 void AddToCache(StringPiece path,
214 int response_code, 195 int response_code,
215 StringPiece response_detail, 196 StringPiece response_detail,
216 StringPiece body) { 197 StringPiece body) {
217 QuicInMemoryCache::GetInstance()->AddSimpleResponse( 198 QuicInMemoryCache::GetInstance()->AddSimpleResponse(
218 "test.example.com", path, response_code, body); 199 "test.example.com", path, response_code, body);
219 } 200 }
220 201
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 CTPolicyEnforcer ct_policy_enforcer_; 243 CTPolicyEnforcer ct_policy_enforcer_;
263 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; 244 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_;
264 std::unique_ptr<ProxyService> proxy_service_; 245 std::unique_ptr<ProxyService> proxy_service_;
265 std::unique_ptr<HttpAuthHandlerFactory> auth_handler_factory_; 246 std::unique_ptr<HttpAuthHandlerFactory> auth_handler_factory_;
266 HttpServerPropertiesImpl http_server_properties_; 247 HttpServerPropertiesImpl http_server_properties_;
267 HttpNetworkSession::Params params_; 248 HttpNetworkSession::Params params_;
268 std::unique_ptr<TestTransactionFactory> transaction_factory_; 249 std::unique_ptr<TestTransactionFactory> transaction_factory_;
269 HttpRequestInfo request_; 250 HttpRequestInfo request_;
270 std::string request_body_; 251 std::string request_body_;
271 std::unique_ptr<UploadDataStream> upload_data_stream_; 252 std::unique_ptr<UploadDataStream> upload_data_stream_;
272 std::unique_ptr<ServerThread> server_thread_; 253 std::unique_ptr<QuicSimpleServer> server_;
273 IPEndPoint server_address_; 254 IPEndPoint server_address_;
274 std::string server_hostname_; 255 std::string server_hostname_;
275 QuicConfig server_config_; 256 QuicConfig server_config_;
276 QuicCryptoServerConfig::ConfigOptions server_config_options_; 257 QuicCryptoServerConfig::ConfigOptions server_config_options_;
277 bool server_started_; 258 bool server_started_;
278 bool strike_register_no_startup_period_; 259 bool strike_register_no_startup_period_;
279 }; 260 };
280 261
281 INSTANTIATE_TEST_CASE_P(Tests, 262 INSTANTIATE_TEST_CASE_P(Tests,
282 QuicEndToEndTest, 263 QuicEndToEndTest,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 base::RunLoop().Run(); 364 base::RunLoop().Run();
384 365
385 for (size_t i = 0; i < num_requests; ++i) { 366 for (size_t i = 0; i < num_requests; ++i) {
386 CheckResponse(*consumers[i], "HTTP/1.1 200", kResponseBody); 367 CheckResponse(*consumers[i], "HTTP/1.1 200", kResponseBody);
387 } 368 }
388 base::STLDeleteElements(&consumers); 369 base::STLDeleteElements(&consumers);
389 } 370 }
390 371
391 } // namespace test 372 } // namespace test
392 } // namespace net 373 } // namespace net
OLDNEW
« no previous file with comments | « net/net.gypi ('k') | net/quic/core/quic_end_to_end_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698