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