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

Side by Side Diff: services/service_manager/runner/host/child_process_host_unittest.cc

Issue 2576233002: Consolidating the mojo NativeRunner functionality. (Closed)
Patch Set: Clean-up. Created 4 years 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
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 "services/service_manager/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/service_manager/native_runner_delegate.h"
24 #include "testing/gtest/include/gtest/gtest.h"
25
26 namespace service_manager {
27 namespace {
28
29 const char kTestServiceName[] = "host_test_service";
30
31 const base::FilePath::CharType kPackagesPath[] = FILE_PATH_LITERAL("Packages");
32 const base::FilePath::CharType kServiceExtension[] =
33 FILE_PATH_LITERAL(".service");
34
35 void ProcessReadyCallbackAdapater(const base::Closure& callback,
36 base::ProcessId process_id) {
37 callback.Run();
38 }
39
40 class ProcessDelegate : public mojo::edk::ProcessDelegate {
41 public:
42 ProcessDelegate() {}
43 ~ProcessDelegate() override {}
44
45 private:
46 void OnShutdownComplete() override {}
47 DISALLOW_COPY_AND_ASSIGN(ProcessDelegate);
48 };
49
50 class NativeRunnerDelegateImpl : public NativeRunnerDelegate {
51 public:
52 NativeRunnerDelegateImpl() {}
53 ~NativeRunnerDelegateImpl() override {}
54
55 size_t get_and_clear_adjust_count() {
56 size_t count = 0;
57 std::swap(count, adjust_count_);
58 return count;
59 }
60
61 private:
62 // NativeRunnerDelegate:
63 void AdjustCommandLineArgumentsForTarget(
64 const Identity& target,
65 base::CommandLine* command_line) override {
66 adjust_count_++;
67 }
68
69 size_t adjust_count_ = 0;
70
71 DISALLOW_COPY_AND_ASSIGN(NativeRunnerDelegateImpl);
72 };
73
74 #if defined(OS_ANDROID)
75 // TODO(qsr): Multiprocess service manager tests are not supported on android.
76 #define MAYBE_StartJoin DISABLED_StartJoin
77 #else
78 #define MAYBE_StartJoin StartJoin
79 #endif // defined(OS_ANDROID)
80 TEST(ChildProcessHostTest, MAYBE_StartJoin) {
81 base::FilePath service_manager_dir;
82 PathService::Get(base::DIR_MODULE, &service_manager_dir);
83 base::MessageLoop message_loop;
84 scoped_refptr<base::SequencedWorkerPool> blocking_pool(
85 new base::SequencedWorkerPool(3, "blocking_pool",
86 base::TaskPriority::USER_VISIBLE));
87
88 base::Thread io_thread("io_thread");
89 base::Thread::Options options;
90 options.message_loop_type = base::MessageLoop::TYPE_IO;
91 io_thread.StartWithOptions(options);
92
93 ProcessDelegate delegate;
94 mojo::edk::InitIPCSupport(&delegate, io_thread.task_runner());
95
96 base::FilePath test_service_path =
97 base::FilePath(kPackagesPath).AppendASCII(kTestServiceName)
98 .AppendASCII(kTestServiceName) .AddExtension(kServiceExtension);
99
100 NativeRunnerDelegateImpl native_runner_delegate;
101 ChildProcessHost child_process_host(blocking_pool.get(),
102 &native_runner_delegate, false,
103 Identity(), test_service_path);
104 base::RunLoop run_loop;
105 child_process_host.Start(
106 Identity(),
107 base::Bind(&ProcessReadyCallbackAdapater, run_loop.QuitClosure()),
108 base::Bind(&base::DoNothing));
109 run_loop.Run();
110
111 child_process_host.Join();
112 blocking_pool->Shutdown();
113 mojo::edk::ShutdownIPCSupport();
114 EXPECT_EQ(1u, native_runner_delegate.get_and_clear_adjust_count());
115 }
116
117 } // namespace
118 } // namespace service_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698