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