blob: 9be0abcacfd908fb31358a0f8fc9a6d172176b5e [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001// 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.
4
James Robinsonb4b7af22014-12-05 11:21:01 -08005#include "shell/shell_test_base.h"
James Robinson646469d2014-10-03 15:33:28 -07006
Benjamin Lerman993869e2015-03-24 13:35:28 +01007#include "base/bind.h"
James Robinson646469d2014-10-03 15:33:28 -07008#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"
James Robinsonb4b7af22014-12-05 11:21:01 -080014#include "shell/filename_util.h"
James Robinson646469d2014-10-03 15:33:28 -070015#include "url/gurl.h"
16
James Robinson646469d2014-10-03 15:33:28 -070017namespace shell {
18namespace test {
19
Benjamin Lerman993869e2015-03-24 13:35:28 +010020namespace {
21
22void QuitIfRunning() {
23 if (base::MessageLoop::current() &&
24 base::MessageLoop::current()->is_running()) {
25 base::MessageLoop::current()->QuitWhenIdle();
26 }
27}
28
29} // namespace
30
James Robinson646469d2014-10-03 15:33:28 -070031ShellTestBase::ShellTestBase() {
32}
33
34ShellTestBase::~ShellTestBase() {
35}
36
37void ShellTestBase::SetUp() {
Viet-Trung Luu0ba64d62015-02-19 14:50:19 -080038 CHECK(shell_context_.Init());
Benjamin Lerman44228512015-01-28 17:20:41 +010039 SetUpTestApplications();
James Robinson646469d2014-10-03 15:33:28 -070040}
41
Viet-Trung Luu0ba64d62015-02-19 14:50:19 -080042void ShellTestBase::TearDown() {
43 shell_context_.Shutdown();
44}
45
Viet-Trung Luubd07e3a2015-04-09 12:43:29 -070046mojo::ScopedMessagePipeHandle ShellTestBase::ConnectToService(
James Robinson646469d2014-10-03 15:33:28 -070047 const GURL& application_url,
48 const std::string& service_name) {
Viet-Trung Luubd07e3a2015-04-09 12:43:29 -070049 mojo::ServiceProviderPtr services;
Benjamin Lerman993869e2015-03-24 13:35:28 +010050 shell_context_.application_manager()->ConnectToApplication(
Viet-Trung Luubd07e3a2015-04-09 12:43:29 -070051 application_url, GURL(), mojo::GetProxy(&services), nullptr,
Benjamin Lerman993869e2015-03-24 13:35:28 +010052 base::Bind(&QuitIfRunning));
Viet-Trung Luubd07e3a2015-04-09 12:43:29 -070053 mojo::MessagePipe pipe;
Benjamin Lerman993869e2015-03-24 13:35:28 +010054 services->ConnectToService(service_name, pipe.handle1.Pass());
55 return pipe.handle0.Pass();
Benjamin Lerman7d036f02014-12-23 10:39:19 +010056}
57
58#if !defined(OS_ANDROID)
59void ShellTestBase::SetUpTestApplications() {
Dave Moore2a897b02015-02-10 11:44:32 -080060 // Set the URLResolver origin to be the same as the base file path for
James Robinson646469d2014-10-03 15:33:28 -070061 // local files. This is primarily for test convenience, so that references
62 // to unknown mojo: urls that do not have specific local file or custom
63 // mappings registered on the URL resolver are treated as shared libraries.
64 base::FilePath service_dir;
65 CHECK(PathService::Get(base::DIR_MODULE, &service_dir));
Dave Moore2a897b02015-02-10 11:44:32 -080066 shell_context_.url_resolver()->SetMojoBaseURL(FilePathToFileURL(service_dir));
James Robinson646469d2014-10-03 15:33:28 -070067}
Benjamin Lerman7d036f02014-12-23 10:39:19 +010068#endif
James Robinson646469d2014-10-03 15:33:28 -070069
70} // namespace test
71} // namespace shell