OLD | NEW |
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 <string> | 6 #include <string> |
6 | 7 |
7 #include "base/bind.h" | 8 #include "base/bind.h" |
8 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "net/base/address_list.h" | 11 #include "net/base/address_list.h" |
12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
13 #include "net/base/ip_address.h" | 13 #include "net/base/ip_address.h" |
14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
15 #include "net/base/test_completion_callback.h" | 15 #include "net/base/test_completion_callback.h" |
16 #include "net/dns/mock_host_resolver.h" | 16 #include "net/dns/mock_host_resolver.h" |
17 #include "net/log/net_log.h" | 17 #include "net/log/net_log.h" |
18 #include "net/log/test_net_log.h" | 18 #include "net/log/test_net_log.h" |
19 #include "net/log/test_net_log_entry.h" | 19 #include "net/log/test_net_log_entry.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 void set_close_server_socket_on_next_send(bool close) { | 79 void set_close_server_socket_on_next_send(bool close) { |
80 close_server_socket_on_next_send_ = close; | 80 close_server_socket_on_next_send_ = close; |
81 } | 81 } |
82 | 82 |
83 protected: | 83 protected: |
84 base::RunLoop connect_loop_; | 84 base::RunLoop connect_loop_; |
85 uint16_t listen_port_; | 85 uint16_t listen_port_; |
86 TestNetLog net_log_; | 86 TestNetLog net_log_; |
87 ClientSocketFactory* const socket_factory_; | 87 ClientSocketFactory* const socket_factory_; |
88 scoped_ptr<StreamSocket> sock_; | 88 std::unique_ptr<StreamSocket> sock_; |
89 scoped_ptr<StreamSocket> connected_sock_; | 89 std::unique_ptr<StreamSocket> connected_sock_; |
90 | 90 |
91 private: | 91 private: |
92 scoped_ptr<TCPServerSocket> listen_sock_; | 92 std::unique_ptr<TCPServerSocket> listen_sock_; |
93 bool close_server_socket_on_next_send_; | 93 bool close_server_socket_on_next_send_; |
94 }; | 94 }; |
95 | 95 |
96 void TransportClientSocketTest::SetUp() { | 96 void TransportClientSocketTest::SetUp() { |
97 ::testing::TestWithParam<ClientSocketTestTypes>::SetUp(); | 97 ::testing::TestWithParam<ClientSocketTestTypes>::SetUp(); |
98 | 98 |
99 // Open a server socket on an ephemeral port. | 99 // Open a server socket on an ephemeral port. |
100 listen_sock_.reset(new TCPServerSocket(NULL, NetLog::Source())); | 100 listen_sock_.reset(new TCPServerSocket(NULL, NetLog::Source())); |
101 IPEndPoint local_address(IPAddress::IPv4Localhost(), 0); | 101 IPEndPoint local_address(IPAddress::IPv4Localhost(), 0); |
102 ASSERT_EQ(OK, listen_sock_->Listen(local_address, 1)); | 102 ASSERT_EQ(OK, listen_sock_->Listen(local_address, 1)); |
103 // Get the server's address (including the actual port number). | 103 // Get the server's address (including the actual port number). |
104 ASSERT_EQ(OK, listen_sock_->GetLocalAddress(&local_address)); | 104 ASSERT_EQ(OK, listen_sock_->GetLocalAddress(&local_address)); |
105 listen_port_ = local_address.port(); | 105 listen_port_ = local_address.port(); |
106 listen_sock_->Accept(&connected_sock_, | 106 listen_sock_->Accept(&connected_sock_, |
107 base::Bind(&TransportClientSocketTest::AcceptCallback, | 107 base::Bind(&TransportClientSocketTest::AcceptCallback, |
108 base::Unretained(this))); | 108 base::Unretained(this))); |
109 | 109 |
110 AddressList addr; | 110 AddressList addr; |
111 // MockHostResolver resolves everything to 127.0.0.1. | 111 // MockHostResolver resolves everything to 127.0.0.1. |
112 scoped_ptr<HostResolver> resolver(new MockHostResolver()); | 112 std::unique_ptr<HostResolver> resolver(new MockHostResolver()); |
113 HostResolver::RequestInfo info(HostPortPair("localhost", listen_port_)); | 113 HostResolver::RequestInfo info(HostPortPair("localhost", listen_port_)); |
114 TestCompletionCallback callback; | 114 TestCompletionCallback callback; |
115 int rv = resolver->Resolve(info, DEFAULT_PRIORITY, &addr, callback.callback(), | 115 int rv = resolver->Resolve(info, DEFAULT_PRIORITY, &addr, callback.callback(), |
116 NULL, BoundNetLog()); | 116 NULL, BoundNetLog()); |
117 CHECK_EQ(ERR_IO_PENDING, rv); | 117 CHECK_EQ(ERR_IO_PENDING, rv); |
118 rv = callback.WaitForResult(); | 118 rv = callback.WaitForResult(); |
119 CHECK_EQ(rv, OK); | 119 CHECK_EQ(rv, OK); |
120 sock_ = socket_factory_->CreateTransportClientSocket(addr, NULL, &net_log_, | 120 sock_ = socket_factory_->CreateTransportClientSocket(addr, NULL, &net_log_, |
121 NetLog::Source()); | 121 NetLog::Source()); |
122 } | 122 } |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 462 |
463 // It's possible the read is blocked because it's already read all the data. | 463 // It's possible the read is blocked because it's already read all the data. |
464 // Close the server socket, so there will at least be a 0-byte read. | 464 // Close the server socket, so there will at least be a 0-byte read. |
465 CloseServerSocket(); | 465 CloseServerSocket(); |
466 | 466 |
467 rv = callback.WaitForResult(); | 467 rv = callback.WaitForResult(); |
468 EXPECT_GE(rv, 0); | 468 EXPECT_GE(rv, 0); |
469 } | 469 } |
470 | 470 |
471 } // namespace net | 471 } // namespace net |
OLD | NEW |