| 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_aura_mus_test_suite.h" | 5 #include "ui/views/mus/views_aura_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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 32 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 33 if (!cmd_line->HasSwitch(name)) | 33 if (!cmd_line->HasSwitch(name)) |
| 34 cmd_line->AppendSwitch(name); | 34 cmd_line->AppendSwitch(name); |
| 35 } | 35 } |
| 36 | 36 |
| 37 class DefaultService : public service_manager::Service { | 37 class DefaultService : public service_manager::Service { |
| 38 public: | 38 public: |
| 39 DefaultService() {} | 39 DefaultService() {} |
| 40 ~DefaultService() override {} | 40 ~DefaultService() override {} |
| 41 | 41 |
| 42 // service_manager::Service: |
| 43 bool OnConnect(const service_manager::ServiceInfo& remote_info, |
| 44 service_manager::InterfaceRegistry* registry) override { |
| 45 return false; |
| 46 } |
| 47 |
| 42 private: | 48 private: |
| 43 DISALLOW_COPY_AND_ASSIGN(DefaultService); | 49 DISALLOW_COPY_AND_ASSIGN(DefaultService); |
| 44 }; | 50 }; |
| 45 | 51 |
| 46 class PlatformTestHelperMus : public PlatformTestHelper { | 52 class PlatformTestHelperMus : public PlatformTestHelper { |
| 47 public: | 53 public: |
| 48 PlatformTestHelperMus(service_manager::Connector* connector, | 54 PlatformTestHelperMus(service_manager::Connector* connector, |
| 49 const service_manager::Identity& identity) { | 55 const service_manager::Identity& identity) { |
| 50 // It is necessary to recreate the MusClient for each test, | 56 // It is necessary to recreate the MusClient for each test, |
| 51 // since a new MessageLoop is created for each test. | 57 // since a new MessageLoop is created for each test. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 base::WaitableEvent::InitialState::NOT_SIGNALED); | 119 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 114 thread_.task_runner()->PostTask( | 120 thread_.task_runner()->PostTask( |
| 115 FROM_HERE, base::Bind(&ServiceManagerConnection::CloneConnector, | 121 FROM_HERE, base::Bind(&ServiceManagerConnection::CloneConnector, |
| 116 base::Unretained(this), &wait)); | 122 base::Unretained(this), &wait)); |
| 117 wait.Wait(); | 123 wait.Wait(); |
| 118 DCHECK(service_manager_connector_); | 124 DCHECK(service_manager_connector_); |
| 119 return service_manager_connector_.get(); | 125 return service_manager_connector_.get(); |
| 120 } | 126 } |
| 121 | 127 |
| 122 void CloneConnector(base::WaitableEvent* wait) { | 128 void CloneConnector(base::WaitableEvent* wait) { |
| 123 service_manager_connector_ = | 129 service_manager_connector_ = context_->connector()->Clone(); |
| 124 service_manager_connection_->connector()->Clone(); | |
| 125 wait->Signal(); | 130 wait->Signal(); |
| 126 } | 131 } |
| 127 | 132 |
| 128 void SetUpConnections(base::WaitableEvent* wait) { | 133 void SetUpConnections(base::WaitableEvent* wait) { |
| 129 background_service_manager_ = | 134 background_service_manager_ = |
| 130 base::MakeUnique<service_manager::BackgroundServiceManager>(); | 135 base::MakeUnique<service_manager::BackgroundServiceManager>(); |
| 131 background_service_manager_->Init(nullptr); | 136 background_service_manager_->Init(nullptr); |
| 132 service_ = base::MakeUnique<DefaultService>(); | 137 context_ = |
| 133 service_manager_connection_ = | |
| 134 base::MakeUnique<service_manager::ServiceContext>( | 138 base::MakeUnique<service_manager::ServiceContext>( |
| 135 service_.get(), | 139 base::MakeUnique<DefaultService>(), |
| 136 background_service_manager_->CreateServiceRequest(GetTestName())); | 140 background_service_manager_->CreateServiceRequest(GetTestName())); |
| 137 | 141 |
| 138 // ui/views/mus requires a WindowManager running, so launch test_wm. | 142 // ui/views/mus requires a WindowManager running, so launch test_wm. |
| 139 service_manager::Connector* connector = | 143 service_manager::Connector* connector = context_->connector(); |
| 140 service_manager_connection_->connector(); | |
| 141 connector->Connect("service:test_wm"); | 144 connector->Connect("service:test_wm"); |
| 142 service_manager_connector_ = connector->Clone(); | 145 service_manager_connector_ = connector->Clone(); |
| 143 service_manager_identity_ = service_manager_connection_->identity(); | 146 service_manager_identity_ = context_->identity(); |
| 144 wait->Signal(); | 147 wait->Signal(); |
| 145 } | 148 } |
| 146 | 149 |
| 147 void TearDownConnections(base::WaitableEvent* wait) { | 150 void TearDownConnections(base::WaitableEvent* wait) { |
| 148 service_manager_connection_.reset(); | 151 context_.reset(); |
| 149 wait->Signal(); | 152 wait->Signal(); |
| 150 } | 153 } |
| 151 | 154 |
| 152 // Returns the name of the test executable, e.g. "exe:views_mus_unittests". | 155 // Returns the name of the test executable, e.g. "exe:views_mus_unittests". |
| 153 std::string GetTestName() { | 156 std::string GetTestName() { |
| 154 base::FilePath executable = base::CommandLine::ForCurrentProcess() | 157 base::FilePath executable = base::CommandLine::ForCurrentProcess() |
| 155 ->GetProgram() | 158 ->GetProgram() |
| 156 .BaseName() | 159 .BaseName() |
| 157 .RemoveExtension(); | 160 .RemoveExtension(); |
| 158 return std::string("exe:") + executable.MaybeAsASCII(); | 161 return std::string("exe:") + executable.MaybeAsASCII(); |
| 159 } | 162 } |
| 160 | 163 |
| 161 base::Thread thread_; | 164 base::Thread thread_; |
| 162 std::unique_ptr<service_manager::BackgroundServiceManager> | 165 std::unique_ptr<service_manager::BackgroundServiceManager> |
| 163 background_service_manager_; | 166 background_service_manager_; |
| 164 std::unique_ptr<service_manager::ServiceContext> service_manager_connection_; | 167 std::unique_ptr<service_manager::ServiceContext> context_; |
| 165 std::unique_ptr<DefaultService> service_; | |
| 166 std::unique_ptr<service_manager::Connector> service_manager_connector_; | 168 std::unique_ptr<service_manager::Connector> service_manager_connector_; |
| 167 service_manager::Identity service_manager_identity_; | 169 service_manager::Identity service_manager_identity_; |
| 168 | 170 |
| 169 DISALLOW_COPY_AND_ASSIGN(ServiceManagerConnection); | 171 DISALLOW_COPY_AND_ASSIGN(ServiceManagerConnection); |
| 170 }; | 172 }; |
| 171 | 173 |
| 172 ViewsAuraMusTestSuite::ViewsAuraMusTestSuite(int argc, char** argv) | 174 ViewsAuraMusTestSuite::ViewsAuraMusTestSuite(int argc, char** argv) |
| 173 : ViewsTestSuite(argc, argv) {} | 175 : ViewsTestSuite(argc, argv) {} |
| 174 | 176 |
| 175 ViewsAuraMusTestSuite::~ViewsAuraMusTestSuite() {} | 177 ViewsAuraMusTestSuite::~ViewsAuraMusTestSuite() {} |
| 176 | 178 |
| 177 void ViewsAuraMusTestSuite::Initialize() { | 179 void ViewsAuraMusTestSuite::Initialize() { |
| 178 PlatformTestHelper::SetIsMus(); | 180 PlatformTestHelper::SetIsMus(); |
| 179 // Let other services know that we're running in tests. Do this with a | 181 // Let other services know that we're running in tests. Do this with a |
| 180 // command line flag to avoid making blocking calls to other processes for | 182 // command line flag to avoid making blocking calls to other processes for |
| 181 // setup for tests (e.g. to unlock the screen in the window manager). | 183 // setup for tests (e.g. to unlock the screen in the window manager). |
| 182 EnsureCommandLineSwitch(ui::switches::kUseTestConfig); | 184 EnsureCommandLineSwitch(ui::switches::kUseTestConfig); |
| 183 | 185 |
| 184 ViewsTestSuite::Initialize(); | 186 ViewsTestSuite::Initialize(); |
| 185 service_manager_connections_ = base::MakeUnique<ServiceManagerConnection>(); | 187 service_manager_connections_ = base::MakeUnique<ServiceManagerConnection>(); |
| 186 } | 188 } |
| 187 | 189 |
| 188 void ViewsAuraMusTestSuite::Shutdown() { | 190 void ViewsAuraMusTestSuite::Shutdown() { |
| 189 service_manager_connections_.reset(); | 191 service_manager_connections_.reset(); |
| 190 ViewsTestSuite::Shutdown(); | 192 ViewsTestSuite::Shutdown(); |
| 191 } | 193 } |
| 192 | 194 |
| 193 } // namespace views | 195 } // namespace views |
| OLD | NEW |