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

Side by Side Diff: ipc/ipc_send_fds_test.cc

Issue 10387218: Make GlobalDescriptors::MaybeGet return -1 when the key is not found. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor clean-up. Created 8 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
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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "ipc/ipc_tests.h" 7 #include "ipc/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_wrapper.h" 17 #include "base/eintr_wrapper.h"
18 #include "base/message_loop.h" 18 #include "base/message_loop.h"
19 #include "ipc/ipc_channel.h" 19 #include "ipc/ipc_channel.h"
20 #include "ipc/ipc_message_utils.h" 20 #include "ipc/ipc_message_utils.h"
21 #include "ipc/ipc_multiprocess_test.h"
21 #include "testing/multiprocess_func_list.h" 22 #include "testing/multiprocess_func_list.h"
22 23
23 #if defined(OS_POSIX) 24 #if defined(OS_POSIX)
24 #include "base/file_descriptor_posix.h" 25 #include "base/file_descriptor_posix.h"
25 26
26 namespace { 27 namespace {
27 28
28 const unsigned kNumFDsToSend = 20; 29 const unsigned kNumFDsToSend = 20;
29 const char* kDevZeroPath = "/dev/zero"; 30 const char* kDevZeroPath = "/dev/zero";
30 31
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 CHECK(listener.GotExpectedNumberOfDescriptors()); 126 CHECK(listener.GotExpectedNumberOfDescriptors());
126 127
127 return 0; 128 return 0;
128 } 129 }
129 130
130 } // namespace 131 } // namespace
131 132
132 // --------------------------------------------------------------------------- 133 // ---------------------------------------------------------------------------
133 #if defined(OS_MACOSX) 134 #if defined(OS_MACOSX)
134 // TODO(port): Make this test cross-platform. 135 // TODO(port): Make this test cross-platform.
135 MULTIPROCESS_TEST_MAIN(RunTestDescriptorClientSandboxed) { 136 MULTIPROCESS_IPC_TEST_MAIN(RunTestDescriptorClientSandboxed) {
136 struct stat st; 137 struct stat st;
137 const int fd = open(kDevZeroPath, O_RDONLY); 138 const int fd = open(kDevZeroPath, O_RDONLY);
138 fstat(fd, &st); 139 fstat(fd, &st);
139 if (HANDLE_EINTR(close(fd)) < 0) { 140 if (HANDLE_EINTR(close(fd)) < 0) {
140 return -1; 141 return -1;
141 } 142 }
142 143
143 // Enable the Sandbox. 144 // Enable the Sandbox.
144 char* error_buff = NULL; 145 char* error_buff = NULL;
145 int error = sandbox_init(kSBXProfilePureComputation, SANDBOX_NAMED, 146 int error = sandbox_init(kSBXProfilePureComputation, SANDBOX_NAMED,
(...skipping 24 matching lines...) Expand all
170 &listener); 171 &listener);
171 ASSERT_TRUE(chan.Connect()); 172 ASSERT_TRUE(chan.Connect());
172 173
173 base::ProcessHandle process_handle = SpawnChild( 174 base::ProcessHandle process_handle = SpawnChild(
174 TEST_DESCRIPTOR_CLIENT_SANDBOXED, 175 TEST_DESCRIPTOR_CLIENT_SANDBOXED,
175 &chan); 176 &chan);
176 TestDescriptorServer(chan, process_handle); 177 TestDescriptorServer(chan, process_handle);
177 } 178 }
178 #endif // defined(OS_MACOSX) 179 #endif // defined(OS_MACOSX)
179 180
180 MULTIPROCESS_TEST_MAIN(RunTestDescriptorClient) { 181 MULTIPROCESS_IPC_TEST_MAIN(RunTestDescriptorClient) {
181 struct stat st; 182 struct stat st;
182 const int fd = open(kDevZeroPath, O_RDONLY); 183 const int fd = open(kDevZeroPath, O_RDONLY);
183 fstat(fd, &st); 184 fstat(fd, &st);
184 EXPECT_GE(HANDLE_EINTR(close(fd)), 0); 185 EXPECT_GE(HANDLE_EINTR(close(fd)), 0);
185 186
186 return TestDescriptorClient(st.st_ino); 187 return TestDescriptorClient(st.st_ino);
187 } 188 }
188 189
189 TEST_F(IPCChannelTest, DescriptorTest) { 190 TEST_F(IPCChannelTest, DescriptorTest) {
190 // Setup IPC channel. 191 // Setup IPC channel.
191 MyChannelDescriptorListener listener(-1); 192 MyChannelDescriptorListener listener(-1);
192 193
193 IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_SERVER, 194 IPC::Channel chan(kTestClientChannel, IPC::Channel::MODE_SERVER,
194 &listener); 195 &listener);
195 ASSERT_TRUE(chan.Connect()); 196 ASSERT_TRUE(chan.Connect());
196 197
197 base::ProcessHandle process_handle = SpawnChild(TEST_DESCRIPTOR_CLIENT, 198 base::ProcessHandle process_handle = SpawnChild(TEST_DESCRIPTOR_CLIENT,
198 &chan); 199 &chan);
199 TestDescriptorServer(chan, process_handle); 200 TestDescriptorServer(chan, process_handle);
200 } 201 }
201 202
202 #endif // defined(OS_POSIX) 203 #endif // defined(OS_POSIX)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698