summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-04 01:02:45 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-04 01:02:45 +0000
commitfc459f2e0327c93184a12f81d725732a3b4f5915 (patch)
tree8591c1b440cc37b5b0b076274af201456c625884
parentf4d7649d41f602fa4ce419471ad09d7492ac1dbc (diff)
downloadchromium_src-fc459f2e0327c93184a12f81d725732a3b4f5915.zip
chromium_src-fc459f2e0327c93184a12f81d725732a3b4f5915.tar.gz
chromium_src-fc459f2e0327c93184a12f81d725732a3b4f5915.tar.bz2
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
-rw-r--r--mojo/mojo.gyp24
-rw-r--r--mojo/shell/child_process_host_unittest.cc56
-rw-r--r--mojo/shell/desktop/mojo_main.cc39
-rw-r--r--mojo/shell/shell_test_base.cc19
-rw-r--r--mojo/shell/shell_test_base.h33
-rw-r--r--mojo/shell/shell_test_main.cc31
6 files changed, 163 insertions, 39 deletions
diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp
index 0d0c059..c991fa5 100644
--- a/mojo/mojo.gyp
+++ b/mojo/mojo.gyp
@@ -51,6 +51,7 @@
'mojo_service_manager_unittests',
'mojo_shell',
'mojo_shell_lib',
+ 'mojo_shell_tests',
'mojo_system',
'mojo_system_impl',
'mojo_system_unittests',
@@ -575,6 +576,29 @@
],
},
{
+ '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',
'type': 'executable',
'dependencies': [
diff --git a/mojo/shell/child_process_host_unittest.cc b/mojo/shell/child_process_host_unittest.cc
new file mode 100644
index 0000000..37f06c3
--- /dev/null
+++ b/mojo/shell/child_process_host_unittest.cc
@@ -0,0 +1,56 @@
+// 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
diff --git a/mojo/shell/desktop/mojo_main.cc b/mojo/shell/desktop/mojo_main.cc
index f2ef50a..ee58800 100644
--- a/mojo/shell/desktop/mojo_main.cc
+++ b/mojo/shell/desktop/mojo_main.cc
@@ -5,60 +5,21 @@
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/logging.h"
-#include "base/macros.h" // TODO(vtl): Remove.
#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/shell/child_process.h"
-#include "mojo/shell/child_process_host.h" // TODO(vtl): Remove.
#include "mojo/shell/context.h"
#include "mojo/shell/init.h"
#include "mojo/shell/run.h"
#include "mojo/shell/switches.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) {
base::AtExitManager at_exit;
mojo::Environment env;
base::CommandLine::Init(argc, argv);
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.
if (scoped_ptr<mojo::shell::ChildProcess> child_process =
mojo::shell::ChildProcess::Create(
diff --git a/mojo/shell/shell_test_base.cc b/mojo/shell/shell_test_base.cc
new file mode 100644
index 0000000..f258af4
--- /dev/null
+++ b/mojo/shell/shell_test_base.cc
@@ -0,0 +1,19 @@
+// 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
diff --git a/mojo/shell/shell_test_base.h b/mojo/shell/shell_test_base.h
new file mode 100644
index 0000000..afaf27c
--- /dev/null
+++ b/mojo/shell/shell_test_base.h
@@ -0,0 +1,33 @@
+// 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_
diff --git a/mojo/shell/shell_test_main.cc b/mojo/shell/shell_test_main.cc
new file mode 100644
index 0000000..7f057f7
--- /dev/null
+++ b/mojo/shell/shell_test_main.cc
@@ -0,0 +1,31 @@
+// 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)));
+}