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

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

Issue 2547583002: Landing Recent QUIC changes until Fri Nov 18 23:21:04 2016 +0000 (Closed)
Patch Set: Remove explicit HTTP/2 enum usage 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/url_request/url_request_context_builder.h ('k') | 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"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "net/base/load_timing_info.h" 13 #include "net/base/load_timing_info.h"
14 #include "net/base/network_delegate.h" 14 #include "net/base/network_delegate.h"
15 #include "net/cert/mock_cert_verifier.h" 15 #include "net/cert/mock_cert_verifier.h"
16 #include "net/dns/mapped_host_resolver.h" 16 #include "net/dns/mapped_host_resolver.h"
17 #include "net/dns/mock_host_resolver.h" 17 #include "net/dns/mock_host_resolver.h"
18 #include "net/quic/chromium/crypto/proof_source_chromium.h" 18 #include "net/quic/chromium/crypto/proof_source_chromium.h"
19 #include "net/quic/test_tools/crypto_test_utils.h" 19 #include "net/quic/test_tools/crypto_test_utils.h"
20 #include "net/test/cert_test_util.h" 20 #include "net/test/cert_test_util.h"
21 #include "net/test/gtest_util.h" 21 #include "net/test/gtest_util.h"
22 #include "net/test/test_data_directory.h" 22 #include "net/test/test_data_directory.h"
23 #include "net/tools/quic/quic_in_memory_cache.h" 23 #include "net/tools/quic/quic_http_response_cache.h"
24 #include "net/tools/quic/quic_simple_server.h" 24 #include "net/tools/quic/quic_simple_server.h"
25 #include "net/url_request/url_request.h" 25 #include "net/url_request/url_request.h"
26 #include "net/url_request/url_request_test_util.h" 26 #include "net/url_request/url_request_test_util.h"
27 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
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 {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 std::unique_ptr<URLRequest> CreateRequest(const GURL& url, 86 std::unique_ptr<URLRequest> CreateRequest(const GURL& url,
87 RequestPriority priority, 87 RequestPriority priority,
88 URLRequest::Delegate* delegate) { 88 URLRequest::Delegate* delegate) {
89 return context_->CreateRequest(url, priority, delegate); 89 return context_->CreateRequest(url, priority, delegate);
90 } 90 }
91 91
92 private: 92 private:
93 void StartQuicServer() { 93 void StartQuicServer() {
94 // Set up in-memory cache. 94 // Set up in-memory cache.
95 in_memory_cache_.AddSimpleResponse(kTestServerHost, kHelloPath, 95 response_cache_.AddSimpleResponse(kTestServerHost, kHelloPath, kHelloStatus,
96 kHelloStatus, kHelloBodyValue); 96 kHelloBodyValue);
97 net::QuicConfig config; 97 net::QuicConfig config;
98 // Set up server certs. 98 // Set up server certs.
99 std::unique_ptr<net::ProofSourceChromium> proof_source( 99 std::unique_ptr<net::ProofSourceChromium> proof_source(
100 new net::ProofSourceChromium()); 100 new net::ProofSourceChromium());
101 base::FilePath directory = GetTestCertsDirectory(); 101 base::FilePath directory = GetTestCertsDirectory();
102 CHECK(proof_source->Initialize( 102 CHECK(proof_source->Initialize(
103 directory.Append(FILE_PATH_LITERAL("quic_test.example.com.crt")), 103 directory.Append(FILE_PATH_LITERAL("quic_test.example.com.crt")),
104 directory.Append(FILE_PATH_LITERAL("quic_test.example.com.key.pkcs8")), 104 directory.Append(FILE_PATH_LITERAL("quic_test.example.com.key.pkcs8")),
105 directory.Append(FILE_PATH_LITERAL("quic_test.example.com.key.sct")))); 105 directory.Append(FILE_PATH_LITERAL("quic_test.example.com.key.sct"))));
106 server_.reset(new QuicSimpleServer( 106 server_.reset(new QuicSimpleServer(
107 test::CryptoTestUtils::ProofSourceForTesting(), config, 107 test::CryptoTestUtils::ProofSourceForTesting(), config,
108 net::QuicCryptoServerConfig::ConfigOptions(), AllSupportedVersions(), 108 net::QuicCryptoServerConfig::ConfigOptions(), AllSupportedVersions(),
109 &in_memory_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)
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 test.example.com:" +
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 QuicInMemoryCache in_memory_cache_; 127 QuicHttpResponseCache response_cache_;
128 MockCertVerifier cert_verifier_; 128 MockCertVerifier cert_verifier_;
129 }; 129 };
130 130
131 // A URLRequest::Delegate that checks LoadTimingInfo when response headers are 131 // A URLRequest::Delegate that checks LoadTimingInfo when response headers are
132 // received. 132 // received.
133 class CheckLoadTimingDelegate : public TestDelegate { 133 class CheckLoadTimingDelegate : public TestDelegate {
134 public: 134 public:
135 CheckLoadTimingDelegate(bool session_reused) 135 CheckLoadTimingDelegate(bool session_reused)
136 : session_reused_(session_reused) {} 136 : session_reused_(session_reused) {}
137 void OnResponseStarted(URLRequest* request, int error) override { 137 void OnResponseStarted(URLRequest* request, int error) override {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « net/url_request/url_request_context_builder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698