| 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 // Note: This file also tests child_process.*. |
| 6 | 6 |
| 7 #include "services/service_manager/runner/host/child_process_host.h" | 7 #include "services/service_manager/runner/host/child_process_host.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
| 20 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
| 21 #include "mojo/edk/embedder/embedder.h" | 21 #include "mojo/edk/embedder/embedder.h" |
| 22 #include "mojo/edk/embedder/process_delegate.h" | 22 #include "mojo/edk/embedder/process_delegate.h" |
| 23 #include "services/service_manager/native_runner_delegate.h" | 23 #include "services/service_manager/native_runner_delegate.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 25 |
| 26 namespace service_manager { | 26 namespace service_manager { |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 const char kTestServiceName[] = "host_test_service"; |
| 30 |
| 31 const base::FilePath::CharType kPackagesPath[] = FILE_PATH_LITERAL("Packages"); |
| 32 const base::FilePath::CharType kServiceExtension[] = |
| 33 FILE_PATH_LITERAL(".service"); |
| 34 |
| 29 void ProcessReadyCallbackAdapater(const base::Closure& callback, | 35 void ProcessReadyCallbackAdapater(const base::Closure& callback, |
| 30 base::ProcessId process_id) { | 36 base::ProcessId process_id) { |
| 31 callback.Run(); | 37 callback.Run(); |
| 32 } | 38 } |
| 33 | 39 |
| 34 class ProcessDelegate : public mojo::edk::ProcessDelegate { | 40 class ProcessDelegate : public mojo::edk::ProcessDelegate { |
| 35 public: | 41 public: |
| 36 ProcessDelegate() {} | 42 ProcessDelegate() {} |
| 37 ~ProcessDelegate() override {} | 43 ~ProcessDelegate() override {} |
| 38 | 44 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 64 | 70 |
| 65 DISALLOW_COPY_AND_ASSIGN(NativeRunnerDelegateImpl); | 71 DISALLOW_COPY_AND_ASSIGN(NativeRunnerDelegateImpl); |
| 66 }; | 72 }; |
| 67 | 73 |
| 68 #if defined(OS_ANDROID) | 74 #if defined(OS_ANDROID) |
| 69 // TODO(qsr): Multiprocess service manager tests are not supported on android. | 75 // TODO(qsr): Multiprocess service manager tests are not supported on android. |
| 70 #define MAYBE_StartJoin DISABLED_StartJoin | 76 #define MAYBE_StartJoin DISABLED_StartJoin |
| 71 #else | 77 #else |
| 72 #define MAYBE_StartJoin StartJoin | 78 #define MAYBE_StartJoin StartJoin |
| 73 #endif // defined(OS_ANDROID) | 79 #endif // defined(OS_ANDROID) |
| 74 // Just tests starting the child process and joining it (without starting an | |
| 75 // app). | |
| 76 TEST(ChildProcessHostTest, MAYBE_StartJoin) { | 80 TEST(ChildProcessHostTest, MAYBE_StartJoin) { |
| 77 base::FilePath service_manager_dir; | 81 base::FilePath service_manager_dir; |
| 78 PathService::Get(base::DIR_MODULE, &service_manager_dir); | 82 PathService::Get(base::DIR_MODULE, &service_manager_dir); |
| 79 base::MessageLoop message_loop; | 83 base::MessageLoop message_loop; |
| 80 scoped_refptr<base::SequencedWorkerPool> blocking_pool( | 84 scoped_refptr<base::SequencedWorkerPool> blocking_pool( |
| 81 new base::SequencedWorkerPool(3, "blocking_pool", | 85 new base::SequencedWorkerPool(3, "blocking_pool", |
| 82 base::TaskPriority::USER_VISIBLE)); | 86 base::TaskPriority::USER_VISIBLE)); |
| 83 | 87 |
| 84 base::Thread io_thread("io_thread"); | 88 base::Thread io_thread("io_thread"); |
| 85 base::Thread::Options options; | 89 base::Thread::Options options; |
| 86 options.message_loop_type = base::MessageLoop::TYPE_IO; | 90 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 87 io_thread.StartWithOptions(options); | 91 io_thread.StartWithOptions(options); |
| 88 | 92 |
| 89 ProcessDelegate delegate; | 93 ProcessDelegate delegate; |
| 90 mojo::edk::InitIPCSupport(&delegate, io_thread.task_runner()); | 94 mojo::edk::InitIPCSupport(&delegate, io_thread.task_runner()); |
| 91 | 95 |
| 96 base::FilePath test_service_path = |
| 97 base::FilePath(kPackagesPath).AppendASCII(kTestServiceName) |
| 98 .AppendASCII(kTestServiceName) .AddExtension(kServiceExtension); |
| 99 |
| 92 NativeRunnerDelegateImpl native_runner_delegate; | 100 NativeRunnerDelegateImpl native_runner_delegate; |
| 93 ChildProcessHost child_process_host(blocking_pool.get(), | 101 ChildProcessHost child_process_host(blocking_pool.get(), |
| 94 &native_runner_delegate, false, | 102 &native_runner_delegate, false, |
| 95 Identity(), base::FilePath()); | 103 Identity(), test_service_path); |
| 96 base::RunLoop run_loop; | 104 base::RunLoop run_loop; |
| 97 child_process_host.Start( | 105 child_process_host.Start( |
| 98 Identity(), | 106 Identity(), |
| 99 base::Bind(&ProcessReadyCallbackAdapater, run_loop.QuitClosure()), | 107 base::Bind(&ProcessReadyCallbackAdapater, run_loop.QuitClosure()), |
| 100 base::Bind(&base::DoNothing)); | 108 base::Bind(&base::DoNothing)); |
| 101 run_loop.Run(); | 109 run_loop.Run(); |
| 102 | 110 |
| 103 child_process_host.Join(); | 111 child_process_host.Join(); |
| 104 blocking_pool->Shutdown(); | 112 blocking_pool->Shutdown(); |
| 105 mojo::edk::ShutdownIPCSupport(); | 113 mojo::edk::ShutdownIPCSupport(); |
| 106 EXPECT_EQ(1u, native_runner_delegate.get_and_clear_adjust_count()); | 114 EXPECT_EQ(1u, native_runner_delegate.get_and_clear_adjust_count()); |
| 107 } | 115 } |
| 108 | 116 |
| 109 } // namespace | 117 } // namespace |
| 110 } // namespace service_manager | 118 } // namespace service_manager |
| OLD | NEW |