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 "mojo/shell/runner/host/child_process_host.h" | 7 #include "mojo/shell/runner/host/child_process_host.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "mojo/edk/embedder/embedder.h" |
| 19 #include "mojo/edk/embedder/process_delegate.h" |
18 #include "mojo/message_pump/message_pump_mojo.h" | 20 #include "mojo/message_pump/message_pump_mojo.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" | |
21 #include "third_party/mojo/src/mojo/edk/embedder/process_delegate.h" | |
22 | 22 |
23 namespace mojo { | 23 namespace mojo { |
24 namespace shell { | 24 namespace shell { |
25 namespace { | 25 namespace { |
26 | 26 |
27 void ProcessReadyCallbackAdapater(const base::Closure& callback, | 27 void ProcessReadyCallbackAdapater(const base::Closure& callback, |
28 base::ProcessId process_id) { | 28 base::ProcessId process_id) { |
29 callback.Run(); | 29 callback.Run(); |
30 } | 30 } |
31 | 31 |
32 class ProcessDelegate : public embedder::ProcessDelegate { | 32 class ProcessDelegate : public edk::ProcessDelegate { |
33 public: | 33 public: |
34 ProcessDelegate() {} | 34 ProcessDelegate() {} |
35 ~ProcessDelegate() override {} | 35 ~ProcessDelegate() override {} |
36 | 36 |
37 private: | 37 private: |
38 void OnShutdownComplete() override {} | 38 void OnShutdownComplete() override {} |
39 DISALLOW_COPY_AND_ASSIGN(ProcessDelegate); | 39 DISALLOW_COPY_AND_ASSIGN(ProcessDelegate); |
40 }; | 40 }; |
41 | 41 |
42 #if defined(OS_ANDROID) | 42 #if defined(OS_ANDROID) |
43 // TODO(qsr): Multiprocess shell tests are not supported on android. | 43 // TODO(qsr): Multiprocess shell tests are not supported on android. |
44 #define MAYBE_StartJoin DISABLED_StartJoin | 44 #define MAYBE_StartJoin DISABLED_StartJoin |
45 #else | 45 #else |
46 #define MAYBE_StartJoin StartJoin | 46 #define MAYBE_StartJoin StartJoin |
47 #endif // defined(OS_ANDROID) | 47 #endif // defined(OS_ANDROID) |
48 // Just tests starting the child process and joining it (without starting an | 48 // Just tests starting the child process and joining it (without starting an |
49 // app). | 49 // app). |
50 TEST(ChildProcessHostTest, MAYBE_StartJoin) { | 50 TEST(ChildProcessHostTest, MAYBE_StartJoin) { |
51 base::CommandLine::ForCurrentProcess()->AppendSwitch("use-new-edk"); | |
52 | |
53 base::FilePath shell_dir; | 51 base::FilePath shell_dir; |
54 PathService::Get(base::DIR_MODULE, &shell_dir); | 52 PathService::Get(base::DIR_MODULE, &shell_dir); |
55 base::MessageLoop message_loop( | 53 base::MessageLoop message_loop( |
56 scoped_ptr<base::MessagePump>(new common::MessagePumpMojo())); | 54 scoped_ptr<base::MessagePump>(new common::MessagePumpMojo())); |
57 scoped_refptr<base::SequencedWorkerPool> blocking_pool( | 55 scoped_refptr<base::SequencedWorkerPool> blocking_pool( |
58 new base::SequencedWorkerPool(3, "blocking_pool")); | 56 new base::SequencedWorkerPool(3, "blocking_pool")); |
59 | 57 |
60 base::Thread io_thread("io_thread"); | 58 base::Thread io_thread("io_thread"); |
61 base::Thread::Options options; | 59 base::Thread::Options options; |
62 options.message_loop_type = base::MessageLoop::TYPE_IO; | 60 options.message_loop_type = base::MessageLoop::TYPE_IO; |
63 io_thread.StartWithOptions(options); | 61 io_thread.StartWithOptions(options); |
64 | 62 |
65 ProcessDelegate delegate; | 63 ProcessDelegate delegate; |
66 embedder::InitIPCSupport( | 64 edk::InitIPCSupport(&delegate, io_thread.task_runner()); |
67 embedder::ProcessType::NONE, &delegate, io_thread.task_runner(), | |
68 embedder::ScopedPlatformHandle()); | |
69 | 65 |
70 ChildProcessHost child_process_host(blocking_pool.get(), false, | 66 ChildProcessHost child_process_host(blocking_pool.get(), false, |
71 base::FilePath()); | 67 base::FilePath()); |
72 base::RunLoop run_loop; | 68 base::RunLoop run_loop; |
73 child_process_host.Start( | 69 child_process_host.Start( |
74 base::Bind(&ProcessReadyCallbackAdapater, run_loop.QuitClosure())); | 70 base::Bind(&ProcessReadyCallbackAdapater, run_loop.QuitClosure())); |
75 run_loop.Run(); | 71 run_loop.Run(); |
76 | 72 |
77 child_process_host.ExitNow(123); | 73 child_process_host.ExitNow(123); |
78 int exit_code = child_process_host.Join(); | 74 int exit_code = child_process_host.Join(); |
79 VLOG(2) << "Joined child: exit_code = " << exit_code; | 75 VLOG(2) << "Joined child: exit_code = " << exit_code; |
80 EXPECT_EQ(123, exit_code); | 76 EXPECT_EQ(123, exit_code); |
81 blocking_pool->Shutdown(); | 77 blocking_pool->Shutdown(); |
82 embedder::ShutdownIPCSupport(); | 78 edk::ShutdownIPCSupport(); |
83 } | 79 } |
84 | 80 |
85 } // namespace | 81 } // namespace |
86 } // namespace shell | 82 } // namespace shell |
87 } // namespace mojo | 83 } // namespace mojo |
OLD | NEW |