summaryrefslogtreecommitdiffstats
path: root/mojo/common
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-08 22:58:37 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-08 22:58:37 +0000
commit3bc1379a4b6868206964e646f03e867a279cc454 (patch)
treece78f896e1f8d7d0f4debad576152122bd156b6c /mojo/common
parent3e9d30eea530bb866325f2c94ebcc353e1c5ed39 (diff)
downloadchromium_src-3bc1379a4b6868206964e646f03e867a279cc454.zip
chromium_src-3bc1379a4b6868206964e646f03e867a279cc454.tar.gz
chromium_src-3bc1379a4b6868206964e646f03e867a279cc454.tar.bz2
Mojo: MultiprocessTestBase -> MultiprocessTestHelper.
Because inheritance sucks. R=sky@chromium.org Review URL: https://codereview.chromium.org/190943003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255798 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/common')
-rw-r--r--mojo/common/test/multiprocess_test_helper.cc (renamed from mojo/common/test/multiprocess_test_base.cc)51
-rw-r--r--mojo/common/test/multiprocess_test_helper.h (renamed from mojo/common/test/multiprocess_test_base.h)27
-rw-r--r--mojo/common/test/multiprocess_test_helper_unittest.cc (renamed from mojo/common/test/multiprocess_test_base_unittest.cc)38
3 files changed, 44 insertions, 72 deletions
diff --git a/mojo/common/test/multiprocess_test_base.cc b/mojo/common/test/multiprocess_test_helper.cc
index 028990e..c3ae63d 100644
--- a/mojo/common/test/multiprocess_test_base.cc
+++ b/mojo/common/test/multiprocess_test_helper.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "mojo/common/test/multiprocess_test_base.h"
+#include "mojo/common/test/multiprocess_test_helper.h"
#include "base/command_line.h"
#include "base/logging.h"
@@ -14,43 +14,29 @@
namespace mojo {
namespace test {
-MultiprocessTestBase::MultiprocessTestBase()
+MultiprocessTestHelper::MultiprocessTestHelper()
: test_child_handle_(base::kNullProcessHandle) {
-}
-
-MultiprocessTestBase::~MultiprocessTestBase() {
- CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
-}
-
-void MultiprocessTestBase::SetUp() {
- CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
-
- MultiProcessTest::SetUp();
-
platform_channel_pair_.reset(new embedder::PlatformChannelPair());
server_platform_handle = platform_channel_pair_->PassServerHandle();
}
-void MultiprocessTestBase::TearDown() {
+MultiprocessTestHelper::~MultiprocessTestHelper() {
CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
-
server_platform_handle.reset();
platform_channel_pair_.reset();
-
- MultiProcessTest::TearDown();
}
-void MultiprocessTestBase::StartChild(const std::string& test_child_name) {
+void MultiprocessTestHelper::StartChild(const std::string& test_child_name) {
CHECK(platform_channel_pair_.get());
CHECK(!test_child_name.empty());
CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
std::string test_child_main = test_child_name + "TestChildMain";
- CommandLine unused(CommandLine::NO_PROGRAM);
+ CommandLine command_line(base::GetMultiProcessTestChildBaseCommandLine());
embedder::HandlePassingInformation handle_passing_info;
platform_channel_pair_->PrepareToPassClientHandleToChildProcess(
- &unused, &handle_passing_info);
+ &command_line, &handle_passing_info);
base::LaunchOptions options;
#if defined(OS_POSIX)
@@ -62,39 +48,26 @@ void MultiprocessTestBase::StartChild(const std::string& test_child_name) {
#error "Not supported yet."
#endif
- test_child_handle_ = SpawnChildWithOptions(test_child_main, options, false);
+ test_child_handle_ = base::SpawnMultiProcessTestChild(
+ test_child_main, command_line, options, false);
platform_channel_pair_->ChildProcessLaunched();
CHECK_NE(test_child_handle_, base::kNullProcessHandle);
}
-int MultiprocessTestBase::WaitForChildShutdown() {
+int MultiprocessTestHelper::WaitForChildShutdown() {
CHECK_NE(test_child_handle_, base::kNullProcessHandle);
- static const int kTimeoutSeconds = 5;
int rv = -1;
CHECK(base::WaitForExitCodeWithTimeout(
- test_child_handle_, &rv, base::TimeDelta::FromSeconds(kTimeoutSeconds)));
+ test_child_handle_, &rv, TestTimeouts::action_timeout()));
base::CloseProcessHandle(test_child_handle_);
test_child_handle_ = base::kNullProcessHandle;
return rv;
}
-CommandLine MultiprocessTestBase::MakeCmdLine(const std::string& procname,
- bool debug_on_start) {
- CHECK(platform_channel_pair_.get());
-
- CommandLine command_line =
- base::MultiProcessTest::MakeCmdLine(procname, debug_on_start);
- embedder::HandlePassingInformation unused;
- platform_channel_pair_->PrepareToPassClientHandleToChildProcess(&command_line,
- &unused);
-
- return command_line;
-}
-
// static
-void MultiprocessTestBase::ChildSetup() {
+void MultiprocessTestHelper::ChildSetup() {
CHECK(CommandLine::InitializedForCurrentProcess());
client_platform_handle =
embedder::PlatformChannelPair::PassClientHandleFromParentProcess(
@@ -102,7 +75,7 @@ void MultiprocessTestBase::ChildSetup() {
}
// static
-embedder::ScopedPlatformHandle MultiprocessTestBase::client_platform_handle;
+embedder::ScopedPlatformHandle MultiprocessTestHelper::client_platform_handle;
} // namespace test
} // namespace mojo
diff --git a/mojo/common/test/multiprocess_test_base.h b/mojo/common/test/multiprocess_test_helper.h
index 5e68fe1..103dcf4 100644
--- a/mojo/common/test/multiprocess_test_base.h
+++ b/mojo/common/test/multiprocess_test_helper.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef MOJO_COMMON_TEST_MULTIPROCESS_TEST_BASE_H_
-#define MOJO_COMMON_TEST_MULTIPROCESS_TEST_BASE_H_
+#ifndef MOJO_COMMON_TEST_MULTIPROCESS_TEST_HELPER_H_
+#define MOJO_COMMON_TEST_MULTIPROCESS_TEST_HELPER_H_
#include <string>
@@ -11,6 +11,7 @@
#include "base/compiler_specific.h"
#include "base/process/process_handle.h"
#include "base/test/multiprocess_test.h"
+#include "base/test/test_timeouts.h"
#include "mojo/system/embedder/scoped_platform_handle.h"
#include "testing/multiprocess_func_list.h"
@@ -22,13 +23,10 @@ class PlatformChannelPair;
namespace test {
-class MultiprocessTestBase : public base::MultiProcessTest {
+class MultiprocessTestHelper {
public:
- MultiprocessTestBase();
- virtual ~MultiprocessTestBase();
-
- virtual void SetUp() OVERRIDE;
- virtual void TearDown() OVERRIDE;
+ MultiprocessTestHelper();
+ ~MultiprocessTestHelper();
// Start a child process and run the "main" function "named" |test_child_name|
// declared using |MOJO_MULTIPROCESS_TEST_CHILD_MAIN()| (below).
@@ -51,26 +49,23 @@ class MultiprocessTestBase : public base::MultiProcessTest {
static embedder::ScopedPlatformHandle client_platform_handle;
private:
- virtual CommandLine MakeCmdLine(const std::string& procname,
- bool debug_on_start) OVERRIDE;
-
scoped_ptr<embedder::PlatformChannelPair> platform_channel_pair_;
// Valid after |StartChild()| and before |WaitForChildShutdown()|.
base::ProcessHandle test_child_handle_;
- DISALLOW_COPY_AND_ASSIGN(MultiprocessTestBase);
+ DISALLOW_COPY_AND_ASSIGN(MultiprocessTestHelper);
};
// Use this to declare the child process's "main()" function for tests using
-// |MultiprocessTestBase|. It returns an |int|, which will be the process's exit
-// code (but see the comment about |WaitForChildShutdown()|).
+// |MultiprocessTestHelper|. It returns an |int|, which will be the process's
+// exit code (but see the comment about |WaitForChildShutdown()|).
#define MOJO_MULTIPROCESS_TEST_CHILD_MAIN(test_child_name) \
MULTIPROCESS_TEST_MAIN_WITH_SETUP( \
test_child_name ## TestChildMain, \
- ::mojo::test::MultiprocessTestBase::ChildSetup)
+ ::mojo::test::MultiprocessTestHelper::ChildSetup)
} // namespace test
} // namespace mojo
-#endif // MOJO_COMMON_TEST_MULTIPROCESS_TEST_BASE_H_
+#endif // MOJO_COMMON_TEST_MULTIPROCESS_TEST_HELPER_H_
diff --git a/mojo/common/test/multiprocess_test_base_unittest.cc b/mojo/common/test/multiprocess_test_helper_unittest.cc
index 659b83d..a61ac22 100644
--- a/mojo/common/test/multiprocess_test_base_unittest.cc
+++ b/mojo/common/test/multiprocess_test_helper_unittest.cc
@@ -2,12 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "mojo/common/test/multiprocess_test_base.h"
+#include "mojo/common/test/multiprocess_test_helper.h"
#include "base/logging.h"
#include "build/build_config.h"
#include "mojo/common/test/test_utils.h"
#include "mojo/system/embedder/scoped_platform_handle.h"
+#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_POSIX)
#include <fcntl.h>
@@ -55,41 +56,44 @@ bool ReadByte(const embedder::PlatformHandle& handle, char* c) {
return bytes_read == 1;
}
-typedef MultiprocessTestBase MultiprocessTestBaseTest;
+typedef testing::Test MultiprocessTestHelperTest;
-TEST_F(MultiprocessTestBaseTest, RunChild) {
+TEST_F(MultiprocessTestHelperTest, RunChild) {
if (SkipTest())
return;
- EXPECT_TRUE(server_platform_handle.is_valid());
+ MultiprocessTestHelper helper;
+ EXPECT_TRUE(helper.server_platform_handle.is_valid());
- StartChild("RunChild");
- EXPECT_EQ(123, WaitForChildShutdown());
+ helper.StartChild("RunChild");
+ EXPECT_EQ(123, helper.WaitForChildShutdown());
}
MOJO_MULTIPROCESS_TEST_CHILD_MAIN(RunChild) {
- CHECK(MultiprocessTestBaseTest::client_platform_handle.is_valid());
+ CHECK(MultiprocessTestHelper::client_platform_handle.is_valid());
return 123;
}
-TEST_F(MultiprocessTestBaseTest, TestChildMainNotFound) {
+TEST_F(MultiprocessTestHelperTest, TestChildMainNotFound) {
if (SkipTest())
return;
- StartChild("NoSuchTestChildMain");
- int result = WaitForChildShutdown();
+ MultiprocessTestHelper helper;
+ helper.StartChild("NoSuchTestChildMain");
+ int result = helper.WaitForChildShutdown();
EXPECT_FALSE(result >= 0 && result <= 127);
}
-TEST_F(MultiprocessTestBaseTest, PassedChannel) {
+TEST_F(MultiprocessTestHelperTest, PassedChannel) {
if (SkipTest())
return;
- EXPECT_TRUE(server_platform_handle.is_valid());
- StartChild("PassedChannel");
+ MultiprocessTestHelper helper;
+ EXPECT_TRUE(helper.server_platform_handle.is_valid());
+ helper.StartChild("PassedChannel");
// Take ownership of the handle.
- embedder::ScopedPlatformHandle handle = server_platform_handle.Pass();
+ embedder::ScopedPlatformHandle handle = helper.server_platform_handle.Pass();
// The handle should be non-blocking.
EXPECT_TRUE(IsNonBlocking(handle.get()));
@@ -104,15 +108,15 @@ TEST_F(MultiprocessTestBaseTest, PassedChannel) {
EXPECT_EQ(c + 1, d);
// And return it, incremented again.
- EXPECT_EQ(c + 2, WaitForChildShutdown());
+ EXPECT_EQ(c + 2, helper.WaitForChildShutdown());
}
MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PassedChannel) {
- CHECK(MultiprocessTestBaseTest::client_platform_handle.is_valid());
+ CHECK(MultiprocessTestHelper::client_platform_handle.is_valid());
// Take ownership of the handle.
embedder::ScopedPlatformHandle handle =
- MultiprocessTestBaseTest::client_platform_handle.Pass();
+ MultiprocessTestHelper::client_platform_handle.Pass();
// The handle should be non-blocking.
EXPECT_TRUE(IsNonBlocking(handle.get()));