Remove obsolete entries from .gitignore.
[chromium-blink-merge.git] / mojo / runner / shell_test_base.cc
blob517a6910ceed94bf356b0b7d344538e7a52aa441
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mojo/runner/shell_test_base.h"
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h"
11 #include "base/logging.h"
12 #include "base/path_service.h"
13 #include "build/build_config.h"
14 #include "mojo/shell/capability_filter.h"
15 #include "mojo/util/filename_util.h"
16 #include "url/gurl.h"
18 namespace mojo {
19 namespace runner {
20 namespace test {
22 namespace {
24 void QuitIfRunning() {
25 if (base::MessageLoop::current() &&
26 base::MessageLoop::current()->is_running()) {
27 base::MessageLoop::current()->QuitWhenIdle();
31 } // namespace
33 ShellTestBase::ShellTestBase() : shell_context_(GetTestAppFilePath()) {}
35 ShellTestBase::~ShellTestBase() {
38 void ShellTestBase::SetUp() {
39 CHECK(shell_context_.Init());
42 void ShellTestBase::TearDown() {
43 shell_context_.Shutdown();
46 ScopedMessagePipeHandle ShellTestBase::ConnectToService(
47 const GURL& application_url,
48 const std::string& service_name) {
49 ServiceProviderPtr services;
50 mojo::URLRequestPtr request(mojo::URLRequest::New());
51 request->url = mojo::String::From(application_url.spec());
53 scoped_ptr<shell::ConnectToApplicationParams> params(
54 new shell::ConnectToApplicationParams);
55 params->SetURLInfo(request.Pass());
56 params->set_services(GetProxy(&services));
57 params->set_filter(shell::GetPermissiveCapabilityFilter());
58 params->set_on_application_end(base::Bind(&QuitIfRunning));
59 shell_context_.application_manager()->ConnectToApplication(params.Pass());
60 MessagePipe pipe;
61 services->ConnectToService(service_name, pipe.handle1.Pass());
62 return pipe.handle0.Pass();
65 #if !defined(OS_ANDROID)
66 base::FilePath ShellTestBase::GetTestAppFilePath() const {
67 base::FilePath shell_dir;
68 PathService::Get(base::DIR_MODULE, &shell_dir);
69 return shell_dir;
71 #endif
73 } // namespace test
74 } // namespace runner
75 } // namespace mojo