summaryrefslogtreecommitdiffstats
path: root/mojo/shell/child_process_host_unittest.cc
blob: 97bc96dca08d25d873a7ec287644c404a7de3634 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Note: This file also tests child_process.*.

#include "mojo/shell/child_process_host.h"

#include "base/logging.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "mojo/common/message_pump_mojo.h"
#include "mojo/shell/context.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace mojo {
namespace shell {
namespace test {
namespace {

class TestChildProcessHostDelegate : public ChildProcessHost::Delegate {
 public:
  TestChildProcessHostDelegate() {}
  virtual ~TestChildProcessHostDelegate() {}
  virtual void WillStart() OVERRIDE {
    VLOG(2) << "TestChildProcessHostDelegate::WillStart()";
  }
  virtual void DidStart(bool success) OVERRIDE {
    VLOG(2) << "TestChildProcessHostDelegate::DidStart(" << success << ")";
    base::MessageLoop::current()->QuitWhenIdle();
  }
};

typedef testing::Test ChildProcessHostTest;

TEST_F(ChildProcessHostTest, Basic) {
  base::MessageLoop message_loop(
      scoped_ptr<base::MessagePump>(new common::MessagePumpMojo()));

  Context context;
  TestChildProcessHostDelegate child_process_host_delegate;
  ChildProcessHost child_process_host(&context,
                                      &child_process_host_delegate,
                                      ChildProcess::TYPE_TEST);
  child_process_host.Start();
  message_loop.Run();
  int exit_code = child_process_host.Join();
  VLOG(2) << "Joined child: exit_code = " << exit_code;
  EXPECT_EQ(0, exit_code);
}

}  // namespace
}  // namespace test
}  // namespace shell
}  // namespace mojo