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

Side by Side Diff: services/service_manager/public/cpp/lib/service_test.cc

Issue 2860023002: Eliminate lib directory for service manager client lib. (Closed)
Patch Set: Created 3 years, 7 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
(Empty)
1 // Copyright 2016 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 #include "services/service_manager/public/cpp/service_test.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h"
10 #include "base/threading/thread.h"
11 #include "base/values.h"
12 #include "mojo/edk/embedder/embedder.h"
13 #include "mojo/edk/embedder/scoped_ipc_support.h"
14 #include "services/service_manager/background/background_service_manager.h"
15 #include "services/service_manager/public/cpp/service.h"
16 #include "services/service_manager/public/cpp/service_context.h"
17
18 namespace service_manager {
19 namespace test {
20
21 ServiceTestClient::ServiceTestClient(ServiceTest* test) : test_(test) {}
22
23 ServiceTestClient::~ServiceTestClient() {}
24
25 void ServiceTestClient::OnStart() {
26 test_->OnStartCalled(context()->connector(), context()->identity().name(),
27 context()->identity().user_id());
28 }
29
30 void ServiceTestClient::OnBindInterface(
31 const BindSourceInfo& source_info,
32 const std::string& interface_name,
33 mojo::ScopedMessagePipeHandle interface_pipe) {}
34
35 ServiceTest::ServiceTest() {}
36
37 ServiceTest::ServiceTest(const std::string& test_name, bool init_edk)
38 : test_name_(test_name), init_edk_(init_edk) {}
39
40 ServiceTest::~ServiceTest() {}
41
42 void ServiceTest::InitTestName(const std::string& test_name) {
43 DCHECK(test_name_.empty());
44 test_name_ = test_name;
45 }
46
47 std::unique_ptr<Service> ServiceTest::CreateService() {
48 return base::MakeUnique<ServiceTestClient>(this);
49 }
50
51 std::unique_ptr<base::MessageLoop> ServiceTest::CreateMessageLoop() {
52 return base::MakeUnique<base::MessageLoop>();
53 }
54
55 void ServiceTest::OnStartCalled(Connector* connector,
56 const std::string& name,
57 const std::string& user_id) {
58 DCHECK_EQ(connector_, connector);
59 initialize_name_ = name;
60 initialize_userid_ = user_id;
61 initialize_called_.Run();
62 }
63
64 void ServiceTest::SetUp() {
65 message_loop_ = CreateMessageLoop();
66
67 DCHECK(!init_edk_);
68
69 background_service_manager_ =
70 base::MakeUnique<service_manager::BackgroundServiceManager>(
71 nullptr, nullptr);
72
73 // Create the service manager connection. We don't proceed until we get our
74 // Service's OnStart() method is called.
75 base::RunLoop run_loop;
76 base::MessageLoop::ScopedNestableTaskAllower allow(
77 base::MessageLoop::current());
78 initialize_called_ = run_loop.QuitClosure();
79
80 mojom::ServicePtr service;
81 context_ = base::MakeUnique<ServiceContext>(CreateService(),
82 mojom::ServiceRequest(&service));
83 background_service_manager_->RegisterService(
84 Identity(test_name_, mojom::kRootUserID), std::move(service), nullptr);
85 connector_ = context_->connector();
86 run_loop.Run();
87 }
88
89 void ServiceTest::TearDown() {
90 background_service_manager_.reset();
91 context_.reset();
92 message_loop_.reset();
93 }
94
95 } // namespace test
96 } // namespace service_manager
OLDNEW
« no previous file with comments | « services/service_manager/public/cpp/lib/service_runner.cc ('k') | services/service_manager/public/cpp/service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698