OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/public/cpp/service_test.h" | 5 #include "services/service_manager/public/cpp/service_test.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/threading/thread.h" | |
11 #include "mojo/edk/embedder/embedder.h" | |
12 #include "mojo/edk/embedder/scoped_ipc_support.h" | |
13 #include "services/service_manager/background/background_service_manager.h" | 10 #include "services/service_manager/background/background_service_manager.h" |
14 #include "services/service_manager/public/cpp/service.h" | 11 #include "services/service_manager/public/cpp/service.h" |
15 #include "services/service_manager/public/cpp/service_context.h" | 12 #include "services/service_manager/public/cpp/service_context.h" |
16 | 13 |
17 namespace service_manager { | 14 namespace service_manager { |
18 namespace test { | 15 namespace test { |
19 | 16 |
20 ServiceTestClient::ServiceTestClient(ServiceTest* test) : test_(test) {} | 17 ServiceTestClient::ServiceTestClient(ServiceTest* test) : test_(test) {} |
21 | 18 |
22 ServiceTestClient::~ServiceTestClient() {} | 19 ServiceTestClient::~ServiceTestClient() {} |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 const std::string& name, | 53 const std::string& name, |
57 const std::string& user_id) { | 54 const std::string& user_id) { |
58 DCHECK_EQ(connector_, connector); | 55 DCHECK_EQ(connector_, connector); |
59 initialize_name_ = name; | 56 initialize_name_ = name; |
60 initialize_userid_ = user_id; | 57 initialize_userid_ = user_id; |
61 initialize_called_.Run(); | 58 initialize_called_.Run(); |
62 } | 59 } |
63 | 60 |
64 void ServiceTest::SetUp() { | 61 void ServiceTest::SetUp() { |
65 message_loop_ = CreateMessageLoop(); | 62 message_loop_ = CreateMessageLoop(); |
66 | 63 background_service_manager_.reset( |
67 DCHECK(!init_edk_); | 64 new service_manager::BackgroundServiceManager); |
68 | 65 auto init_params = base::MakeUnique<BackgroundServiceManager::InitParams>(); |
69 background_service_manager_ = | 66 init_params->init_edk = init_edk_; |
70 base::MakeUnique<service_manager::BackgroundServiceManager>( | 67 background_service_manager_->Init(std::move(init_params)); |
71 nullptr, nullptr); | |
72 | 68 |
73 // Create the service manager connection. We don't proceed until we get our | 69 // Create the service manager connection. We don't proceed until we get our |
74 // Service's OnStart() method is called. | 70 // Service's OnStart() method is called. |
75 base::RunLoop run_loop; | 71 base::RunLoop run_loop; |
76 base::MessageLoop::ScopedNestableTaskAllower allow( | 72 base::MessageLoop::ScopedNestableTaskAllower allow( |
77 base::MessageLoop::current()); | 73 base::MessageLoop::current()); |
78 initialize_called_ = run_loop.QuitClosure(); | 74 initialize_called_ = run_loop.QuitClosure(); |
79 | 75 |
80 mojom::ServicePtr service; | 76 context_.reset(new ServiceContext( |
81 context_ = base::MakeUnique<ServiceContext>(CreateService(), | 77 CreateService(), |
82 mojom::ServiceRequest(&service)); | 78 background_service_manager_->CreateServiceRequest(test_name_))); |
83 background_service_manager_->RegisterService( | |
84 Identity(test_name_, mojom::kRootUserID), std::move(service), nullptr); | |
85 connector_ = context_->connector(); | 79 connector_ = context_->connector(); |
| 80 |
86 run_loop.Run(); | 81 run_loop.Run(); |
87 } | 82 } |
88 | 83 |
89 void ServiceTest::TearDown() { | 84 void ServiceTest::TearDown() { |
90 background_service_manager_.reset(); | 85 background_service_manager_.reset(); |
91 message_loop_.reset(); | 86 message_loop_.reset(); |
92 context_.reset(); | 87 context_.reset(); |
93 } | 88 } |
94 | 89 |
95 } // namespace test | 90 } // namespace test |
96 } // namespace service_manager | 91 } // namespace service_manager |
OLD | NEW |