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 // Note: This file also tests child_process.*.
7 #include "mojo/shell/child_process_host.h"
9 #include "base/logging.h"
10 #include "base/macros.h"
11 #include "base/message_loop/message_loop.h"
12 #include "mojo/common/message_pump_mojo.h"
13 #include "mojo/shell/context.h"
14 #include "testing/gtest/include/gtest/gtest.h"
21 class TestChildProcessHostDelegate
: public ChildProcessHost::Delegate
{
23 TestChildProcessHostDelegate() {}
24 virtual ~TestChildProcessHostDelegate() {}
25 virtual void WillStart() OVERRIDE
{
26 VLOG(2) << "TestChildProcessHostDelegate::WillStart()";
28 virtual void DidStart(bool success
) OVERRIDE
{
29 VLOG(2) << "TestChildProcessHostDelegate::DidStart(" << success
<< ")";
30 base::MessageLoop::current()->QuitWhenIdle();
34 typedef testing::Test ChildProcessHostTest
;
36 TEST_F(ChildProcessHostTest
, Basic
) {
38 base::MessageLoop
message_loop(
39 scoped_ptr
<base::MessagePump
>(new common::MessagePumpMojo()));
41 TestChildProcessHostDelegate child_process_host_delegate
;
42 ChildProcessHost
child_process_host(&context
,
43 &child_process_host_delegate
,
44 ChildProcess::TYPE_TEST
);
45 child_process_host
.Start();
47 int exit_code
= child_process_host
.Join();
48 VLOG(2) << "Joined child: exit_code = " << exit_code
;
49 EXPECT_EQ(0, exit_code
);