| 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" | 
|   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_in_memory_cache.h" | 
|   24 #include "net/tools/quic/quic_simple_server.h" |   24 #include "net/tools/quic/quic_simple_server.h" | 
|   25 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" |  | 
|   26 #include "net/url_request/url_request.h" |   25 #include "net/url_request/url_request.h" | 
|   27 #include "net/url_request/url_request_test_util.h" |   26 #include "net/url_request/url_request_test_util.h" | 
|   28 #include "testing/gmock/include/gmock/gmock.h" |   27 #include "testing/gmock/include/gmock/gmock.h" | 
|   29 #include "testing/gtest/include/gtest/gtest.h" |   28 #include "testing/gtest/include/gtest/gtest.h" | 
|   30 #include "url/gurl.h" |   29 #include "url/gurl.h" | 
|   31  |   30  | 
|   32 namespace net { |   31 namespace net { | 
|   33  |   32  | 
|   34 namespace { |   33 namespace { | 
|   35  |   34  | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   86  |   85  | 
|   87   std::unique_ptr<URLRequest> CreateRequest(const GURL& url, |   86   std::unique_ptr<URLRequest> CreateRequest(const GURL& url, | 
|   88                                             RequestPriority priority, |   87                                             RequestPriority priority, | 
|   89                                             URLRequest::Delegate* delegate) { |   88                                             URLRequest::Delegate* delegate) { | 
|   90     return context_->CreateRequest(url, priority, delegate); |   89     return context_->CreateRequest(url, priority, delegate); | 
|   91   } |   90   } | 
|   92  |   91  | 
|   93  private: |   92  private: | 
|   94   void StartQuicServer() { |   93   void StartQuicServer() { | 
|   95     // Set up in-memory cache. |   94     // Set up in-memory cache. | 
|   96     test::QuicInMemoryCachePeer::ResetForTests(); |   95     in_memory_cache_.AddSimpleResponse(kTestServerHost, kHelloPath, | 
|   97     QuicInMemoryCache::GetInstance()->AddSimpleResponse( |   96                                        kHelloStatus, kHelloBodyValue); | 
|   98         kTestServerHost, kHelloPath, kHelloStatus, kHelloBodyValue); |  | 
|   99     net::QuicConfig config; |   97     net::QuicConfig config; | 
|  100     // Set up server certs. |   98     // Set up server certs. | 
|  101     std::unique_ptr<net::ProofSourceChromium> proof_source( |   99     std::unique_ptr<net::ProofSourceChromium> proof_source( | 
|  102         new net::ProofSourceChromium()); |  100         new net::ProofSourceChromium()); | 
|  103     base::FilePath directory = GetTestCertsDirectory(); |  101     base::FilePath directory = GetTestCertsDirectory(); | 
|  104     CHECK(proof_source->Initialize( |  102     CHECK(proof_source->Initialize( | 
|  105         directory.Append(FILE_PATH_LITERAL("quic_test.example.com.crt")), |  103         directory.Append(FILE_PATH_LITERAL("quic_test.example.com.crt")), | 
|  106         directory.Append(FILE_PATH_LITERAL("quic_test.example.com.key.pkcs8")), |  104         directory.Append(FILE_PATH_LITERAL("quic_test.example.com.key.pkcs8")), | 
|  107         directory.Append(FILE_PATH_LITERAL("quic_test.example.com.key.sct")))); |  105         directory.Append(FILE_PATH_LITERAL("quic_test.example.com.key.sct")))); | 
|  108     server_.reset(new QuicSimpleServer( |  106     server_.reset(new QuicSimpleServer( | 
|  109         test::CryptoTestUtils::ProofSourceForTesting(), config, |  107         test::CryptoTestUtils::ProofSourceForTesting(), config, | 
|  110         net::QuicCryptoServerConfig::ConfigOptions(), AllSupportedVersions())); |  108         net::QuicCryptoServerConfig::ConfigOptions(), AllSupportedVersions(), | 
 |  109         &in_memory_cache_)); | 
|  111     int rv = server_->Listen( |  110     int rv = server_->Listen( | 
|  112         net::IPEndPoint(net::IPAddress::IPv4AllZeros(), kTestServerPort)); |  111         net::IPEndPoint(net::IPAddress::IPv4AllZeros(), kTestServerPort)); | 
|  113     EXPECT_GE(rv, 0) << "Quic server fails to start"; |  112     EXPECT_GE(rv, 0) << "Quic server fails to start"; | 
|  114  |  113  | 
|  115     std::unique_ptr<MockHostResolver> resolver(new MockHostResolver()); |  114     std::unique_ptr<MockHostResolver> resolver(new MockHostResolver()); | 
|  116     resolver->rules()->AddRule("test.example.com", "127.0.0.1"); |  115     resolver->rules()->AddRule("test.example.com", "127.0.0.1"); | 
|  117     host_resolver_.reset(new MappedHostResolver(std::move(resolver))); |  116     host_resolver_.reset(new MappedHostResolver(std::move(resolver))); | 
|  118     // 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) | 
|  119     // reach the server running on localhost. |  118     // reach the server running on localhost. | 
|  120     std::string map_rule = "MAP test.example.com test.example.com:" + |  119     std::string map_rule = "MAP test.example.com test.example.com:" + | 
|  121                            base::IntToString(server_->server_address().port()); |  120                            base::IntToString(server_->server_address().port()); | 
|  122     EXPECT_TRUE(host_resolver_->AddRuleFromString(map_rule)); |  121     EXPECT_TRUE(host_resolver_->AddRuleFromString(map_rule)); | 
|  123   } |  122   } | 
|  124  |  123  | 
|  125   std::unique_ptr<MappedHostResolver> host_resolver_; |  124   std::unique_ptr<MappedHostResolver> host_resolver_; | 
|  126   std::unique_ptr<QuicSimpleServer> server_; |  125   std::unique_ptr<QuicSimpleServer> server_; | 
|  127   std::unique_ptr<TestURLRequestContext> context_; |  126   std::unique_ptr<TestURLRequestContext> context_; | 
 |  127   QuicInMemoryCache in_memory_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  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 |