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 "testing/gtest/include/gtest/gtest.h"
12 class RenderThreadImplBrowserIPCTestHelper::DummyListener
13 : public IPC::Listener
{
15 bool OnMessageReceived(const IPC::Message
& message
) override
{ return true; }
18 RenderThreadImplBrowserIPCTestHelper::RenderThreadImplBrowserIPCTestHelper() {
19 message_loop_
.reset(new base::MessageLoopForIO());
21 channel_id_
= IPC::Channel::GenerateVerifiedChannelID("");
22 dummy_listener_
.reset(new DummyListener());
26 if (IPC::ChannelMojo::ShouldBeUsed()) {
29 channel_
= IPC::ChannelProxy::Create(channel_id_
, IPC::Channel::MODE_SERVER
,
30 dummy_listener_
.get(),
31 ipc_thread_
->task_runner(), nullptr);
35 RenderThreadImplBrowserIPCTestHelper::~RenderThreadImplBrowserIPCTestHelper() {
38 void RenderThreadImplBrowserIPCTestHelper::SetupIpcThread() {
39 ipc_thread_
.reset(new base::Thread("test_ipc_thread"));
40 base::Thread::Options options
;
41 options
.message_loop_type
= base::MessageLoop::TYPE_IO
;
42 ASSERT_TRUE(ipc_thread_
->StartWithOptions(options
));
45 void RenderThreadImplBrowserIPCTestHelper::SetupMojo() {
48 ipc_support_
.reset(new IPC::ScopedIPCSupport(ipc_thread_
->task_runner()));
49 mojo_application_host_
.reset(new MojoApplicationHost());
50 mojo_application_host_
->OverrideIOTaskRunnerForTest(
51 ipc_thread_
->task_runner());
53 channel_
= IPC::ChannelProxy::Create(
54 IPC::ChannelMojo::CreateServerFactory(ipc_thread_
->task_runner(),
55 channel_id_
, nullptr),
56 dummy_listener_
.get(), ipc_thread_
->task_runner());
58 mojo_application_host_
->Init();
59 mojo_application_host_
->Activate(channel_
.get(),
60 base::GetCurrentProcessHandle());
63 scoped_refptr
<base::SingleThreadTaskRunner
>
64 RenderThreadImplBrowserIPCTestHelper::GetIOTaskRunner() const {
65 return ipc_thread_
->task_runner();
68 } // namespace content