OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 TestDelegate delegate_; | 224 TestDelegate delegate_; |
225 scoped_ptr<URLRequest> req_; | 225 scoped_ptr<URLRequest> req_; |
226 }; | 226 }; |
227 | 227 |
228 class MockCreateHelper : public WebSocketHandshakeStreamBase::CreateHelper { | 228 class MockCreateHelper : public WebSocketHandshakeStreamBase::CreateHelper { |
229 public: | 229 public: |
230 // GoogleMock does not appear to play nicely with move-only types like | 230 // GoogleMock does not appear to play nicely with move-only types like |
231 // scoped_ptr, so this forwarding method acts as a workaround. | 231 // scoped_ptr, so this forwarding method acts as a workaround. |
232 virtual WebSocketHandshakeStreamBase* CreateBasicStream( | 232 virtual WebSocketHandshakeStreamBase* CreateBasicStream( |
233 scoped_ptr<ClientSocketHandle> connection, | 233 scoped_ptr<ClientSocketHandle> connection, |
234 bool using_proxy) OVERRIDE { | 234 bool using_proxy) override { |
235 // Discard the arguments since we don't need them anyway. | 235 // Discard the arguments since we don't need them anyway. |
236 return CreateBasicStreamMock(); | 236 return CreateBasicStreamMock(); |
237 } | 237 } |
238 | 238 |
239 MOCK_METHOD0(CreateBasicStreamMock, | 239 MOCK_METHOD0(CreateBasicStreamMock, |
240 WebSocketHandshakeStreamBase*()); | 240 WebSocketHandshakeStreamBase*()); |
241 | 241 |
242 MOCK_METHOD2(CreateSpdyStream, | 242 MOCK_METHOD2(CreateSpdyStream, |
243 WebSocketHandshakeStreamBase*(const base::WeakPtr<SpdySession>&, | 243 WebSocketHandshakeStreamBase*(const base::WeakPtr<SpdySession>&, |
244 bool)); | 244 bool)); |
245 }; | 245 }; |
246 | 246 |
247 class FakeWebSocketHandshakeStream : public WebSocketHandshakeStreamBase { | 247 class FakeWebSocketHandshakeStream : public WebSocketHandshakeStreamBase { |
248 public: | 248 public: |
249 FakeWebSocketHandshakeStream() : initialize_stream_was_called_(false) {} | 249 FakeWebSocketHandshakeStream() : initialize_stream_was_called_(false) {} |
250 | 250 |
251 bool initialize_stream_was_called() const { | 251 bool initialize_stream_was_called() const { |
252 return initialize_stream_was_called_; | 252 return initialize_stream_was_called_; |
253 } | 253 } |
254 | 254 |
255 // Fake implementation of HttpStreamBase methods. | 255 // Fake implementation of HttpStreamBase methods. |
256 virtual int InitializeStream(const HttpRequestInfo* request_info, | 256 virtual int InitializeStream(const HttpRequestInfo* request_info, |
257 RequestPriority priority, | 257 RequestPriority priority, |
258 const BoundNetLog& net_log, | 258 const BoundNetLog& net_log, |
259 const CompletionCallback& callback) OVERRIDE { | 259 const CompletionCallback& callback) override { |
260 initialize_stream_was_called_ = true; | 260 initialize_stream_was_called_ = true; |
261 return ERR_IO_PENDING; | 261 return ERR_IO_PENDING; |
262 } | 262 } |
263 | 263 |
264 virtual int SendRequest(const HttpRequestHeaders& request_headers, | 264 virtual int SendRequest(const HttpRequestHeaders& request_headers, |
265 HttpResponseInfo* response, | 265 HttpResponseInfo* response, |
266 const CompletionCallback& callback) OVERRIDE { | 266 const CompletionCallback& callback) override { |
267 return ERR_IO_PENDING; | 267 return ERR_IO_PENDING; |
268 } | 268 } |
269 | 269 |
270 virtual int ReadResponseHeaders(const CompletionCallback& callback) OVERRIDE { | 270 virtual int ReadResponseHeaders(const CompletionCallback& callback) override { |
271 return ERR_IO_PENDING; | 271 return ERR_IO_PENDING; |
272 } | 272 } |
273 | 273 |
274 virtual int ReadResponseBody(IOBuffer* buf, | 274 virtual int ReadResponseBody(IOBuffer* buf, |
275 int buf_len, | 275 int buf_len, |
276 const CompletionCallback& callback) OVERRIDE { | 276 const CompletionCallback& callback) override { |
277 return ERR_IO_PENDING; | 277 return ERR_IO_PENDING; |
278 } | 278 } |
279 | 279 |
280 virtual void Close(bool not_reusable) OVERRIDE {} | 280 virtual void Close(bool not_reusable) override {} |
281 | 281 |
282 virtual bool IsResponseBodyComplete() const OVERRIDE { return false; } | 282 virtual bool IsResponseBodyComplete() const override { return false; } |
283 | 283 |
284 virtual bool CanFindEndOfResponse() const OVERRIDE { return false; } | 284 virtual bool CanFindEndOfResponse() const override { return false; } |
285 | 285 |
286 virtual bool IsConnectionReused() const OVERRIDE { return false; } | 286 virtual bool IsConnectionReused() const override { return false; } |
287 virtual void SetConnectionReused() OVERRIDE {} | 287 virtual void SetConnectionReused() override {} |
288 | 288 |
289 virtual bool IsConnectionReusable() const OVERRIDE { return false; } | 289 virtual bool IsConnectionReusable() const override { return false; } |
290 | 290 |
291 virtual int64 GetTotalReceivedBytes() const OVERRIDE { return 0; } | 291 virtual int64 GetTotalReceivedBytes() const override { return 0; } |
292 | 292 |
293 virtual bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const | 293 virtual bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const |
294 OVERRIDE { | 294 override { |
295 return false; | 295 return false; |
296 } | 296 } |
297 | 297 |
298 virtual void GetSSLInfo(SSLInfo* ssl_info) OVERRIDE {} | 298 virtual void GetSSLInfo(SSLInfo* ssl_info) override {} |
299 | 299 |
300 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) | 300 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) |
301 OVERRIDE {} | 301 override {} |
302 | 302 |
303 virtual bool IsSpdyHttpStream() const OVERRIDE { return false; } | 303 virtual bool IsSpdyHttpStream() const override { return false; } |
304 | 304 |
305 virtual void Drain(HttpNetworkSession* session) OVERRIDE {} | 305 virtual void Drain(HttpNetworkSession* session) override {} |
306 | 306 |
307 virtual void SetPriority(RequestPriority priority) OVERRIDE {} | 307 virtual void SetPriority(RequestPriority priority) override {} |
308 | 308 |
309 // Fake implementation of WebSocketHandshakeStreamBase method(s) | 309 // Fake implementation of WebSocketHandshakeStreamBase method(s) |
310 virtual scoped_ptr<WebSocketStream> Upgrade() OVERRIDE { | 310 virtual scoped_ptr<WebSocketStream> Upgrade() override { |
311 return scoped_ptr<WebSocketStream>(); | 311 return scoped_ptr<WebSocketStream>(); |
312 } | 312 } |
313 | 313 |
314 private: | 314 private: |
315 bool initialize_stream_was_called_; | 315 bool initialize_stream_was_called_; |
316 }; | 316 }; |
317 | 317 |
318 TEST_F(URLRequestHttpJobWebSocketTest, RejectedWithoutCreateHelper) { | 318 TEST_F(URLRequestHttpJobWebSocketTest, RejectedWithoutCreateHelper) { |
319 scoped_refptr<TestURLRequestHttpJob> job( | 319 scoped_refptr<TestURLRequestHttpJob> job( |
320 new TestURLRequestHttpJob(req_.get())); | 320 new TestURLRequestHttpJob(req_.get())); |
(...skipping 19 matching lines...) Expand all Loading... |
340 req_->SetLoadFlags(LOAD_DISABLE_CACHE); | 340 req_->SetLoadFlags(LOAD_DISABLE_CACHE); |
341 job->Start(); | 341 job->Start(); |
342 base::RunLoop().RunUntilIdle(); | 342 base::RunLoop().RunUntilIdle(); |
343 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); | 343 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); |
344 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 344 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
345 } | 345 } |
346 | 346 |
347 } // namespace | 347 } // namespace |
348 | 348 |
349 } // namespace net | 349 } // namespace net |
OLD | NEW |