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" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "net/base/filename_util.h" | 13 #include "mojo/shell/filename_util.h" |
14 #include "net/test/embedded_test_server/embedded_test_server.h" | |
15 #include "url/gurl.h" | 14 #include "url/gurl.h" |
16 | 15 |
17 namespace mojo { | 16 namespace mojo { |
18 namespace shell { | 17 namespace shell { |
19 namespace test { | 18 namespace test { |
20 | 19 |
21 ShellTestBase::ShellTestBase() { | 20 ShellTestBase::ShellTestBase() { |
22 } | 21 } |
23 | 22 |
24 ShellTestBase::~ShellTestBase() { | 23 ShellTestBase::~ShellTestBase() { |
25 } | 24 } |
26 | 25 |
27 void ShellTestBase::SetUp() { | 26 void ShellTestBase::SetUp() { |
28 shell_context_.Init(); | 27 shell_context_.Init(); |
29 test_server_.reset(new net::test_server::EmbeddedTestServer()); | |
30 ASSERT_TRUE(test_server_->InitializeAndWaitUntilReady()); | |
31 base::FilePath service_dir; | 28 base::FilePath service_dir; |
32 CHECK(PathService::Get(base::DIR_MODULE, &service_dir)); | 29 CHECK(PathService::Get(base::DIR_MODULE, &service_dir)); |
33 test_server_->ServeFilesFromDirectory(service_dir); | |
34 } | 30 } |
35 | 31 |
36 ScopedMessagePipeHandle ShellTestBase::ConnectToService( | 32 ScopedMessagePipeHandle ShellTestBase::ConnectToService( |
37 const GURL& application_url, | 33 const GURL& application_url, |
38 const std::string& service_name) { | 34 const std::string& service_name) { |
39 // Set the MojoURLResolver origin to be the same as the base file path for | 35 // Set the MojoURLResolver origin to be the same as the base file path for |
40 // local files. This is primarily for test convenience, so that references | 36 // local files. This is primarily for test convenience, so that references |
41 // to unknown mojo: urls that do not have specific local file or custom | 37 // to unknown mojo: urls that do not have specific local file or custom |
42 // mappings registered on the URL resolver are treated as shared libraries. | 38 // mappings registered on the URL resolver are treated as shared libraries. |
43 base::FilePath service_dir; | 39 base::FilePath service_dir; |
44 CHECK(PathService::Get(base::DIR_MODULE, &service_dir)); | 40 CHECK(PathService::Get(base::DIR_MODULE, &service_dir)); |
45 shell_context_.mojo_url_resolver()->SetBaseURL( | 41 shell_context_.mojo_url_resolver()->SetBaseURL( |
46 net::FilePathToFileURL(service_dir)); | 42 FilePathToFileURL(service_dir)); |
47 | 43 |
48 return shell_context_.ConnectToServiceByName( | 44 return shell_context_.ConnectToServiceByName( |
49 application_url, service_name).Pass(); | 45 application_url, service_name).Pass(); |
50 } | 46 } |
51 | 47 |
52 ScopedMessagePipeHandle ShellTestBase::ConnectToServiceViaNetwork( | 48 ScopedMessagePipeHandle ShellTestBase::ConnectToServiceViaNetwork( |
53 const GURL& application_url, | 49 const GURL& application_url, |
54 const std::string& service_name) { | 50 const std::string& service_name) { |
55 shell_context_.mojo_url_resolver()->SetBaseURL( | |
56 test_server_->base_url()); | |
57 | |
58 return shell_context_.ConnectToServiceByName( | 51 return shell_context_.ConnectToServiceByName( |
59 application_url, service_name).Pass(); | 52 application_url, service_name).Pass(); |
60 } | 53 } |
61 | 54 |
62 } // namespace test | 55 } // namespace test |
63 } // namespace shell | 56 } // namespace shell |
64 } // namespace mojo | 57 } // namespace mojo |
OLD | NEW |