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

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

Issue 509133002: Raw SocketDescriptor variant of UnixDomainServerSocket::Accept (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/socket/unix_domain_client_socket_posix.h" 5 #include "net/socket/unix_domain_client_socket_posix.h"
6 6
7 #include <unistd.h> 7 #include <unistd.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 EXPECT_EQ(OK, ConnectSynchronously(&client_socket)); 141 EXPECT_EQ(OK, ConnectSynchronously(&client_socket));
142 EXPECT_TRUE(client_socket.IsConnected()); 142 EXPECT_TRUE(client_socket.IsConnected());
143 // Server has not yet been notified of the connection. 143 // Server has not yet been notified of the connection.
144 EXPECT_FALSE(accepted_socket); 144 EXPECT_FALSE(accepted_socket);
145 145
146 EXPECT_EQ(OK, accept_callback.WaitForResult()); 146 EXPECT_EQ(OK, accept_callback.WaitForResult());
147 EXPECT_TRUE(accepted_socket); 147 EXPECT_TRUE(accepted_socket);
148 EXPECT_TRUE(accepted_socket->IsConnected()); 148 EXPECT_TRUE(accepted_socket->IsConnected());
149 } 149 }
150 150
151 TEST_F(UnixDomainClientSocketTest, ConnectWithSocketDescriptor) {
152 const bool kUseAbstractNamespace = false;
153
154 UnixDomainServerSocket server_socket(CreateAuthCallback(true),
155 kUseAbstractNamespace);
156 EXPECT_EQ(OK, server_socket.ListenWithAddressAndPort(socket_path_, 0, 1));
157
158 SocketDescriptor accepted_socket = kInvalidSocket;
159 TestCompletionCallback accept_callback;
160 EXPECT_EQ(ERR_IO_PENDING,
161 server_socket.AcceptSocketDescriptor(&accepted_socket,
162 accept_callback.callback()));
163 EXPECT_EQ(accepted_socket, kInvalidSocket);
byungchul 2014/08/27 23:35:51 expected value should go first.
Chris Masone 2014/08/28 17:53:16 Done.
164
165 UnixDomainClientSocket client_socket(socket_path_, kUseAbstractNamespace);
166 EXPECT_FALSE(client_socket.IsConnected());
167
168 EXPECT_EQ(OK, ConnectSynchronously(&client_socket));
169 EXPECT_TRUE(client_socket.IsConnected());
170 // Server has not yet been notified of the connection.
171 EXPECT_EQ(accepted_socket, kInvalidSocket);
byungchul 2014/08/27 23:35:51 ditto
Chris Masone 2014/08/28 17:53:16 Done.
172
173 EXPECT_EQ(OK, accept_callback.WaitForResult());
174 EXPECT_GT(accepted_socket, 0);
byungchul 2014/08/27 23:35:51 EXPECT_NE(kInvalidSocket, accepted_socket) because
Chris Masone 2014/08/28 17:53:16 Done.
175 }
176
151 TEST_F(UnixDomainClientSocketTest, ConnectWithAbstractNamespace) { 177 TEST_F(UnixDomainClientSocketTest, ConnectWithAbstractNamespace) {
152 const bool kUseAbstractNamespace = true; 178 const bool kUseAbstractNamespace = true;
153 179
154 UnixDomainClientSocket client_socket(socket_path_, kUseAbstractNamespace); 180 UnixDomainClientSocket client_socket(socket_path_, kUseAbstractNamespace);
155 EXPECT_FALSE(client_socket.IsConnected()); 181 EXPECT_FALSE(client_socket.IsConnected());
156 182
157 #if defined(OS_ANDROID) || defined(OS_LINUX) 183 #if defined(OS_ANDROID) || defined(OS_LINUX)
158 UnixDomainServerSocket server_socket(CreateAuthCallback(true), 184 UnixDomainServerSocket server_socket(CreateAuthCallback(true),
159 kUseAbstractNamespace); 185 kUseAbstractNamespace);
160 EXPECT_EQ(OK, server_socket.ListenWithAddressAndPort(socket_path_, 0, 1)); 186 EXPECT_EQ(OK, server_socket.ListenWithAddressAndPort(socket_path_, 0, 1));
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 accepted_socket.get(), read_buffer.get(), kReadBufferSize, 0)); 413 accepted_socket.get(), read_buffer.get(), kReadBufferSize, 0));
388 414
389 // Disconnect from server side after read-write. 415 // Disconnect from server side after read-write.
390 accepted_socket->Disconnect(); 416 accepted_socket->Disconnect();
391 EXPECT_FALSE(accepted_socket->IsConnected()); 417 EXPECT_FALSE(accepted_socket->IsConnected());
392 EXPECT_FALSE(client_socket.IsConnected()); 418 EXPECT_FALSE(client_socket.IsConnected());
393 } 419 }
394 420
395 } // namespace 421 } // namespace
396 } // namespace net 422 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698