| 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/service.h" | 17 #include "services/shell/public/cpp/service.h" |
| 18 #include "services/shell/public/cpp/shell_connection.h" | 18 #include "services/shell/public/cpp/service_context.h" |
| 19 #include "services/ui/common/switches.h" | 19 #include "services/ui/common/switches.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "ui/views/mus/window_manager_connection.h" | 21 #include "ui/views/mus/window_manager_connection.h" |
| 22 #include "ui/views/test/platform_test_helper.h" | 22 #include "ui/views/test/platform_test_helper.h" |
| 23 #include "ui/views/views_delegate.h" | 23 #include "ui/views/views_delegate.h" |
| 24 | 24 |
| 25 namespace views { | 25 namespace views { |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 void EnsureCommandLineSwitch(const std::string& name) { | 28 void EnsureCommandLineSwitch(const std::string& name) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 110 |
| 111 void CloneConnector(base::WaitableEvent* wait) { | 111 void CloneConnector(base::WaitableEvent* wait) { |
| 112 shell_connector_ = shell_connection_->connector()->Clone(); | 112 shell_connector_ = shell_connection_->connector()->Clone(); |
| 113 wait->Signal(); | 113 wait->Signal(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void SetUpConnections(base::WaitableEvent* wait) { | 116 void SetUpConnections(base::WaitableEvent* wait) { |
| 117 background_shell_.reset(new shell::BackgroundShell); | 117 background_shell_.reset(new shell::BackgroundShell); |
| 118 background_shell_->Init(nullptr); | 118 background_shell_->Init(nullptr); |
| 119 service_.reset(new DefaultService); | 119 service_.reset(new DefaultService); |
| 120 shell_connection_.reset(new shell::ShellConnection( | 120 shell_connection_.reset(new shell::ServiceContext( |
| 121 service_.get(), | 121 service_.get(), |
| 122 background_shell_->CreateServiceRequest(GetTestName()))); | 122 background_shell_->CreateServiceRequest(GetTestName()))); |
| 123 | 123 |
| 124 // ui/views/mus requires a WindowManager running, so launch test_wm. | 124 // ui/views/mus requires a WindowManager running, so launch test_wm. |
| 125 shell::Connector* connector = shell_connection_->connector(); | 125 shell::Connector* connector = shell_connection_->connector(); |
| 126 connector->Connect("mojo:test_wm"); | 126 connector->Connect("mojo:test_wm"); |
| 127 shell_connector_ = connector->Clone(); | 127 shell_connector_ = connector->Clone(); |
| 128 shell_identity_ = shell_connection_->identity(); | 128 shell_identity_ = shell_connection_->identity(); |
| 129 wait->Signal(); | 129 wait->Signal(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void TearDownConnections(base::WaitableEvent* wait) { | 132 void TearDownConnections(base::WaitableEvent* wait) { |
| 133 shell_connection_.reset(); | 133 shell_connection_.reset(); |
| 134 wait->Signal(); | 134 wait->Signal(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 // Returns the name of the test executable, e.g. "exe:views_mus_unittests". | 137 // Returns the name of the test executable, e.g. "exe:views_mus_unittests". |
| 138 std::string GetTestName() { | 138 std::string GetTestName() { |
| 139 base::FilePath executable = base::CommandLine::ForCurrentProcess() | 139 base::FilePath executable = base::CommandLine::ForCurrentProcess() |
| 140 ->GetProgram() | 140 ->GetProgram() |
| 141 .BaseName() | 141 .BaseName() |
| 142 .RemoveExtension(); | 142 .RemoveExtension(); |
| 143 return std::string("exe:") + executable.MaybeAsASCII(); | 143 return std::string("exe:") + executable.MaybeAsASCII(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 base::Thread thread_; | 146 base::Thread thread_; |
| 147 std::unique_ptr<shell::BackgroundShell> background_shell_; | 147 std::unique_ptr<shell::BackgroundShell> background_shell_; |
| 148 std::unique_ptr<shell::ShellConnection> shell_connection_; | 148 std::unique_ptr<shell::ServiceContext> shell_connection_; |
| 149 std::unique_ptr<DefaultService> service_; | 149 std::unique_ptr<DefaultService> service_; |
| 150 std::unique_ptr<shell::Connector> shell_connector_; | 150 std::unique_ptr<shell::Connector> shell_connector_; |
| 151 shell::Identity shell_identity_; | 151 shell::Identity shell_identity_; |
| 152 | 152 |
| 153 DISALLOW_COPY_AND_ASSIGN(ShellConnection); | 153 DISALLOW_COPY_AND_ASSIGN(ShellConnection); |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 ViewsMusTestSuite::ViewsMusTestSuite(int argc, char** argv) | 156 ViewsMusTestSuite::ViewsMusTestSuite(int argc, char** argv) |
| 157 : ViewsTestSuite(argc, argv) {} | 157 : ViewsTestSuite(argc, argv) {} |
| 158 | 158 |
| 159 ViewsMusTestSuite::~ViewsMusTestSuite() {} | 159 ViewsMusTestSuite::~ViewsMusTestSuite() {} |
| 160 | 160 |
| 161 void ViewsMusTestSuite::Initialize() { | 161 void ViewsMusTestSuite::Initialize() { |
| 162 PlatformTestHelper::SetIsMus(); | 162 PlatformTestHelper::SetIsMus(); |
| 163 // Let other mojo apps know that we're running in tests. Do this with a | 163 // Let other mojo apps know that we're running in tests. Do this with a |
| 164 // command line flag to avoid making blocking calls to other processes for | 164 // command line flag to avoid making blocking calls to other processes for |
| 165 // setup for tests (e.g. to unlock the screen in the window manager). | 165 // setup for tests (e.g. to unlock the screen in the window manager). |
| 166 EnsureCommandLineSwitch(ui::switches::kUseTestConfig); | 166 EnsureCommandLineSwitch(ui::switches::kUseTestConfig); |
| 167 | 167 |
| 168 ViewsTestSuite::Initialize(); | 168 ViewsTestSuite::Initialize(); |
| 169 shell_connections_.reset(new ShellConnection); | 169 shell_connections_.reset(new ShellConnection); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void ViewsMusTestSuite::Shutdown() { | 172 void ViewsMusTestSuite::Shutdown() { |
| 173 shell_connections_.reset(); | 173 shell_connections_.reset(); |
| 174 ViewsTestSuite::Shutdown(); | 174 ViewsTestSuite::Shutdown(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 } // namespace views | 177 } // namespace views |
| OLD | NEW |