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

Side by Side Diff: net/socket/transport_client_socket_unittest.cc

Issue 2116983002: Change HostResolver::Resolve() to take an std::unique_ptr<Request>* rather than a RequestHandle* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changed implementation of attach/detach of request Created 4 years, 5 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
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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 base::RunLoop connect_loop_; 89 base::RunLoop connect_loop_;
90 uint16_t listen_port_; 90 uint16_t listen_port_;
91 TestNetLog net_log_; 91 TestNetLog net_log_;
92 ClientSocketFactory* const socket_factory_; 92 ClientSocketFactory* const socket_factory_;
93 std::unique_ptr<StreamSocket> sock_; 93 std::unique_ptr<StreamSocket> sock_;
94 std::unique_ptr<StreamSocket> connected_sock_; 94 std::unique_ptr<StreamSocket> connected_sock_;
95 95
96 private: 96 private:
97 std::unique_ptr<TCPServerSocket> listen_sock_; 97 std::unique_ptr<TCPServerSocket> listen_sock_;
98 bool close_server_socket_on_next_send_; 98 bool close_server_socket_on_next_send_;
99 std::unique_ptr<HostResolver::Request> request_;
mmenke 2016/07/19 19:03:57 This can just be a local in SetUp.
99 }; 100 };
100 101
101 void TransportClientSocketTest::SetUp() { 102 void TransportClientSocketTest::SetUp() {
102 ::testing::TestWithParam<ClientSocketTestTypes>::SetUp(); 103 ::testing::TestWithParam<ClientSocketTestTypes>::SetUp();
103 104
104 // Open a server socket on an ephemeral port. 105 // Open a server socket on an ephemeral port.
105 listen_sock_.reset(new TCPServerSocket(NULL, NetLog::Source())); 106 listen_sock_.reset(new TCPServerSocket(NULL, NetLog::Source()));
106 IPEndPoint local_address(IPAddress::IPv4Localhost(), 0); 107 IPEndPoint local_address(IPAddress::IPv4Localhost(), 0);
107 ASSERT_THAT(listen_sock_->Listen(local_address, 1), IsOk()); 108 ASSERT_THAT(listen_sock_->Listen(local_address, 1), IsOk());
108 // Get the server's address (including the actual port number). 109 // Get the server's address (including the actual port number).
109 ASSERT_THAT(listen_sock_->GetLocalAddress(&local_address), IsOk()); 110 ASSERT_THAT(listen_sock_->GetLocalAddress(&local_address), IsOk());
110 listen_port_ = local_address.port(); 111 listen_port_ = local_address.port();
111 listen_sock_->Accept(&connected_sock_, 112 listen_sock_->Accept(&connected_sock_,
112 base::Bind(&TransportClientSocketTest::AcceptCallback, 113 base::Bind(&TransportClientSocketTest::AcceptCallback,
113 base::Unretained(this))); 114 base::Unretained(this)));
114 115
115 AddressList addr; 116 AddressList addr;
116 // MockHostResolver resolves everything to 127.0.0.1. 117 // MockHostResolver resolves everything to 127.0.0.1.
117 std::unique_ptr<HostResolver> resolver(new MockHostResolver()); 118 std::unique_ptr<HostResolver> resolver(new MockHostResolver());
118 HostResolver::RequestInfo info(HostPortPair("localhost", listen_port_)); 119 HostResolver::RequestInfo info(HostPortPair("localhost", listen_port_));
119 TestCompletionCallback callback; 120 TestCompletionCallback callback;
120 int rv = resolver->Resolve(info, DEFAULT_PRIORITY, &addr, callback.callback(), 121 int rv = resolver->Resolve(info, DEFAULT_PRIORITY, &addr, callback.callback(),
121 NULL, BoundNetLog()); 122 &request_, BoundNetLog());
122 CHECK_EQ(ERR_IO_PENDING, rv); 123 CHECK_EQ(ERR_IO_PENDING, rv);
123 rv = callback.WaitForResult(); 124 rv = callback.WaitForResult();
124 CHECK_EQ(rv, OK); 125 CHECK_EQ(rv, OK);
125 sock_ = socket_factory_->CreateTransportClientSocket(addr, NULL, &net_log_, 126 sock_ = socket_factory_->CreateTransportClientSocket(addr, NULL, &net_log_,
126 NetLog::Source()); 127 NetLog::Source());
127 } 128 }
128 129
129 int TransportClientSocketTest::DrainClientSocket( 130 int TransportClientSocketTest::DrainClientSocket(
130 IOBuffer* buf, 131 IOBuffer* buf,
131 uint32_t buf_len, 132 uint32_t buf_len,
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 469
469 // It's possible the read is blocked because it's already read all the data. 470 // It's possible the read is blocked because it's already read all the data.
470 // Close the server socket, so there will at least be a 0-byte read. 471 // Close the server socket, so there will at least be a 0-byte read.
471 CloseServerSocket(); 472 CloseServerSocket();
472 473
473 rv = callback.WaitForResult(); 474 rv = callback.WaitForResult();
474 EXPECT_GE(rv, 0); 475 EXPECT_GE(rv, 0);
475 } 476 }
476 477
477 } // namespace net 478 } // namespace net
OLDNEW
« net/socket/socks_client_socket_unittest.cc ('K') | « net/socket/ssl_client_socket_pool_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698