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