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

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

Issue 16093005: [Android] Use a "unique" remote debugging socket name on bind failure (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « net/socket/unix_domain_socket_posix.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <errno.h> 5 #include <errno.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <poll.h> 7 #include <poll.h>
8 #include <sys/socket.h> 8 #include <sys/socket.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <sys/time.h> 10 #include <sys/time.h>
(...skipping 21 matching lines...) Expand all
32 #include "net/socket/unix_domain_socket_posix.h" 32 #include "net/socket/unix_domain_socket_posix.h"
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34 34
35 using std::queue; 35 using std::queue;
36 using std::string; 36 using std::string;
37 37
38 namespace net { 38 namespace net {
39 namespace { 39 namespace {
40 40
41 const char kSocketFilename[] = "unix_domain_socket_for_testing"; 41 const char kSocketFilename[] = "unix_domain_socket_for_testing";
42 const char kFallbackSocketName[] = "unix_domain_socket_for_testing_2";
42 const char kInvalidSocketPath[] = "/invalid/path"; 43 const char kInvalidSocketPath[] = "/invalid/path";
43 const char kMsg[] = "hello"; 44 const char kMsg[] = "hello";
44 45
45 enum EventType { 46 enum EventType {
46 EVENT_ACCEPT, 47 EVENT_ACCEPT,
47 EVENT_AUTH_DENIED, 48 EVENT_AUTH_DENIED,
48 EVENT_AUTH_GRANTED, 49 EVENT_AUTH_GRANTED,
49 EVENT_CLOSE, 50 EVENT_CLOSE,
50 EVENT_LISTEN, 51 EVENT_LISTEN,
51 EVENT_READ, 52 EVENT_READ,
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 CreateAndListen(); 248 CreateAndListen();
248 EXPECT_TRUE(socket_.get() == NULL); 249 EXPECT_TRUE(socket_.get() == NULL);
249 } 250 }
250 251
251 #ifdef SOCKET_ABSTRACT_NAMESPACE_SUPPORTED 252 #ifdef SOCKET_ABSTRACT_NAMESPACE_SUPPORTED
252 // Test with an invalid path to make sure that the socket is not backed by a 253 // Test with an invalid path to make sure that the socket is not backed by a
253 // file. 254 // file.
254 TEST_F(UnixDomainSocketTestWithInvalidPath, 255 TEST_F(UnixDomainSocketTestWithInvalidPath,
255 CreateAndListenWithAbstractNamespace) { 256 CreateAndListenWithAbstractNamespace) {
256 socket_ = UnixDomainSocket::CreateAndListenWithAbstractNamespace( 257 socket_ = UnixDomainSocket::CreateAndListenWithAbstractNamespace(
257 file_path_.value(), socket_delegate_.get(), MakeAuthCallback()); 258 file_path_.value(), "", socket_delegate_.get(), MakeAuthCallback());
258 EXPECT_FALSE(socket_.get() == NULL); 259 EXPECT_FALSE(socket_.get() == NULL);
259 } 260 }
261
262 TEST_F(UnixDomainSocketTest, TestFallbackName) {
263 scoped_refptr<UnixDomainSocket> existing_socket =
264 UnixDomainSocket::CreateAndListenWithAbstractNamespace(
265 kSocketFilename, "", socket_delegate_.get(), MakeAuthCallback());
szym 2013/05/29 18:49:04 Do not use kSocketFilename alone. Use MakeSocketPa
mnaganov (inactive) 2013/05/29 20:11:11 But that's for abstract namespace names only. Is f
szym 2013/05/29 20:13:53 The concern is interference with other tests runni
mnaganov (inactive) 2013/05/29 20:37:11 Makes sense. Fixed!
266 EXPECT_FALSE(existing_socket.get() == NULL);
267 // First, try to bind socket with the same name with no fallback name.
268 socket_ =
269 UnixDomainSocket::CreateAndListenWithAbstractNamespace(
270 kSocketFilename, "", socket_delegate_.get(), MakeAuthCallback());
271 EXPECT_TRUE(socket_.get() == NULL);
272 // Now with a fallback name.
273 socket_ = UnixDomainSocket::CreateAndListenWithAbstractNamespace(
274 kSocketFilename,
275 kFallbackSocketName,
276 socket_delegate_.get(),
277 MakeAuthCallback());
278 EXPECT_FALSE(socket_.get() == NULL);
279 existing_socket = NULL;
280 }
260 #endif 281 #endif
261 282
262 TEST_F(UnixDomainSocketTest, TestWithClient) { 283 TEST_F(UnixDomainSocketTest, TestWithClient) {
263 const scoped_ptr<base::Thread> server_thread = CreateAndRunServerThread(); 284 const scoped_ptr<base::Thread> server_thread = CreateAndRunServerThread();
264 EventType event = event_manager_->WaitForEvent(); 285 EventType event = event_manager_->WaitForEvent();
265 ASSERT_EQ(EVENT_LISTEN, event); 286 ASSERT_EQ(EVENT_LISTEN, event);
266 287
267 // Create the client socket. 288 // Create the client socket.
268 const SocketDescriptor sock = CreateClientSocket(); 289 const SocketDescriptor sock = CreateClientSocket();
269 ASSERT_NE(StreamListenSocket::kInvalidSocket, sock); 290 ASSERT_NE(StreamListenSocket::kInvalidSocket, sock);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 325
305 // Send() must fail. 326 // Send() must fail.
306 ssize_t ret = HANDLE_EINTR(send(sock, kMsg, sizeof(kMsg), 0)); 327 ssize_t ret = HANDLE_EINTR(send(sock, kMsg, sizeof(kMsg), 0));
307 ASSERT_EQ(-1, ret); 328 ASSERT_EQ(-1, ret);
308 ASSERT_EQ(EPIPE, errno); 329 ASSERT_EQ(EPIPE, errno);
309 ASSERT_FALSE(event_manager_->HasPendingEvent()); 330 ASSERT_FALSE(event_manager_->HasPendingEvent());
310 } 331 }
311 332
312 } // namespace 333 } // namespace
313 } // namespace net 334 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/unix_domain_socket_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698