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

Side by Side Diff: net/http/http_stream_factory_test_util.h

Issue 1941083002: JobController 1: Adding a new class HttpStreamFactoryImpl::JobController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge unittests to this CL Created 4 years, 7 months 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
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_TEST_UTIL_H_
6 #define NET_HTTP_HTTP_STREAM_FACTORY_TEST_UTIL_H_
7
8 #include "base/memory/ptr_util.h"
9 #include "net/http/http_stream.h"
10 #include "net/http/http_stream_factory.h"
11 #include "net/http/http_stream_factory_impl.h"
12 #include "net/http/http_stream_factory_impl_job.h"
13 #include "net/http/http_stream_factory_impl_job_controller.h"
14 #include "net/proxy/proxy_info.h"
15 #include "net/proxy/proxy_service.h"
16 #include "net/spdy/spdy_test_util_common.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18
19 namespace net {
20
21 // This delegate does nothing when called.
22 class TestHttpStreamRequestDelegate : public HttpStreamRequest::Delegate {
23 public:
24 TestHttpStreamRequestDelegate();
25
26 ~TestHttpStreamRequestDelegate() override;
27
28 MOCK_METHOD3(OnStreamReady,
29 void(const SSLConfig& used_ssl_config,
30 const ProxyInfo& used_proxy_info,
31 HttpStream* stream));
32
33 void OnBidirectionalStreamImplReady(
34 const SSLConfig& used_ssl_config,
35 const ProxyInfo& used_proxy_info,
36 BidirectionalStreamImpl* stream) override {}
37
38 void OnWebSocketHandshakeStreamReady(
39 const SSLConfig& used_ssl_config,
40 const ProxyInfo& used_proxy_info,
41 WebSocketHandshakeStreamBase* stream) override {}
42
43 MOCK_METHOD3(OnStreamFailed,
44 void(int status,
45 const SSLConfig& used_ssl_config,
46 SSLFailureState ssl_failure_state));
47
48 MOCK_METHOD3(OnCertificateError,
49 void(int status,
50 const SSLConfig& used_ssl_config,
51 const SSLInfo& ssl_info));
52
53 MOCK_METHOD4(OnNeedsProxyAuth,
54 void(const HttpResponseInfo& proxy_response,
55 const SSLConfig& used_ssl_config,
56 const ProxyInfo& used_proxy_info,
57 HttpAuthController* auth_controller));
58
59 MOCK_METHOD2(OnNeedsClientAuth,
60 void(const SSLConfig& used_ssl_config,
61 SSLCertRequestInfo* cert_info));
62
63 MOCK_METHOD4(OnHttpsProxyTunnelResponse,
64 void(const HttpResponseInfo& response_info,
65 const SSLConfig& used_ssl_config,
66 const ProxyInfo& used_proxy_info,
67 HttpStream* stream));
68
69 MOCK_METHOD0(OnQuicBroken, void());
70
71 private:
72 DISALLOW_COPY_AND_ASSIGN(TestHttpStreamRequestDelegate);
73 };
74
75 class TestHttpStreamFactoryImplJob : public HttpStreamFactoryImpl::Job {
76 public:
77 TestHttpStreamFactoryImplJob(HttpStreamFactoryImpl::Job::Delegate* delegate,
78 HttpStreamFactoryImpl::JobType job_type,
79 HttpNetworkSession* session,
80 const HttpRequestInfo& request_info,
81 RequestPriority priority,
82 const SSLConfig& server_ssl_config,
83 const SSLConfig& proxy_ssl_config,
84 HostPortPair destination,
85 GURL origin_url,
86 NetLog* net_log);
87
88 TestHttpStreamFactoryImplJob(HttpStreamFactoryImpl::Job::Delegate* delegate,
89 HttpStreamFactoryImpl::JobType job_type,
90 HttpNetworkSession* session,
91 const HttpRequestInfo& request_info,
92 RequestPriority priority,
93 const SSLConfig& server_ssl_config,
94 const SSLConfig& proxy_ssl_config,
95 HostPortPair destination,
96 GURL origin_url,
97 AlternativeService alternative_service,
98 NetLog* net_log);
99
100 ~TestHttpStreamFactoryImplJob() override;
101
102 MOCK_METHOD1(MarkOtherJobComplete, void(const Job& job));
103
104 MOCK_METHOD0(Orphan, void());
105 };
106
107 class TestJobControllerPeer {
108 public:
109 TestJobControllerPeer(NextProto protocol,
110 TestHttpStreamRequestDelegate* request_delegate);
111
112 ~TestJobControllerPeer();
113
114 void CreateRequest(HttpRequestInfo request_info);
115
116 void CancelRequest() { request_.reset(); }
117
118 GURL ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint);
119
120 void ClearMainJob();
121
122 void SetMainJob(HttpStreamFactoryImpl::Job* main_job);
123
124 void SetAlternativeJob(HttpStreamFactoryImpl::Job* main_job);
125
126 void OnStreamFailed(HttpStreamFactoryImpl::Job* job,
127 int status,
128 const SSLConfig& used_ssl_config,
129 SSLFailureState ssl_failure_state);
130
131 void OnStreamReady(HttpStreamFactoryImpl::Job* job,
132 const SSLConfig& used_ssl_config,
133 const ProxyInfo& used_proxy_info);
134
135 void MaybeNotifyFactoryOfCompletion();
136
137 bool IsJobControllerDeleted() {
138 return factory_->job_controller_set_.empty();
139 }
140
141 HttpNetworkSession* session() { return session_.get(); }
142
143 HttpStreamFactoryImpl::JobController* job_controller() {
144 return job_controller_;
145 }
146
147 bool job_bound() { return job_controller_->job_bound_; }
148
149 HttpStreamFactoryImpl::Job* bound_job() {
150 return job_controller_->bound_job_;
151 }
152
153 HttpStreamFactoryImpl::Job* alternative_job() {
154 return job_controller_->alternative_job_.get();
155 }
156
157 HttpStreamFactoryImpl::Job* main_job() {
158 return job_controller_->main_job_.get();
159 }
160
161 private:
162 SpdySessionDependencies session_deps_;
163 TestHttpStreamRequestDelegate* request_delegate_;
164 std::unique_ptr<HttpNetworkSession> session_;
165 HttpStreamFactoryImpl* factory_;
166 HttpStreamFactoryImpl::JobController* job_controller_;
167 std::unique_ptr<HttpStreamFactoryImpl::Request> request_;
168 TestHttpStreamFactoryImplJob* main_job_;
169 TestHttpStreamFactoryImplJob* alternative_job_;
170
171 DISALLOW_COPY_AND_ASSIGN(TestJobControllerPeer);
172 };
173
174 } // namespace net
175
176 #endif // NET_HTTP_HTTP_STREAM_FACTORY_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698