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

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

Issue 2617713002: [WIP] Add DCHECK for mojo::edk::Init().
Patch Set: test Created 3 years, 11 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
OLDNEW
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 #include "services/service_manager/runner/host/service_process_launcher.h" 5 #include "services/service_manager/runner/host/service_process_launcher.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/threading/thread.h"
19 #include "mojo/edk/embedder/embedder.h"
20 #include "mojo/edk/embedder/process_delegate.h"
21 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
22 19
23 namespace service_manager { 20 namespace service_manager {
24 namespace { 21 namespace {
25 22
26 const char kTestServiceName[] = "host_test_service"; 23 const char kTestServiceName[] = "host_test_service";
27 24
28 const base::FilePath::CharType kPackagesPath[] = FILE_PATH_LITERAL("Packages"); 25 const base::FilePath::CharType kPackagesPath[] = FILE_PATH_LITERAL("Packages");
29 26
30 #if defined(OS_WIN) 27 #if defined(OS_WIN)
31 const base::FilePath::CharType kServiceExtension[] = 28 const base::FilePath::CharType kServiceExtension[] =
32 FILE_PATH_LITERAL(".service.exe"); 29 FILE_PATH_LITERAL(".service.exe");
33 #else 30 #else
34 const base::FilePath::CharType kServiceExtension[] = 31 const base::FilePath::CharType kServiceExtension[] =
35 FILE_PATH_LITERAL(".service"); 32 FILE_PATH_LITERAL(".service");
36 #endif 33 #endif
37 34
38 void ProcessReadyCallbackAdapater(const base::Closure& callback, 35 void ProcessReadyCallbackAdapater(const base::Closure& callback,
39 base::ProcessId process_id) { 36 base::ProcessId process_id) {
40 callback.Run(); 37 callback.Run();
41 } 38 }
42 39
43 class ProcessDelegate : public mojo::edk::ProcessDelegate {
44 public:
45 ProcessDelegate() {}
46 ~ProcessDelegate() override {}
47
48 private:
49 void OnShutdownComplete() override {}
50 DISALLOW_COPY_AND_ASSIGN(ProcessDelegate);
51 };
52
53 class ServiceProcessLauncherDelegateImpl 40 class ServiceProcessLauncherDelegateImpl
54 : public ServiceProcessLauncher::Delegate { 41 : public ServiceProcessLauncher::Delegate {
55 public: 42 public:
56 ServiceProcessLauncherDelegateImpl() {} 43 ServiceProcessLauncherDelegateImpl() {}
57 ~ServiceProcessLauncherDelegateImpl() override {} 44 ~ServiceProcessLauncherDelegateImpl() override {}
58 45
59 size_t get_and_clear_adjust_count() { 46 size_t get_and_clear_adjust_count() {
60 size_t count = 0; 47 size_t count = 0;
61 std::swap(count, adjust_count_); 48 std::swap(count, adjust_count_);
62 return count; 49 return count;
(...skipping 19 matching lines...) Expand all
82 #define MAYBE_StartJoin StartJoin 69 #define MAYBE_StartJoin StartJoin
83 #endif // defined(OS_ANDROID) 70 #endif // defined(OS_ANDROID)
84 TEST(ServieProcessLauncherTest, MAYBE_StartJoin) { 71 TEST(ServieProcessLauncherTest, MAYBE_StartJoin) {
85 base::FilePath service_manager_dir; 72 base::FilePath service_manager_dir;
86 PathService::Get(base::DIR_MODULE, &service_manager_dir); 73 PathService::Get(base::DIR_MODULE, &service_manager_dir);
87 base::MessageLoop message_loop; 74 base::MessageLoop message_loop;
88 scoped_refptr<base::SequencedWorkerPool> blocking_pool( 75 scoped_refptr<base::SequencedWorkerPool> blocking_pool(
89 new base::SequencedWorkerPool(3, "blocking_pool", 76 new base::SequencedWorkerPool(3, "blocking_pool",
90 base::TaskPriority::USER_VISIBLE)); 77 base::TaskPriority::USER_VISIBLE));
91 78
92 base::Thread io_thread("io_thread");
93 base::Thread::Options options;
94 options.message_loop_type = base::MessageLoop::TYPE_IO;
95 io_thread.StartWithOptions(options);
96
97 ProcessDelegate delegate;
98 mojo::edk::InitIPCSupport(&delegate, io_thread.task_runner());
99
100 base::FilePath test_service_path = 79 base::FilePath test_service_path =
101 base::FilePath(kPackagesPath).AppendASCII(kTestServiceName) 80 base::FilePath(kPackagesPath).AppendASCII(kTestServiceName)
102 .AppendASCII(kTestServiceName) .AddExtension(kServiceExtension); 81 .AppendASCII(kTestServiceName) .AddExtension(kServiceExtension);
103 82
104 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate; 83 ServiceProcessLauncherDelegateImpl service_process_launcher_delegate;
105 ServiceProcessLauncher launcher(blocking_pool.get(), 84 ServiceProcessLauncher launcher(blocking_pool.get(),
106 &service_process_launcher_delegate, 85 &service_process_launcher_delegate,
107 test_service_path); 86 test_service_path);
108 base::RunLoop run_loop; 87 base::RunLoop run_loop;
109 launcher.Start( 88 launcher.Start(
110 Identity(), 89 Identity(),
111 false, 90 false,
112 base::Bind(&ProcessReadyCallbackAdapater, run_loop.QuitClosure())); 91 base::Bind(&ProcessReadyCallbackAdapater, run_loop.QuitClosure()));
113 run_loop.Run(); 92 run_loop.Run();
114 93
115 launcher.Join(); 94 launcher.Join();
116 blocking_pool->Shutdown(); 95 blocking_pool->Shutdown();
117 mojo::edk::ShutdownIPCSupport();
118 EXPECT_EQ(1u, service_process_launcher_delegate.get_and_clear_adjust_count()); 96 EXPECT_EQ(1u, service_process_launcher_delegate.get_and_clear_adjust_count());
119 } 97 }
120 98
121 } // namespace 99 } // namespace
122 } // namespace service_manager 100 } // namespace service_manager
OLDNEW
« no previous file with comments | « services/service_manager/public/cpp/test/run_all_service_tests.cc ('k') | services/ui/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698