OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/shell/shell_test_base.h" | 5 #include "mojo/shell/shell_test_base.h" |
6 | 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" |
| 11 #include "build/build_config.h" |
| 12 #include "mojo/shell/context.h" |
| 13 #include "net/base/filename_util.h" |
| 14 #include "url/gurl.h" |
| 15 |
7 namespace mojo { | 16 namespace mojo { |
8 namespace shell { | 17 namespace shell { |
9 namespace test { | 18 namespace test { |
10 | 19 |
11 ShellTestBase::ShellTestBase() { | 20 ShellTestBase::ShellTestBase() { |
12 } | 21 } |
13 | 22 |
14 ShellTestBase::~ShellTestBase() { | 23 ShellTestBase::~ShellTestBase() { |
15 } | 24 } |
16 | 25 |
| 26 void ShellTestBase::InitMojo() { |
| 27 DCHECK(!message_loop_); |
| 28 DCHECK(!shell_context_); |
| 29 message_loop_.reset(new base::MessageLoop()); |
| 30 shell_context_.reset(new Context()); |
| 31 } |
| 32 |
| 33 void ShellTestBase::LaunchServiceInProcess( |
| 34 const GURL& service_url, |
| 35 const std::string& service_name, |
| 36 ScopedMessagePipeHandle client_handle) { |
| 37 DCHECK(message_loop_); |
| 38 DCHECK(shell_context_); |
| 39 |
| 40 base::FilePath base_dir = base::MakeAbsoluteFilePath( |
| 41 base::CommandLine::ForCurrentProcess()->GetProgram().DirName()); |
| 42 // On Mac and Windows, libraries are dumped beside the executables. |
| 43 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 44 base::FilePath service_dir(base_dir); |
| 45 #else |
| 46 // On Linux, they're under lib/. |
| 47 base::FilePath service_dir(base_dir.AppendASCII("lib")); |
| 48 #endif |
| 49 shell_context_->set_mojo_origin(net::FilePathToFileURL(service_dir).spec()); |
| 50 |
| 51 shell_context_->service_manager()->ConnectToService( |
| 52 service_url, service_name, client_handle.Pass(), GURL()); |
| 53 } |
| 54 |
17 } // namespace test | 55 } // namespace test |
18 } // namespace shell | 56 } // namespace shell |
19 } // namespace mojo | 57 } // namespace mojo |
OLD | NEW |