| 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_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" |
| 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_service_manager.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/mus_client.h" |
| 23 #include "ui/views/mus/test_utils.h" |
| 23 #include "ui/views/test/platform_test_helper.h" | 24 #include "ui/views/test/platform_test_helper.h" |
| 25 #include "ui/views/test/views_test_helper_aura.h" |
| 24 #include "ui/views/views_delegate.h" | 26 #include "ui/views/views_delegate.h" |
| 25 | 27 |
| 26 namespace views { | 28 namespace views { |
| 27 namespace { | 29 namespace { |
| 28 | 30 |
| 29 void EnsureCommandLineSwitch(const std::string& name) { | 31 void EnsureCommandLineSwitch(const std::string& name) { |
| 30 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 32 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 31 if (!cmd_line->HasSwitch(name)) | 33 if (!cmd_line->HasSwitch(name)) |
| 32 cmd_line->AppendSwitch(name); | 34 cmd_line->AppendSwitch(name); |
| 33 } | 35 } |
| 34 | 36 |
| 35 class DefaultService : public service_manager::Service { | 37 class DefaultService : public service_manager::Service { |
| 36 public: | 38 public: |
| 37 DefaultService() {} | 39 DefaultService() {} |
| 38 ~DefaultService() override {} | 40 ~DefaultService() override {} |
| 39 | 41 |
| 40 private: | 42 private: |
| 41 DISALLOW_COPY_AND_ASSIGN(DefaultService); | 43 DISALLOW_COPY_AND_ASSIGN(DefaultService); |
| 42 }; | 44 }; |
| 43 | 45 |
| 44 class PlatformTestHelperMus : public PlatformTestHelper { | 46 class PlatformTestHelperMus : public PlatformTestHelper { |
| 45 public: | 47 public: |
| 46 PlatformTestHelperMus(service_manager::Connector* connector, | 48 PlatformTestHelperMus(service_manager::Connector* connector, |
| 47 const service_manager::Identity& identity) { | 49 const service_manager::Identity& identity) { |
| 48 // It is necessary to recreate the WindowManagerConnection for each test, | 50 // It is necessary to recreate the MusClient for each test, |
| 49 // since a new MessageLoop is created for each test. | 51 // since a new MessageLoop is created for each test. |
| 50 connection_ = WindowManagerConnection::Create(connector, identity); | 52 mus_client_ = test::MusClientTestApi::Create(connector, identity); |
| 51 } | 53 } |
| 52 ~PlatformTestHelperMus() override {} | 54 ~PlatformTestHelperMus() override {} |
| 53 | 55 |
| 56 // PlatformTestHelper: |
| 57 void OnTestHelperCreated(ViewsTestHelper* helper) override { |
| 58 static_cast<ViewsTestHelperAura*>(helper)->EnableMusWithWindowTreeClient( |
| 59 mus_client_->window_tree_client()); |
| 60 } |
| 61 |
| 54 private: | 62 private: |
| 55 std::unique_ptr<WindowManagerConnection> connection_; | 63 std::unique_ptr<MusClient> mus_client_; |
| 56 | 64 |
| 57 DISALLOW_COPY_AND_ASSIGN(PlatformTestHelperMus); | 65 DISALLOW_COPY_AND_ASSIGN(PlatformTestHelperMus); |
| 58 }; | 66 }; |
| 59 | 67 |
| 60 std::unique_ptr<PlatformTestHelper> CreatePlatformTestHelper( | 68 std::unique_ptr<PlatformTestHelper> CreatePlatformTestHelper( |
| 61 const service_manager::Identity& identity, | 69 const service_manager::Identity& identity, |
| 62 const base::Callback<service_manager::Connector*(void)>& callback) { | 70 const base::Callback<service_manager::Connector*(void)>& callback) { |
| 63 return base::MakeUnique<PlatformTestHelperMus>(callback.Run(), identity); | 71 return base::MakeUnique<PlatformTestHelperMus>(callback.Run(), identity); |
| 64 } | 72 } |
| 65 | 73 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 std::unique_ptr<service_manager::BackgroundServiceManager> | 162 std::unique_ptr<service_manager::BackgroundServiceManager> |
| 155 background_service_manager_; | 163 background_service_manager_; |
| 156 std::unique_ptr<service_manager::ServiceContext> service_manager_connection_; | 164 std::unique_ptr<service_manager::ServiceContext> service_manager_connection_; |
| 157 std::unique_ptr<DefaultService> service_; | 165 std::unique_ptr<DefaultService> service_; |
| 158 std::unique_ptr<service_manager::Connector> service_manager_connector_; | 166 std::unique_ptr<service_manager::Connector> service_manager_connector_; |
| 159 service_manager::Identity service_manager_identity_; | 167 service_manager::Identity service_manager_identity_; |
| 160 | 168 |
| 161 DISALLOW_COPY_AND_ASSIGN(ServiceManagerConnection); | 169 DISALLOW_COPY_AND_ASSIGN(ServiceManagerConnection); |
| 162 }; | 170 }; |
| 163 | 171 |
| 164 ViewsMusTestSuite::ViewsMusTestSuite(int argc, char** argv) | 172 ViewsAuraMusTestSuite::ViewsAuraMusTestSuite(int argc, char** argv) |
| 165 : ViewsTestSuite(argc, argv) {} | 173 : ViewsTestSuite(argc, argv) {} |
| 166 | 174 |
| 167 ViewsMusTestSuite::~ViewsMusTestSuite() {} | 175 ViewsAuraMusTestSuite::~ViewsAuraMusTestSuite() {} |
| 168 | 176 |
| 169 void ViewsMusTestSuite::Initialize() { | 177 void ViewsAuraMusTestSuite::Initialize() { |
| 170 PlatformTestHelper::SetIsMus(); | 178 PlatformTestHelper::SetIsMus(); |
| 171 // Let other services know that we're running in tests. Do this with a | 179 // Let other services know that we're running in tests. Do this with a |
| 172 // command line flag to avoid making blocking calls to other processes for | 180 // command line flag to avoid making blocking calls to other processes for |
| 173 // setup for tests (e.g. to unlock the screen in the window manager). | 181 // setup for tests (e.g. to unlock the screen in the window manager). |
| 174 EnsureCommandLineSwitch(ui::switches::kUseTestConfig); | 182 EnsureCommandLineSwitch(ui::switches::kUseTestConfig); |
| 175 | 183 |
| 176 ViewsTestSuite::Initialize(); | 184 ViewsTestSuite::Initialize(); |
| 177 service_manager_connections_ = base::MakeUnique<ServiceManagerConnection>(); | 185 service_manager_connections_ = base::MakeUnique<ServiceManagerConnection>(); |
| 178 } | 186 } |
| 179 | 187 |
| 180 void ViewsMusTestSuite::Shutdown() { | 188 void ViewsAuraMusTestSuite::Shutdown() { |
| 181 service_manager_connections_.reset(); | 189 service_manager_connections_.reset(); |
| 182 ViewsTestSuite::Shutdown(); | 190 ViewsTestSuite::Shutdown(); |
| 183 } | 191 } |
| 184 | 192 |
| 185 } // namespace views | 193 } // namespace views |
| OLD | NEW |