summaryrefslogtreecommitdiffstats
path: root/ipc/mojo/ipc_mojo_bootstrap_unittest.cc
diff options
context:
space:
mode:
authormorrita <morrita@chromium.org>2014-09-23 14:16:00 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-23 21:16:28 +0000
commit54f6f80c3623a6fb9d3049b6f5e0e23b1d76c34d (patch)
treed5188994206cd43ae680f6e7325ec5c45075b9da /ipc/mojo/ipc_mojo_bootstrap_unittest.cc
parentde9555146d87d2daf5e2e1da425d46b8efc06415 (diff)
downloadchromium_src-54f6f80c3623a6fb9d3049b6f5e0e23b1d76c34d.zip
chromium_src-54f6f80c3623a6fb9d3049b6f5e0e23b1d76c34d.tar.gz
chromium_src-54f6f80c3623a6fb9d3049b6f5e0e23b1d76c34d.tar.bz2
IPC::ChannelMojo: Introduce IPC::MojoBootstrap for Windows
ChannelMojo doesn't work on Windows with existing implementaion and this CL fixes it. On Windows, ChannelHandle isn't immediately usable: The handle has to be activated through ConnectNamedPipe() windows API, which is done in its own Connect() handlshaking phase. ChannelMojo didn't Connect() underlying channel and took the ChannelHandle over so the handle wasn't activated. Instead of hijacking underlying ChannelHandle, this CL actually Connect()s underlying channel, creates a pipe on the server side, send one side of the pipe to the client process, and use the pipe for the MessagePipe initialization. These initialization task is encapsulated behind new MojoBootstrap class. ChannelMojo creates MojoBootstrap class to get the PlatformHandle which is already activated and usable. BUG=377980 TEST=ipc_mojo_bootstrap_unittest.cc, ipc_channel_mojo_unittest.cc R=viettrungluu@chromium.org, darin@chromium.org, yzshen@chromium.org Review URL: https://codereview.chromium.org/553283002 Cr-Commit-Position: refs/heads/master@{#296248}
Diffstat (limited to 'ipc/mojo/ipc_mojo_bootstrap_unittest.cc')
-rw-r--r--ipc/mojo/ipc_mojo_bootstrap_unittest.cc86
1 files changed, 86 insertions, 0 deletions
diff --git a/ipc/mojo/ipc_mojo_bootstrap_unittest.cc b/ipc/mojo/ipc_mojo_bootstrap_unittest.cc
new file mode 100644
index 0000000..207c060
--- /dev/null
+++ b/ipc/mojo/ipc_mojo_bootstrap_unittest.cc
@@ -0,0 +1,86 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ipc/mojo/ipc_mojo_bootstrap.h"
+
+#include "base/base_paths.h"
+#include "base/files/file.h"
+#include "base/message_loop/message_loop.h"
+#include "ipc/ipc_test_base.h"
+
+#if defined(OS_POSIX)
+#include "base/file_descriptor_posix.h"
+#endif
+
+namespace {
+
+class IPCMojoBootstrapTest : public IPCTestBase {
+ protected:
+};
+
+class TestingDelegate : public IPC::MojoBootstrap::Delegate {
+ public:
+ TestingDelegate() : passed_(false) {}
+
+ virtual void OnPipeAvailable(
+ mojo::embedder::ScopedPlatformHandle handle) OVERRIDE;
+ virtual void OnBootstrapError() OVERRIDE;
+
+ bool passed() const { return passed_; }
+
+ private:
+ bool passed_;
+};
+
+void TestingDelegate::OnPipeAvailable(
+ mojo::embedder::ScopedPlatformHandle handle) {
+ passed_ = true;
+ base::MessageLoop::current()->Quit();
+}
+
+void TestingDelegate::OnBootstrapError() {
+ base::MessageLoop::current()->Quit();
+}
+
+TEST_F(IPCMojoBootstrapTest, Connect) {
+ Init("IPCMojoBootstrapTestClient");
+
+ TestingDelegate delegate;
+ scoped_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create(
+ GetTestChannelHandle(), IPC::Channel::MODE_SERVER, &delegate);
+
+ ASSERT_TRUE(bootstrap->Connect());
+#if defined(OS_POSIX)
+ ASSERT_TRUE(StartClientWithFD(bootstrap->GetClientFileDescriptor()));
+#else
+ ASSERT_TRUE(StartClient());
+#endif
+ bootstrap->OnClientLaunched(client_process());
+
+ base::MessageLoop::current()->Run();
+
+ EXPECT_TRUE(delegate.passed());
+ EXPECT_TRUE(WaitForClientShutdown());
+}
+
+// A long running process that connects to us.
+MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCMojoBootstrapTestClient) {
+ base::MessageLoopForIO main_message_loop;
+
+ TestingDelegate delegate;
+ scoped_ptr<IPC::MojoBootstrap> bootstrap = IPC::MojoBootstrap::Create(
+ IPCTestBase::GetChannelName("IPCMojoBootstrapTestClient"),
+ IPC::Channel::MODE_CLIENT,
+ &delegate);
+
+ bootstrap->Connect();
+
+ base::MessageLoop::current()->Run();
+
+ EXPECT_TRUE(delegate.passed());
+
+ return 0;
+}
+
+} // namespace