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

Side by Side Diff: ui/views/mus/views_mus_test_suite.cc

Issue 2651953002: Revert of [Service Manager] Get rid of dynamic service discovery (Closed)
Patch Set: 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
« no previous file with comments | « ui/views/mus/run_all_unittests_mus.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/views/mus/views_mus_test_suite.h" 5 #include "ui/views/mus/views_mus_test_suite.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
15 #include "base/threading/simple_thread.h" 15 #include "base/threading/simple_thread.h"
16 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
17 #include "mojo/edk/embedder/embedder.h"
18 #include "mojo/edk/embedder/scoped_ipc_support.h"
19 #include "services/catalog/catalog.h"
20 #include "services/service_manager/background/background_service_manager.h" 17 #include "services/service_manager/background/background_service_manager.h"
21 #include "services/service_manager/public/cpp/connector.h" 18 #include "services/service_manager/public/cpp/connector.h"
22 #include "services/service_manager/public/cpp/service.h" 19 #include "services/service_manager/public/cpp/service.h"
23 #include "services/service_manager/public/cpp/service_context.h" 20 #include "services/service_manager/public/cpp/service_context.h"
24 #include "services/ui/common/switches.h" 21 #include "services/ui/common/switches.h"
25 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/aura/mus/window_tree_host_mus.h" 23 #include "ui/aura/mus/window_tree_host_mus.h"
27 #include "ui/aura/test/env_test_helper.h" 24 #include "ui/aura/test/env_test_helper.h"
28 #include "ui/aura/window.h" 25 #include "ui/aura/window.h"
29 #include "ui/gl/gl_switches.h" 26 #include "ui/gl/gl_switches.h"
30 #include "ui/views/mus/desktop_window_tree_host_mus.h" 27 #include "ui/views/mus/desktop_window_tree_host_mus.h"
31 #include "ui/views/mus/mus_client.h" 28 #include "ui/views/mus/mus_client.h"
32 #include "ui/views/mus/test_utils.h" 29 #include "ui/views/mus/test_utils.h"
33 #include "ui/views/test/platform_test_helper.h" 30 #include "ui/views/test/platform_test_helper.h"
34 #include "ui/views/test/views_test_helper_aura.h" 31 #include "ui/views/test/views_test_helper_aura.h"
35 #include "ui/views/views_delegate.h" 32 #include "ui/views/views_delegate.h"
36 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 33 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
37 34
38 namespace views { 35 namespace views {
39 namespace { 36 namespace {
40 37
41 const base::FilePath::CharType kCatalogFilename[] =
42 FILE_PATH_LITERAL("views_mus_tests_catalog.json");
43
44 void EnsureCommandLineSwitch(const std::string& name) { 38 void EnsureCommandLineSwitch(const std::string& name) {
45 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 39 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
46 if (!cmd_line->HasSwitch(name)) 40 if (!cmd_line->HasSwitch(name))
47 cmd_line->AppendSwitch(name); 41 cmd_line->AppendSwitch(name);
48 } 42 }
49 43
50 class DefaultService : public service_manager::Service { 44 class DefaultService : public service_manager::Service {
51 public: 45 public:
52 DefaultService() {} 46 DefaultService() {}
53 ~DefaultService() override {} 47 ~DefaultService() override {}
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 const service_manager::Identity& identity, 92 const service_manager::Identity& identity,
99 const base::Callback<service_manager::Connector*(void)>& callback) { 93 const base::Callback<service_manager::Connector*(void)>& callback) {
100 return base::MakeUnique<PlatformTestHelperMus>(callback.Run(), identity); 94 return base::MakeUnique<PlatformTestHelperMus>(callback.Run(), identity);
101 } 95 }
102 96
103 } // namespace 97 } // namespace
104 98
105 class ServiceManagerConnection { 99 class ServiceManagerConnection {
106 public: 100 public:
107 ServiceManagerConnection() 101 ServiceManagerConnection()
108 : thread_("Persistent service_manager connections"), 102 : thread_("Persistent service_manager connections") {
109 ipc_thread_("IPC thread") {
110 catalog::Catalog::LoadDefaultCatalogManifest(
111 base::FilePath(kCatalogFilename));
112 mojo::edk::Init();
113 ipc_thread_.StartWithOptions(
114 base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
115 ipc_support_ = base::MakeUnique<mojo::edk::ScopedIPCSupport>(
116 ipc_thread_.task_runner(),
117 mojo::edk::ScopedIPCSupport::ShutdownPolicy::CLEAN);
118
119 base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC, 103 base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC,
120 base::WaitableEvent::InitialState::NOT_SIGNALED); 104 base::WaitableEvent::InitialState::NOT_SIGNALED);
121 base::Thread::Options options; 105 base::Thread::Options options;
122 thread_.StartWithOptions(options); 106 thread_.StartWithOptions(options);
123 thread_.task_runner()->PostTask( 107 thread_.task_runner()->PostTask(
124 FROM_HERE, base::Bind(&ServiceManagerConnection::SetUpConnections, 108 FROM_HERE, base::Bind(&ServiceManagerConnection::SetUpConnections,
125 base::Unretained(this), &wait)); 109 base::Unretained(this), &wait));
126 wait.Wait(); 110 wait.Wait();
127 111
128 // WindowManagerConnection cannot be created from here yet, although the 112 // WindowManagerConnection cannot be created from here yet, although the
(...skipping 29 matching lines...) Expand all
158 return service_manager_connector_.get(); 142 return service_manager_connector_.get();
159 } 143 }
160 144
161 void CloneConnector(base::WaitableEvent* wait) { 145 void CloneConnector(base::WaitableEvent* wait) {
162 service_manager_connector_ = context_->connector()->Clone(); 146 service_manager_connector_ = context_->connector()->Clone();
163 wait->Signal(); 147 wait->Signal();
164 } 148 }
165 149
166 void SetUpConnections(base::WaitableEvent* wait) { 150 void SetUpConnections(base::WaitableEvent* wait) {
167 background_service_manager_ = 151 background_service_manager_ =
168 base::MakeUnique<service_manager::BackgroundServiceManager>( 152 base::MakeUnique<service_manager::BackgroundServiceManager>();
169 nullptr, nullptr); 153 background_service_manager_->Init(nullptr);
170 service_manager::mojom::ServicePtr service;
171 context_ = base::MakeUnique<service_manager::ServiceContext>( 154 context_ = base::MakeUnique<service_manager::ServiceContext>(
172 base::MakeUnique<DefaultService>(), 155 base::MakeUnique<DefaultService>(),
173 service_manager::mojom::ServiceRequest(&service)); 156 background_service_manager_->CreateServiceRequest(GetTestName()));
174 background_service_manager_->RegisterService(
175 service_manager::Identity(
176 GetTestName(), service_manager::mojom::kRootUserID),
177 std::move(service), nullptr);
178 157
179 // ui/views/mus requires a WindowManager running, so launch test_wm. 158 // ui/views/mus requires a WindowManager running, so launch test_wm.
180 service_manager::Connector* connector = context_->connector(); 159 service_manager::Connector* connector = context_->connector();
181 connector->Connect("test_wm"); 160 connector->Connect("test_wm");
182 service_manager_connector_ = connector->Clone(); 161 service_manager_connector_ = connector->Clone();
183 service_manager_identity_ = context_->identity(); 162 service_manager_identity_ = context_->identity();
184 wait->Signal(); 163 wait->Signal();
185 } 164 }
186 165
187 void TearDownConnections(base::WaitableEvent* wait) { 166 void TearDownConnections(base::WaitableEvent* wait) {
188 context_.reset(); 167 context_.reset();
189 wait->Signal(); 168 wait->Signal();
190 } 169 }
191 170
192 // Returns the name of the test executable, e.g. 171 // Returns the name of the test executable, e.g.
193 // "views_mus_unittests". 172 // "views_mus_unittests".
194 std::string GetTestName() { 173 std::string GetTestName() {
195 base::FilePath executable = base::CommandLine::ForCurrentProcess() 174 base::FilePath executable = base::CommandLine::ForCurrentProcess()
196 ->GetProgram() 175 ->GetProgram()
197 .BaseName() 176 .BaseName()
198 .RemoveExtension(); 177 .RemoveExtension();
199 return std::string("") + executable.MaybeAsASCII(); 178 return std::string("") + executable.MaybeAsASCII();
200 } 179 }
201 180
202 base::Thread thread_; 181 base::Thread thread_;
203 base::Thread ipc_thread_;
204 std::unique_ptr<mojo::edk::ScopedIPCSupport> ipc_support_;
205 std::unique_ptr<service_manager::BackgroundServiceManager> 182 std::unique_ptr<service_manager::BackgroundServiceManager>
206 background_service_manager_; 183 background_service_manager_;
207 std::unique_ptr<service_manager::ServiceContext> context_; 184 std::unique_ptr<service_manager::ServiceContext> context_;
208 std::unique_ptr<service_manager::Connector> service_manager_connector_; 185 std::unique_ptr<service_manager::Connector> service_manager_connector_;
209 service_manager::Identity service_manager_identity_; 186 service_manager::Identity service_manager_identity_;
210 187
211 DISALLOW_COPY_AND_ASSIGN(ServiceManagerConnection); 188 DISALLOW_COPY_AND_ASSIGN(ServiceManagerConnection);
212 }; 189 };
213 190
214 ViewsMusTestSuite::ViewsMusTestSuite(int argc, char** argv) 191 ViewsMusTestSuite::ViewsMusTestSuite(int argc, char** argv)
(...skipping 13 matching lines...) Expand all
228 ViewsTestSuite::Initialize(); 205 ViewsTestSuite::Initialize();
229 service_manager_connections_ = base::MakeUnique<ServiceManagerConnection>(); 206 service_manager_connections_ = base::MakeUnique<ServiceManagerConnection>();
230 } 207 }
231 208
232 void ViewsMusTestSuite::Shutdown() { 209 void ViewsMusTestSuite::Shutdown() {
233 service_manager_connections_.reset(); 210 service_manager_connections_.reset();
234 ViewsTestSuite::Shutdown(); 211 ViewsTestSuite::Shutdown();
235 } 212 }
236 213
237 } // namespace views 214 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/run_all_unittests_mus.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698