| 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 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 using ::testing::Return; | 28 using ::testing::Return; |
| 29 | 29 |
| 30 // Inherit from URLRequestHttpJob to expose the priority and some | 30 // Inherit from URLRequestHttpJob to expose the priority and some |
| 31 // other hidden functions. | 31 // other hidden functions. |
| 32 class TestURLRequestHttpJob : public URLRequestHttpJob { | 32 class TestURLRequestHttpJob : public URLRequestHttpJob { |
| 33 public: | 33 public: |
| 34 explicit TestURLRequestHttpJob(URLRequest* request) | 34 explicit TestURLRequestHttpJob(URLRequest* request) |
| 35 : URLRequestHttpJob(request, request->context()->network_delegate(), | 35 : URLRequestHttpJob(request, |
| 36 request->context()->network_delegate(), |
| 36 request->context()->http_user_agent_settings()) {} | 37 request->context()->http_user_agent_settings()) {} |
| 37 | 38 |
| 38 using URLRequestHttpJob::SetPriority; | 39 using URLRequestHttpJob::SetPriority; |
| 39 using URLRequestHttpJob::Start; | 40 using URLRequestHttpJob::Start; |
| 40 using URLRequestHttpJob::Kill; | 41 using URLRequestHttpJob::Kill; |
| 41 using URLRequestHttpJob::priority; | 42 using URLRequestHttpJob::priority; |
| 42 | 43 |
| 43 protected: | 44 protected: |
| 44 virtual ~TestURLRequestHttpJob() {} | 45 virtual ~TestURLRequestHttpJob() {} |
| 45 }; | 46 }; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // Creates a second transaction. | 123 // Creates a second transaction. |
| 123 job->Start(); | 124 job->Start(); |
| 124 ASSERT_TRUE(network_layer_.last_transaction()); | 125 ASSERT_TRUE(network_layer_.last_transaction()); |
| 125 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); | 126 EXPECT_EQ(LOW, network_layer_.last_transaction()->priority()); |
| 126 } | 127 } |
| 127 | 128 |
| 128 // This base class just serves to set up some things before the TestURLRequest | 129 // This base class just serves to set up some things before the TestURLRequest |
| 129 // constructor is called. | 130 // constructor is called. |
| 130 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test { | 131 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test { |
| 131 protected: | 132 protected: |
| 132 URLRequestHttpJobWebSocketTestBase() : socket_data_(NULL, 0, NULL, 0), | 133 URLRequestHttpJobWebSocketTestBase() |
| 133 context_(true) { | 134 : socket_data_(NULL, 0, NULL, 0), context_(true) { |
| 134 // A Network Delegate is required for the WebSocketHandshakeStreamBase | 135 // A Network Delegate is required for the WebSocketHandshakeStreamBase |
| 135 // object to be passed on to the HttpNetworkTransaction. | 136 // object to be passed on to the HttpNetworkTransaction. |
| 136 context_.set_network_delegate(&network_delegate_); | 137 context_.set_network_delegate(&network_delegate_); |
| 137 | 138 |
| 138 // Attempting to create real ClientSocketHandles is not going to work out so | 139 // Attempting to create real ClientSocketHandles is not going to work out so |
| 139 // well. Set up a fake socket factory. | 140 // well. Set up a fake socket factory. |
| 140 socket_factory_.AddSocketDataProvider(&socket_data_); | 141 socket_factory_.AddSocketDataProvider(&socket_data_); |
| 141 context_.set_client_socket_factory(&socket_factory_); | 142 context_.set_client_socket_factory(&socket_factory_); |
| 142 context_.Init(); | 143 context_.Init(); |
| 143 } | 144 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 171 public: | 172 public: |
| 172 // GoogleMock does not appear to play nicely with move-only types like | 173 // GoogleMock does not appear to play nicely with move-only types like |
| 173 // scoped_ptr, so this forwarding method acts as a workaround. | 174 // scoped_ptr, so this forwarding method acts as a workaround. |
| 174 virtual WebSocketHandshakeStreamBase* CreateBasicStream( | 175 virtual WebSocketHandshakeStreamBase* CreateBasicStream( |
| 175 scoped_ptr<ClientSocketHandle> connection, | 176 scoped_ptr<ClientSocketHandle> connection, |
| 176 bool using_proxy) OVERRIDE { | 177 bool using_proxy) OVERRIDE { |
| 177 // Discard the arguments since we don't need them anyway. | 178 // Discard the arguments since we don't need them anyway. |
| 178 return CreateBasicStreamMock(); | 179 return CreateBasicStreamMock(); |
| 179 } | 180 } |
| 180 | 181 |
| 181 MOCK_METHOD0(CreateBasicStreamMock, | 182 MOCK_METHOD0(CreateBasicStreamMock, WebSocketHandshakeStreamBase*()); |
| 182 WebSocketHandshakeStreamBase*()); | |
| 183 | 183 |
| 184 MOCK_METHOD2(CreateSpdyStream, | 184 MOCK_METHOD2(CreateSpdyStream, |
| 185 WebSocketHandshakeStreamBase*(const base::WeakPtr<SpdySession>&, | 185 WebSocketHandshakeStreamBase*(const base::WeakPtr<SpdySession>&, |
| 186 bool)); | 186 bool)); |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 class FakeWebSocketHandshakeStream : public WebSocketHandshakeStreamBase { | 189 class FakeWebSocketHandshakeStream : public WebSocketHandshakeStreamBase { |
| 190 public: | 190 public: |
| 191 FakeWebSocketHandshakeStream() : initialize_stream_was_called_(false) {} | 191 FakeWebSocketHandshakeStream() : initialize_stream_was_called_(false) {} |
| 192 | 192 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 229 |
| 230 virtual bool CanFindEndOfResponse() const OVERRIDE { return false; } | 230 virtual bool CanFindEndOfResponse() const OVERRIDE { return false; } |
| 231 | 231 |
| 232 virtual bool IsConnectionReused() const OVERRIDE { return false; } | 232 virtual bool IsConnectionReused() const OVERRIDE { return false; } |
| 233 virtual void SetConnectionReused() OVERRIDE {} | 233 virtual void SetConnectionReused() OVERRIDE {} |
| 234 | 234 |
| 235 virtual bool IsConnectionReusable() const OVERRIDE { return false; } | 235 virtual bool IsConnectionReusable() const OVERRIDE { return false; } |
| 236 | 236 |
| 237 virtual int64 GetTotalReceivedBytes() const OVERRIDE { return 0; } | 237 virtual int64 GetTotalReceivedBytes() const OVERRIDE { return 0; } |
| 238 | 238 |
| 239 virtual bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const | 239 virtual bool GetLoadTimingInfo( |
| 240 OVERRIDE { | 240 LoadTimingInfo* load_timing_info) const OVERRIDE { |
| 241 return false; | 241 return false; |
| 242 } | 242 } |
| 243 | 243 |
| 244 virtual void GetSSLInfo(SSLInfo* ssl_info) OVERRIDE {} | 244 virtual void GetSSLInfo(SSLInfo* ssl_info) OVERRIDE {} |
| 245 | 245 |
| 246 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) | 246 virtual void GetSSLCertRequestInfo( |
| 247 OVERRIDE {} | 247 SSLCertRequestInfo* cert_request_info) OVERRIDE {} |
| 248 | 248 |
| 249 virtual bool IsSpdyHttpStream() const OVERRIDE { return false; } | 249 virtual bool IsSpdyHttpStream() const OVERRIDE { return false; } |
| 250 | 250 |
| 251 virtual void Drain(HttpNetworkSession* session) OVERRIDE {} | 251 virtual void Drain(HttpNetworkSession* session) OVERRIDE {} |
| 252 | 252 |
| 253 virtual void SetPriority(RequestPriority priority) OVERRIDE {} | 253 virtual void SetPriority(RequestPriority priority) OVERRIDE {} |
| 254 | 254 |
| 255 // Fake implementation of WebSocketHandshakeStreamBase method(s) | 255 // Fake implementation of WebSocketHandshakeStreamBase method(s) |
| 256 virtual scoped_ptr<WebSocketStream> Upgrade() OVERRIDE { | 256 virtual scoped_ptr<WebSocketStream> Upgrade() OVERRIDE { |
| 257 return scoped_ptr<WebSocketStream>(); | 257 return scoped_ptr<WebSocketStream>(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 288 req_.SetLoadFlags(LOAD_DISABLE_CACHE); | 288 req_.SetLoadFlags(LOAD_DISABLE_CACHE); |
| 289 job->Start(); | 289 job->Start(); |
| 290 base::RunLoop().RunUntilIdle(); | 290 base::RunLoop().RunUntilIdle(); |
| 291 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_.status().status()); | 291 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_.status().status()); |
| 292 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 292 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
| 293 } | 293 } |
| 294 | 294 |
| 295 } // namespace | 295 } // namespace |
| 296 | 296 |
| 297 } // namespace net | 297 } // namespace net |
| OLD | NEW |