| Index: ipc/ipc_mojo_bootstrap_unittest.cc
|
| diff --git a/ipc/ipc_mojo_bootstrap_unittest.cc b/ipc/ipc_mojo_bootstrap_unittest.cc
|
| index b036faca5752144678cc4e77e7a5779968f5f09c..c6cde3ec6368d91645efc76996796670758342b9 100644
|
| --- a/ipc/ipc_mojo_bootstrap_unittest.cc
|
| +++ b/ipc/ipc_mojo_bootstrap_unittest.cc
|
| @@ -18,6 +18,7 @@
|
| #include "mojo/edk/embedder/embedder.h"
|
| #include "mojo/edk/test/mojo_test_base.h"
|
| #include "mojo/edk/test/multiprocess_test_helper.h"
|
| +#include "mojo/public/cpp/bindings/associated_binding.h"
|
|
|
| #if defined(OS_POSIX)
|
| #include "base/file_descriptor_posix.h"
|
| @@ -25,47 +26,62 @@
|
|
|
| namespace {
|
|
|
| -class IPCMojoBootstrapTest : public testing::Test {
|
| - protected:
|
| - mojo::edk::test::MultiprocessTestHelper helper_;
|
| -};
|
| +constexpr int32_t kTestServerPid = 42;
|
| +constexpr int32_t kTestClientPid = 4242;
|
|
|
| -class TestingDelegate : public IPC::MojoBootstrap::Delegate {
|
| +class PeerPidReceiver : public IPC::mojom::Channel {
|
| public:
|
| - explicit TestingDelegate(const base::Closure& quit_callback)
|
| - : passed_(false), quit_callback_(quit_callback) {}
|
| + PeerPidReceiver(IPC::mojom::ChannelAssociatedRequest request,
|
| + const base::Closure& on_peer_pid_set)
|
| + : binding_(this, std::move(request)), on_peer_pid_set_(on_peer_pid_set) {}
|
| + ~PeerPidReceiver() override {}
|
| +
|
| + // mojom::Channel:
|
| + void SetPeerPid(int32_t pid) override {
|
| + peer_pid_ = pid;
|
| + on_peer_pid_set_.Run();
|
| + }
|
|
|
| - void OnPipesAvailable(
|
| - IPC::mojom::ChannelAssociatedPtr sender,
|
| - IPC::mojom::ChannelAssociatedRequest receiver) override;
|
| + void Receive(const std::vector<uint8_t>& data,
|
| + base::Optional<std::vector<IPC::mojom::SerializedHandlePtr>>
|
| + handles) override {}
|
|
|
| - bool passed() const { return passed_; }
|
| + void GetAssociatedInterface(
|
| + const std::string& name,
|
| + IPC::mojom::GenericInterfaceAssociatedRequest request) override {}
|
| +
|
| + int32_t peer_pid() const { return peer_pid_; }
|
|
|
| private:
|
| - bool passed_;
|
| - const base::Closure quit_callback_;
|
| + mojo::AssociatedBinding<IPC::mojom::Channel> binding_;
|
| + const base::Closure on_peer_pid_set_;
|
| + int32_t peer_pid_ = -1;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(PeerPidReceiver);
|
| };
|
|
|
| -void TestingDelegate::OnPipesAvailable(
|
| - IPC::mojom::ChannelAssociatedPtr sender,
|
| - IPC::mojom::ChannelAssociatedRequest receiver) {
|
| - passed_ = true;
|
| - quit_callback_.Run();
|
| -}
|
| +class IPCMojoBootstrapTest : public testing::Test {
|
| + protected:
|
| + mojo::edk::test::MultiprocessTestHelper helper_;
|
| +};
|
|
|
| TEST_F(IPCMojoBootstrapTest, Connect) {
|
| base::MessageLoop message_loop;
|
| - base::RunLoop run_loop;
|
| - TestingDelegate delegate(run_loop.QuitClosure());
|
| std::unique_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create(
|
| helper_.StartChild("IPCMojoBootstrapTestClient"),
|
| - IPC::Channel::MODE_SERVER, &delegate,
|
| - base::ThreadTaskRunnerHandle::Get());
|
| + IPC::Channel::MODE_SERVER, base::ThreadTaskRunnerHandle::Get());
|
|
|
| - bootstrap->Connect();
|
| + IPC::mojom::ChannelAssociatedPtr sender;
|
| + IPC::mojom::ChannelAssociatedRequest receiver;
|
| + bootstrap->Connect(&sender, &receiver);
|
| + sender->SetPeerPid(kTestServerPid);
|
| +
|
| + base::RunLoop run_loop;
|
| + PeerPidReceiver impl(std::move(receiver), run_loop.QuitClosure());
|
| run_loop.Run();
|
|
|
| - EXPECT_TRUE(delegate.passed());
|
| + EXPECT_EQ(kTestClientPid, impl.peer_pid());
|
| +
|
| EXPECT_TRUE(helper_.WaitForChildTestShutdown());
|
| }
|
|
|
| @@ -74,18 +90,22 @@ MULTIPROCESS_TEST_MAIN_WITH_SETUP(
|
| IPCMojoBootstrapTestClientTestChildMain,
|
| ::mojo::edk::test::MultiprocessTestHelper::ChildSetup) {
|
| base::MessageLoop message_loop;
|
| - base::RunLoop run_loop;
|
| - TestingDelegate delegate(run_loop.QuitClosure());
|
| std::unique_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create(
|
| std::move(mojo::edk::test::MultiprocessTestHelper::primordial_pipe),
|
| - IPC::Channel::MODE_CLIENT, &delegate,
|
| - base::ThreadTaskRunnerHandle::Get());
|
| + IPC::Channel::MODE_CLIENT, base::ThreadTaskRunnerHandle::Get());
|
|
|
| - bootstrap->Connect();
|
| + IPC::mojom::ChannelAssociatedPtr sender;
|
| + IPC::mojom::ChannelAssociatedRequest receiver;
|
| + bootstrap->Connect(&sender, &receiver);
|
| + sender->SetPeerPid(kTestClientPid);
|
|
|
| + base::RunLoop run_loop;
|
| + PeerPidReceiver impl(std::move(receiver), run_loop.QuitClosure());
|
| run_loop.Run();
|
|
|
| - return delegate.passed() ? 0 : 1;
|
| + EXPECT_EQ(kTestServerPid, impl.peer_pid());
|
| +
|
| + return 0;
|
| }
|
|
|
| } // namespace
|
|
|