| 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 | |
| 35 void ProcessReadyCallbackAdapater(const base::Closure& callback, | 29 void ProcessReadyCallbackAdapater(const base::Closure& callback, |
| 36 base::ProcessId process_id) { | 30 base::ProcessId process_id) { |
| 37 callback.Run(); | 31 callback.Run(); |
| 38 } | 32 } |
| 39 | 33 |
| 40 class ProcessDelegate : public mojo::edk::ProcessDelegate { | 34 class ProcessDelegate : public mojo::edk::ProcessDelegate { |
| 41 public: | 35 public: |
| 42 ProcessDelegate() {} | 36 ProcessDelegate() {} |
| 43 ~ProcessDelegate() override {} | 37 ~ProcessDelegate() override {} |
| 44 | 38 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 70 | 64 |
| 71 DISALLOW_COPY_AND_ASSIGN(NativeRunnerDelegateImpl); | 65 DISALLOW_COPY_AND_ASSIGN(NativeRunnerDelegateImpl); |
| 72 }; | 66 }; |
| 73 | 67 |
| 74 #if defined(OS_ANDROID) | 68 #if defined(OS_ANDROID) |
| 75 // TODO(qsr): Multiprocess service manager tests are not supported on android. | 69 // TODO(qsr): Multiprocess service manager tests are not supported on android. |
| 76 #define MAYBE_StartJoin DISABLED_StartJoin | 70 #define MAYBE_StartJoin DISABLED_StartJoin |
| 77 #else | 71 #else |
| 78 #define MAYBE_StartJoin StartJoin | 72 #define MAYBE_StartJoin StartJoin |
| 79 #endif // defined(OS_ANDROID) | 73 #endif // defined(OS_ANDROID) |
| 74 // Just tests starting the child process and joining it (without starting an |
| 75 // app). |
| 80 TEST(ChildProcessHostTest, MAYBE_StartJoin) { | 76 TEST(ChildProcessHostTest, MAYBE_StartJoin) { |
| 81 base::FilePath service_manager_dir; | 77 base::FilePath service_manager_dir; |
| 82 PathService::Get(base::DIR_MODULE, &service_manager_dir); | 78 PathService::Get(base::DIR_MODULE, &service_manager_dir); |
| 83 base::MessageLoop message_loop; | 79 base::MessageLoop message_loop; |
| 84 scoped_refptr<base::SequencedWorkerPool> blocking_pool( | 80 scoped_refptr<base::SequencedWorkerPool> blocking_pool( |
| 85 new base::SequencedWorkerPool(3, "blocking_pool", | 81 new base::SequencedWorkerPool(3, "blocking_pool", |
| 86 base::TaskPriority::USER_VISIBLE)); | 82 base::TaskPriority::USER_VISIBLE)); |
| 87 | 83 |
| 88 base::Thread io_thread("io_thread"); | 84 base::Thread io_thread("io_thread"); |
| 89 base::Thread::Options options; | 85 base::Thread::Options options; |
| 90 options.message_loop_type = base::MessageLoop::TYPE_IO; | 86 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 91 io_thread.StartWithOptions(options); | 87 io_thread.StartWithOptions(options); |
| 92 | 88 |
| 93 ProcessDelegate delegate; | 89 ProcessDelegate delegate; |
| 94 mojo::edk::InitIPCSupport(&delegate, io_thread.task_runner()); | 90 mojo::edk::InitIPCSupport(&delegate, io_thread.task_runner()); |
| 95 | 91 |
| 96 base::FilePath test_service_path = | |
| 97 base::FilePath(kPackagesPath).AppendASCII(kTestServiceName) | |
| 98 .AppendASCII(kTestServiceName) .AddExtension(kServiceExtension); | |
| 99 | |
| 100 NativeRunnerDelegateImpl native_runner_delegate; | 92 NativeRunnerDelegateImpl native_runner_delegate; |
| 101 ChildProcessHost child_process_host(blocking_pool.get(), | 93 ChildProcessHost child_process_host(blocking_pool.get(), |
| 102 &native_runner_delegate, false, | 94 &native_runner_delegate, false, |
| 103 Identity(), test_service_path); | 95 Identity(), base::FilePath()); |
| 104 base::RunLoop run_loop; | 96 base::RunLoop run_loop; |
| 105 child_process_host.Start( | 97 child_process_host.Start( |
| 106 Identity(), | 98 Identity(), |
| 107 base::Bind(&ProcessReadyCallbackAdapater, run_loop.QuitClosure()), | 99 base::Bind(&ProcessReadyCallbackAdapater, run_loop.QuitClosure()), |
| 108 base::Bind(&base::DoNothing)); | 100 base::Bind(&base::DoNothing)); |
| 109 run_loop.Run(); | 101 run_loop.Run(); |
| 110 | 102 |
| 111 child_process_host.Join(); | 103 child_process_host.Join(); |
| 112 blocking_pool->Shutdown(); | 104 blocking_pool->Shutdown(); |
| 113 mojo::edk::ShutdownIPCSupport(); | 105 mojo::edk::ShutdownIPCSupport(); |
| 114 EXPECT_EQ(1u, native_runner_delegate.get_and_clear_adjust_count()); | 106 EXPECT_EQ(1u, native_runner_delegate.get_and_clear_adjust_count()); |
| 115 } | 107 } |
| 116 | 108 |
| 117 } // namespace | 109 } // namespace |
| 118 } // namespace service_manager | 110 } // namespace service_manager |
| OLD | NEW |