• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #include "mojo/shell/shell_test_base.h"
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 "base/path_service.h"
12 #include "build/build_config.h"
13 #include "mojo/shell/context.h"
14 #include "net/base/filename_util.h"
15 #include "url/gurl.h"
16 
17 namespace mojo {
18 namespace shell {
19 namespace test {
20 
ShellTestBase()21 ShellTestBase::ShellTestBase() {
22 }
23 
~ShellTestBase()24 ShellTestBase::~ShellTestBase() {
25 }
26 
InitMojo()27 void ShellTestBase::InitMojo() {
28   DCHECK(!message_loop_);
29   DCHECK(!shell_context_);
30   message_loop_.reset(new base::MessageLoop());
31   shell_context_.reset(new Context());
32 }
33 
LaunchServiceInProcess(const GURL & service_url,const std::string & service_name,ScopedMessagePipeHandle client_handle)34 void ShellTestBase::LaunchServiceInProcess(
35     const GURL& service_url,
36     const std::string& service_name,
37     ScopedMessagePipeHandle client_handle) {
38   DCHECK(message_loop_);
39   DCHECK(shell_context_);
40 
41   base::FilePath base_dir;
42   CHECK(PathService::Get(base::DIR_EXE, &base_dir));
43   // On android, the library is bundled with the app.
44 #if defined(OS_ANDROID)
45   base::FilePath service_dir;
46   CHECK(PathService::Get(base::DIR_MODULE, &service_dir));
47   // On Mac and Windows, libraries are dumped beside the executables.
48 #elif defined(OS_MACOSX) || defined(OS_WIN)
49   base::FilePath service_dir(base_dir);
50 #else
51   // On Linux, they're under lib/.
52   base::FilePath service_dir(base_dir.AppendASCII("lib"));
53 #endif
54   shell_context_->mojo_url_resolver()->set_origin(
55       net::FilePathToFileURL(service_dir).spec());
56 
57   shell_context_->service_manager()->ConnectToService(
58       service_url, service_name, client_handle.Pass(), GURL());
59 }
60 
61 }  // namespace test
62 }  // namespace shell
63 }  // namespace mojo
64