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 "services/service_manager/runner/host/service_process_launcher.h" | 5 #include "services/service_manager/runner/host/service_process_launcher.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/threading/thread.h" |
| 19 #include "mojo/edk/embedder/embedder.h" |
| 20 #include "mojo/edk/embedder/scoped_ipc_support.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
19 | 22 |
20 namespace service_manager { | 23 namespace service_manager { |
21 namespace { | 24 namespace { |
22 | 25 |
23 const char kTestServiceName[] = "host_test_service"; | 26 const char kTestServiceName[] = "host_test_service"; |
24 | 27 |
| 28 const base::FilePath::CharType kPackagesPath[] = FILE_PATH_LITERAL("Packages"); |
| 29 |
25 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
26 const base::FilePath::CharType kServiceExtension[] = | 31 const base::FilePath::CharType kServiceExtension[] = |
27 FILE_PATH_LITERAL(".service.exe"); | 32 FILE_PATH_LITERAL(".service.exe"); |
28 #else | 33 #else |
29 const base::FilePath::CharType kServiceExtension[] = | 34 const base::FilePath::CharType kServiceExtension[] = |
30 FILE_PATH_LITERAL(".service"); | 35 FILE_PATH_LITERAL(".service"); |
31 #endif | 36 #endif |
32 | 37 |
33 void ProcessReadyCallbackAdapater(const base::Closure& callback, | 38 void ProcessReadyCallbackAdapater(const base::Closure& callback, |
34 base::ProcessId process_id) { | 39 base::ProcessId process_id) { |
(...skipping 24 matching lines...) Expand all Loading... |
59 | 64 |
60 DISALLOW_COPY_AND_ASSIGN(ServiceProcessLauncherDelegateImpl); | 65 DISALLOW_COPY_AND_ASSIGN(ServiceProcessLauncherDelegateImpl); |
61 }; | 66 }; |
62 | 67 |
63 #if defined(OS_ANDROID) | 68 #if defined(OS_ANDROID) |
64 // TODO(qsr): Multiprocess service manager tests are not supported on android. | 69 // TODO(qsr): Multiprocess service manager tests are not supported on android. |
65 #define MAYBE_StartJoin DISABLED_StartJoin | 70 #define MAYBE_StartJoin DISABLED_StartJoin |
66 #else | 71 #else |
67 #define MAYBE_StartJoin StartJoin | 72 #define MAYBE_StartJoin StartJoin |
68 #endif // defined(OS_ANDROID) | 73 #endif // defined(OS_ANDROID) |
69 TEST(ServiceProcessLauncherTest, MAYBE_StartJoin) { | 74 TEST(ServieProcessLauncherTest, MAYBE_StartJoin) { |
70 base::FilePath service_manager_dir; | 75 base::FilePath service_manager_dir; |
71 PathService::Get(base::DIR_MODULE, &service_manager_dir); | 76 PathService::Get(base::DIR_MODULE, &service_manager_dir); |
72 base::MessageLoop message_loop; | 77 base::MessageLoop message_loop; |
73 scoped_refptr<base::SequencedWorkerPool> blocking_pool( | 78 scoped_refptr<base::SequencedWorkerPool> blocking_pool( |
74 new base::SequencedWorkerPool(3, "blocking_pool", | 79 new base::SequencedWorkerPool(3, "blocking_pool", |
75 base::TaskPriority::USER_VISIBLE)); | 80 base::TaskPriority::USER_VISIBLE)); |
76 | 81 |
77 base::FilePath test_service_path; | 82 base::Thread io_thread("io_thread"); |
78 base::PathService::Get(base::DIR_EXE, &test_service_path); | 83 base::Thread::Options options; |
79 test_service_path = test_service_path.AppendASCII(kTestServiceName) | 84 options.message_loop_type = base::MessageLoop::TYPE_IO; |
80 .AddExtension(kServiceExtension); | 85 io_thread.StartWithOptions(options); |
| 86 |
| 87 auto ipc_support = base::MakeUnique<mojo::edk::ScopedIPCSupport>( |
| 88 io_thread.task_runner(), |
| 89 mojo::edk::ScopedIPCSupport::ShutdownPolicy::CLEAN); |
| 90 |
| 91 base::FilePath test_service_path = |
| 92 base::FilePath(kPackagesPath).AppendASCII(kTestServiceName) |
| 93 .AppendASCII(kTestServiceName) .AddExtension(kServiceExtension); |
81 | 94 |
82 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate; | 95 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate; |
83 ServiceProcessLauncher launcher(blocking_pool.get(), | 96 ServiceProcessLauncher launcher(blocking_pool.get(), |
84 &service_process_launcher_delegate, | 97 &service_process_launcher_delegate, |
85 test_service_path); | 98 test_service_path); |
86 base::RunLoop run_loop; | 99 base::RunLoop run_loop; |
87 launcher.Start( | 100 launcher.Start( |
88 Identity(), | 101 Identity(), |
89 false, | 102 false, |
90 base::Bind(&ProcessReadyCallbackAdapater, run_loop.QuitClosure())); | 103 base::Bind(&ProcessReadyCallbackAdapater, run_loop.QuitClosure())); |
91 run_loop.Run(); | 104 run_loop.Run(); |
92 | 105 |
93 launcher.Join(); | 106 launcher.Join(); |
94 blocking_pool->Shutdown(); | 107 blocking_pool->Shutdown(); |
| 108 ipc_support.reset(); |
95 | 109 |
96 EXPECT_EQ(1u, service_process_launcher_delegate.get_and_clear_adjust_count()); | 110 EXPECT_EQ(1u, service_process_launcher_delegate.get_and_clear_adjust_count()); |
97 } | 111 } |
98 | 112 |
99 } // namespace | 113 } // namespace |
100 } // namespace service_manager | 114 } // namespace service_manager |
OLD | NEW |