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"
20 // Subclass just so we can observe |DidStart()|.
21 class TestChildProcessHost
: public ChildProcessHost
{
23 explicit TestChildProcessHost(Context
* context
) : ChildProcessHost(context
) {}
24 ~TestChildProcessHost() override
{}
26 void DidStart(bool success
) override
{
28 ChildProcessHost::DidStart(success
);
29 base::MessageLoop::current()->QuitWhenIdle();
33 DISALLOW_COPY_AND_ASSIGN(TestChildProcessHost
);
36 #if defined(OS_ANDROID)
37 // TODO(qsr): Multiprocess shell tests are not supported on android.
38 #define MAYBE_StartJoin DISABLED_StartJoin
40 #define MAYBE_StartJoin StartJoin
41 #endif // defined(OS_ANDROID)
42 // Just tests starting the child process and joining it (without starting an
44 TEST(ChildProcessHostTest
, MAYBE_StartJoin
) {
46 base::MessageLoop
message_loop(
47 scoped_ptr
<base::MessagePump
>(new common::MessagePumpMojo()));
49 TestChildProcessHost
child_process_host(&context
);
50 child_process_host
.Start();
52 child_process_host
.ExitNow(123);
53 int exit_code
= child_process_host
.Join();
54 VLOG(2) << "Joined child: exit_code = " << exit_code
;
55 EXPECT_EQ(123, exit_code
);