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

Side by Side Diff: net/url_request/url_request_quic_unittest.cc

Issue 2693083002: Server push cancellation: fix host resolver set up in URLRequestQuicTest (Closed)
Patch Set: address rch's comments Created 3 years, 10 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 17 matching lines...) Expand all
28 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
29 #include "url/gurl.h" 29 #include "url/gurl.h"
30 30
31 namespace net { 31 namespace net {
32 32
33 namespace { 33 namespace {
34 34
35 // This must match the certificate used (quic_test.example.com.crt and 35 // This must match the certificate used (quic_test.example.com.crt and
36 // quic_test.example.com.key.pkcs8). 36 // quic_test.example.com.key.pkcs8).
37 const int kTestServerPort = 6121; 37 const int kTestServerPort = 6121;
38 const char kTestServerHost[] = "test.example.com:6121"; 38 const char kTestServerHost[] = "test.example.com";
39 // Used as a simple response from the server. 39 // Used as a simple response from the server.
40 const char kHelloPath[] = "/hello.txt"; 40 const char kHelloPath[] = "/hello.txt";
41 const char kHelloBodyValue[] = "Hello from QUIC Server"; 41 const char kHelloBodyValue[] = "Hello from QUIC Server";
42 const int kHelloStatus = 200; 42 const int kHelloStatus = 200;
43 43
44 class URLRequestQuicTest : public ::testing::Test { 44 class URLRequestQuicTest : public ::testing::Test {
45 protected: 45 protected:
46 URLRequestQuicTest() : context_(new TestURLRequestContext(true)) { 46 URLRequestQuicTest() : context_(new TestURLRequestContext(true)) {
47 StartQuicServer(); 47 StartQuicServer();
48 48
49 std::unique_ptr<HttpNetworkSession::Params> params( 49 std::unique_ptr<HttpNetworkSession::Params> params(
50 new HttpNetworkSession::Params); 50 new HttpNetworkSession::Params);
51 CertVerifyResult verify_result; 51 CertVerifyResult verify_result;
52 verify_result.verified_cert = ImportCertFromFile( 52 verify_result.verified_cert = ImportCertFromFile(
53 GetTestCertsDirectory(), "quic_test.example.com.crt"); 53 GetTestCertsDirectory(), "quic_test.example.com.crt");
54 cert_verifier_.AddResultForCertAndHost(verify_result.verified_cert.get(), 54 cert_verifier_.AddResultForCertAndHost(verify_result.verified_cert.get(),
55 "test.example.com", verify_result, 55 "test.example.com", verify_result,
56 OK); 56 OK);
57 verify_result.verified_cert = ImportCertFromFile( 57 verify_result.verified_cert = ImportCertFromFile(
58 GetTestCertsDirectory(), "quic_test_ecc.example.com.crt"); 58 GetTestCertsDirectory(), "quic_test_ecc.example.com.crt");
59 cert_verifier_.AddResultForCertAndHost(verify_result.verified_cert.get(), 59 cert_verifier_.AddResultForCertAndHost(verify_result.verified_cert.get(),
60 "test.example.com", verify_result, 60 "test.example.com", verify_result,
61 OK); 61 OK);
62 // To simplify the test, and avoid the race with the HTTP request, we force 62 // To simplify the test, and avoid the race with the HTTP request, we force
63 // QUIC for these requests. 63 // QUIC for these requests.
64 params->origins_to_force_quic_on.insert( 64 params->origins_to_force_quic_on.insert(HostPortPair(kTestServerHost, 443));
65 HostPortPair::FromString(kTestServerHost));
66 params->cert_verifier = &cert_verifier_; 65 params->cert_verifier = &cert_verifier_;
67 params->enable_quic = true; 66 params->enable_quic = true;
68 params->host_resolver = host_resolver_.get(); 67 context_->set_host_resolver(host_resolver_.get());
69 context_->set_http_network_session_params(std::move(params)); 68 context_->set_http_network_session_params(std::move(params));
70 context_->set_cert_verifier(&cert_verifier_); 69 context_->set_cert_verifier(&cert_verifier_);
71 } 70 }
72 71
73 void TearDown() override { 72 void TearDown() override {
74 if (server_) 73 if (server_)
75 server_->Shutdown(); 74 server_->Shutdown();
76 } 75 }
77 76
78 // Sets a NetworkDelegate to use for |context_|. Must be done before Init(). 77 // Sets a NetworkDelegate to use for |context_|. Must be done before Init().
(...skipping 28 matching lines...) Expand all
107 test::crypto_test_utils::ProofSourceForTesting(), config, 106 test::crypto_test_utils::ProofSourceForTesting(), config,
108 net::QuicCryptoServerConfig::ConfigOptions(), AllSupportedVersions(), 107 net::QuicCryptoServerConfig::ConfigOptions(), AllSupportedVersions(),
109 &response_cache_)); 108 &response_cache_));
110 int rv = server_->Listen( 109 int rv = server_->Listen(
111 net::IPEndPoint(net::IPAddress::IPv4AllZeros(), kTestServerPort)); 110 net::IPEndPoint(net::IPAddress::IPv4AllZeros(), kTestServerPort));
112 EXPECT_GE(rv, 0) << "Quic server fails to start"; 111 EXPECT_GE(rv, 0) << "Quic server fails to start";
113 112
114 std::unique_ptr<MockHostResolver> resolver(new MockHostResolver()); 113 std::unique_ptr<MockHostResolver> resolver(new MockHostResolver());
115 resolver->rules()->AddRule("test.example.com", "127.0.0.1"); 114 resolver->rules()->AddRule("test.example.com", "127.0.0.1");
116 host_resolver_.reset(new MappedHostResolver(std::move(resolver))); 115 host_resolver_.reset(new MappedHostResolver(std::move(resolver)));
117 // Use a mapped host resolver so that request for test.example.com (port 80) 116 // Use a mapped host resolver so that request for test.example.com
118 // reach the server running on localhost. 117 // reach the server running on localhost.
119 std::string map_rule = "MAP test.example.com test.example.com:" + 118 std::string map_rule = "MAP test.example.com test.example.com:" +
120 base::IntToString(server_->server_address().port()); 119 base::IntToString(server_->server_address().port());
121 EXPECT_TRUE(host_resolver_->AddRuleFromString(map_rule)); 120 EXPECT_TRUE(host_resolver_->AddRuleFromString(map_rule));
122 } 121 }
123 122
124 std::unique_ptr<MappedHostResolver> host_resolver_; 123 std::unique_ptr<MappedHostResolver> host_resolver_;
125 std::unique_ptr<QuicSimpleServer> server_; 124 std::unique_ptr<QuicSimpleServer> server_;
126 std::unique_ptr<TestURLRequestContext> context_; 125 std::unique_ptr<TestURLRequestContext> context_;
127 QuicHttpResponseCache response_cache_; 126 QuicHttpResponseCache response_cache_;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 ASSERT_TRUE(request2->is_pending()); 236 ASSERT_TRUE(request2->is_pending());
238 run_loop.Run(); 237 run_loop.Run();
239 238
240 EXPECT_TRUE(request->status().is_success()); 239 EXPECT_TRUE(request->status().is_success());
241 EXPECT_TRUE(request2->status().is_success()); 240 EXPECT_TRUE(request2->status().is_success());
242 EXPECT_EQ(kHelloBodyValue, delegate.data_received()); 241 EXPECT_EQ(kHelloBodyValue, delegate.data_received());
243 EXPECT_EQ(kHelloBodyValue, delegate2.data_received()); 242 EXPECT_EQ(kHelloBodyValue, delegate2.data_received());
244 } 243 }
245 244
246 } // namespace net 245 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698