Extension syncing: Introduce a NeedsSync pref
[chromium-blink-merge.git] / ipc / mojo / ipc_mojo_perftest.cc
blob17a43a077e63eb61a8436fb576042037334b9163
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 "base/run_loop.h"
7 #include "ipc/ipc_perftest_support.h"
8 #include "ipc/mojo/ipc_channel_mojo.h"
9 #include "third_party/mojo/src/mojo/edk/embedder/test_embedder.h"
11 namespace {
13 // This is needed because we rely on //base/test:test_support_perf and
14 // it provides main() which doesn't have Mojo initialization. We need
15 // some way to call InitWithSimplePlatformSupport() only once before
16 // using Mojo.
17 struct MojoInitialier {
18 MojoInitialier() {
19 mojo::embedder::test::InitWithSimplePlatformSupport();
23 base::LazyInstance<MojoInitialier> g_mojo_initializer
24 = LAZY_INSTANCE_INITIALIZER;
26 class MojoChannelPerfTest : public IPC::test::IPCChannelPerfTestBase {
27 public:
28 typedef IPC::test::IPCChannelPerfTestBase Super;
30 MojoChannelPerfTest();
32 void TearDown() override {
33 IPC::test::IPCChannelPerfTestBase::TearDown();
36 scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
37 const IPC::ChannelHandle& handle,
38 base::SequencedTaskRunner* runner) override {
39 return IPC::ChannelMojo::CreateServerFactory(runner, handle, nullptr);
42 bool DidStartClient() override {
43 bool ok = IPCTestBase::DidStartClient();
44 DCHECK(ok);
45 return ok;
49 MojoChannelPerfTest::MojoChannelPerfTest() {
50 g_mojo_initializer.Get();
54 TEST_F(MojoChannelPerfTest, ChannelPingPong) {
55 RunTestChannelPingPong(GetDefaultTestParams());
57 base::RunLoop run_loop;
58 run_loop.RunUntilIdle();
61 TEST_F(MojoChannelPerfTest, ChannelProxyPingPong) {
62 RunTestChannelProxyPingPong(GetDefaultTestParams());
64 base::RunLoop run_loop;
65 run_loop.RunUntilIdle();
68 class MojoTestClient : public IPC::test::PingPongTestClient {
69 public:
70 typedef IPC::test::PingPongTestClient SuperType;
72 MojoTestClient();
74 scoped_ptr<IPC::Channel> CreateChannel(IPC::Listener* listener) override;
77 MojoTestClient::MojoTestClient() {
78 g_mojo_initializer.Get();
81 scoped_ptr<IPC::Channel> MojoTestClient::CreateChannel(
82 IPC::Listener* listener) {
83 return scoped_ptr<IPC::Channel>(IPC::ChannelMojo::Create(
84 task_runner(), IPCTestBase::GetChannelName("PerformanceClient"),
85 IPC::Channel::MODE_CLIENT, listener, nullptr));
88 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient) {
89 MojoTestClient client;
90 int rv = client.RunMain();
92 base::RunLoop run_loop;
93 run_loop.RunUntilIdle();
95 return rv;
98 } // namespace