Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "testing/gmock/include/gmock/gmock.h" | |
| 16 | |
| 17 namespace net { | |
| 18 | |
| 19 class HttpStreamFactoryImplPeer { | |
| 20 public: | |
| 21 static void AddJobController( | |
| 22 HttpStreamFactoryImpl* factory, | |
| 23 HttpStreamFactoryImpl::JobController* job_controller) { | |
| 24 factory->job_controller_set_.insert(base::WrapUnique(job_controller)); | |
| 25 } | |
| 26 | |
| 27 static bool IsJobControllerDeleted(HttpStreamFactoryImpl* factory) { | |
| 28 return factory->job_controller_set_.empty(); | |
| 29 } | |
| 30 | |
| 31 static HttpStreamFactoryImpl::JobFactory* GetDefaultJobFactory( | |
| 32 HttpStreamFactoryImpl* factory) { | |
| 33 return factory->job_factory_.get(); | |
| 34 } | |
| 35 }; | |
| 36 | |
| 37 // This delegate does nothing when called. | |
| 38 class MockHttpStreamRequestDelegate : public HttpStreamRequest::Delegate { | |
| 39 public: | |
| 40 MockHttpStreamRequestDelegate(); | |
| 41 | |
| 42 ~MockHttpStreamRequestDelegate() override; | |
| 43 | |
| 44 MOCK_METHOD3(OnStreamReady, | |
| 45 void(const SSLConfig& used_ssl_config, | |
| 46 const ProxyInfo& used_proxy_info, | |
| 47 HttpStream* stream)); | |
| 48 | |
| 49 MOCK_METHOD3(OnBidirectionalStreamImplReady, | |
| 50 void(const SSLConfig& used_ssl_config, | |
| 51 const ProxyInfo& used_proxy_info, | |
| 52 BidirectionalStreamImpl* stream)); | |
| 53 | |
| 54 MOCK_METHOD3(OnWebSocketHandshakeStreamReady, | |
| 55 void(const SSLConfig& used_ssl_config, | |
| 56 const ProxyInfo& used_proxy_info, | |
| 57 WebSocketHandshakeStreamBase* stream)); | |
| 58 | |
| 59 MOCK_METHOD3(OnStreamFailed, | |
| 60 void(int status, | |
| 61 const SSLConfig& used_ssl_config, | |
| 62 SSLFailureState ssl_failure_state)); | |
| 63 | |
| 64 MOCK_METHOD3(OnCertificateError, | |
| 65 void(int status, | |
| 66 const SSLConfig& used_ssl_config, | |
| 67 const SSLInfo& ssl_info)); | |
| 68 | |
| 69 MOCK_METHOD4(OnNeedsProxyAuth, | |
| 70 void(const HttpResponseInfo& proxy_response, | |
| 71 const SSLConfig& used_ssl_config, | |
| 72 const ProxyInfo& used_proxy_info, | |
| 73 HttpAuthController* auth_controller)); | |
| 74 | |
| 75 MOCK_METHOD2(OnNeedsClientAuth, | |
| 76 void(const SSLConfig& used_ssl_config, | |
| 77 SSLCertRequestInfo* cert_info)); | |
| 78 | |
| 79 MOCK_METHOD4(OnHttpsProxyTunnelResponse, | |
| 80 void(const HttpResponseInfo& response_info, | |
| 81 const SSLConfig& used_ssl_config, | |
| 82 const ProxyInfo& used_proxy_info, | |
| 83 HttpStream* stream)); | |
| 84 | |
| 85 MOCK_METHOD0(OnQuicBroken, void()); | |
| 86 | |
| 87 private: | |
| 88 DISALLOW_COPY_AND_ASSIGN(MockHttpStreamRequestDelegate); | |
| 89 }; | |
| 90 | |
| 91 class TestHttpStreamFactoryImplJob : public HttpStreamFactoryImpl::Job { | |
|
Ryan Hamilton
2016/06/15 23:34:20
nit: this should be Mock
Zhongyi Shi
2016/06/16 00:02:31
Done.
| |
| 92 public: | |
| 93 TestHttpStreamFactoryImplJob(HttpStreamFactoryImpl::Job::Delegate* delegate, | |
| 94 HttpStreamFactoryImpl::JobType job_type, | |
| 95 HttpNetworkSession* session, | |
| 96 const HttpRequestInfo& request_info, | |
| 97 RequestPriority priority, | |
| 98 const SSLConfig& server_ssl_config, | |
| 99 const SSLConfig& proxy_ssl_config, | |
| 100 HostPortPair destination, | |
| 101 GURL origin_url, | |
| 102 NetLog* net_log); | |
| 103 | |
| 104 TestHttpStreamFactoryImplJob(HttpStreamFactoryImpl::Job::Delegate* delegate, | |
| 105 HttpStreamFactoryImpl::JobType job_type, | |
| 106 HttpNetworkSession* session, | |
| 107 const HttpRequestInfo& request_info, | |
| 108 RequestPriority priority, | |
| 109 const SSLConfig& server_ssl_config, | |
| 110 const SSLConfig& proxy_ssl_config, | |
| 111 HostPortPair destination, | |
| 112 GURL origin_url, | |
| 113 AlternativeService alternative_service, | |
| 114 NetLog* net_log); | |
| 115 | |
| 116 ~TestHttpStreamFactoryImplJob() override; | |
| 117 | |
| 118 MOCK_METHOD1(Start, void(HttpStreamRequest::StreamType stream_type)); | |
| 119 | |
| 120 MOCK_METHOD1(MarkOtherJobComplete, void(const Job& job)); | |
| 121 | |
| 122 MOCK_METHOD0(Orphan, void()); | |
| 123 }; | |
| 124 | |
| 125 class TestJobFactory : public HttpStreamFactoryImpl::JobFactory { | |
| 126 public: | |
| 127 TestJobFactory(); | |
| 128 ~TestJobFactory() override; | |
| 129 | |
| 130 HttpStreamFactoryImpl::Job* CreateJob( | |
| 131 HttpStreamFactoryImpl::Job::Delegate* delegate, | |
| 132 HttpStreamFactoryImpl::JobType job_type, | |
| 133 HttpNetworkSession* session, | |
| 134 const HttpRequestInfo& request_info, | |
| 135 RequestPriority priority, | |
| 136 const SSLConfig& server_ssl_config, | |
| 137 const SSLConfig& proxy_ssl_config, | |
| 138 HostPortPair destination, | |
| 139 GURL origin_url, | |
| 140 NetLog* net_log) override; | |
| 141 | |
| 142 HttpStreamFactoryImpl::Job* CreateJob( | |
| 143 HttpStreamFactoryImpl::Job::Delegate* delegate, | |
| 144 HttpStreamFactoryImpl::JobType job_type, | |
| 145 HttpNetworkSession* session, | |
| 146 const HttpRequestInfo& request_info, | |
| 147 RequestPriority priority, | |
| 148 const SSLConfig& server_ssl_config, | |
| 149 const SSLConfig& proxy_ssl_config, | |
| 150 HostPortPair destination, | |
| 151 GURL origin_url, | |
| 152 AlternativeService alternative_service, | |
| 153 NetLog* net_log) override; | |
| 154 | |
| 155 TestHttpStreamFactoryImplJob* main_job() const { return main_job_; } | |
| 156 TestHttpStreamFactoryImplJob* alternative_job() const { | |
| 157 return alternative_job_; | |
| 158 } | |
| 159 | |
| 160 private: | |
| 161 TestHttpStreamFactoryImplJob* main_job_; | |
| 162 TestHttpStreamFactoryImplJob* alternative_job_; | |
| 163 }; | |
| 164 | |
| 165 } // namespace net | |
| 166 | |
| 167 #endif // NET_HTTP_HTTP_STREAM_FACTORY_TEST_UTIL_H_ | |
| OLD | NEW |