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"
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"
24 void QuitIfRunning() {
25 if (base::MessageLoop::current() &&
26 base::MessageLoop::current()->is_running()) {
27 base::MessageLoop::current()->QuitWhenIdle();
33 ShellTestBase::ShellTestBase() {
36 ShellTestBase::~ShellTestBase() {
39 void ShellTestBase::SetUp() {
40 CHECK(shell_context_
.Init());
41 SetUpTestApplications();
44 void ShellTestBase::TearDown() {
45 shell_context_
.Shutdown();
48 ScopedMessagePipeHandle
ShellTestBase::ConnectToService(
49 const GURL
& application_url
,
50 const std::string
& service_name
) {
51 ServiceProviderPtr services
;
52 mojo::URLRequestPtr
request(mojo::URLRequest::New());
53 request
->url
= mojo::String::From(application_url
.spec());
54 shell_context_
.application_manager()->ConnectToApplication(
55 nullptr, request
.Pass(), std::string(), GURL(), GetProxy(&services
),
56 nullptr, shell::GetPermissiveCapabilityFilter(),
57 base::Bind(&QuitIfRunning
));
59 services
->ConnectToService(service_name
, pipe
.handle1
.Pass());
60 return pipe
.handle0
.Pass();
63 #if !defined(OS_ANDROID)
64 void ShellTestBase::SetUpTestApplications() {
65 // Set the URLResolver origin to be the same as the base file path for
66 // local files. This is primarily for test convenience, so that references
67 // to unknown mojo: URLs that do not have specific local file or custom
68 // mappings registered on the URL resolver are treated as shared libraries.
69 base::FilePath service_dir
;
70 CHECK(PathService::Get(base::DIR_MODULE
, &service_dir
));
71 shell_context_
.url_resolver()->SetMojoBaseURL(
72 util::FilePathToFileURL(service_dir
));