Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320)
[chromium-blink-merge.git] / content / test / render_thread_impl_browser_test_ipc_helper.cc
blob7f038859433ac473e341486db8036df448b2f4ad
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
3 // found in the LICENSE file.
5 #include "content/test/render_thread_impl_browser_test_ipc_helper.h"
7 #include "content/common/mojo/channel_init.h"
8 #include "ipc/mojo/ipc_channel_mojo_host.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace content {
13 class RenderThreadImplBrowserIPCTestHelper::DummyListener
14 : public IPC::Listener {
15 public:
16 bool OnMessageReceived(const IPC::Message& message) override { return true; }
19 RenderThreadImplBrowserIPCTestHelper::RenderThreadImplBrowserIPCTestHelper() {
20 message_loop_.reset(new base::MessageLoopForIO());
22 channel_id_ = IPC::Channel::GenerateVerifiedChannelID("");
23 dummy_listener_.reset(new DummyListener());
25 SetupIpcThread();
27 if (IPC::ChannelMojo::ShouldBeUsed()) {
28 SetupMojo();
29 } else {
30 channel_ = IPC::ChannelProxy::Create(channel_id_, IPC::Channel::MODE_SERVER,
31 dummy_listener_.get(),
32 ipc_thread_->task_runner());
36 RenderThreadImplBrowserIPCTestHelper::~RenderThreadImplBrowserIPCTestHelper() {
39 void RenderThreadImplBrowserIPCTestHelper::SetupIpcThread() {
40 ipc_thread_.reset(new base::Thread("test_ipc_thread"));
41 base::Thread::Options options;
42 options.message_loop_type = base::MessageLoop::TYPE_IO;
43 ASSERT_TRUE(ipc_thread_->StartWithOptions(options));
46 void RenderThreadImplBrowserIPCTestHelper::SetupMojo() {
47 InitializeMojo();
49 ipc_support_.reset(new IPC::ScopedIPCSupport(ipc_thread_->task_runner()));
50 mojo_host_.reset(new IPC::ChannelMojoHost(ipc_thread_->task_runner()));
51 mojo_application_host_.reset(new MojoApplicationHost());
52 mojo_application_host_->OverrideIOTaskRunnerForTest(
53 ipc_thread_->task_runner());
55 channel_ = IPC::ChannelProxy::Create(
56 IPC::ChannelMojo::CreateServerFactory(mojo_host_->channel_delegate(),
57 channel_id_),
58 dummy_listener_.get(), ipc_thread_->task_runner());
60 mojo_application_host_->Init();
61 mojo_application_host_->Activate(channel_.get(),
62 base::GetCurrentProcessHandle());
63 mojo_host_->OnClientLaunched(base::GetCurrentProcessHandle());
66 scoped_refptr<base::SingleThreadTaskRunner>
67 RenderThreadImplBrowserIPCTestHelper::GetIOTaskRunner() const {
68 return ipc_thread_->task_runner();
71 } // namespace content