Add Mojo application test support to Chromium.
Needed to support Chromium Mojo application tests: For example: https://codereview.chromium.org/709923003 The Mojo CL: https://codereview.chromium.org/695593002 (env changes support the cross-repo ApplicationTestBase) TODO: Add GYP versions of GN apptest support targets. BUG=392646 TEST=mojo/application:test_support builds with GN. R=jamesr@chromium.org Review URL: https://codereview.chromium.org/710403002 Cr-Commit-Position: refs/heads/master@{#303779}
This commit is contained in:
@ -18,3 +18,11 @@ source_set("application") {
|
||||
"//mojo/environment:chromium",
|
||||
]
|
||||
}
|
||||
|
||||
source_set("test_support") {
|
||||
testonly = true
|
||||
sources = [ "application_test_main_chromium.cc" ]
|
||||
|
||||
public_deps = [ "//mojo/public/cpp/application:test_support" ]
|
||||
deps = [ "//base" ]
|
||||
}
|
||||
|
51
mojo/application/application_test_main_chromium.cc
Normal file
51
mojo/application/application_test_main_chromium.cc
Normal file
@ -0,0 +1,51 @@
|
||||
// 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/at_exit.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
#include "mojo/public/c/system/main.h"
|
||||
#include "mojo/public/cpp/application/application_delegate.h"
|
||||
#include "mojo/public/cpp/application/application_impl.h"
|
||||
#include "mojo/public/cpp/application/application_test_base.h"
|
||||
#include "mojo/public/cpp/system/message_pipe.h"
|
||||
|
||||
MojoResult MojoMain(MojoHandle shell_handle) {
|
||||
// An AtExitManager instance is needed to construct message loops.
|
||||
base::AtExitManager at_exit;
|
||||
|
||||
{
|
||||
// This loop is used for init, and then destroyed before running tests.
|
||||
base::MessageLoop message_loop;
|
||||
|
||||
// Construct an ApplicationImpl just for the GTEST commandline arguments.
|
||||
// GTEST command line arguments are supported amid application arguments:
|
||||
// $ mojo_shell 'mojo:example_apptests arg1 --gtest_filter=foo arg2'
|
||||
mojo::ApplicationDelegate dummy_application_delegate;
|
||||
mojo::ApplicationImpl app(&dummy_application_delegate, shell_handle);
|
||||
CHECK(app.WaitForInitialize());
|
||||
|
||||
// InitGoogleTest expects (argc + 1) elements, including a terminating NULL.
|
||||
// It also removes GTEST arguments from |argv| and updates the |argc| count.
|
||||
// TODO(msw): Provide tests access to these actual command line arguments.
|
||||
const std::vector<std::string>& args = app.args();
|
||||
CHECK_LT(args.size(), static_cast<size_t>(std::numeric_limits<int>::max()));
|
||||
int argc = static_cast<int>(args.size());
|
||||
std::vector<const char*> argv(argc + 1);
|
||||
for (int i = 0; i < argc; ++i)
|
||||
argv[i] = args[i].c_str();
|
||||
argv[argc] = nullptr;
|
||||
|
||||
testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0])));
|
||||
mojo::test::SetShellHandle(app.UnbindShell());
|
||||
}
|
||||
|
||||
int result = RUN_ALL_TESTS();
|
||||
|
||||
shell_handle = mojo::test::PassShellHandle().release().value();
|
||||
MojoResult close_result = MojoClose(shell_handle);
|
||||
CHECK_EQ(close_result, MOJO_RESULT_OK);
|
||||
|
||||
return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN;
|
||||
}
|
@ -28,6 +28,8 @@ component("chromium_impl") {
|
||||
"default_async_waiter_impl.h",
|
||||
"default_logger_impl.cc",
|
||||
"default_logger_impl.h",
|
||||
"default_run_loop_impl.cc",
|
||||
"default_run_loop_impl.h",
|
||||
]
|
||||
|
||||
defines = [
|
||||
|
23
mojo/environment/default_run_loop_impl.cc
Normal file
23
mojo/environment/default_run_loop_impl.cc
Normal file
@ -0,0 +1,23 @@
|
||||
// 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/environment/default_run_loop_impl.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/message_loop/message_loop.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace internal {
|
||||
|
||||
void InstantiateDefaultRunLoopImpl() {
|
||||
// Not leaked: accessible from |base::MessageLoop::current()|.
|
||||
new base::MessageLoop();
|
||||
}
|
||||
|
||||
void DestroyDefaultRunLoopImpl() {
|
||||
delete base::MessageLoop::current();
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace mojo
|
19
mojo/environment/default_run_loop_impl.h
Normal file
19
mojo/environment/default_run_loop_impl.h
Normal file
@ -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.
|
||||
|
||||
#ifndef MOJO_ENVIRONMENT_DEFAULT_RUN_LOOP_IMPL_H_
|
||||
#define MOJO_ENVIRONMENT_DEFAULT_RUN_LOOP_IMPL_H_
|
||||
|
||||
#include "mojo/environment/mojo_environment_impl_export.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace internal {
|
||||
|
||||
MOJO_ENVIRONMENT_IMPL_EXPORT void InstantiateDefaultRunLoopImpl();
|
||||
MOJO_ENVIRONMENT_IMPL_EXPORT void DestroyDefaultRunLoopImpl();
|
||||
|
||||
} // namespace internal
|
||||
} // namespace mojo
|
||||
|
||||
#endif // MOJO_ENVIRONMENT_DEFAULT_RUN_LOOP_IMPL_H_
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "mojo/environment/default_async_waiter_impl.h"
|
||||
#include "mojo/environment/default_logger_impl.h"
|
||||
#include "mojo/environment/default_run_loop_impl.h"
|
||||
|
||||
namespace mojo {
|
||||
|
||||
@ -33,4 +34,14 @@ const MojoLogger* Environment::GetDefaultLogger() {
|
||||
return internal::GetDefaultLoggerImpl();
|
||||
}
|
||||
|
||||
// static
|
||||
void Environment::InstantiateDefaultRunLoop() {
|
||||
internal::InstantiateDefaultRunLoopImpl();
|
||||
}
|
||||
|
||||
// static
|
||||
void Environment::DestroyDefaultRunLoop() {
|
||||
internal::DestroyDefaultRunLoopImpl();
|
||||
}
|
||||
|
||||
} // namespace mojo
|
||||
|
@ -133,6 +133,8 @@
|
||||
'environment/default_async_waiter_impl.h',
|
||||
'environment/default_logger_impl.cc',
|
||||
'environment/default_logger_impl.h',
|
||||
'environment/default_run_loop_impl.cc',
|
||||
'environment/default_run_loop_impl.h',
|
||||
],
|
||||
'include_dirs': [
|
||||
'..',
|
||||
|
Reference in New Issue
Block a user