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 // Note: This file also tests child_process.*. | 5 #include "services/service_manager/runner/host/service_process_launcher.h" |
6 | |
7 #include "services/service_manager/runner/host/child_process_host.h" | |
8 | 6 |
9 #include <memory> | 7 #include <memory> |
10 #include <utility> | 8 #include <utility> |
11 | 9 |
12 #include "base/bind.h" | 10 #include "base/bind.h" |
13 #include "base/callback.h" | 11 #include "base/callback.h" |
14 #include "base/command_line.h" | 12 #include "base/command_line.h" |
15 #include "base/logging.h" | 13 #include "base/logging.h" |
16 #include "base/macros.h" | 14 #include "base/macros.h" |
17 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
18 #include "base/path_service.h" | 16 #include "base/path_service.h" |
19 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
20 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
21 #include "mojo/edk/embedder/embedder.h" | 19 #include "mojo/edk/embedder/embedder.h" |
22 #include "mojo/edk/embedder/process_delegate.h" | 20 #include "mojo/edk/embedder/process_delegate.h" |
23 #include "services/service_manager/native_runner_delegate.h" | |
24 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
25 | 22 |
26 namespace service_manager { | 23 namespace service_manager { |
27 namespace { | 24 namespace { |
28 | 25 |
29 const char kTestServiceName[] = "host_test_service"; | 26 const char kTestServiceName[] = "host_test_service"; |
30 | 27 |
31 const base::FilePath::CharType kPackagesPath[] = FILE_PATH_LITERAL("Packages"); | 28 const base::FilePath::CharType kPackagesPath[] = FILE_PATH_LITERAL("Packages"); |
32 | 29 |
33 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
(...skipping 12 matching lines...) Expand all Loading... |
46 class ProcessDelegate : public mojo::edk::ProcessDelegate { | 43 class ProcessDelegate : public mojo::edk::ProcessDelegate { |
47 public: | 44 public: |
48 ProcessDelegate() {} | 45 ProcessDelegate() {} |
49 ~ProcessDelegate() override {} | 46 ~ProcessDelegate() override {} |
50 | 47 |
51 private: | 48 private: |
52 void OnShutdownComplete() override {} | 49 void OnShutdownComplete() override {} |
53 DISALLOW_COPY_AND_ASSIGN(ProcessDelegate); | 50 DISALLOW_COPY_AND_ASSIGN(ProcessDelegate); |
54 }; | 51 }; |
55 | 52 |
56 class NativeRunnerDelegateImpl : public NativeRunnerDelegate { | 53 class ServiceProcessLauncherDelegateImpl |
| 54 : public ServiceProcessLauncher::Delegate { |
57 public: | 55 public: |
58 NativeRunnerDelegateImpl() {} | 56 ServiceProcessLauncherDelegateImpl() {} |
59 ~NativeRunnerDelegateImpl() override {} | 57 ~ServiceProcessLauncherDelegateImpl() override {} |
60 | 58 |
61 size_t get_and_clear_adjust_count() { | 59 size_t get_and_clear_adjust_count() { |
62 size_t count = 0; | 60 size_t count = 0; |
63 std::swap(count, adjust_count_); | 61 std::swap(count, adjust_count_); |
64 return count; | 62 return count; |
65 } | 63 } |
66 | 64 |
67 private: | 65 private: |
68 // NativeRunnerDelegate: | 66 // ServiceProcessLauncher::Delegate: |
69 void AdjustCommandLineArgumentsForTarget( | 67 void AdjustCommandLineArgumentsForTarget( |
70 const Identity& target, | 68 const Identity& target, |
71 base::CommandLine* command_line) override { | 69 base::CommandLine* command_line) override { |
72 adjust_count_++; | 70 adjust_count_++; |
73 } | 71 } |
74 | 72 |
75 size_t adjust_count_ = 0; | 73 size_t adjust_count_ = 0; |
76 | 74 |
77 DISALLOW_COPY_AND_ASSIGN(NativeRunnerDelegateImpl); | 75 DISALLOW_COPY_AND_ASSIGN(ServiceProcessLauncherDelegateImpl); |
78 }; | 76 }; |
79 | 77 |
80 #if defined(OS_ANDROID) | 78 #if defined(OS_ANDROID) |
81 // TODO(qsr): Multiprocess service manager tests are not supported on android. | 79 // TODO(qsr): Multiprocess service manager tests are not supported on android. |
82 #define MAYBE_StartJoin DISABLED_StartJoin | 80 #define MAYBE_StartJoin DISABLED_StartJoin |
83 #else | 81 #else |
84 #define MAYBE_StartJoin StartJoin | 82 #define MAYBE_StartJoin StartJoin |
85 #endif // defined(OS_ANDROID) | 83 #endif // defined(OS_ANDROID) |
86 TEST(ChildProcessHostTest, MAYBE_StartJoin) { | 84 TEST(ServieProcessLauncherTest, MAYBE_StartJoin) { |
87 base::FilePath service_manager_dir; | 85 base::FilePath service_manager_dir; |
88 PathService::Get(base::DIR_MODULE, &service_manager_dir); | 86 PathService::Get(base::DIR_MODULE, &service_manager_dir); |
89 base::MessageLoop message_loop; | 87 base::MessageLoop message_loop; |
90 scoped_refptr<base::SequencedWorkerPool> blocking_pool( | 88 scoped_refptr<base::SequencedWorkerPool> blocking_pool( |
91 new base::SequencedWorkerPool(3, "blocking_pool", | 89 new base::SequencedWorkerPool(3, "blocking_pool", |
92 base::TaskPriority::USER_VISIBLE)); | 90 base::TaskPriority::USER_VISIBLE)); |
93 | 91 |
94 base::Thread io_thread("io_thread"); | 92 base::Thread io_thread("io_thread"); |
95 base::Thread::Options options; | 93 base::Thread::Options options; |
96 options.message_loop_type = base::MessageLoop::TYPE_IO; | 94 options.message_loop_type = base::MessageLoop::TYPE_IO; |
97 io_thread.StartWithOptions(options); | 95 io_thread.StartWithOptions(options); |
98 | 96 |
99 ProcessDelegate delegate; | 97 ProcessDelegate delegate; |
100 mojo::edk::InitIPCSupport(&delegate, io_thread.task_runner()); | 98 mojo::edk::InitIPCSupport(&delegate, io_thread.task_runner()); |
101 | 99 |
102 base::FilePath test_service_path = | 100 base::FilePath test_service_path = |
103 base::FilePath(kPackagesPath).AppendASCII(kTestServiceName) | 101 base::FilePath(kPackagesPath).AppendASCII(kTestServiceName) |
104 .AppendASCII(kTestServiceName) .AddExtension(kServiceExtension); | 102 .AppendASCII(kTestServiceName) .AddExtension(kServiceExtension); |
105 | 103 |
106 NativeRunnerDelegateImpl native_runner_delegate; | 104 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate; |
107 ChildProcessHost child_process_host(blocking_pool.get(), | 105 ServiceProcessLauncher launcher(blocking_pool.get(), |
108 &native_runner_delegate, false, | 106 &service_process_launcher_delegate, |
109 Identity(), test_service_path); | 107 test_service_path); |
110 base::RunLoop run_loop; | 108 base::RunLoop run_loop; |
111 child_process_host.Start( | 109 launcher.Start( |
112 Identity(), | 110 Identity(), |
113 base::Bind(&ProcessReadyCallbackAdapater, run_loop.QuitClosure()), | 111 false, |
114 base::Bind(&base::DoNothing)); | 112 base::Bind(&ProcessReadyCallbackAdapater, run_loop.QuitClosure())); |
115 run_loop.Run(); | 113 run_loop.Run(); |
116 | 114 |
117 child_process_host.Join(); | 115 launcher.Join(); |
118 blocking_pool->Shutdown(); | 116 blocking_pool->Shutdown(); |
119 mojo::edk::ShutdownIPCSupport(); | 117 mojo::edk::ShutdownIPCSupport(); |
120 EXPECT_EQ(1u, native_runner_delegate.get_and_clear_adjust_count()); | 118 EXPECT_EQ(1u, service_process_launcher_delegate.get_and_clear_adjust_count()); |
121 } | 119 } |
122 | 120 |
123 } // namespace | 121 } // namespace |
124 } // namespace service_manager | 122 } // namespace service_manager |
OLD | NEW |