| 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 <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" |
| 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" | |
| 18 #include "net/log/net_log_event_type.h" | 17 #include "net/log/net_log_event_type.h" |
| 18 #include "net/log/net_log_source.h" |
| 19 #include "net/log/net_log_with_source.h" |
| 19 #include "net/log/test_net_log.h" | 20 #include "net/log/test_net_log.h" |
| 20 #include "net/log/test_net_log_entry.h" | 21 #include "net/log/test_net_log_entry.h" |
| 21 #include "net/log/test_net_log_util.h" | 22 #include "net/log/test_net_log_util.h" |
| 22 #include "net/socket/client_socket_factory.h" | 23 #include "net/socket/client_socket_factory.h" |
| 23 #include "net/socket/tcp_client_socket.h" | 24 #include "net/socket/tcp_client_socket.h" |
| 24 #include "net/socket/tcp_server_socket.h" | 25 #include "net/socket/tcp_server_socket.h" |
| 25 #include "net/test/gtest_util.h" | 26 #include "net/test/gtest_util.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 28 #include "testing/platform_test.h" | 29 #include "testing/platform_test.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 97 |
| 97 private: | 98 private: |
| 98 std::unique_ptr<TCPServerSocket> listen_sock_; | 99 std::unique_ptr<TCPServerSocket> listen_sock_; |
| 99 bool close_server_socket_on_next_send_; | 100 bool close_server_socket_on_next_send_; |
| 100 }; | 101 }; |
| 101 | 102 |
| 102 void TransportClientSocketTest::SetUp() { | 103 void TransportClientSocketTest::SetUp() { |
| 103 ::testing::TestWithParam<ClientSocketTestTypes>::SetUp(); | 104 ::testing::TestWithParam<ClientSocketTestTypes>::SetUp(); |
| 104 | 105 |
| 105 // Open a server socket on an ephemeral port. | 106 // Open a server socket on an ephemeral port. |
| 106 listen_sock_.reset(new TCPServerSocket(NULL, NetLog::Source())); | 107 listen_sock_.reset(new TCPServerSocket(NULL, NetLogSource())); |
| 107 IPEndPoint local_address(IPAddress::IPv4Localhost(), 0); | 108 IPEndPoint local_address(IPAddress::IPv4Localhost(), 0); |
| 108 ASSERT_THAT(listen_sock_->Listen(local_address, 1), IsOk()); | 109 ASSERT_THAT(listen_sock_->Listen(local_address, 1), IsOk()); |
| 109 // Get the server's address (including the actual port number). | 110 // Get the server's address (including the actual port number). |
| 110 ASSERT_THAT(listen_sock_->GetLocalAddress(&local_address), IsOk()); | 111 ASSERT_THAT(listen_sock_->GetLocalAddress(&local_address), IsOk()); |
| 111 listen_port_ = local_address.port(); | 112 listen_port_ = local_address.port(); |
| 112 listen_sock_->Accept(&connected_sock_, | 113 listen_sock_->Accept(&connected_sock_, |
| 113 base::Bind(&TransportClientSocketTest::AcceptCallback, | 114 base::Bind(&TransportClientSocketTest::AcceptCallback, |
| 114 base::Unretained(this))); | 115 base::Unretained(this))); |
| 115 | 116 |
| 116 AddressList addr; | 117 AddressList addr; |
| 117 // MockHostResolver resolves everything to 127.0.0.1. | 118 // MockHostResolver resolves everything to 127.0.0.1. |
| 118 std::unique_ptr<HostResolver> resolver(new MockHostResolver()); | 119 std::unique_ptr<HostResolver> resolver(new MockHostResolver()); |
| 119 HostResolver::RequestInfo info(HostPortPair("localhost", listen_port_)); | 120 HostResolver::RequestInfo info(HostPortPair("localhost", listen_port_)); |
| 120 TestCompletionCallback callback; | 121 TestCompletionCallback callback; |
| 121 std::unique_ptr<HostResolver::Request> request; | 122 std::unique_ptr<HostResolver::Request> request; |
| 122 int rv = resolver->Resolve(info, DEFAULT_PRIORITY, &addr, callback.callback(), | 123 int rv = resolver->Resolve(info, DEFAULT_PRIORITY, &addr, callback.callback(), |
| 123 &request, NetLogWithSource()); | 124 &request, NetLogWithSource()); |
| 124 CHECK_EQ(ERR_IO_PENDING, rv); | 125 CHECK_EQ(ERR_IO_PENDING, rv); |
| 125 rv = callback.WaitForResult(); | 126 rv = callback.WaitForResult(); |
| 126 CHECK_EQ(rv, OK); | 127 CHECK_EQ(rv, OK); |
| 127 sock_ = socket_factory_->CreateTransportClientSocket(addr, NULL, &net_log_, | 128 sock_ = socket_factory_->CreateTransportClientSocket(addr, NULL, &net_log_, |
| 128 NetLog::Source()); | 129 NetLogSource()); |
| 129 } | 130 } |
| 130 | 131 |
| 131 int TransportClientSocketTest::DrainClientSocket( | 132 int TransportClientSocketTest::DrainClientSocket( |
| 132 IOBuffer* buf, | 133 IOBuffer* buf, |
| 133 uint32_t buf_len, | 134 uint32_t buf_len, |
| 134 uint32_t bytes_to_read, | 135 uint32_t bytes_to_read, |
| 135 TestCompletionCallback* callback) { | 136 TestCompletionCallback* callback) { |
| 136 int rv = OK; | 137 int rv = OK; |
| 137 uint32_t bytes_read = 0; | 138 uint32_t bytes_read = 0; |
| 138 | 139 |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 | 471 |
| 471 // It's possible the read is blocked because it's already read all the data. | 472 // It's possible the read is blocked because it's already read all the data. |
| 472 // Close the server socket, so there will at least be a 0-byte read. | 473 // Close the server socket, so there will at least be a 0-byte read. |
| 473 CloseServerSocket(); | 474 CloseServerSocket(); |
| 474 | 475 |
| 475 rv = callback.WaitForResult(); | 476 rv = callback.WaitForResult(); |
| 476 EXPECT_GE(rv, 0); | 477 EXPECT_GE(rv, 0); |
| 477 } | 478 } |
| 478 | 479 |
| 479 } // namespace net | 480 } // namespace net |
| OLD | NEW |