OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // Note: This file also tests child_process.*. | |
6 | |
7 #include "services/shell/runner/host/child_process_host.h" | |
8 | |
9 #include <memory> | |
10 #include <utility> | |
11 | |
12 #include "base/bind.h" | |
13 #include "base/callback.h" | |
14 #include "base/command_line.h" | |
15 #include "base/logging.h" | |
16 #include "base/macros.h" | |
17 #include "base/message_loop/message_loop.h" | |
18 #include "base/path_service.h" | |
19 #include "base/run_loop.h" | |
20 #include "base/threading/thread.h" | |
21 #include "mojo/edk/embedder/embedder.h" | |
22 #include "mojo/edk/embedder/process_delegate.h" | |
23 #include "services/shell/native_runner_delegate.h" | |
24 #include "testing/gtest/include/gtest/gtest.h" | |
25 | |
26 namespace shell { | |
27 namespace { | |
28 | |
29 void ProcessReadyCallbackAdapater(const base::Closure& callback, | |
30 base::ProcessId process_id) { | |
31 callback.Run(); | |
32 } | |
33 | |
34 class ProcessDelegate : public mojo::edk::ProcessDelegate { | |
35 public: | |
36 ProcessDelegate() {} | |
37 ~ProcessDelegate() override {} | |
38 | |
39 private: | |
40 void OnShutdownComplete() override {} | |
41 DISALLOW_COPY_AND_ASSIGN(ProcessDelegate); | |
42 }; | |
43 | |
44 class NativeRunnerDelegateImpl : public NativeRunnerDelegate { | |
45 public: | |
46 NativeRunnerDelegateImpl() {} | |
47 ~NativeRunnerDelegateImpl() override {} | |
48 | |
49 size_t get_and_clear_adjust_count() { | |
50 size_t count = 0; | |
51 std::swap(count, adjust_count_); | |
52 return count; | |
53 } | |
54 | |
55 private: | |
56 // NativeRunnerDelegate: | |
57 void AdjustCommandLineArgumentsForTarget( | |
58 const Identity& target, | |
59 base::CommandLine* command_line) override { | |
60 adjust_count_++; | |
61 } | |
62 | |
63 size_t adjust_count_ = 0; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(NativeRunnerDelegateImpl); | |
66 }; | |
67 | |
68 #if defined(OS_ANDROID) | |
69 // TODO(qsr): Multiprocess shell tests are not supported on android. | |
70 #define MAYBE_StartJoin DISABLED_StartJoin | |
71 #else | |
72 #define MAYBE_StartJoin StartJoin | |
73 #endif // defined(OS_ANDROID) | |
74 // Just tests starting the child process and joining it (without starting an | |
75 // app). | |
76 TEST(ChildProcessHostTest, MAYBE_StartJoin) { | |
77 base::FilePath shell_dir; | |
78 PathService::Get(base::DIR_MODULE, &shell_dir); | |
79 base::MessageLoop message_loop; | |
80 scoped_refptr<base::SequencedWorkerPool> blocking_pool( | |
81 new base::SequencedWorkerPool(3, "blocking_pool", | |
82 base::TaskPriority::USER_VISIBLE)); | |
83 | |
84 base::Thread io_thread("io_thread"); | |
85 base::Thread::Options options; | |
86 options.message_loop_type = base::MessageLoop::TYPE_IO; | |
87 io_thread.StartWithOptions(options); | |
88 | |
89 ProcessDelegate delegate; | |
90 mojo::edk::InitIPCSupport(&delegate, io_thread.task_runner()); | |
91 | |
92 NativeRunnerDelegateImpl native_runner_delegate; | |
93 ChildProcessHost child_process_host(blocking_pool.get(), | |
94 &native_runner_delegate, false, | |
95 Identity(), base::FilePath()); | |
96 base::RunLoop run_loop; | |
97 child_process_host.Start( | |
98 Identity(), | |
99 base::Bind(&ProcessReadyCallbackAdapater, run_loop.QuitClosure()), | |
100 base::Bind(&base::DoNothing)); | |
101 run_loop.Run(); | |
102 | |
103 child_process_host.Join(); | |
104 blocking_pool->Shutdown(); | |
105 mojo::edk::ShutdownIPCSupport(); | |
106 EXPECT_EQ(1u, native_runner_delegate.get_and_clear_adjust_count()); | |
107 } | |
108 | |
109 } // namespace | |
110 } // namespace shell | |
OLD | NEW |