blob: c52c8c78c26d37df5f1bc1ba1bd8616abf8a8aa8 [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001// 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.
4
5// Note: This file also tests child_process.*.
6
James Robinsonb4b7af22014-12-05 11:21:01 -08007#include "shell/child_process_host.h"
James Robinson646469d2014-10-03 15:33:28 -07008
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"
James Robinsonb4b7af22014-12-05 11:21:01 -080013#include "shell/context.h"
James Robinson646469d2014-10-03 15:33:28 -070014#include "testing/gtest/include/gtest/gtest.h"
15
16namespace mojo {
17namespace shell {
18namespace test {
19namespace {
20
21class TestChildProcessHostDelegate : public ChildProcessHost::Delegate {
22 public:
23 TestChildProcessHostDelegate() {}
Viet-Trung Luu153dd212014-10-21 14:41:15 -070024 ~TestChildProcessHostDelegate() {}
James Robinsone1b30cf2014-10-21 12:25:40 -070025 void WillStart() override {
James Robinson646469d2014-10-03 15:33:28 -070026 VLOG(2) << "TestChildProcessHostDelegate::WillStart()";
27 }
James Robinsone1b30cf2014-10-21 12:25:40 -070028 void DidStart(bool success) override {
James Robinson646469d2014-10-03 15:33:28 -070029 VLOG(2) << "TestChildProcessHostDelegate::DidStart(" << success << ")";
30 base::MessageLoop::current()->QuitWhenIdle();
31 }
32};
33
34typedef testing::Test ChildProcessHostTest;
35
Benjamin Lerman7d036f02014-12-23 10:39:19 +010036#if defined(OS_ANDROID)
37// TODO(qsr): Multiprocess shell tests are not supported on android.
38#define MAYBE_Basic DISABLED_Basic
39#else
40#define MAYBE_Basic Basic
41#endif // defined(OS_ANDROID)
42TEST_F(ChildProcessHostTest, MAYBE_Basic) {
James Robinson646469d2014-10-03 15:33:28 -070043 Context context;
44 base::MessageLoop message_loop(
45 scoped_ptr<base::MessagePump>(new common::MessagePumpMojo()));
46 context.Init();
47 TestChildProcessHostDelegate child_process_host_delegate;
James Robinsonb4b7af22014-12-05 11:21:01 -080048 ChildProcessHost child_process_host(&context, &child_process_host_delegate,
James Robinson646469d2014-10-03 15:33:28 -070049 ChildProcess::TYPE_TEST);
50 child_process_host.Start();
51 message_loop.Run();
52 int exit_code = child_process_host.Join();
53 VLOG(2) << "Joined child: exit_code = " << exit_code;
54 EXPECT_EQ(0, exit_code);
Viet-Trung Luu0ba64d62015-02-19 14:50:19 -080055
56 context.Shutdown();
James Robinson646469d2014-10-03 15:33:28 -070057}
58
59} // namespace
60} // namespace test
61} // namespace shell
62} // namespace mojo