Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1179)

Side by Side Diff: mojo/shell/runner/host/child_process_host_unittest.cc

Issue 1877753003: Move mojo\shell to services\shell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@62scan
Patch Set: . Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/shell/runner/host/child_process_host.cc ('k') | mojo/shell/runner/host/host_unittests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « mojo/shell/runner/host/child_process_host.cc ('k') | mojo/shell/runner/host/host_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698