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

Unified Diff: ui/views/mus/run_all_unittests_mus.cc

Issue 1984403002: Revert of Reland: mus: Add views_mus_interactive_ui_tests target (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/mus/interactive_ui_tests_mus.cc ('k') | ui/views/mus/views_mus_test_suite.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/mus/run_all_unittests_mus.cc
diff --git a/ui/views/mus/run_all_unittests_mus.cc b/ui/views/mus/run_all_unittests_mus.cc
index 05e4f0c82a2770200a1878c6c3d1f62fe7206028..52bc71a5a836ef44e09acd25ee53ffb46adc5648 100644
--- a/ui/views/mus/run_all_unittests_mus.cc
+++ b/ui/views/mus/run_all_unittests_mus.cc
@@ -2,8 +2,143 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ui/views/mus/views_mus_test_suite.h"
+#include "ui/views/run_all_unittests.h"
+
+#include <memory>
+
+#include "base/run_loop.h"
+#include "base/synchronization/waitable_event.h"
+#include "base/threading/simple_thread.h"
+#include "base/threading/thread.h"
+#include "services/shell/background/background_shell.h"
+#include "services/shell/public/cpp/connector.h"
+#include "services/shell/public/cpp/shell_client.h"
+#include "services/shell/public/cpp/shell_connection.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/views/mus/window_manager_connection.h"
+#include "ui/views/test/platform_test_helper.h"
+#include "ui/views/views_delegate.h"
+
+namespace views {
+namespace {
+
+const char kTestName[] = "exe:views_mus_unittests";
+
+class DefaultShellClient : public shell::ShellClient {
+ public:
+ DefaultShellClient() {}
+ ~DefaultShellClient() override {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DefaultShellClient);
+};
+
+class PlatformTestHelperMus : public PlatformTestHelper {
+ public:
+ PlatformTestHelperMus() {}
+ ~PlatformTestHelperMus() override {}
+
+ // PlatformTestHelper:
+ bool IsMus() const override { return true; }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PlatformTestHelperMus);
+};
+
+std::unique_ptr<PlatformTestHelper> CreatePlatformTestHelper(
+ shell::Connector* connector,
+ const shell::Identity& identity) {
+ if (!WindowManagerConnection::Exists())
+ WindowManagerConnection::Create(connector, identity);
+ return base::WrapUnique(new PlatformTestHelperMus);
+}
+
+class ShellConnection {
+ public:
+ ShellConnection() : thread_("Persistent shell connections") {
+ base::WaitableEvent wait(false, false);
+ base::Thread::Options options;
+ thread_.StartWithOptions(options);
+ thread_.task_runner()->PostTask(
+ FROM_HERE, base::Bind(&ShellConnection::SetUpConnections,
+ base::Unretained(this), &wait));
+ wait.Wait();
+
+ // WindowManagerConnection cannot be created from here yet, although the
+ // connector and identity are available at this point. This is because
+ // WindowManagerConnection needs a ViewsDelegate and a MessageLoop to have
+ // been installed first. So delay the creation until the necessary
+ // dependencies have been met.
+ PlatformTestHelper::set_factory(base::Bind(
+ &CreatePlatformTestHelper, shell_connector_.get(), shell_identity_));
+ }
+
+ ~ShellConnection() {
+ views::WindowManagerConnection::Reset();
+ base::WaitableEvent wait(false, false);
+ thread_.task_runner()->PostTask(
+ FROM_HERE, base::Bind(&ShellConnection::TearDownConnections,
+ base::Unretained(this), &wait));
+ wait.Wait();
+ }
+
+ private:
+ void SetUpConnections(base::WaitableEvent* wait) {
+ background_shell_.reset(new shell::BackgroundShell);
+ background_shell_->Init(nullptr);
+ shell_client_.reset(new DefaultShellClient);
+ shell_connection_.reset(new shell::ShellConnection(
+ shell_client_.get(),
+ background_shell_->CreateShellClientRequest(kTestName)));
+
+ // ui/views/mus requires a WindowManager running, for now use the desktop
+ // one.
+ shell::Connector* connector = shell_connection_->connector();
+ connector->Connect("mojo:desktop_wm");
+ shell_connector_ = connector->Clone();
+ shell_identity_ = shell_connection_->identity();
+ wait->Signal();
+ }
+
+ void TearDownConnections(base::WaitableEvent* wait) {
+ shell_connection_.reset();
+ wait->Signal();
+ }
+
+ base::Thread thread_;
+ std::unique_ptr<shell::BackgroundShell> background_shell_;
+ std::unique_ptr<shell::ShellConnection> shell_connection_;
+ std::unique_ptr<DefaultShellClient> shell_client_;
+ std::unique_ptr<shell::Connector> shell_connector_;
+ shell::Identity shell_identity_;
+
+ DISALLOW_COPY_AND_ASSIGN(ShellConnection);
+};
+
+class ViewMusTestSuite : public ViewTestSuite {
+ public:
+ ViewMusTestSuite(int argc, char** argv) : ViewTestSuite(argc, argv) {}
+
+ protected:
+ void Initialize() override {
+ ViewTestSuite::Initialize();
+ shell_connections_.reset(new ShellConnection);
+ }
+
+ void Shutdown() override {
+ shell_connections_.reset();
+ ViewTestSuite::Shutdown();
+ }
+
+ private:
+ std::unique_ptr<ShellConnection> shell_connections_;
+
+ DISALLOW_COPY_AND_ASSIGN(ViewMusTestSuite);
+};
+
+} // namespace
+} // namespace views
int MasterProcessMain(int argc, char** argv) {
- return views::ViewsMusTestSuite(argc, argv).RunTests();
+ return views::ViewMusTestSuite(argc, argv).RunTests();
}
« no previous file with comments | « ui/views/mus/interactive_ui_tests_mus.cc ('k') | ui/views/mus/views_mus_test_suite.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698