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