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