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 "shell/shell_test_base.h" | 5 #include "shell/shell_test_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 void QuitIfRunning() { | 22 void QuitIfRunning() { |
23 if (base::MessageLoop::current() && | 23 if (base::MessageLoop::current() && |
24 base::MessageLoop::current()->is_running()) { | 24 base::MessageLoop::current()->is_running()) { |
25 base::MessageLoop::current()->QuitWhenIdle(); | 25 base::MessageLoop::current()->QuitWhenIdle(); |
26 } | 26 } |
27 } | 27 } |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 ShellTestBase::ShellTestBase() { | 31 ShellTestBase::ShellTestBase() {} |
32 } | |
33 | 32 |
34 ShellTestBase::~ShellTestBase() { | 33 ShellTestBase::~ShellTestBase() {} |
35 } | |
36 | 34 |
37 void ShellTestBase::SetUp() { | 35 void ShellTestBase::SetUp() { |
38 CHECK(shell_context_.Init()); | 36 CHECK(shell_context_.Init()); |
39 SetUpTestApplications(); | 37 SetUpTestApplications(); |
40 } | 38 } |
41 | 39 |
42 void ShellTestBase::TearDown() { | 40 void ShellTestBase::TearDown() { |
43 shell_context_.Shutdown(); | 41 shell_context_.Shutdown(); |
44 } | 42 } |
45 | 43 |
46 mojo::ScopedMessagePipeHandle ShellTestBase::ConnectToService( | 44 mojo::ScopedMessagePipeHandle ShellTestBase::ConnectToService( |
47 const GURL& application_url, | 45 const GURL& application_url, |
48 const std::string& service_name) { | 46 const std::string& service_name) { |
49 mojo::ServiceProviderPtr services; | 47 mojo::ServiceProviderPtr services; |
50 shell_context_.application_manager()->ConnectToApplication( | 48 shell_context_.application_manager()->ConnectToApplication( |
51 application_url, GURL(), mojo::GetProxy(&services), nullptr, | 49 application_url, GURL(), mojo::GetProxy(&services), |
52 base::Bind(&QuitIfRunning)); | 50 base::Bind(&QuitIfRunning)); |
53 mojo::MessagePipe pipe; | 51 mojo::MessagePipe pipe; |
54 services->ConnectToService(service_name, pipe.handle1.Pass()); | 52 services->ConnectToService(service_name, pipe.handle1.Pass()); |
55 return pipe.handle0.Pass(); | 53 return pipe.handle0.Pass(); |
56 } | 54 } |
57 | 55 |
58 #if !defined(OS_ANDROID) | 56 #if !defined(OS_ANDROID) |
59 void ShellTestBase::SetUpTestApplications() { | 57 void ShellTestBase::SetUpTestApplications() { |
60 // Set the URLResolver origin to be the same as the base file path for | 58 // Set the URLResolver origin to be the same as the base file path for |
61 // local files. This is primarily for test convenience, so that references | 59 // 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 | 60 // 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. | 61 // mappings registered on the URL resolver are treated as shared libraries. |
64 base::FilePath service_dir; | 62 base::FilePath service_dir; |
65 CHECK(PathService::Get(base::DIR_MODULE, &service_dir)); | 63 CHECK(PathService::Get(base::DIR_MODULE, &service_dir)); |
66 shell_context_.url_resolver()->SetMojoBaseURL(FilePathToFileURL(service_dir)); | 64 shell_context_.url_resolver()->SetMojoBaseURL(FilePathToFileURL(service_dir)); |
67 } | 65 } |
68 #endif | 66 #endif |
69 | 67 |
70 } // namespace test | 68 } // namespace test |
71 } // namespace shell | 69 } // namespace shell |
OLD | NEW |