| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |