xref: /aosp_15_r20/external/cronet/net/http/http_stream_factory_test_util.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 HttpStreamFactory::StreamRequestInfo & request_info,RequestPriority priority,ProxyInfo proxy_info,const std::vector<SSLConfig::CertAndStatus> & allowed_bad_certs,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 HttpStreamFactory::StreamRequestInfo& request_info,
24     RequestPriority priority,
25     ProxyInfo proxy_info,
26     const std::vector<SSLConfig::CertAndStatus>& allowed_bad_certs,
27     url::SchemeHostPort destination,
28     GURL origin_url,
29     NextProto alternative_protocol,
30     quic::ParsedQuicVersion quic_version,
31     bool is_websocket,
32     bool enable_ip_based_pooling,
33     NetLog* net_log)
34     : HttpStreamFactory::Job(delegate,
35                              job_type,
36                              session,
37                              request_info,
38                              priority,
39                              proxy_info,
40                              allowed_bad_certs,
41                              std::move(destination),
42                              origin_url,
43                              alternative_protocol,
44                              quic_version,
45                              is_websocket,
46                              enable_ip_based_pooling,
47                              net_log) {
48   DCHECK(!is_waiting());
49 }
50 
51 MockHttpStreamFactoryJob::~MockHttpStreamFactoryJob() = default;
52 
DoResume()53 void MockHttpStreamFactoryJob::DoResume() {
54   HttpStreamFactory::Job::Resume();
55 }
56 
57 TestJobFactory::TestJobFactory() = default;
58 
59 TestJobFactory::~TestJobFactory() = default;
60 
CreateJob(HttpStreamFactory::Job::Delegate * delegate,HttpStreamFactory::JobType job_type,HttpNetworkSession * session,const HttpStreamFactory::StreamRequestInfo & request_info,RequestPriority priority,const ProxyInfo & proxy_info,const std::vector<SSLConfig::CertAndStatus> & allowed_bad_certs,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 ())61 std::unique_ptr<HttpStreamFactory::Job> TestJobFactory::CreateJob(
62     HttpStreamFactory::Job::Delegate* delegate,
63     HttpStreamFactory::JobType job_type,
64     HttpNetworkSession* session,
65     const HttpStreamFactory::StreamRequestInfo& request_info,
66     RequestPriority priority,
67     const ProxyInfo& proxy_info,
68     const std::vector<SSLConfig::CertAndStatus>& allowed_bad_certs,
69     url::SchemeHostPort destination,
70     GURL origin_url,
71     bool is_websocket,
72     bool enable_ip_based_pooling,
73     NetLog* net_log,
74     NextProto alternative_protocol = kProtoUnknown,
75     quic::ParsedQuicVersion quic_version =
76         quic::ParsedQuicVersion::Unsupported()) {
77   auto job = std::make_unique<MockHttpStreamFactoryJob>(
78       delegate, job_type, session, request_info, priority, proxy_info,
79       allowed_bad_certs, std::move(destination), origin_url,
80       alternative_protocol, quic_version, is_websocket, enable_ip_based_pooling,
81       net_log);
82 
83   // Keep raw pointer to Job but pass ownership.
84   switch (job_type) {
85     case HttpStreamFactory::MAIN:
86       main_job_ = job.get();
87       break;
88     case HttpStreamFactory::ALTERNATIVE:
89       alternative_job_ = job.get();
90       break;
91     case HttpStreamFactory::DNS_ALPN_H3:
92       dns_alpn_h3_job_ = job.get();
93       break;
94     case HttpStreamFactory::PRECONNECT:
95       main_job_ = job.get();
96       break;
97     case HttpStreamFactory::PRECONNECT_DNS_ALPN_H3:
98       main_job_ = job.get();
99       break;
100   }
101   return job;
102 }
103 
104 }  // namespace net
105