Provide simple fling bookkeeping for telemetry
[chromium-blink-merge.git] / content / test / render_thread_impl_browser_test_ipc_helper.cc
blobe58f8c1f7a0a5e02810cea3ce28d245bbae85cf1
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 ipc_thread_->task_runner(),
58 channel_id_),
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