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 "ipc/mojo/ipc_channel_mojo.h" | 5 #include "ipc/mojo/ipc_channel_mojo.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/pickle.h" | 11 #include "base/pickle.h" |
12 #include "base/test/test_timeouts.h" | |
12 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
13 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
14 #include "ipc/ipc_test_base.h" | 15 #include "ipc/ipc_test_base.h" |
15 #include "ipc/ipc_test_channel_listener.h" | 16 #include "ipc/ipc_test_channel_listener.h" |
16 #include "ipc/mojo/ipc_channel_mojo_host.h" | 17 #include "ipc/mojo/ipc_channel_mojo_host.h" |
17 #include "ipc/mojo/ipc_mojo_handle_attachment.h" | 18 #include "ipc/mojo/ipc_mojo_handle_attachment.h" |
18 #include "ipc/mojo/ipc_mojo_message_helper.h" | 19 #include "ipc/mojo/ipc_mojo_message_helper.h" |
19 | 20 |
20 #if defined(OS_POSIX) | 21 #if defined(OS_POSIX) |
21 #include "base/file_descriptor_posix.h" | 22 #include "base/file_descriptor_posix.h" |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 client.Connect(); | 572 client.Connect(); |
572 listener.set_sender(client.channel()); | 573 listener.set_sender(client.channel()); |
573 | 574 |
574 base::MessageLoop::current()->Run(); | 575 base::MessageLoop::current()->Run(); |
575 | 576 |
576 return 0; | 577 return 0; |
577 } | 578 } |
578 | 579 |
579 #endif | 580 #endif |
580 | 581 |
582 #if defined(OS_LINUX) | |
583 | |
584 const base::ProcessId kMagicChildId = 54321; | |
585 | |
586 class ListenerThatVerifiesPeerPid : public IPC::Listener { | |
587 public: | |
588 ListenerThatVerifiesPeerPid() {} | |
agl
2015/02/25 02:45:29
Won't the compiler synthesise the empty constructo
Hajime Morrita
2015/02/25 19:13:06
It should. removed.
| |
589 ~ListenerThatVerifiesPeerPid() override {} | |
590 | |
591 void OnChannelConnected(int32 peer_pid) override { | |
592 EXPECT_EQ(peer_pid, kMagicChildId); | |
593 base::MessageLoop::current()->Quit(); | |
594 } | |
595 | |
596 bool OnMessageReceived(const IPC::Message& message) override { | |
597 NOTREACHED(); | |
598 return true; | |
599 } | |
600 | |
agl
2015/02/25 02:45:29
remove blank line.
Hajime Morrita
2015/02/25 19:13:05
Done.
| |
601 }; | |
602 | |
603 TEST_F(IPCChannelMojoTest, VerifyGlobalPid) { | |
604 Init("IPCChannelMojoTestVerifyGlobalPidClient"); | |
605 | |
606 ListenerThatVerifiesPeerPid listener; | |
607 CreateChannel(&listener); | |
608 ASSERT_TRUE(ConnectChannel()); | |
609 ASSERT_TRUE(StartClient()); | |
610 | |
611 base::MessageLoop::current()->Run(); | |
612 this->channel()->Close(); | |
613 | |
614 EXPECT_TRUE(WaitForClientShutdown()); | |
615 DestroyChannel(); | |
616 } | |
617 | |
618 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCChannelMojoTestVerifyGlobalPidClient) { | |
619 IPC::Channel::SetGlobalPid(kMagicChildId); | |
620 ListenerThatQuits listener; | |
621 ChannelClient client(&listener, | |
622 "IPCChannelMojoTestVerifyGlobalPidClient"); | |
623 client.Connect(); | |
624 | |
625 base::MessageLoop::current()->Run(); | |
626 | |
627 return 0; | |
628 } | |
629 | |
630 #endif | |
agl
2015/02/25 02:45:29
" // OS_LINUX" at the end of the line.
Hajime Morrita
2015/02/25 19:13:06
Done.
| |
631 | |
581 } // namespace | 632 } // namespace |
OLD | NEW |