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

Side by Side Diff: net/spdy/spdy_proxy_client_socket_unittest.cc

Issue 8990001: base::Bind: Convert most of net/http. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clang. Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/spdy/spdy_proxy_client_socket.h" 5 #include "net/spdy/spdy_proxy_client_socket.h"
6 6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
7 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
8 #include "net/base/address_list.h" 10 #include "net/base/address_list.h"
9 #include "net/base/net_log.h" 11 #include "net/base/net_log.h"
10 #include "net/base/net_log_unittest.h" 12 #include "net/base/net_log_unittest.h"
11 #include "net/base/mock_host_resolver.h" 13 #include "net/base/mock_host_resolver.h"
12 #include "net/base/test_completion_callback.h" 14 #include "net/base/test_completion_callback.h"
13 #include "net/base/winsock_init.h" 15 #include "net/base/winsock_init.h"
14 #include "net/http/http_response_info.h" 16 #include "net/http/http_response_info.h"
15 #include "net/http/http_response_headers.h" 17 #include "net/http/http_response_headers.h"
16 #include "net/socket/client_socket_factory.h" 18 #include "net/socket/client_socket_factory.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 "/"); 95 "/");
94 } 96 }
95 97
96 void Run(int steps) { 98 void Run(int steps) {
97 data_->StopAfter(steps); 99 data_->StopAfter(steps);
98 data_->Run(); 100 data_->Run();
99 } 101 }
100 102
101 scoped_ptr<SpdyProxyClientSocket> sock_; 103 scoped_ptr<SpdyProxyClientSocket> sock_;
102 TestCompletionCallback read_callback_; 104 TestCompletionCallback read_callback_;
103 TestOldCompletionCallback read_callback_old_;
104 TestCompletionCallback write_callback_; 105 TestCompletionCallback write_callback_;
105 scoped_refptr<DeterministicSocketData> data_; 106 scoped_refptr<DeterministicSocketData> data_;
106 107
107 private: 108 private:
108 scoped_refptr<HttpNetworkSession> session_; 109 scoped_refptr<HttpNetworkSession> session_;
109 scoped_refptr<IOBuffer> read_buf_; 110 scoped_refptr<IOBuffer> read_buf_;
110 SpdySessionDependencies session_deps_; 111 SpdySessionDependencies session_deps_;
111 MockConnect connect_data_; 112 MockConnect connect_data_;
112 scoped_refptr<SpdySession> spdy_session_; 113 scoped_refptr<SpdySession> spdy_session_;
113 scoped_refptr<SpdyStream> spdy_stream_; 114 scoped_refptr<SpdyStream> spdy_stream_;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 connection->Init(endpoint_host_port_pair_.ToString(), 186 connection->Init(endpoint_host_port_pair_.ToString(),
186 transport_params_, LOWEST, CompletionCallback(), 187 transport_params_, LOWEST, CompletionCallback(),
187 session_->GetTransportSocketPool(), 188 session_->GetTransportSocketPool(),
188 BoundNetLog())); 189 BoundNetLog()));
189 spdy_session_->InitializeWithSocket(connection.release(), false, OK); 190 spdy_session_->InitializeWithSocket(connection.release(), false, OK);
190 191
191 // Create the SPDY Stream 192 // Create the SPDY Stream
192 ASSERT_EQ( 193 ASSERT_EQ(
193 OK, 194 OK,
194 spdy_session_->CreateStream(url_, LOWEST, &spdy_stream_, BoundNetLog(), 195 spdy_session_->CreateStream(url_, LOWEST, &spdy_stream_, BoundNetLog(),
195 NULL)); 196 CompletionCallback()));
196 197
197 // Create the SpdyProxyClientSocket 198 // Create the SpdyProxyClientSocket
198 sock_.reset( 199 sock_.reset(
199 new SpdyProxyClientSocket(spdy_stream_, user_agent_, 200 new SpdyProxyClientSocket(spdy_stream_, user_agent_,
200 endpoint_host_port_pair_, url_, 201 endpoint_host_port_pair_, url_,
201 proxy_host_port_, session_->http_auth_cache(), 202 proxy_host_port_, session_->http_auth_cache(),
202 session_->http_auth_handler_factory())); 203 session_->http_auth_handler_factory()));
203 } 204 }
204 205
205 scoped_refptr<IOBufferWithSize> SpdyProxyClientSocketTest::CreateBuffer( 206 scoped_refptr<IOBufferWithSize> SpdyProxyClientSocketTest::CreateBuffer(
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 858 Initialize(reads, arraysize(reads), writes, arraysize(writes));
858 859
859 AssertConnectFails(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); 860 AssertConnectFails(ERR_HTTPS_PROXY_TUNNEL_RESPONSE);
860 861
861 Run(2); // SpdySession consumes the next two reads and sends then to 862 Run(2); // SpdySession consumes the next two reads and sends then to
862 // sock_ to be buffered. 863 // sock_ to be buffered.
863 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, 864 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED,
864 sock_->Read(NULL, 1, CompletionCallback())); 865 sock_->Read(NULL, 1, CompletionCallback()));
865 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1 + kLen2)); 866 scoped_refptr<IOBuffer> buf(new IOBuffer(kLen1 + kLen2));
866 scoped_ptr<HttpStream> stream(sock_->CreateConnectResponseStream()); 867 scoped_ptr<HttpStream> stream(sock_->CreateConnectResponseStream());
867 stream->ReadResponseBody(buf, kLen1 + kLen2, &read_callback_old_); 868 stream->ReadResponseBody(buf, kLen1 + kLen2, read_callback_.callback());
868 } 869 }
869 870
870 // ----------- Reads and Writes 871 // ----------- Reads and Writes
871 872
872 TEST_F(SpdyProxyClientSocketTest, AsyncReadAroundWrite) { 873 TEST_F(SpdyProxyClientSocketTest, AsyncReadAroundWrite) {
873 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); 874 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame());
874 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2)); 875 scoped_ptr<spdy::SpdyFrame> msg2(ConstructBodyFrame(kMsg2, kLen2));
875 MockWrite writes[] = { 876 MockWrite writes[] = {
876 CreateMockWrite(*conn, 0, false), 877 CreateMockWrite(*conn, 0, false),
877 CreateMockWrite(*msg2, 3, false), 878 CreateMockWrite(*msg2, 3, false),
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 1224
1224 Run(2); 1225 Run(2);
1225 1226
1226 EXPECT_TRUE(sock_.get()); 1227 EXPECT_TRUE(sock_.get());
1227 EXPECT_TRUE(read_callback_.have_result()); 1228 EXPECT_TRUE(read_callback_.have_result());
1228 EXPECT_TRUE(write_callback_.have_result()); 1229 EXPECT_TRUE(write_callback_.have_result());
1229 } 1230 }
1230 1231
1231 // CompletionCallback that causes the SpdyProxyClientSocket to be 1232 // CompletionCallback that causes the SpdyProxyClientSocket to be
1232 // deleted when Run is invoked. 1233 // deleted when Run is invoked.
1233 class DeleteSockCallback : public TestOldCompletionCallback { 1234 class DeleteSockCallback : public TestCompletionCallbackBase {
1234 public: 1235 public:
1235 explicit DeleteSockCallback(scoped_ptr<SpdyProxyClientSocket>* sock) 1236 explicit DeleteSockCallback(scoped_ptr<SpdyProxyClientSocket>* sock)
1236 : sock_(sock) { 1237 : sock_(sock),
1238 ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
1239 base::Bind(&DeleteSockCallback::OnComplete,
1240 base::Unretained(this)))) {
1237 } 1241 }
1238 1242
1239 virtual ~DeleteSockCallback() { 1243 virtual ~DeleteSockCallback() {
1240 } 1244 }
1241 1245
1242 virtual void RunWithParams(const Tuple1<int>& params) OVERRIDE { 1246 const CompletionCallback& callback() const { return callback_; }
1247
1248 private:
1249 void OnComplete(int result) {
1243 sock_->reset(NULL); 1250 sock_->reset(NULL);
1244 TestOldCompletionCallback::RunWithParams(params); 1251 SetResult(result);
1245 } 1252 }
1246 1253
1247 private:
1248 scoped_ptr<SpdyProxyClientSocket>* sock_; 1254 scoped_ptr<SpdyProxyClientSocket>* sock_;
1255 CompletionCallback callback_;
1256
1257 DISALLOW_COPY_AND_ASSIGN(DeleteSockCallback);
1249 }; 1258 };
1250 1259
1251 // If the socket is Reset when both a read and write are pending, and the 1260 // If the socket is Reset when both a read and write are pending, and the
1252 // read callback causes the socket to be deleted, the write callback should 1261 // read callback causes the socket to be deleted, the write callback should
1253 // not be called. 1262 // not be called.
1254 TEST_F(SpdyProxyClientSocketTest, RstWithReadAndWritePendingDelete) { 1263 TEST_F(SpdyProxyClientSocketTest, RstWithReadAndWritePendingDelete) {
1255 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame()); 1264 scoped_ptr<spdy::SpdyFrame> conn(ConstructConnectRequestFrame());
1256 MockWrite writes[] = { 1265 MockWrite writes[] = {
1257 CreateMockWrite(*conn, 0, false), 1266 CreateMockWrite(*conn, 0, false),
1258 MockWrite(true, ERR_IO_PENDING, 2), 1267 MockWrite(true, ERR_IO_PENDING, 2),
1259 }; 1268 };
1260 1269
1261 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame()); 1270 scoped_ptr<spdy::SpdyFrame> resp(ConstructConnectReplyFrame());
1262 scoped_ptr<spdy::SpdyFrame> rst(ConstructSpdyRstStream(1, spdy::CANCEL)); 1271 scoped_ptr<spdy::SpdyFrame> rst(ConstructSpdyRstStream(1, spdy::CANCEL));
1263 MockRead reads[] = { 1272 MockRead reads[] = {
1264 CreateMockRead(*resp, 1, true), 1273 CreateMockRead(*resp, 1, true),
1265 CreateMockRead(*rst, 3, true), 1274 CreateMockRead(*rst, 3, true),
1266 }; 1275 };
1267 1276
1268 Initialize(reads, arraysize(reads), writes, arraysize(writes)); 1277 Initialize(reads, arraysize(reads), writes, arraysize(writes));
1269 1278
1270 AssertConnectSucceeds(); 1279 AssertConnectSucceeds();
1271 1280
1272 EXPECT_TRUE(sock_->IsConnected()); 1281 EXPECT_TRUE(sock_->IsConnected());
1273 1282
1274 DeleteSockCallback read_callback(&sock_); 1283 DeleteSockCallback read_callback(&sock_);
1275 1284
1276 scoped_refptr<IOBuffer> read_buf(new IOBuffer(kLen1)); 1285 scoped_refptr<IOBuffer> read_buf(new IOBuffer(kLen1));
1277 ASSERT_EQ(ERR_IO_PENDING, 1286 ASSERT_EQ(ERR_IO_PENDING,
1278 sock_->Read(read_buf, kLen1, 1287 sock_->Read(read_buf, kLen1, read_callback.callback()));
1279 base::Bind(&DeleteSockCallback::Run<int>,
1280 base::Unretained(&read_callback))));
1281 1288
1282 scoped_refptr<IOBufferWithSize> write_buf(CreateBuffer(kMsg1, kLen1)); 1289 scoped_refptr<IOBufferWithSize> write_buf(CreateBuffer(kMsg1, kLen1));
1283 EXPECT_EQ(ERR_IO_PENDING, sock_->Write(write_buf, write_buf->size(), 1290 EXPECT_EQ(ERR_IO_PENDING, sock_->Write(write_buf, write_buf->size(),
1284 write_callback_.callback())); 1291 write_callback_.callback()));
1285 1292
1286 Run(2); 1293 Run(2);
1287 1294
1288 EXPECT_FALSE(sock_.get()); 1295 EXPECT_FALSE(sock_.get());
1289 EXPECT_TRUE(read_callback.have_result()); 1296 EXPECT_TRUE(read_callback.have_result());
1290 EXPECT_FALSE(write_callback_.have_result()); 1297 EXPECT_FALSE(write_callback_.have_result());
1291 } 1298 }
1292 1299
1293 } // namespace net 1300 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698