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

Side by Side Diff: net/http/http_stream_factory_impl_unittest.cc

Issue 667923003: Standardize usage of virtual/override/final in net/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « net/http/http_stream_factory_impl_request_unittest.cc ('k') | net/http/http_stream_parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_stream_factory_impl.h" 5 #include "net/http/http_stream_factory_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 class MockWebSocketHandshakeStream : public WebSocketHandshakeStreamBase { 46 class MockWebSocketHandshakeStream : public WebSocketHandshakeStreamBase {
47 public: 47 public:
48 enum StreamType { 48 enum StreamType {
49 kStreamTypeBasic, 49 kStreamTypeBasic,
50 kStreamTypeSpdy, 50 kStreamTypeSpdy,
51 }; 51 };
52 52
53 explicit MockWebSocketHandshakeStream(StreamType type) : type_(type) {} 53 explicit MockWebSocketHandshakeStream(StreamType type) : type_(type) {}
54 54
55 virtual ~MockWebSocketHandshakeStream() {} 55 ~MockWebSocketHandshakeStream() override {}
56 56
57 StreamType type() const { 57 StreamType type() const {
58 return type_; 58 return type_;
59 } 59 }
60 60
61 // HttpStreamBase methods 61 // HttpStreamBase methods
62 virtual int InitializeStream(const HttpRequestInfo* request_info, 62 int InitializeStream(const HttpRequestInfo* request_info,
63 RequestPriority priority, 63 RequestPriority priority,
64 const BoundNetLog& net_log, 64 const BoundNetLog& net_log,
65 const CompletionCallback& callback) override { 65 const CompletionCallback& callback) override {
66 return ERR_IO_PENDING; 66 return ERR_IO_PENDING;
67 } 67 }
68 virtual int SendRequest(const HttpRequestHeaders& request_headers, 68 int SendRequest(const HttpRequestHeaders& request_headers,
69 HttpResponseInfo* response, 69 HttpResponseInfo* response,
70 const CompletionCallback& callback) override { 70 const CompletionCallback& callback) override {
71 return ERR_IO_PENDING; 71 return ERR_IO_PENDING;
72 } 72 }
73 virtual int ReadResponseHeaders(const CompletionCallback& callback) override { 73 int ReadResponseHeaders(const CompletionCallback& callback) override {
74 return ERR_IO_PENDING; 74 return ERR_IO_PENDING;
75 } 75 }
76 virtual int ReadResponseBody(IOBuffer* buf, 76 int ReadResponseBody(IOBuffer* buf,
77 int buf_len, 77 int buf_len,
78 const CompletionCallback& callback) override { 78 const CompletionCallback& callback) override {
79 return ERR_IO_PENDING; 79 return ERR_IO_PENDING;
80 } 80 }
81 virtual void Close(bool not_reusable) override {} 81 void Close(bool not_reusable) override {}
82 virtual bool IsResponseBodyComplete() const override { return false; } 82 bool IsResponseBodyComplete() const override { return false; }
83 virtual bool CanFindEndOfResponse() const override { return false; } 83 bool CanFindEndOfResponse() const override { return false; }
84 virtual bool IsConnectionReused() const override { return false; } 84 bool IsConnectionReused() const override { return false; }
85 virtual void SetConnectionReused() override {} 85 void SetConnectionReused() override {}
86 virtual bool IsConnectionReusable() const override { return false; } 86 bool IsConnectionReusable() const override { return false; }
87 virtual int64 GetTotalReceivedBytes() const override { return 0; } 87 int64 GetTotalReceivedBytes() const override { return 0; }
88 virtual bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const 88 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override {
89 override {
90 return false; 89 return false;
91 } 90 }
92 virtual void GetSSLInfo(SSLInfo* ssl_info) override {} 91 void GetSSLInfo(SSLInfo* ssl_info) override {}
93 virtual void GetSSLCertRequestInfo( 92 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override {}
94 SSLCertRequestInfo* cert_request_info) override {} 93 bool IsSpdyHttpStream() const override { return false; }
95 virtual bool IsSpdyHttpStream() const override { return false; } 94 void Drain(HttpNetworkSession* session) override {}
96 virtual void Drain(HttpNetworkSession* session) override {} 95 void SetPriority(RequestPriority priority) override {}
97 virtual void SetPriority(RequestPriority priority) override {}
98 96
99 virtual scoped_ptr<WebSocketStream> Upgrade() override { 97 scoped_ptr<WebSocketStream> Upgrade() override {
100 return scoped_ptr<WebSocketStream>(); 98 return scoped_ptr<WebSocketStream>();
101 } 99 }
102 100
103 private: 101 private:
104 const StreamType type_; 102 const StreamType type_;
105 }; 103 };
106 104
107 // HttpStreamFactoryImpl subclass that can wait until a preconnect is complete. 105 // HttpStreamFactoryImpl subclass that can wait until a preconnect is complete.
108 class MockHttpStreamFactoryImplForPreconnect : public HttpStreamFactoryImpl { 106 class MockHttpStreamFactoryImplForPreconnect : public HttpStreamFactoryImpl {
109 public: 107 public:
110 MockHttpStreamFactoryImplForPreconnect(HttpNetworkSession* session, 108 MockHttpStreamFactoryImplForPreconnect(HttpNetworkSession* session,
111 bool for_websockets) 109 bool for_websockets)
112 : HttpStreamFactoryImpl(session, for_websockets), 110 : HttpStreamFactoryImpl(session, for_websockets),
113 preconnect_done_(false), 111 preconnect_done_(false),
114 waiting_for_preconnect_(false) {} 112 waiting_for_preconnect_(false) {}
115 113
116 114
117 void WaitForPreconnects() { 115 void WaitForPreconnects() {
118 while (!preconnect_done_) { 116 while (!preconnect_done_) {
119 waiting_for_preconnect_ = true; 117 waiting_for_preconnect_ = true;
120 base::MessageLoop::current()->Run(); 118 base::MessageLoop::current()->Run();
121 waiting_for_preconnect_ = false; 119 waiting_for_preconnect_ = false;
122 } 120 }
123 } 121 }
124 122
125 private: 123 private:
126 // HttpStreamFactoryImpl methods. 124 // HttpStreamFactoryImpl methods.
127 virtual void OnPreconnectsCompleteInternal() override { 125 void OnPreconnectsCompleteInternal() override {
128 preconnect_done_ = true; 126 preconnect_done_ = true;
129 if (waiting_for_preconnect_) 127 if (waiting_for_preconnect_)
130 base::MessageLoop::current()->Quit(); 128 base::MessageLoop::current()->Quit();
131 } 129 }
132 130
133 bool preconnect_done_; 131 bool preconnect_done_;
134 bool waiting_for_preconnect_; 132 bool waiting_for_preconnect_;
135 }; 133 };
136 134
137 class StreamRequestWaiter : public HttpStreamRequest::Delegate { 135 class StreamRequestWaiter : public HttpStreamRequest::Delegate {
138 public: 136 public:
139 StreamRequestWaiter() 137 StreamRequestWaiter()
140 : waiting_for_stream_(false), 138 : waiting_for_stream_(false),
141 stream_done_(false) {} 139 stream_done_(false) {}
142 140
143 // HttpStreamRequest::Delegate 141 // HttpStreamRequest::Delegate
144 142
145 virtual void OnStreamReady( 143 void OnStreamReady(const SSLConfig& used_ssl_config,
146 const SSLConfig& used_ssl_config, 144 const ProxyInfo& used_proxy_info,
147 const ProxyInfo& used_proxy_info, 145 HttpStreamBase* stream) override {
148 HttpStreamBase* stream) override {
149 stream_done_ = true; 146 stream_done_ = true;
150 if (waiting_for_stream_) 147 if (waiting_for_stream_)
151 base::MessageLoop::current()->Quit(); 148 base::MessageLoop::current()->Quit();
152 stream_.reset(stream); 149 stream_.reset(stream);
153 used_ssl_config_ = used_ssl_config; 150 used_ssl_config_ = used_ssl_config;
154 used_proxy_info_ = used_proxy_info; 151 used_proxy_info_ = used_proxy_info;
155 } 152 }
156 153
157 virtual void OnWebSocketHandshakeStreamReady( 154 void OnWebSocketHandshakeStreamReady(
158 const SSLConfig& used_ssl_config, 155 const SSLConfig& used_ssl_config,
159 const ProxyInfo& used_proxy_info, 156 const ProxyInfo& used_proxy_info,
160 WebSocketHandshakeStreamBase* stream) override { 157 WebSocketHandshakeStreamBase* stream) override {
161 stream_done_ = true; 158 stream_done_ = true;
162 if (waiting_for_stream_) 159 if (waiting_for_stream_)
163 base::MessageLoop::current()->Quit(); 160 base::MessageLoop::current()->Quit();
164 websocket_stream_.reset(stream); 161 websocket_stream_.reset(stream);
165 used_ssl_config_ = used_ssl_config; 162 used_ssl_config_ = used_ssl_config;
166 used_proxy_info_ = used_proxy_info; 163 used_proxy_info_ = used_proxy_info;
167 } 164 }
168 165
169 virtual void OnStreamFailed( 166 void OnStreamFailed(int status, const SSLConfig& used_ssl_config) override {}
170 int status,
171 const SSLConfig& used_ssl_config) override {}
172 167
173 virtual void OnCertificateError( 168 void OnCertificateError(int status,
174 int status, 169 const SSLConfig& used_ssl_config,
175 const SSLConfig& used_ssl_config, 170 const SSLInfo& ssl_info) override {}
176 const SSLInfo& ssl_info) override {}
177 171
178 virtual void OnNeedsProxyAuth(const HttpResponseInfo& proxy_response, 172 void OnNeedsProxyAuth(const HttpResponseInfo& proxy_response,
179 const SSLConfig& used_ssl_config, 173 const SSLConfig& used_ssl_config,
180 const ProxyInfo& used_proxy_info, 174 const ProxyInfo& used_proxy_info,
181 HttpAuthController* auth_controller) override {} 175 HttpAuthController* auth_controller) override {}
182 176
183 virtual void OnNeedsClientAuth(const SSLConfig& used_ssl_config, 177 void OnNeedsClientAuth(const SSLConfig& used_ssl_config,
184 SSLCertRequestInfo* cert_info) override {} 178 SSLCertRequestInfo* cert_info) override {}
185 179
186 virtual void OnHttpsProxyTunnelResponse(const HttpResponseInfo& response_info, 180 void OnHttpsProxyTunnelResponse(const HttpResponseInfo& response_info,
187 const SSLConfig& used_ssl_config, 181 const SSLConfig& used_ssl_config,
188 const ProxyInfo& used_proxy_info, 182 const ProxyInfo& used_proxy_info,
189 HttpStreamBase* stream) override {} 183 HttpStreamBase* stream) override {}
190 184
191 void WaitForStream() { 185 void WaitForStream() {
192 while (!stream_done_) { 186 while (!stream_done_) {
193 waiting_for_stream_ = true; 187 waiting_for_stream_ = true;
194 base::MessageLoop::current()->Run(); 188 base::MessageLoop::current()->Run();
195 waiting_for_stream_ = false; 189 waiting_for_stream_ = false;
196 } 190 }
197 } 191 }
198 192
199 const SSLConfig& used_ssl_config() const { 193 const SSLConfig& used_ssl_config() const {
(...skipping 25 matching lines...) Expand all
225 DISALLOW_COPY_AND_ASSIGN(StreamRequestWaiter); 219 DISALLOW_COPY_AND_ASSIGN(StreamRequestWaiter);
226 }; 220 };
227 221
228 class WebSocketSpdyHandshakeStream : public MockWebSocketHandshakeStream { 222 class WebSocketSpdyHandshakeStream : public MockWebSocketHandshakeStream {
229 public: 223 public:
230 explicit WebSocketSpdyHandshakeStream( 224 explicit WebSocketSpdyHandshakeStream(
231 const base::WeakPtr<SpdySession>& spdy_session) 225 const base::WeakPtr<SpdySession>& spdy_session)
232 : MockWebSocketHandshakeStream(kStreamTypeSpdy), 226 : MockWebSocketHandshakeStream(kStreamTypeSpdy),
233 spdy_session_(spdy_session) {} 227 spdy_session_(spdy_session) {}
234 228
235 virtual ~WebSocketSpdyHandshakeStream() {} 229 ~WebSocketSpdyHandshakeStream() override {}
236 230
237 SpdySession* spdy_session() { return spdy_session_.get(); } 231 SpdySession* spdy_session() { return spdy_session_.get(); }
238 232
239 private: 233 private:
240 base::WeakPtr<SpdySession> spdy_session_; 234 base::WeakPtr<SpdySession> spdy_session_;
241 }; 235 };
242 236
243 class WebSocketBasicHandshakeStream : public MockWebSocketHandshakeStream { 237 class WebSocketBasicHandshakeStream : public MockWebSocketHandshakeStream {
244 public: 238 public:
245 explicit WebSocketBasicHandshakeStream( 239 explicit WebSocketBasicHandshakeStream(
246 scoped_ptr<ClientSocketHandle> connection) 240 scoped_ptr<ClientSocketHandle> connection)
247 : MockWebSocketHandshakeStream(kStreamTypeBasic), 241 : MockWebSocketHandshakeStream(kStreamTypeBasic),
248 connection_(connection.Pass()) {} 242 connection_(connection.Pass()) {}
249 243
250 virtual ~WebSocketBasicHandshakeStream() { 244 ~WebSocketBasicHandshakeStream() override {
251 connection_->socket()->Disconnect(); 245 connection_->socket()->Disconnect();
252 } 246 }
253 247
254 ClientSocketHandle* connection() { return connection_.get(); } 248 ClientSocketHandle* connection() { return connection_.get(); }
255 249
256 private: 250 private:
257 scoped_ptr<ClientSocketHandle> connection_; 251 scoped_ptr<ClientSocketHandle> connection_;
258 }; 252 };
259 253
260 class WebSocketStreamCreateHelper 254 class WebSocketStreamCreateHelper
261 : public WebSocketHandshakeStreamBase::CreateHelper { 255 : public WebSocketHandshakeStreamBase::CreateHelper {
262 public: 256 public:
263 virtual ~WebSocketStreamCreateHelper() {} 257 ~WebSocketStreamCreateHelper() override {}
264 258
265 virtual WebSocketHandshakeStreamBase* CreateBasicStream( 259 WebSocketHandshakeStreamBase* CreateBasicStream(
266 scoped_ptr<ClientSocketHandle> connection, 260 scoped_ptr<ClientSocketHandle> connection,
267 bool using_proxy) override { 261 bool using_proxy) override {
268 return new WebSocketBasicHandshakeStream(connection.Pass()); 262 return new WebSocketBasicHandshakeStream(connection.Pass());
269 } 263 }
270 264
271 virtual WebSocketHandshakeStreamBase* CreateSpdyStream( 265 WebSocketHandshakeStreamBase* CreateSpdyStream(
272 const base::WeakPtr<SpdySession>& spdy_session, 266 const base::WeakPtr<SpdySession>& spdy_session,
273 bool use_relative_url) override { 267 bool use_relative_url) override {
274 return new WebSocketSpdyHandshakeStream(spdy_session); 268 return new WebSocketSpdyHandshakeStream(spdy_session);
275 } 269 }
276 }; 270 };
277 271
278 struct TestCase { 272 struct TestCase {
279 int num_streams; 273 int num_streams;
280 bool ssl; 274 bool ssl;
281 }; 275 };
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); 1297 EXPECT_TRUE(waiter.used_proxy_info().is_direct());
1304 1298
1305 // Make sure there is no orphaned job. it is already canceled. 1299 // Make sure there is no orphaned job. it is already canceled.
1306 ASSERT_EQ(0u, static_cast<HttpStreamFactoryImpl*>( 1300 ASSERT_EQ(0u, static_cast<HttpStreamFactoryImpl*>(
1307 session->http_stream_factory_for_websocket())->num_orphaned_jobs()); 1301 session->http_stream_factory_for_websocket())->num_orphaned_jobs());
1308 } 1302 }
1309 1303
1310 } // namespace 1304 } // namespace
1311 1305
1312 } // namespace net 1306 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_request_unittest.cc ('k') | net/http/http_stream_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698