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

Unified Diff: mojo/application/public/cpp/lib/application_test_base.cc

Issue 1565343003: Move mojo/application/public -> mojo/shell/public (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fetcher
Patch Set: . Created 4 years, 11 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/public/cpp/lib/application_test_base.cc
diff --git a/mojo/application/public/cpp/lib/application_test_base.cc b/mojo/application/public/cpp/lib/application_test_base.cc
deleted file mode 100644
index bd8df6dffdfae172d6f3d08fd73cb8c36cf36a78..0000000000000000000000000000000000000000
--- a/mojo/application/public/cpp/lib/application_test_base.cc
+++ /dev/null
@@ -1,158 +0,0 @@
-// 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 <utility>
-
-#include "base/command_line.h"
-#include "base/strings/utf_string_conversions.h"
-#include "mojo/application/public/cpp/application_impl.h"
-#include "mojo/application/public/cpp/application_test_base.h"
-#include "mojo/application/public/interfaces/application.mojom.h"
-#include "mojo/public/cpp/bindings/binding.h"
-#include "mojo/public/cpp/environment/environment.h"
-#include "mojo/public/cpp/system/message_pipe.h"
-
-namespace mojo {
-namespace test {
-
-namespace {
-// Share the application URL with multiple application tests.
-String g_url;
-
-// Application request handle passed from the shell in MojoMain, stored in
-// between SetUp()/TearDown() so we can (re-)intialize new ApplicationImpls.
-InterfaceRequest<Application> g_application_request;
-
-// Shell pointer passed in the initial mojo.Application.Initialize() call,
-// stored in between initial setup and the first test and between SetUp/TearDown
-// calls so we can (re-)initialize new ApplicationImpls.
-ShellPtr g_shell;
-
-class ShellGrabber : public Application {
- public:
- explicit ShellGrabber(InterfaceRequest<Application> application_request)
- : binding_(this, std::move(application_request)) {}
-
- void WaitForInitialize() {
- // Initialize is always the first call made on Application.
- MOJO_CHECK(binding_.WaitForIncomingMethodCall());
- }
-
- private:
- // Application implementation.
- void Initialize(ShellPtr shell, const mojo::String& url) override {
- g_url = url;
- g_application_request = binding_.Unbind();
- g_shell = std::move(shell);
- }
-
- void AcceptConnection(const String& requestor_url,
- InterfaceRequest<ServiceProvider> services,
- ServiceProviderPtr exposed_services,
- Array<String> allowed_interfaces,
- const String& url) override {
- MOJO_CHECK(false);
- }
-
- void OnQuitRequested(const Callback<void(bool)>& callback) override {
- MOJO_CHECK(false);
- }
-
- Binding<Application> binding_;
-};
-
-} // namespace
-
-MojoResult RunAllTests(MojoHandle application_request_handle) {
- {
- // This loop is used for init, and then destroyed before running tests.
- Environment::InstantiateDefaultRunLoop();
-
- // 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());
-
- int argc = 0;
- base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
- const char** argv = new const char* [cmd_line->argv().size() + 1];
-#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
- }
- argv[argc] = nullptr;
-
- testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0])));
-
- Environment::DestroyDefaultRunLoop();
- }
-
- int result = RUN_ALL_TESTS();
-
- // Shut down our message pipes before exiting.
- (void)g_application_request.PassMessagePipe();
- g_shell.reset();
-
- return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN;
-}
-
-ApplicationTestBase::ApplicationTestBase() : application_impl_(nullptr) {
-}
-
-ApplicationTestBase::~ApplicationTestBase() {
-}
-
-ApplicationDelegate* ApplicationTestBase::GetApplicationDelegate() {
- return &default_application_delegate_;
-}
-
-void ApplicationTestBase::SetUp() {
- // A run loop is recommended for ApplicationImpl initialization and
- // communication.
- if (ShouldCreateDefaultRunLoop())
- Environment::InstantiateDefaultRunLoop();
-
- MOJO_CHECK(g_application_request.is_pending());
- MOJO_CHECK(g_shell);
-
- // New applications are constructed for each test to avoid persisting state.
- application_impl_ = new ApplicationImpl(GetApplicationDelegate(),
- std::move(g_application_request));
-
- // Fake application initialization.
- Application* application = application_impl_;
- application->Initialize(std::move(g_shell), g_url);
-}
-
-void ApplicationTestBase::TearDown() {
- MOJO_CHECK(!g_application_request.is_pending());
- MOJO_CHECK(!g_shell);
-
- // TODO: commented out until http://crbug.com/533107 is solved.
- // {
- // ApplicationImpl::TestApi test_api(application_impl_);
- // test_api.UnbindConnections(&g_application_request, &g_shell);
- // }
- delete application_impl_;
- if (ShouldCreateDefaultRunLoop())
- Environment::DestroyDefaultRunLoop();
-}
-
-bool ApplicationTestBase::ShouldCreateDefaultRunLoop() {
- return true;
-}
-
-
-} // namespace test
-} // namespace mojo
« no previous file with comments | « mojo/application/public/cpp/lib/application_runner.cc ('k') | mojo/application/public/cpp/lib/application_test_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698