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

Side by Side Diff: mojo/shell/domain_socket/unix_domain_server_socket_posix_unittest.cc

Issue 736443002: SocketDescriptor should not be used as a boolean (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « mojo/BUILD.gn ('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 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 "mojo/shell/domain_socket/unix_domain_server_socket_posix.h" 5 #include "mojo/shell/domain_socket/unix_domain_server_socket_posix.h"
6 6
7 #include <vector> 7 #include <vector>
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 EXPECT_EQ(net::OK, server_socket.ListenWithPath(socket_path_, 1)); 76 EXPECT_EQ(net::OK, server_socket.ListenWithPath(socket_path_, 1));
77 } 77 }
78 78
79 TEST_F(UnixDomainServerSocketTest, AcceptWithForbiddenUser) { 79 TEST_F(UnixDomainServerSocketTest, AcceptWithForbiddenUser) {
80 const bool kUseAbstractNamespace = false; 80 const bool kUseAbstractNamespace = false;
81 81
82 UnixDomainServerSocket server_socket(CreateAuthCallback(false), 82 UnixDomainServerSocket server_socket(CreateAuthCallback(false),
83 kUseAbstractNamespace); 83 kUseAbstractNamespace);
84 EXPECT_EQ(net::OK, server_socket.ListenWithPath(socket_path_, 1)); 84 EXPECT_EQ(net::OK, server_socket.ListenWithPath(socket_path_, 1));
85 85
86 SocketDescriptor accepted_socket; 86 SocketDescriptor accepted_socket = kInvalidSocket;
87 TestCompletionCallback accept_callback; 87 TestCompletionCallback accept_callback;
88 EXPECT_EQ(net::ERR_IO_PENDING, 88 EXPECT_EQ(net::ERR_IO_PENDING,
89 server_socket.Accept(&accepted_socket, accept_callback.callback())); 89 server_socket.Accept(&accepted_socket, accept_callback.callback()));
90 EXPECT_FALSE(accepted_socket); 90 EXPECT_EQ(accepted_socket, kInvalidSocket);
91 91
92 UnixDomainClientSocket client_socket(socket_path_, kUseAbstractNamespace); 92 UnixDomainClientSocket client_socket(socket_path_, kUseAbstractNamespace);
93 EXPECT_FALSE(client_socket.IsConnected()); 93 EXPECT_FALSE(client_socket.IsConnected());
94 94
95 // Connect() will return net::OK before the server rejects the connection. 95 // Connect() will return net::OK before the server rejects the connection.
96 TestCompletionCallback connect_callback; 96 TestCompletionCallback connect_callback;
97 int rv = connect_callback.GetResult( 97 int rv = connect_callback.GetResult(
98 client_socket.Connect(connect_callback.callback())); 98 client_socket.Connect(connect_callback.callback()));
99 ASSERT_EQ(net::OK, rv); 99 ASSERT_EQ(net::OK, rv);
100 100
101 // Run message loop so server can process incoming connection attempt. 101 // Run message loop so server can process incoming connection attempt.
102 { 102 {
103 base::RunLoop run_loop; 103 base::RunLoop run_loop;
104 run_loop.RunUntilIdle(); 104 run_loop.RunUntilIdle();
105 } 105 }
106 EXPECT_FALSE(client_socket.IsConnected()); 106 EXPECT_FALSE(client_socket.IsConnected());
107 107
108 // The server socket should not have called |accept_callback| or modified 108 // The server socket should not have called |accept_callback| or modified
109 // |accepted_socket|. 109 // |accepted_socket|.
110 EXPECT_FALSE(accept_callback.have_result()); 110 EXPECT_FALSE(accept_callback.have_result());
111 EXPECT_FALSE(accepted_socket); 111 EXPECT_EQ(accepted_socket, kInvalidSocket);
112 } 112 }
113 113
114 // Normal cases including read/write are tested by UnixDomainClientSocketTest. 114 // Normal cases including read/write are tested by UnixDomainClientSocketTest.
115 115
116 } // namespace shell 116 } // namespace shell
117 } // namespace mojo 117 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698