OLD | NEW |
---|---|
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 Loading... | |
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( |
65 HostPortPair::FromString(kTestServerHost)); | 65 HostPortPair::FromString("test.example.com:443")); |
Ryan Hamilton
2017/02/14 05:22:04
nit: HostPortPair(kTestServerHost, 443));
Zhongyi Shi
2017/02/14 05:52:57
Done.
| |
66 params->cert_verifier = &cert_verifier_; | 66 params->cert_verifier = &cert_verifier_; |
67 params->enable_quic = true; | 67 params->enable_quic = true; |
68 params->host_resolver = host_resolver_.get(); | 68 context_->set_host_resolver(host_resolver_.get()); |
Ryan Hamilton
2017/02/14 05:22:03
Did the old code not actually work?
Zhongyi Shi
2017/02/14 05:52:57
The old code is not using the host resolver rules
| |
69 context_->set_http_network_session_params(std::move(params)); | 69 context_->set_http_network_session_params(std::move(params)); |
70 context_->set_cert_verifier(&cert_verifier_); | 70 context_->set_cert_verifier(&cert_verifier_); |
71 } | 71 } |
72 | 72 |
73 void TearDown() override { | 73 void TearDown() override { |
74 if (server_) | 74 if (server_) |
75 server_->Shutdown(); | 75 server_->Shutdown(); |
76 } | 76 } |
77 | 77 |
78 // Sets a NetworkDelegate to use for |context_|. Must be done before Init(). | 78 // Sets a NetworkDelegate to use for |context_|. Must be done before Init(). |
(...skipping 28 matching lines...) Expand all Loading... | |
107 test::crypto_test_utils::ProofSourceForTesting(), config, | 107 test::crypto_test_utils::ProofSourceForTesting(), config, |
108 net::QuicCryptoServerConfig::ConfigOptions(), AllSupportedVersions(), | 108 net::QuicCryptoServerConfig::ConfigOptions(), AllSupportedVersions(), |
109 &response_cache_)); | 109 &response_cache_)); |
110 int rv = server_->Listen( | 110 int rv = server_->Listen( |
111 net::IPEndPoint(net::IPAddress::IPv4AllZeros(), kTestServerPort)); | 111 net::IPEndPoint(net::IPAddress::IPv4AllZeros(), kTestServerPort)); |
112 EXPECT_GE(rv, 0) << "Quic server fails to start"; | 112 EXPECT_GE(rv, 0) << "Quic server fails to start"; |
113 | 113 |
114 std::unique_ptr<MockHostResolver> resolver(new MockHostResolver()); | 114 std::unique_ptr<MockHostResolver> resolver(new MockHostResolver()); |
115 resolver->rules()->AddRule("test.example.com", "127.0.0.1"); | 115 resolver->rules()->AddRule("test.example.com", "127.0.0.1"); |
116 host_resolver_.reset(new MappedHostResolver(std::move(resolver))); | 116 host_resolver_.reset(new MappedHostResolver(std::move(resolver))); |
117 // Use a mapped host resolver so that request for test.example.com (port 80) | 117 // Use a mapped host resolver so that request for test.example.com (port 80) |
Ryan Hamilton
2017/02/14 05:22:04
Is port 80 really correct in this comment?
Zhongyi Shi
2017/02/14 05:52:57
Done.
| |
118 // reach the server running on localhost. | 118 // reach the server running on localhost. |
119 std::string map_rule = "MAP test.example.com test.example.com:" + | 119 std::string map_rule = "MAP test.example.com:443 test.example.com:" + |
Ryan Hamilton
2017/02/14 05:22:04
Is 443 required here?
Zhongyi Shi
2017/02/14 05:52:57
Aha, it's not required here. I was following the h
| |
120 base::IntToString(server_->server_address().port()); | 120 base::IntToString(server_->server_address().port()); |
121 EXPECT_TRUE(host_resolver_->AddRuleFromString(map_rule)); | 121 EXPECT_TRUE(host_resolver_->AddRuleFromString(map_rule)); |
122 } | 122 } |
123 | 123 |
124 std::unique_ptr<MappedHostResolver> host_resolver_; | 124 std::unique_ptr<MappedHostResolver> host_resolver_; |
125 std::unique_ptr<QuicSimpleServer> server_; | 125 std::unique_ptr<QuicSimpleServer> server_; |
126 std::unique_ptr<TestURLRequestContext> context_; | 126 std::unique_ptr<TestURLRequestContext> context_; |
127 QuicHttpResponseCache response_cache_; | 127 QuicHttpResponseCache response_cache_; |
128 MockCertVerifier cert_verifier_; | 128 MockCertVerifier cert_verifier_; |
129 }; | 129 }; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 ASSERT_TRUE(request2->is_pending()); | 237 ASSERT_TRUE(request2->is_pending()); |
238 run_loop.Run(); | 238 run_loop.Run(); |
239 | 239 |
240 EXPECT_TRUE(request->status().is_success()); | 240 EXPECT_TRUE(request->status().is_success()); |
241 EXPECT_TRUE(request2->status().is_success()); | 241 EXPECT_TRUE(request2->status().is_success()); |
242 EXPECT_EQ(kHelloBodyValue, delegate.data_received()); | 242 EXPECT_EQ(kHelloBodyValue, delegate.data_received()); |
243 EXPECT_EQ(kHelloBodyValue, delegate2.data_received()); | 243 EXPECT_EQ(kHelloBodyValue, delegate2.data_received()); |
244 } | 244 } |
245 | 245 |
246 } // namespace net | 246 } // namespace net |
OLD | NEW |