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

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

Issue 2427443002: Replace remaining shell references with service manager (Closed)
Patch Set: Created 4 years, 2 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/views_mus_test_suite.h ('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/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
14 #include "base/threading/simple_thread.h" 14 #include "base/threading/simple_thread.h"
15 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
16 #include "services/service_manager/background/background_shell.h" 16 #include "services/service_manager/background/background_service_manager.h"
17 #include "services/service_manager/public/cpp/connector.h" 17 #include "services/service_manager/public/cpp/connector.h"
18 #include "services/service_manager/public/cpp/service.h" 18 #include "services/service_manager/public/cpp/service.h"
19 #include "services/service_manager/public/cpp/service_context.h" 19 #include "services/service_manager/public/cpp/service_context.h"
20 #include "services/ui/common/switches.h" 20 #include "services/ui/common/switches.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/views/mus/window_manager_connection.h" 22 #include "ui/views/mus/window_manager_connection.h"
23 #include "ui/views/test/platform_test_helper.h" 23 #include "ui/views/test/platform_test_helper.h"
24 #include "ui/views/views_delegate.h" 24 #include "ui/views/views_delegate.h"
25 25
26 namespace views { 26 namespace views {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 }; 58 };
59 59
60 std::unique_ptr<PlatformTestHelper> CreatePlatformTestHelper( 60 std::unique_ptr<PlatformTestHelper> CreatePlatformTestHelper(
61 const service_manager::Identity& identity, 61 const service_manager::Identity& identity,
62 const base::Callback<service_manager::Connector*(void)>& callback) { 62 const base::Callback<service_manager::Connector*(void)>& callback) {
63 return base::MakeUnique<PlatformTestHelperMus>(callback.Run(), identity); 63 return base::MakeUnique<PlatformTestHelperMus>(callback.Run(), identity);
64 } 64 }
65 65
66 } // namespace 66 } // namespace
67 67
68 class ShellConnection { 68 class ServiceManagerConnection {
69 public: 69 public:
70 ShellConnection() : thread_("Persistent service_manager connections") { 70 ServiceManagerConnection()
71 : thread_("Persistent service_manager connections") {
71 base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC, 72 base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC,
72 base::WaitableEvent::InitialState::NOT_SIGNALED); 73 base::WaitableEvent::InitialState::NOT_SIGNALED);
73 base::Thread::Options options; 74 base::Thread::Options options;
74 thread_.StartWithOptions(options); 75 thread_.StartWithOptions(options);
75 thread_.task_runner()->PostTask( 76 thread_.task_runner()->PostTask(
76 FROM_HERE, base::Bind(&ShellConnection::SetUpConnections, 77 FROM_HERE, base::Bind(&ServiceManagerConnection::SetUpConnections,
77 base::Unretained(this), &wait)); 78 base::Unretained(this), &wait));
78 wait.Wait(); 79 wait.Wait();
79 80
80 // WindowManagerConnection cannot be created from here yet, although the 81 // WindowManagerConnection cannot be created from here yet, although the
81 // connector and identity are available at this point. This is because 82 // connector and identity are available at this point. This is because
82 // WindowManagerConnection needs a ViewsDelegate and a MessageLoop to have 83 // WindowManagerConnection needs a ViewsDelegate and a MessageLoop to have
83 // been installed first. So delay the creation until the necessary 84 // been installed first. So delay the creation until the necessary
84 // dependencies have been met. 85 // dependencies have been met.
85 PlatformTestHelper::set_factory(base::Bind( 86 PlatformTestHelper::set_factory(
86 &CreatePlatformTestHelper, service_manager_identity_, 87 base::Bind(&CreatePlatformTestHelper, service_manager_identity_,
87 base::Bind(&ShellConnection::GetConnector, base::Unretained(this)))); 88 base::Bind(&ServiceManagerConnection::GetConnector,
89 base::Unretained(this))));
88 } 90 }
89 91
90 ~ShellConnection() { 92 ~ServiceManagerConnection() {
91 base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC, 93 base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC,
92 base::WaitableEvent::InitialState::NOT_SIGNALED); 94 base::WaitableEvent::InitialState::NOT_SIGNALED);
93 thread_.task_runner()->PostTask( 95 thread_.task_runner()->PostTask(
94 FROM_HERE, base::Bind(&ShellConnection::TearDownConnections, 96 FROM_HERE, base::Bind(&ServiceManagerConnection::TearDownConnections,
95 base::Unretained(this), &wait)); 97 base::Unretained(this), &wait));
96 wait.Wait(); 98 wait.Wait();
97 } 99 }
98 100
99 private: 101 private:
100 service_manager::Connector* GetConnector() { 102 service_manager::Connector* GetConnector() {
101 service_manager_connector_.reset(); 103 service_manager_connector_.reset();
102 base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC, 104 base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::AUTOMATIC,
103 base::WaitableEvent::InitialState::NOT_SIGNALED); 105 base::WaitableEvent::InitialState::NOT_SIGNALED);
104 thread_.task_runner()->PostTask(FROM_HERE, 106 thread_.task_runner()->PostTask(
105 base::Bind(&ShellConnection::CloneConnector, 107 FROM_HERE, base::Bind(&ServiceManagerConnection::CloneConnector,
106 base::Unretained(this), &wait)); 108 base::Unretained(this), &wait));
107 wait.Wait(); 109 wait.Wait();
108 DCHECK(service_manager_connector_); 110 DCHECK(service_manager_connector_);
109 return service_manager_connector_.get(); 111 return service_manager_connector_.get();
110 } 112 }
111 113
112 void CloneConnector(base::WaitableEvent* wait) { 114 void CloneConnector(base::WaitableEvent* wait) {
113 service_manager_connector_ = 115 service_manager_connector_ =
114 service_manager_connection_->connector()->Clone(); 116 service_manager_connection_->connector()->Clone();
115 wait->Signal(); 117 wait->Signal();
116 } 118 }
117 119
118 void SetUpConnections(base::WaitableEvent* wait) { 120 void SetUpConnections(base::WaitableEvent* wait) {
119 background_shell_ = base::MakeUnique<service_manager::BackgroundShell>(); 121 background_service_manager_ =
120 background_shell_->Init(nullptr); 122 base::MakeUnique<service_manager::BackgroundServiceManager>();
123 background_service_manager_->Init(nullptr);
121 service_ = base::MakeUnique<DefaultService>(); 124 service_ = base::MakeUnique<DefaultService>();
122 service_manager_connection_ = 125 service_manager_connection_ =
123 base::MakeUnique<service_manager::ServiceContext>( 126 base::MakeUnique<service_manager::ServiceContext>(
124 service_.get(), 127 service_.get(),
125 background_shell_->CreateServiceRequest(GetTestName())); 128 background_service_manager_->CreateServiceRequest(GetTestName()));
126 129
127 // ui/views/mus requires a WindowManager running, so launch test_wm. 130 // ui/views/mus requires a WindowManager running, so launch test_wm.
128 service_manager::Connector* connector = 131 service_manager::Connector* connector =
129 service_manager_connection_->connector(); 132 service_manager_connection_->connector();
130 connector->Connect("service:test_wm"); 133 connector->Connect("service:test_wm");
131 service_manager_connector_ = connector->Clone(); 134 service_manager_connector_ = connector->Clone();
132 service_manager_identity_ = service_manager_connection_->identity(); 135 service_manager_identity_ = service_manager_connection_->identity();
133 wait->Signal(); 136 wait->Signal();
134 } 137 }
135 138
136 void TearDownConnections(base::WaitableEvent* wait) { 139 void TearDownConnections(base::WaitableEvent* wait) {
137 service_manager_connection_.reset(); 140 service_manager_connection_.reset();
138 wait->Signal(); 141 wait->Signal();
139 } 142 }
140 143
141 // Returns the name of the test executable, e.g. "exe:views_mus_unittests". 144 // Returns the name of the test executable, e.g. "exe:views_mus_unittests".
142 std::string GetTestName() { 145 std::string GetTestName() {
143 base::FilePath executable = base::CommandLine::ForCurrentProcess() 146 base::FilePath executable = base::CommandLine::ForCurrentProcess()
144 ->GetProgram() 147 ->GetProgram()
145 .BaseName() 148 .BaseName()
146 .RemoveExtension(); 149 .RemoveExtension();
147 return std::string("exe:") + executable.MaybeAsASCII(); 150 return std::string("exe:") + executable.MaybeAsASCII();
148 } 151 }
149 152
150 base::Thread thread_; 153 base::Thread thread_;
151 std::unique_ptr<service_manager::BackgroundShell> background_shell_; 154 std::unique_ptr<service_manager::BackgroundServiceManager>
155 background_service_manager_;
152 std::unique_ptr<service_manager::ServiceContext> service_manager_connection_; 156 std::unique_ptr<service_manager::ServiceContext> service_manager_connection_;
153 std::unique_ptr<DefaultService> service_; 157 std::unique_ptr<DefaultService> service_;
154 std::unique_ptr<service_manager::Connector> service_manager_connector_; 158 std::unique_ptr<service_manager::Connector> service_manager_connector_;
155 service_manager::Identity service_manager_identity_; 159 service_manager::Identity service_manager_identity_;
156 160
157 DISALLOW_COPY_AND_ASSIGN(ShellConnection); 161 DISALLOW_COPY_AND_ASSIGN(ServiceManagerConnection);
158 }; 162 };
159 163
160 ViewsMusTestSuite::ViewsMusTestSuite(int argc, char** argv) 164 ViewsMusTestSuite::ViewsMusTestSuite(int argc, char** argv)
161 : ViewsTestSuite(argc, argv) {} 165 : ViewsTestSuite(argc, argv) {}
162 166
163 ViewsMusTestSuite::~ViewsMusTestSuite() {} 167 ViewsMusTestSuite::~ViewsMusTestSuite() {}
164 168
165 void ViewsMusTestSuite::Initialize() { 169 void ViewsMusTestSuite::Initialize() {
166 PlatformTestHelper::SetIsMus(); 170 PlatformTestHelper::SetIsMus();
167 // Let other services know that we're running in tests. Do this with a 171 // Let other services know that we're running in tests. Do this with a
168 // command line flag to avoid making blocking calls to other processes for 172 // command line flag to avoid making blocking calls to other processes for
169 // setup for tests (e.g. to unlock the screen in the window manager). 173 // setup for tests (e.g. to unlock the screen in the window manager).
170 EnsureCommandLineSwitch(ui::switches::kUseTestConfig); 174 EnsureCommandLineSwitch(ui::switches::kUseTestConfig);
171 175
172 ViewsTestSuite::Initialize(); 176 ViewsTestSuite::Initialize();
173 service_manager_connections_ = base::MakeUnique<ShellConnection>(); 177 service_manager_connections_ = base::MakeUnique<ServiceManagerConnection>();
174 } 178 }
175 179
176 void ViewsMusTestSuite::Shutdown() { 180 void ViewsMusTestSuite::Shutdown() {
177 service_manager_connections_.reset(); 181 service_manager_connections_.reset();
178 ViewsTestSuite::Shutdown(); 182 ViewsTestSuite::Shutdown();
179 } 183 }
180 184
181 } // namespace views 185 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/views_mus_test_suite.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698