| 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 MockHttpStreamFactoryImplJob : public HttpStreamFactoryImpl::Job { |
| 92 public: |
| 93 MockHttpStreamFactoryImplJob(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 MockHttpStreamFactoryImplJob(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 ~MockHttpStreamFactoryImplJob() 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 // JobFactory for creating MockHttpStreamFactoryImplJobs. |
| 126 class TestJobFactory : public HttpStreamFactoryImpl::JobFactory { |
| 127 public: |
| 128 TestJobFactory(); |
| 129 ~TestJobFactory() override; |
| 130 |
| 131 HttpStreamFactoryImpl::Job* CreateJob( |
| 132 HttpStreamFactoryImpl::Job::Delegate* delegate, |
| 133 HttpStreamFactoryImpl::JobType job_type, |
| 134 HttpNetworkSession* session, |
| 135 const HttpRequestInfo& request_info, |
| 136 RequestPriority priority, |
| 137 const SSLConfig& server_ssl_config, |
| 138 const SSLConfig& proxy_ssl_config, |
| 139 HostPortPair destination, |
| 140 GURL origin_url, |
| 141 NetLog* net_log) override; |
| 142 |
| 143 HttpStreamFactoryImpl::Job* CreateJob( |
| 144 HttpStreamFactoryImpl::Job::Delegate* delegate, |
| 145 HttpStreamFactoryImpl::JobType job_type, |
| 146 HttpNetworkSession* session, |
| 147 const HttpRequestInfo& request_info, |
| 148 RequestPriority priority, |
| 149 const SSLConfig& server_ssl_config, |
| 150 const SSLConfig& proxy_ssl_config, |
| 151 HostPortPair destination, |
| 152 GURL origin_url, |
| 153 AlternativeService alternative_service, |
| 154 NetLog* net_log) override; |
| 155 |
| 156 MockHttpStreamFactoryImplJob* main_job() const { return main_job_; } |
| 157 MockHttpStreamFactoryImplJob* alternative_job() const { |
| 158 return alternative_job_; |
| 159 } |
| 160 |
| 161 private: |
| 162 MockHttpStreamFactoryImplJob* main_job_; |
| 163 MockHttpStreamFactoryImplJob* alternative_job_; |
| 164 }; |
| 165 |
| 166 } // namespace net |
| 167 |
| 168 #endif // NET_HTTP_HTTP_STREAM_FACTORY_TEST_UTIL_H_ |
| OLD | NEW |