| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "chrome/common/ipc_tests.h" | 7 #include "chrome/common/ipc_tests.h" |
| 8 | 8 |
| 9 #if defined(OS_MACOSX) | 9 #if defined(OS_MACOSX) |
| 10 extern "C" { | 10 extern "C" { |
| 11 #include <sandbox.h> | 11 #include <sandbox.h> |
| 12 } | 12 } |
| 13 #endif | 13 #endif |
| 14 #include <fcntl.h> | 14 #include <fcntl.h> |
| 15 #include <sys/stat.h> | 15 #include <sys/stat.h> |
| 16 | 16 |
| 17 #include "base/eintr_wrappers.h" |
| 17 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 18 #include "chrome/common/ipc_channel.h" | 19 #include "chrome/common/ipc_channel.h" |
| 19 #include "chrome/common/ipc_message_utils.h" | 20 #include "chrome/common/ipc_message_utils.h" |
| 20 | 21 |
| 21 #if defined(OS_POSIX) | 22 #if defined(OS_POSIX) |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 const unsigned kNumFDsToSend = 20; | 26 const unsigned kNumFDsToSend = 20; |
| 26 const char* kDevZeroPath = "/dev/zero"; | 27 const char* kDevZeroPath = "/dev/zero"; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 116 |
| 116 } // namespace | 117 } // namespace |
| 117 | 118 |
| 118 // --------------------------------------------------------------------------- | 119 // --------------------------------------------------------------------------- |
| 119 #if defined(OS_MACOSX) | 120 #if defined(OS_MACOSX) |
| 120 // TODO(port): Make this test cross-platform. | 121 // TODO(port): Make this test cross-platform. |
| 121 MULTIPROCESS_TEST_MAIN(RunTestDescriptorClientSandboxed) { | 122 MULTIPROCESS_TEST_MAIN(RunTestDescriptorClientSandboxed) { |
| 122 struct stat st; | 123 struct stat st; |
| 123 const int fd = open(kDevZeroPath, O_RDONLY); | 124 const int fd = open(kDevZeroPath, O_RDONLY); |
| 124 fstat(fd, &st); | 125 fstat(fd, &st); |
| 125 close(fd); | 126 HANDLE_EINTR(close(fd)); |
| 126 | 127 |
| 127 // Enable the Sandbox. | 128 // Enable the Sandbox. |
| 128 char* error_buff = NULL; | 129 char* error_buff = NULL; |
| 129 int error = sandbox_init(kSBXProfilePureComputation, SANDBOX_NAMED, | 130 int error = sandbox_init(kSBXProfilePureComputation, SANDBOX_NAMED, |
| 130 &error_buff); | 131 &error_buff); |
| 131 bool success = (error == 0 && error_buff == NULL); | 132 bool success = (error == 0 && error_buff == NULL); |
| 132 if (!success) { | 133 if (!success) { |
| 133 return -1; | 134 return -1; |
| 134 } | 135 } |
| 135 | 136 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 158 TEST_DESCRIPTOR_CLIENT_SANDBOXED, | 159 TEST_DESCRIPTOR_CLIENT_SANDBOXED, |
| 159 &chan); | 160 &chan); |
| 160 TestDescriptorServer(chan, process_handle); | 161 TestDescriptorServer(chan, process_handle); |
| 161 } | 162 } |
| 162 #endif // defined(OS_MACOSX) | 163 #endif // defined(OS_MACOSX) |
| 163 | 164 |
| 164 MULTIPROCESS_TEST_MAIN(RunTestDescriptorClient) { | 165 MULTIPROCESS_TEST_MAIN(RunTestDescriptorClient) { |
| 165 struct stat st; | 166 struct stat st; |
| 166 const int fd = open(kDevZeroPath, O_RDONLY); | 167 const int fd = open(kDevZeroPath, O_RDONLY); |
| 167 fstat(fd, &st); | 168 fstat(fd, &st); |
| 168 close(fd); | 169 HANDLE_EINTR(close(fd)); |
| 169 | 170 |
| 170 return TestDescriptorClient(st.st_ino); | 171 return TestDescriptorClient(st.st_ino); |
| 171 } | 172 } |
| 172 | 173 |
| 173 TEST_F(IPCChannelTest, DescriptorTest) { | 174 TEST_F(IPCChannelTest, DescriptorTest) { |
| 174 // Setup IPC channel. | 175 // Setup IPC channel. |
| 175 MyChannelDescriptorListener listener(-1); | 176 MyChannelDescriptorListener listener(-1); |
| 176 | 177 |
| 177 IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_SERVER, | 178 IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_SERVER, |
| 178 &listener); | 179 &listener); |
| 179 chan.Connect(); | 180 chan.Connect(); |
| 180 | 181 |
| 181 base::ProcessHandle process_handle = SpawnChild(TEST_DESCRIPTOR_CLIENT, | 182 base::ProcessHandle process_handle = SpawnChild(TEST_DESCRIPTOR_CLIENT, |
| 182 &chan); | 183 &chan); |
| 183 TestDescriptorServer(chan, process_handle); | 184 TestDescriptorServer(chan, process_handle); |
| 184 } | 185 } |
| 185 | 186 |
| 186 #endif // defined(OS_POSIX) | 187 #endif // defined(OS_POSIX) |
| OLD | NEW |