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

Side by Side Diff: services/service_manager/public/cpp/lib/service_test.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 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
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, bool init_edk) 34 ServiceTest::ServiceTest(const std::string& test_name)
35 : test_name_(test_name), init_edk_(init_edk) {} 35 : test_name_(test_name) {}
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);
(...skipping 10 matching lines...) Expand all
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 auto init_params = base::MakeUnique<BackgroundServiceManager::InitParams>(); 65 auto init_params = base::MakeUnique<BackgroundServiceManager::InitParams>();
66 init_params->init_edk = init_edk_; 66 // Because this is testing utility, so expect Mojo is initialized in
67 // testing framework already. Thus, do not initialize mojo edk in
68 // BackgroundServiceManager.
69 init_params->init_edk = false;
67 background_service_manager_->Init(std::move(init_params)); 70 background_service_manager_->Init(std::move(init_params));
68 71
69 // Create the service manager connection. We don't proceed until we get our 72 // Create the service manager connection. We don't proceed until we get our
70 // Service's OnStart() method is called. 73 // Service's OnStart() method is called.
71 base::RunLoop run_loop; 74 base::RunLoop run_loop;
72 base::MessageLoop::ScopedNestableTaskAllower allow( 75 base::MessageLoop::ScopedNestableTaskAllower allow(
73 base::MessageLoop::current()); 76 base::MessageLoop::current());
74 initialize_called_ = run_loop.QuitClosure(); 77 initialize_called_ = run_loop.QuitClosure();
75 78
76 context_.reset(new ServiceContext( 79 context_.reset(new ServiceContext(
77 CreateService(), 80 CreateService(),
78 background_service_manager_->CreateServiceRequest(test_name_))); 81 background_service_manager_->CreateServiceRequest(test_name_)));
79 connector_ = context_->connector(); 82 connector_ = context_->connector();
80 83
81 run_loop.Run(); 84 run_loop.Run();
82 } 85 }
83 86
84 void ServiceTest::TearDown() { 87 void ServiceTest::TearDown() {
85 background_service_manager_.reset(); 88 background_service_manager_.reset();
86 message_loop_.reset(); 89 message_loop_.reset();
87 context_.reset(); 90 context_.reset();
88 } 91 }
89 92
90 } // namespace test 93 } // namespace test
91 } // namespace service_manager 94 } // namespace service_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698