Update V8 to version 3.29.78 (based on bleeding_edge revision r24051).
[chromium-blink-merge.git] / ipc / mojo / ipc_mojo_perftest.cc
blobd4337037a9dcacda733d77637d7141275cfb0f07
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 "base/lazy_instance.h"
6 #include "ipc/ipc_perftest_support.h"
7 #include "ipc/mojo/ipc_channel_mojo.h"
8 #include "mojo/embedder/test_embedder.h"
10 namespace {
12 // This is needed because we rely on //base/test:test_support_perf and
13 // it provides main() which doesn't have Mojo initialization. We need
14 // some way to call InitWithSimplePlatformSupport() only once before
15 // using Mojo.
16 struct MojoInitialier {
17 MojoInitialier() {
18 mojo::embedder::test::InitWithSimplePlatformSupport();
22 base::LazyInstance<MojoInitialier> g_mojo_initializer
23 = LAZY_INSTANCE_INITIALIZER;
25 class MojoChannelPerfTest : public IPC::test::IPCChannelPerfTestBase {
26 public:
27 typedef IPC::test::IPCChannelPerfTestBase Super;
29 MojoChannelPerfTest();
31 virtual scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
32 const IPC::ChannelHandle& handle,
33 base::TaskRunner* runner) OVERRIDE {
34 return IPC::ChannelMojo::CreateFactory(
35 handle, IPC::Channel::MODE_SERVER, runner);
38 void set_io_thread_task_runner(base::TaskRunner* runner) {
39 io_thread_task_runner_ = runner;
42 private:
43 base::TaskRunner* io_thread_task_runner_;
46 MojoChannelPerfTest::MojoChannelPerfTest()
47 : io_thread_task_runner_() {
48 g_mojo_initializer.Get();
52 TEST_F(MojoChannelPerfTest, ChannelPingPong) {
53 RunTestChannelPingPong(GetDefaultTestParams());
56 TEST_F(MojoChannelPerfTest, ChannelProxyPingPong) {
57 RunTestChannelProxyPingPong(GetDefaultTestParams());
60 class MojoTestClient : public IPC::test::PingPongTestClient {
61 public:
62 typedef IPC::test::PingPongTestClient SuperType;
64 MojoTestClient();
66 virtual scoped_ptr<IPC::Channel> CreateChannel(
67 IPC::Listener* listener) OVERRIDE;
70 MojoTestClient::MojoTestClient() {
71 g_mojo_initializer.Get();
74 scoped_ptr<IPC::Channel> MojoTestClient::CreateChannel(
75 IPC::Listener* listener) {
76 return scoped_ptr<IPC::Channel>(IPC::ChannelMojo::Create(
77 IPCTestBase::GetChannelName("PerformanceClient"),
78 IPC::Channel::MODE_CLIENT, listener,
79 task_runner()));
82 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient) {
83 MojoTestClient client;
84 return client.RunMain();
87 } // namespace