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"
13 class RenderThreadImplBrowserIPCTestHelper::DummyListener
14 : public IPC::Listener
{
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());
27 if (IPC::ChannelMojo::ShouldBeUsed()) {
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() {
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 ipc_thread_
->task_runner(),
59 dummy_listener_
.get(), ipc_thread_
->task_runner());
61 mojo_application_host_
->Init();
62 mojo_application_host_
->Activate(channel_
.get(),
63 base::GetCurrentProcessHandle());
64 mojo_host_
->OnClientLaunched(base::GetCurrentProcessHandle());
67 scoped_refptr
<base::SingleThreadTaskRunner
>
68 RenderThreadImplBrowserIPCTestHelper::GetIOTaskRunner() const {
69 return ipc_thread_
->task_runner();
72 } // namespace content