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

Side by Side Diff: ui/views/mus/views_mus_test_suite.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 unified diff | Download patch
« no previous file with comments | « ui/views/mus/views_mus_test_suite.h ('k') | ui/views/run_all_unittests.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/views/mus/views_mus_test_suite.h"
6
7 #include <memory>
8
9 #include "base/command_line.h"
10 #include "base/files/file_path.h"
11 #include "base/run_loop.h"
12 #include "base/synchronization/waitable_event.h"
13 #include "base/threading/simple_thread.h"
14 #include "base/threading/thread.h"
15 #include "services/shell/background/background_shell.h"
16 #include "services/shell/public/cpp/connector.h"
17 #include "services/shell/public/cpp/shell_client.h"
18 #include "services/shell/public/cpp/shell_connection.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/views/mus/window_manager_connection.h"
21 #include "ui/views/test/platform_test_helper.h"
22 #include "ui/views/views_delegate.h"
23
24 namespace views {
25 namespace {
26
27 class DefaultShellClient : public shell::ShellClient {
28 public:
29 DefaultShellClient() {}
30 ~DefaultShellClient() override {}
31
32 private:
33 DISALLOW_COPY_AND_ASSIGN(DefaultShellClient);
34 };
35
36 class PlatformTestHelperMus : public PlatformTestHelper {
37 public:
38 PlatformTestHelperMus() {}
39 ~PlatformTestHelperMus() override {}
40
41 private:
42 DISALLOW_COPY_AND_ASSIGN(PlatformTestHelperMus);
43 };
44
45 std::unique_ptr<PlatformTestHelper> CreatePlatformTestHelper(
46 shell::Connector* connector,
47 const shell::Identity& identity) {
48 if (!WindowManagerConnection::Exists())
49 WindowManagerConnection::Create(connector, identity);
50 return base::WrapUnique(new PlatformTestHelperMus);
51 }
52
53 } // namespace
54
55 class ShellConnection {
56 public:
57 ShellConnection() : thread_("Persistent shell connections") {
58 base::WaitableEvent wait(false, false);
59 base::Thread::Options options;
60 thread_.StartWithOptions(options);
61 thread_.task_runner()->PostTask(
62 FROM_HERE, base::Bind(&ShellConnection::SetUpConnections,
63 base::Unretained(this), &wait));
64 wait.Wait();
65
66 // WindowManagerConnection cannot be created from here yet, although the
67 // connector and identity are available at this point. This is because
68 // WindowManagerConnection needs a ViewsDelegate and a MessageLoop to have
69 // been installed first. So delay the creation until the necessary
70 // dependencies have been met.
71 PlatformTestHelper::set_factory(base::Bind(
72 &CreatePlatformTestHelper, shell_connector_.get(), shell_identity_));
73 }
74
75 ~ShellConnection() {
76 views::WindowManagerConnection::Reset();
77 base::WaitableEvent wait(false, false);
78 thread_.task_runner()->PostTask(
79 FROM_HERE, base::Bind(&ShellConnection::TearDownConnections,
80 base::Unretained(this), &wait));
81 wait.Wait();
82 }
83
84 private:
85 void SetUpConnections(base::WaitableEvent* wait) {
86 background_shell_.reset(new shell::BackgroundShell);
87 background_shell_->Init(nullptr);
88 shell_client_.reset(new DefaultShellClient);
89 shell_connection_.reset(new shell::ShellConnection(
90 shell_client_.get(),
91 background_shell_->CreateShellClientRequest(GetTestName())));
92
93 // ui/views/mus requires a WindowManager running, for now use the desktop
94 // one.
95 shell::Connector* connector = shell_connection_->connector();
96 connector->Connect("mojo:desktop_wm");
97 shell_connector_ = connector->Clone();
98 shell_identity_ = shell_connection_->identity();
99 wait->Signal();
100 }
101
102 void TearDownConnections(base::WaitableEvent* wait) {
103 shell_connection_.reset();
104 wait->Signal();
105 }
106
107 // Returns the name of the test executable, e.g. "exe:views_mus_unittests".
108 std::string GetTestName() {
109 base::FilePath executable = base::CommandLine::ForCurrentProcess()
110 ->GetProgram()
111 .BaseName()
112 .RemoveExtension();
113 return std::string("exe:") + executable.MaybeAsASCII();
114 }
115
116 base::Thread thread_;
117 std::unique_ptr<shell::BackgroundShell> background_shell_;
118 std::unique_ptr<shell::ShellConnection> shell_connection_;
119 std::unique_ptr<DefaultShellClient> shell_client_;
120 std::unique_ptr<shell::Connector> shell_connector_;
121 shell::Identity shell_identity_;
122
123 DISALLOW_COPY_AND_ASSIGN(ShellConnection);
124 };
125
126 ViewsMusTestSuite::ViewsMusTestSuite(int argc, char** argv)
127 : ViewTestSuite(argc, argv) {}
128
129 ViewsMusTestSuite::~ViewsMusTestSuite() {}
130
131 void ViewsMusTestSuite::Initialize() {
132 PlatformTestHelper::SetIsMus();
133 ViewTestSuite::Initialize();
134 shell_connections_.reset(new ShellConnection);
135 }
136
137 void ViewsMusTestSuite::Shutdown() {
138 shell_connections_.reset();
139 ViewTestSuite::Shutdown();
140 }
141
142 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/views_mus_test_suite.h ('k') | ui/views/run_all_unittests.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698