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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "mojo/edk/embedder/channel_init.h" | 10 #include "mojo/edk/embedder/channel_init.h" |
11 #include "mojo/edk/embedder/platform_channel_pair.h" | 11 #include "mojo/edk/embedder/platform_channel_pair.h" |
12 #include "mojo/shell/domain_socket/net_errors.h" | 12 #include "shell/domain_socket/net_errors.h" |
13 #include "mojo/shell/domain_socket/socket_descriptor.h" | 13 #include "shell/domain_socket/socket_descriptor.h" |
14 #include "mojo/shell/domain_socket/test_completion_callback.h" | 14 #include "shell/domain_socket/test_completion_callback.h" |
15 #include "mojo/shell/domain_socket/unix_domain_client_socket_posix.h" | 15 #include "shell/domain_socket/unix_domain_client_socket_posix.h" |
16 #include "mojo/shell/external_application_registrar_connection.h" | 16 #include "shell/external_application_registrar_connection.h" |
17 #include "mojo/shell/incoming_connection_listener_posix.h" | 17 #include "shell/incoming_connection_listener_posix.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 namespace mojo { | 20 namespace mojo { |
21 namespace shell { | 21 namespace shell { |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Delegate implementation that expects success. | 24 // Delegate implementation that expects success. |
25 class TestDelegate : public IncomingConnectionListenerPosix::Delegate { | 25 class TestDelegate : public IncomingConnectionListenerPosix::Delegate { |
26 public: | 26 public: |
27 TestDelegate() {} | 27 TestDelegate() {} |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 IncomingConnectionListenerPosix listener(socket_path_, &fail_delegate); | 118 IncomingConnectionListenerPosix listener(socket_path_, &fail_delegate); |
119 | 119 |
120 // Create the socket file. | 120 // Create the socket file. |
121 ASSERT_EQ(1, base::WriteFile(socket_path_, "1", 1)); | 121 ASSERT_EQ(1, base::WriteFile(socket_path_, "1", 1)); |
122 ASSERT_TRUE(base::PathExists(socket_path_)); | 122 ASSERT_TRUE(base::PathExists(socket_path_)); |
123 | 123 |
124 // Render it undeletable, but in a way that the test harness can recover | 124 // Render it undeletable, but in a way that the test harness can recover |
125 // later. | 125 // later. |
126 int temp_dir_perms = 0; | 126 int temp_dir_perms = 0; |
127 ASSERT_TRUE(base::GetPosixFilePermissions(temp_dir_.path(), &temp_dir_perms)); | 127 ASSERT_TRUE(base::GetPosixFilePermissions(temp_dir_.path(), &temp_dir_perms)); |
128 ASSERT_TRUE( | 128 ASSERT_TRUE(base::SetPosixFilePermissions( |
129 base::SetPosixFilePermissions(temp_dir_.path(), | 129 temp_dir_.path(), base::FILE_PERMISSION_READ_BY_USER | |
130 base::FILE_PERMISSION_READ_BY_USER | | 130 base::FILE_PERMISSION_WRITE_BY_USER)); |
131 base::FILE_PERMISSION_WRITE_BY_USER)); | |
132 // The listener should fail to start up. | 131 // The listener should fail to start up. |
133 listener.StartListening(); | 132 listener.StartListening(); |
134 | 133 |
135 ASSERT_TRUE(base::SetPosixFilePermissions(temp_dir_.path(), temp_dir_perms)); | 134 ASSERT_TRUE(base::SetPosixFilePermissions(temp_dir_.path(), temp_dir_perms)); |
136 } | 135 } |
137 | 136 |
138 TEST_F(IncomingConnectionListenerTest, ConnectFails_SocketDirNonexistent) { | 137 TEST_F(IncomingConnectionListenerTest, ConnectFails_SocketDirNonexistent) { |
139 base::FilePath nonexistent_dir(temp_dir_.path() | 138 base::FilePath nonexistent_dir(temp_dir_.path() |
140 .Append(FILE_PATH_LITERAL("dir")) | 139 .Append(FILE_PATH_LITERAL("dir")) |
141 .Append(FILE_PATH_LITERAL("file"))); | 140 .Append(FILE_PATH_LITERAL("file"))); |
142 | 141 |
143 ListeningFailsDelegate fail_delegate(net::ERR_FILE_NOT_FOUND); | 142 ListeningFailsDelegate fail_delegate(net::ERR_FILE_NOT_FOUND); |
144 IncomingConnectionListenerPosix listener(nonexistent_dir, &fail_delegate); | 143 IncomingConnectionListenerPosix listener(nonexistent_dir, &fail_delegate); |
145 | 144 |
146 // The listener should fail to start up. | 145 // The listener should fail to start up. |
147 listener.StartListening(); | 146 listener.StartListening(); |
148 } | 147 } |
149 | 148 |
150 } // namespace shell | 149 } // namespace shell |
151 } // namespace mojo | 150 } // namespace mojo |
OLD | NEW |