| 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 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/threading/simple_thread.h" | 13 #include "base/threading/simple_thread.h" |
| 14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 15 #include "services/shell/background/background_shell.h" | 15 #include "services/shell/background/background_shell.h" |
| 16 #include "services/shell/public/cpp/connector.h" | 16 #include "services/shell/public/cpp/connector.h" |
| 17 #include "services/shell/public/cpp/shell_client.h" | 17 #include "services/shell/public/cpp/service.h" |
| 18 #include "services/shell/public/cpp/shell_connection.h" | 18 #include "services/shell/public/cpp/shell_connection.h" |
| 19 #include "services/ui/common/gpu_service.h" | 19 #include "services/ui/common/gpu_service.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 { |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 void EnsureCommandLineSwitch(const std::string& name) { | 29 void EnsureCommandLineSwitch(const std::string& name) { |
| 30 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 30 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 31 if (!cmd_line->HasSwitch(name)) | 31 if (!cmd_line->HasSwitch(name)) |
| 32 cmd_line->AppendSwitch(name); | 32 cmd_line->AppendSwitch(name); |
| 33 } | 33 } |
| 34 | 34 |
| 35 class DefaultShellClient : public shell::ShellClient { | 35 class DefaultService : public shell::Service { |
| 36 public: | 36 public: |
| 37 DefaultShellClient() {} | 37 DefaultService() {} |
| 38 ~DefaultShellClient() override {} | 38 ~DefaultService() override {} |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 DISALLOW_COPY_AND_ASSIGN(DefaultShellClient); | 41 DISALLOW_COPY_AND_ASSIGN(DefaultService); |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 class PlatformTestHelperMus : public PlatformTestHelper { | 44 class PlatformTestHelperMus : public PlatformTestHelper { |
| 45 public: | 45 public: |
| 46 PlatformTestHelperMus(shell::Connector* connector, | 46 PlatformTestHelperMus(shell::Connector* connector, |
| 47 const shell::Identity& identity) { | 47 const shell::Identity& identity) { |
| 48 ui::GpuService::Initialize(connector); | 48 ui::GpuService::Initialize(connector); |
| 49 // It is necessary to recreate the WindowManagerConnection for each test, | 49 // It is necessary to recreate the WindowManagerConnection for each test, |
| 50 // since a new MessageLoop is created for each test. | 50 // since a new MessageLoop is created for each test. |
| 51 connection_ = WindowManagerConnection::Create(connector, identity); | 51 connection_ = WindowManagerConnection::Create(connector, identity); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 111 } |
| 112 | 112 |
| 113 void CloneConnector(base::WaitableEvent* wait) { | 113 void CloneConnector(base::WaitableEvent* wait) { |
| 114 shell_connector_ = shell_connection_->connector()->Clone(); | 114 shell_connector_ = shell_connection_->connector()->Clone(); |
| 115 wait->Signal(); | 115 wait->Signal(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void SetUpConnections(base::WaitableEvent* wait) { | 118 void SetUpConnections(base::WaitableEvent* wait) { |
| 119 background_shell_.reset(new shell::BackgroundShell); | 119 background_shell_.reset(new shell::BackgroundShell); |
| 120 background_shell_->Init(nullptr); | 120 background_shell_->Init(nullptr); |
| 121 shell_client_.reset(new DefaultShellClient); | 121 service_.reset(new DefaultService); |
| 122 shell_connection_.reset(new shell::ShellConnection( | 122 shell_connection_.reset(new shell::ShellConnection( |
| 123 shell_client_.get(), | 123 service_.get(), |
| 124 background_shell_->CreateShellClientRequest(GetTestName()))); | 124 background_shell_->CreateServiceRequest(GetTestName()))); |
| 125 | 125 |
| 126 // ui/views/mus requires a WindowManager running, so launch test_wm. | 126 // ui/views/mus requires a WindowManager running, so launch test_wm. |
| 127 shell::Connector* connector = shell_connection_->connector(); | 127 shell::Connector* connector = shell_connection_->connector(); |
| 128 connector->Connect("mojo:test_wm"); | 128 connector->Connect("mojo:test_wm"); |
| 129 shell_connector_ = connector->Clone(); | 129 shell_connector_ = connector->Clone(); |
| 130 shell_identity_ = shell_connection_->identity(); | 130 shell_identity_ = shell_connection_->identity(); |
| 131 wait->Signal(); | 131 wait->Signal(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void TearDownConnections(base::WaitableEvent* wait) { | 134 void TearDownConnections(base::WaitableEvent* wait) { |
| 135 shell_connection_.reset(); | 135 shell_connection_.reset(); |
| 136 wait->Signal(); | 136 wait->Signal(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 // Returns the name of the test executable, e.g. "exe:views_mus_unittests". | 139 // Returns the name of the test executable, e.g. "exe:views_mus_unittests". |
| 140 std::string GetTestName() { | 140 std::string GetTestName() { |
| 141 base::FilePath executable = base::CommandLine::ForCurrentProcess() | 141 base::FilePath executable = base::CommandLine::ForCurrentProcess() |
| 142 ->GetProgram() | 142 ->GetProgram() |
| 143 .BaseName() | 143 .BaseName() |
| 144 .RemoveExtension(); | 144 .RemoveExtension(); |
| 145 return std::string("exe:") + executable.MaybeAsASCII(); | 145 return std::string("exe:") + executable.MaybeAsASCII(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 base::Thread thread_; | 148 base::Thread thread_; |
| 149 std::unique_ptr<shell::BackgroundShell> background_shell_; | 149 std::unique_ptr<shell::BackgroundShell> background_shell_; |
| 150 std::unique_ptr<shell::ShellConnection> shell_connection_; | 150 std::unique_ptr<shell::ShellConnection> shell_connection_; |
| 151 std::unique_ptr<DefaultShellClient> shell_client_; | 151 std::unique_ptr<DefaultService> service_; |
| 152 std::unique_ptr<shell::Connector> shell_connector_; | 152 std::unique_ptr<shell::Connector> shell_connector_; |
| 153 shell::Identity shell_identity_; | 153 shell::Identity shell_identity_; |
| 154 | 154 |
| 155 DISALLOW_COPY_AND_ASSIGN(ShellConnection); | 155 DISALLOW_COPY_AND_ASSIGN(ShellConnection); |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 ViewsMusTestSuite::ViewsMusTestSuite(int argc, char** argv) | 158 ViewsMusTestSuite::ViewsMusTestSuite(int argc, char** argv) |
| 159 : ViewsTestSuite(argc, argv) {} | 159 : ViewsTestSuite(argc, argv) {} |
| 160 | 160 |
| 161 ViewsMusTestSuite::~ViewsMusTestSuite() {} | 161 ViewsMusTestSuite::~ViewsMusTestSuite() {} |
| 162 | 162 |
| 163 void ViewsMusTestSuite::Initialize() { | 163 void ViewsMusTestSuite::Initialize() { |
| 164 PlatformTestHelper::SetIsMus(); | 164 PlatformTestHelper::SetIsMus(); |
| 165 // Let other mojo apps know that we're running in tests. Do this with a | 165 // Let other mojo apps know that we're running in tests. Do this with a |
| 166 // command line flag to avoid making blocking calls to other processes for | 166 // command line flag to avoid making blocking calls to other processes for |
| 167 // setup for tests (e.g. to unlock the screen in the window manager). | 167 // setup for tests (e.g. to unlock the screen in the window manager). |
| 168 EnsureCommandLineSwitch(ui::switches::kUseTestConfig); | 168 EnsureCommandLineSwitch(ui::switches::kUseTestConfig); |
| 169 | 169 |
| 170 ViewsTestSuite::Initialize(); | 170 ViewsTestSuite::Initialize(); |
| 171 shell_connections_.reset(new ShellConnection); | 171 shell_connections_.reset(new ShellConnection); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void ViewsMusTestSuite::Shutdown() { | 174 void ViewsMusTestSuite::Shutdown() { |
| 175 shell_connections_.reset(); | 175 shell_connections_.reset(); |
| 176 ViewsTestSuite::Shutdown(); | 176 ViewsTestSuite::Shutdown(); |
| 177 } | 177 } |
| 178 | 178 |
| 179 } // namespace views | 179 } // namespace views |
| OLD | NEW |