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 "services/service_manager/background/background_service_manager.h" | 10 #include "services/service_manager/background/background_service_manager.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 } | 24 } |
25 | 25 |
26 bool ServiceTestClient::OnConnect(const ServiceInfo& remote_info, | 26 bool ServiceTestClient::OnConnect(const ServiceInfo& remote_info, |
27 InterfaceRegistry* registry) { | 27 InterfaceRegistry* registry) { |
28 return false; | 28 return false; |
29 } | 29 } |
30 | 30 |
31 | 31 |
32 ServiceTest::ServiceTest() {} | 32 ServiceTest::ServiceTest() {} |
33 | 33 |
34 ServiceTest::ServiceTest(const std::string& test_name) | 34 ServiceTest::ServiceTest(const std::string& test_name, bool init_edk) |
35 : test_name_(test_name) {} | 35 : test_name_(test_name), init_edk_(init_edk) {} |
36 | 36 |
37 ServiceTest::~ServiceTest() {} | 37 ServiceTest::~ServiceTest() {} |
38 | 38 |
39 void ServiceTest::InitTestName(const std::string& test_name) { | 39 void ServiceTest::InitTestName(const std::string& test_name) { |
40 DCHECK(test_name_.empty()); | 40 DCHECK(test_name_.empty()); |
41 test_name_ = test_name; | 41 test_name_ = test_name; |
42 } | 42 } |
43 | 43 |
44 std::unique_ptr<Service> ServiceTest::CreateService() { | 44 std::unique_ptr<Service> ServiceTest::CreateService() { |
45 return base::MakeUnique<ServiceTestClient>(this); | 45 return base::MakeUnique<ServiceTestClient>(this); |
46 } | 46 } |
47 | 47 |
48 std::unique_ptr<base::MessageLoop> ServiceTest::CreateMessageLoop() { | 48 std::unique_ptr<base::MessageLoop> ServiceTest::CreateMessageLoop() { |
49 return base::MakeUnique<base::MessageLoop>(); | 49 return base::MakeUnique<base::MessageLoop>(); |
50 } | 50 } |
51 | 51 |
52 void ServiceTest::OnStartCalled(Connector* connector, | 52 void ServiceTest::OnStartCalled(Connector* connector, |
53 const std::string& name, | 53 const std::string& name, |
54 const std::string& user_id) { | 54 const std::string& user_id) { |
55 DCHECK_EQ(connector_, connector); | 55 DCHECK_EQ(connector_, connector); |
56 initialize_name_ = name; | 56 initialize_name_ = name; |
57 initialize_userid_ = user_id; | 57 initialize_userid_ = user_id; |
58 initialize_called_.Run(); | 58 initialize_called_.Run(); |
59 } | 59 } |
60 | 60 |
61 void ServiceTest::SetUp() { | 61 void ServiceTest::SetUp() { |
62 message_loop_ = CreateMessageLoop(); | 62 message_loop_ = CreateMessageLoop(); |
63 background_service_manager_.reset( | 63 background_service_manager_.reset( |
64 new service_manager::BackgroundServiceManager); | 64 new service_manager::BackgroundServiceManager); |
65 background_service_manager_->Init(nullptr); | 65 auto init_params = base::MakeUnique<BackgroundServiceManager::InitParams>(); |
| 66 init_params->init_edk = init_edk_; |
| 67 background_service_manager_->Init(std::move(init_params)); |
66 | 68 |
67 // 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 |
68 // Service's OnStart() method is called. | 70 // Service's OnStart() method is called. |
69 base::RunLoop run_loop; | 71 base::RunLoop run_loop; |
70 base::MessageLoop::ScopedNestableTaskAllower allow( | 72 base::MessageLoop::ScopedNestableTaskAllower allow( |
71 base::MessageLoop::current()); | 73 base::MessageLoop::current()); |
72 initialize_called_ = run_loop.QuitClosure(); | 74 initialize_called_ = run_loop.QuitClosure(); |
73 | 75 |
74 context_.reset(new ServiceContext( | 76 context_.reset(new ServiceContext( |
75 CreateService(), | 77 CreateService(), |
76 background_service_manager_->CreateServiceRequest(test_name_))); | 78 background_service_manager_->CreateServiceRequest(test_name_))); |
77 connector_ = context_->connector(); | 79 connector_ = context_->connector(); |
78 | 80 |
79 run_loop.Run(); | 81 run_loop.Run(); |
80 } | 82 } |
81 | 83 |
82 void ServiceTest::TearDown() { | 84 void ServiceTest::TearDown() { |
83 background_service_manager_.reset(); | 85 background_service_manager_.reset(); |
84 message_loop_.reset(); | 86 message_loop_.reset(); |
85 context_.reset(); | 87 context_.reset(); |
86 } | 88 } |
87 | 89 |
88 } // namespace test | 90 } // namespace test |
89 } // namespace service_manager | 91 } // namespace service_manager |
OLD | NEW |