OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #elif defined(OS_POSIX) | 9 #elif defined(OS_POSIX) |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 MessageLoop::current()->Run(); | 233 MessageLoop::current()->Run(); |
234 | 234 |
235 // Close Channel so client gets its OnChannelError() callback fired. | 235 // Close Channel so client gets its OnChannelError() callback fired. |
236 chan.Close(); | 236 chan.Close(); |
237 | 237 |
238 // Cleanup child process. | 238 // Cleanup child process. |
239 EXPECT_TRUE(base::WaitForSingleProcess(process_handle, 5000)); | 239 EXPECT_TRUE(base::WaitForSingleProcess(process_handle, 5000)); |
240 base::CloseProcessHandle(process_handle); | 240 base::CloseProcessHandle(process_handle); |
241 } | 241 } |
242 | 242 |
| 243 #if defined(OS_WIN) |
| 244 TEST_F(IPCChannelTest, ChannelTestExistingPipe) { |
| 245 MyChannelListener channel_listener; |
| 246 // Setup IPC channel with existing pipe. Specify name in Chrome format. |
| 247 std::string name("\\\\.\\pipe\\chrome."); |
| 248 name.append(kTestClientChannel); |
| 249 const DWORD open_mode = PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | |
| 250 FILE_FLAG_FIRST_PIPE_INSTANCE; |
| 251 HANDLE pipe = CreateNamedPipeA(name.c_str(), |
| 252 open_mode, |
| 253 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, |
| 254 1, |
| 255 4096, |
| 256 4096, |
| 257 5000, |
| 258 NULL); |
| 259 IPC::Channel chan(IPC::ChannelHandle(pipe), IPC::Channel::MODE_SERVER, |
| 260 &channel_listener); |
| 261 // Channel will duplicate the handle. |
| 262 CloseHandle(pipe); |
| 263 ASSERT_TRUE(chan.Connect()); |
| 264 |
| 265 channel_listener.Init(&chan); |
| 266 |
| 267 base::ProcessHandle process_handle = SpawnChild(TEST_CLIENT, &chan); |
| 268 ASSERT_TRUE(process_handle); |
| 269 |
| 270 Send(&chan, "hello from parent"); |
| 271 |
| 272 // Run message loop. |
| 273 MessageLoop::current()->Run(); |
| 274 |
| 275 // Close Channel so client gets its OnChannelError() callback fired. |
| 276 chan.Close(); |
| 277 |
| 278 // Cleanup child process. |
| 279 EXPECT_TRUE(base::WaitForSingleProcess(process_handle, 5000)); |
| 280 base::CloseProcessHandle(process_handle); |
| 281 } |
| 282 #endif // defined (OS_WIN) |
| 283 |
243 TEST_F(IPCChannelTest, ChannelProxyTest) { | 284 TEST_F(IPCChannelTest, ChannelProxyTest) { |
244 MyChannelListener channel_listener; | 285 MyChannelListener channel_listener; |
245 | 286 |
246 // The thread needs to out-live the ChannelProxy. | 287 // The thread needs to out-live the ChannelProxy. |
247 base::Thread thread("ChannelProxyTestServer"); | 288 base::Thread thread("ChannelProxyTestServer"); |
248 base::Thread::Options options; | 289 base::Thread::Options options; |
249 options.message_loop_type = MessageLoop::TYPE_IO; | 290 options.message_loop_type = MessageLoop::TYPE_IO; |
250 thread.StartWithOptions(options); | 291 thread.StartWithOptions(options); |
251 { | 292 { |
252 // setup IPC channel proxy | 293 // setup IPC channel proxy |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 #endif // PERFORMANCE_TEST | 578 #endif // PERFORMANCE_TEST |
538 | 579 |
539 int main(int argc, char** argv) { | 580 int main(int argc, char** argv) { |
540 #ifdef PERFORMANCE_TEST | 581 #ifdef PERFORMANCE_TEST |
541 int retval = base::PerfTestSuite(argc, argv).Run(); | 582 int retval = base::PerfTestSuite(argc, argv).Run(); |
542 #else | 583 #else |
543 int retval = base::TestSuite(argc, argv).Run(); | 584 int retval = base::TestSuite(argc, argv).Run(); |
544 #endif | 585 #endif |
545 return retval; | 586 return retval; |
546 } | 587 } |
OLD | NEW |