Mojo: Add an extremely skeletal mojo_shell_tests.

For now, I'm just testing ChildProcess/ChildProcessHost (turned the
"manual" test code into a proper automated test).

I'll add an app-loading test shortly.

R=sky@chromium.org

Review URL: https://codereview.chromium.org/313653005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274692 0039d316-1c4b-4281-b951-d872f2087c98
parent f4d7649d
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
'mojo_service_manager_unittests', 'mojo_service_manager_unittests',
'mojo_shell', 'mojo_shell',
'mojo_shell_lib', 'mojo_shell_lib',
'mojo_shell_tests',
'mojo_system', 'mojo_system',
'mojo_system_impl', 'mojo_system_impl',
'mojo_system_unittests', 'mojo_system_unittests',
...@@ -574,6 +575,29 @@ ...@@ -574,6 +575,29 @@
'shell/desktop/mojo_main.cc', 'shell/desktop/mojo_main.cc',
], ],
}, },
{
'target_name': 'mojo_shell_tests',
'type': 'executable',
'dependencies': [
'../base/base.gyp:base',
'../base/base.gyp:test_support_base',
'../testing/gtest.gyp:gtest',
# TODO(vtl): We don't currently need this, but I imagine we will soon.
# '../ui/gl/gl.gyp:gl',
'../url/url.gyp:url_lib',
'mojo_common_lib',
'mojo_environment_chromium',
'mojo_service_manager',
'mojo_shell_lib',
'mojo_system_impl',
],
'sources': [
'shell/child_process_host_unittest.cc',
'shell/shell_test_base.cc',
'shell/shell_test_base.h',
'shell/shell_test_main.cc',
],
},
{ {
'target_name': 'mojo_service_manager_unittests', 'target_name': 'mojo_service_manager_unittests',
'type': 'executable', 'type': 'executable',
......
// 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 "mojo/shell/shell_test_base.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 ShellTestBase 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
...@@ -5,60 +5,21 @@ ...@@ -5,60 +5,21 @@
#include "base/at_exit.h" #include "base/at_exit.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" // TODO(vtl): Remove.
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "mojo/common/message_pump_mojo.h" // TODO(vtl): Remove.
#include "mojo/public/cpp/environment/environment.h" #include "mojo/public/cpp/environment/environment.h"
#include "mojo/shell/child_process.h" #include "mojo/shell/child_process.h"
#include "mojo/shell/child_process_host.h" // TODO(vtl): Remove.
#include "mojo/shell/context.h" #include "mojo/shell/context.h"
#include "mojo/shell/init.h" #include "mojo/shell/init.h"
#include "mojo/shell/run.h" #include "mojo/shell/run.h"
#include "mojo/shell/switches.h" #include "mojo/shell/switches.h"
#include "ui/gl/gl_surface.h" #include "ui/gl/gl_surface.h"
namespace {
// TODO(vtl): Remove.
class TestChildProcessHostDelegate
: public mojo::shell::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();
}
};
} // namespace
int main(int argc, char** argv) { int main(int argc, char** argv) {
base::AtExitManager at_exit; base::AtExitManager at_exit;
mojo::Environment env; mojo::Environment env;
base::CommandLine::Init(argc, argv); base::CommandLine::Init(argc, argv);
mojo::shell::InitializeLogging(); mojo::shell::InitializeLogging();
// TODO(vtl): Move this a proper test (and remove includes marked "remove").
if (base::CommandLine::ForCurrentProcess()->HasSwitch("run-test-child")) {
base::MessageLoop message_loop(
scoped_ptr<base::MessagePump>(new mojo::common::MessagePumpMojo()));
mojo::shell::Context context;
TestChildProcessHostDelegate child_process_host_delegate;
mojo::shell::ChildProcessHost child_process_host(
&context, &child_process_host_delegate,
mojo::shell::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;
return 0;
}
// TODO(vtl): Unify parent and child process cases to the extent possible. // TODO(vtl): Unify parent and child process cases to the extent possible.
if (scoped_ptr<mojo::shell::ChildProcess> child_process = if (scoped_ptr<mojo::shell::ChildProcess> child_process =
mojo::shell::ChildProcess::Create( mojo::shell::ChildProcess::Create(
......
// 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.
#include "mojo/shell/shell_test_base.h"
namespace mojo {
namespace shell {
namespace test {
ShellTestBase::ShellTestBase() {
}
ShellTestBase::~ShellTestBase() {
}
} // namespace test
} // namespace shell
} // namespace mojo
// 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.
#ifndef MOJO_SHELL_SHELL_TEST_BASE_H_
#define MOJO_SHELL_SHELL_TEST_BASE_H_
#include "base/at_exit.h"
#include "base/macros.h"
#include "mojo/public/cpp/environment/environment.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo {
namespace shell {
namespace test {
class ShellTestBase : public testing::Test {
public:
ShellTestBase();
virtual ~ShellTestBase();
private:
base::ShadowingAtExitManager at_exit_manager_;
Environment environment_;
DISALLOW_COPY_AND_ASSIGN(ShellTestBase);
};
} // namespace test
} // namespace shell
} // namespace mojo
#endif // MOJO_SYSTEM_SHELL_SHELLASE_H_
// 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.
#include "base/bind.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/test/launcher/unit_test_launcher.h"
#include "base/test/test_suite.h"
#include "mojo/shell/child_process.h"
#include "mojo/shell/switches.h"
#include "testing/gtest/include/gtest/gtest.h"
int main(int argc, char** argv) {
base::CommandLine::Init(argc, argv);
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kChildProcessType)) {
scoped_ptr<mojo::shell::ChildProcess> child_process =
mojo::shell::ChildProcess::Create(command_line);
CHECK(child_process);
child_process->Main();
return 0;
}
base::TestSuite test_suite(argc, argv);
return base::LaunchUnitTests(
argc, argv, base::Bind(&base::TestSuite::Run,
base::Unretained(&test_suite)));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment