• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/http/http_stream_factory_test_util.h"
6 
7 #include <utility>
8 
9 #include "net/proxy_resolution/proxy_info.h"
10 #include "url/scheme_host_port.h"
11 
12 using ::testing::_;
13 
14 namespace net {
15 MockHttpStreamRequestDelegate::MockHttpStreamRequestDelegate() = default;
16 
17 MockHttpStreamRequestDelegate::~MockHttpStreamRequestDelegate() = default;
18 
MockHttpStreamFactoryJob(HttpStreamFactory::Job::Delegate * delegate,HttpStreamFactory::JobType job_type,HttpNetworkSession * session,const HttpRequestInfo & request_info,RequestPriority priority,ProxyInfo proxy_info,const SSLConfig & server_ssl_config,const SSLConfig & proxy_ssl_config,url::SchemeHostPort destination,GURL origin_url,NextProto alternative_protocol,quic::ParsedQuicVersion quic_version,bool is_websocket,bool enable_ip_based_pooling,NetLog * net_log)19 MockHttpStreamFactoryJob::MockHttpStreamFactoryJob(
20     HttpStreamFactory::Job::Delegate* delegate,
21     HttpStreamFactory::JobType job_type,
22     HttpNetworkSession* session,
23     const HttpRequestInfo& request_info,
24     RequestPriority priority,
25     ProxyInfo proxy_info,
26     const SSLConfig& server_ssl_config,
27     const SSLConfig& proxy_ssl_config,
28     url::SchemeHostPort destination,
29     GURL origin_url,
30     NextProto alternative_protocol,
31     quic::ParsedQuicVersion quic_version,
32     bool is_websocket,
33     bool enable_ip_based_pooling,
34     NetLog* net_log)
35     : HttpStreamFactory::Job(delegate,
36                              job_type,
37                              session,
38                              request_info,
39                              priority,
40                              proxy_info,
41                              server_ssl_config,
42                              proxy_ssl_config,
43                              std::move(destination),
44                              origin_url,
45                              alternative_protocol,
46                              quic_version,
47                              is_websocket,
48                              enable_ip_based_pooling,
49                              net_log) {
50   DCHECK(!is_waiting());
51 }
52 
53 MockHttpStreamFactoryJob::~MockHttpStreamFactoryJob() = default;
54 
DoResume()55 void MockHttpStreamFactoryJob::DoResume() {
56   HttpStreamFactory::Job::Resume();
57 }
58 
59 TestJobFactory::TestJobFactory() = default;
60 
61 TestJobFactory::~TestJobFactory() = default;
62 
CreateJob(HttpStreamFactory::Job::Delegate * delegate,HttpStreamFactory::JobType job_type,HttpNetworkSession * session,const HttpRequestInfo & request_info,RequestPriority priority,const ProxyInfo & proxy_info,const SSLConfig & server_ssl_config,const SSLConfig & proxy_ssl_config,url::SchemeHostPort destination,GURL origin_url,bool is_websocket,bool enable_ip_based_pooling,NetLog * net_log,NextProto alternative_protocol=kProtoUnknown,quic::ParsedQuicVersion quic_version=quic::ParsedQuicVersion::Unsupported ())63 std::unique_ptr<HttpStreamFactory::Job> TestJobFactory::CreateJob(
64     HttpStreamFactory::Job::Delegate* delegate,
65     HttpStreamFactory::JobType job_type,
66     HttpNetworkSession* session,
67     const HttpRequestInfo& request_info,
68     RequestPriority priority,
69     const ProxyInfo& proxy_info,
70     const SSLConfig& server_ssl_config,
71     const SSLConfig& proxy_ssl_config,
72     url::SchemeHostPort destination,
73     GURL origin_url,
74     bool is_websocket,
75     bool enable_ip_based_pooling,
76     NetLog* net_log,
77     NextProto alternative_protocol = kProtoUnknown,
78     quic::ParsedQuicVersion quic_version =
79         quic::ParsedQuicVersion::Unsupported()) {
80   auto job = std::make_unique<MockHttpStreamFactoryJob>(
81       delegate, job_type, session, request_info, priority, proxy_info,
82       SSLConfig(), SSLConfig(), std::move(destination), origin_url,
83       alternative_protocol, quic_version, is_websocket, enable_ip_based_pooling,
84       net_log);
85 
86   // Keep raw pointer to Job but pass ownership.
87   switch (job_type) {
88     case HttpStreamFactory::MAIN:
89       main_job_ = job.get();
90       break;
91     case HttpStreamFactory::ALTERNATIVE:
92       alternative_job_ = job.get();
93       break;
94     case HttpStreamFactory::DNS_ALPN_H3:
95       dns_alpn_h3_job_ = job.get();
96       break;
97     case HttpStreamFactory::PRECONNECT:
98       main_job_ = job.get();
99       break;
100     case HttpStreamFactory::PRECONNECT_DNS_ALPN_H3:
101       main_job_ = job.get();
102       break;
103   }
104   return job;
105 }
106 
107 }  // namespace net
108