Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Unified Diff: mojo/application/application_test_base_chromium.cc

Issue 1057603003: Simplify mojo_shell since it's now only used for Mandoline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update scripts Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/application/application_test_base_chromium.cc
diff --git a/third_party/mojo/src/mojo/public/cpp/application/lib/application_test_base.cc b/mojo/application/application_test_base_chromium.cc
similarity index 68%
copy from third_party/mojo/src/mojo/public/cpp/application/lib/application_test_base.cc
copy to mojo/application/application_test_base_chromium.cc
index af6e13a29110eccb58b688b4efa0e799e85612d5..4d74f4f27aaa3867aacbf412b8932829a37dee1d 100644
--- a/third_party/mojo/src/mojo/public/cpp/application/lib/application_test_base.cc
+++ b/mojo/application/application_test_base_chromium.cc
@@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "mojo/public/cpp/application/application_test_base.h"
+#include "mojo/application/application_test_base_chromium.h"
+#include "base/command_line.h"
+#include "base/strings/utf_string_conversions.h"
#include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/environment/environment.h"
@@ -14,9 +16,6 @@ namespace mojo {
namespace test {
namespace {
-// Share the application command-line arguments with multiple application tests.
-Array<String> g_args;
-
// Share the application URL with multiple application tests.
String g_url;
@@ -29,19 +28,10 @@ InterfaceRequest<Application> g_application_request;
// calls so we can (re-)initialize new ApplicationImpls.
ShellPtr g_shell;
-void InitializeArgs(int argc, std::vector<const char*> argv) {
- MOJO_CHECK(g_args.is_null());
- for (const char* arg : argv) {
- if (arg)
- g_args.push_back(arg);
- }
-}
-
-class ShellAndArgumentGrabber : public Application {
+class ShellGrabber : public Application {
public:
- ShellAndArgumentGrabber(Array<String>* args,
- InterfaceRequest<Application> application_request)
- : args_(args), binding_(this, application_request.Pass()) {}
+ explicit ShellGrabber(InterfaceRequest<Application> application_request)
+ : binding_(this, application_request.Pass()) {}
void WaitForInitialize() {
// Initialize is always the first call made on Application.
@@ -53,7 +43,6 @@ class ShellAndArgumentGrabber : public Application {
void Initialize(ShellPtr shell,
Array<String> args,
const mojo::String& url) override {
- *args_ = args.Pass();
g_url = url;
g_application_request = binding_.Unbind();
g_shell = shell.Pass();
@@ -68,45 +57,40 @@ class ShellAndArgumentGrabber : public Application {
void RequestQuit() override { MOJO_CHECK(false); }
- Array<String>* args_;
Binding<Application> binding_;
};
} // namespace
-const Array<String>& Args() {
- return g_args;
-}
-
MojoResult RunAllTests(MojoHandle application_request_handle) {
{
// This loop is used for init, and then destroyed before running tests.
Environment::InstantiateDefaultRunLoop();
- // Grab the shell handle and GTEST commandline arguments.
- // GTEST command line arguments are supported amid application arguments:
- // $ mojo_shell mojo:example_apptests
- // --args-for='mojo:example_apptests arg1 --gtest_filter=foo arg2'
- Array<String> args;
- ShellAndArgumentGrabber grabber(
- &args, MakeRequest<Application>(MakeScopedHandle(
- MessagePipeHandle(application_request_handle))));
+ // Grab the shell handle.
+ ShellGrabber grabber(
+ MakeRequest<Application>(MakeScopedHandle(
+ MessagePipeHandle(application_request_handle))));
grabber.WaitForInitialize();
MOJO_CHECK(g_shell);
MOJO_CHECK(g_application_request.is_pending());
- // InitGoogleTest expects (argc + 1) elements, including a terminating null.
- // It also removes GTEST arguments from |argv| and updates the |argc| count.
- MOJO_CHECK(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].get().c_str();
- argv[argc] = nullptr;
+ int argc = 0;
+ base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
+ const char** argv = new const char* [cmd_line->argv().size()];
+#if defined(OS_WIN)
+ std::vector<std::string> local_strings;
+#endif
+ for (auto& arg : cmd_line->argv()) {
+#if defined(OS_WIN)
+ local_strings.push_back(base::WideToUTF8(arg));
+ argv[argc++] = local_strings.back().c_str();
+#else
+ argv[argc++] = arg.c_str();
+#endif
+ }
testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0])));
- InitializeArgs(argc, argv);
Environment::DestroyDefaultRunLoop();
}
@@ -144,7 +128,8 @@ void ApplicationTestBase::SetUp() {
g_application_request.Pass());
// Fake application initialization with the given command line arguments.
- application_impl_->Initialize(g_shell.Pass(), g_args.Clone(), g_url);
+ Array<String> empty_args;
+ application_impl_->Initialize(g_shell.Pass(), empty_args.Clone(), g_url);
}
void ApplicationTestBase::TearDown() {
« no previous file with comments | « mojo/application/application_test_base_chromium.h ('k') | mojo/application/application_test_main_chromium.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698