James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 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. |
| 4 | |
James Robinson | b4b7af2 | 2014-12-05 11:21:01 -0800 | [diff] [blame] | 5 | #include "shell/shell_test_base.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 6 | |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 7 | #include "base/bind.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 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" |
James Robinson | b4b7af2 | 2014-12-05 11:21:01 -0800 | [diff] [blame] | 14 | #include "shell/filename_util.h" |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 15 | #include "url/gurl.h" |
| 16 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 17 | namespace shell { |
| 18 | namespace test { |
| 19 | |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 20 | namespace { |
| 21 | |
| 22 | void QuitIfRunning() { |
| 23 | if (base::MessageLoop::current() && |
| 24 | base::MessageLoop::current()->is_running()) { |
| 25 | base::MessageLoop::current()->QuitWhenIdle(); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | } // namespace |
| 30 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 31 | ShellTestBase::ShellTestBase() { |
| 32 | } |
| 33 | |
| 34 | ShellTestBase::~ShellTestBase() { |
| 35 | } |
| 36 | |
| 37 | void ShellTestBase::SetUp() { |
Viet-Trung Luu | 0ba64d6 | 2015-02-19 14:50:19 -0800 | [diff] [blame] | 38 | CHECK(shell_context_.Init()); |
Benjamin Lerman | 4422851 | 2015-01-28 17:20:41 +0100 | [diff] [blame] | 39 | SetUpTestApplications(); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Viet-Trung Luu | 0ba64d6 | 2015-02-19 14:50:19 -0800 | [diff] [blame] | 42 | void ShellTestBase::TearDown() { |
| 43 | shell_context_.Shutdown(); |
| 44 | } |
| 45 | |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 46 | mojo::ScopedMessagePipeHandle ShellTestBase::ConnectToService( |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 47 | const GURL& application_url, |
| 48 | const std::string& service_name) { |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 49 | mojo::ServiceProviderPtr services; |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 50 | shell_context_.application_manager()->ConnectToApplication( |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 51 | application_url, GURL(), mojo::GetProxy(&services), nullptr, |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 52 | base::Bind(&QuitIfRunning)); |
Viet-Trung Luu | bd07e3a | 2015-04-09 12:43:29 -0700 | [diff] [blame] | 53 | mojo::MessagePipe pipe; |
Benjamin Lerman | 993869e | 2015-03-24 13:35:28 +0100 | [diff] [blame] | 54 | services->ConnectToService(service_name, pipe.handle1.Pass()); |
| 55 | return pipe.handle0.Pass(); |
Benjamin Lerman | 7d036f0 | 2014-12-23 10:39:19 +0100 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | #if !defined(OS_ANDROID) |
| 59 | void ShellTestBase::SetUpTestApplications() { |
Dave Moore | 2a897b0 | 2015-02-10 11:44:32 -0800 | [diff] [blame] | 60 | // Set the URLResolver origin to be the same as the base file path for |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 61 | // 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 Moore | 2a897b0 | 2015-02-10 11:44:32 -0800 | [diff] [blame] | 66 | shell_context_.url_resolver()->SetMojoBaseURL(FilePathToFileURL(service_dir)); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 67 | } |
Benjamin Lerman | 7d036f0 | 2014-12-23 10:39:19 +0100 | [diff] [blame] | 68 | #endif |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 69 | |
| 70 | } // namespace test |
| 71 | } // namespace shell |