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

Side by Side Diff: services/ui/ws/window_server_test_base.cc

Issue 2559703003: Converts WindowTreeClientTest to be in terms of aura (Closed)
Patch Set: feedback Created 4 years 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
OLDNEW
(Empty)
1 // Copyright 2015 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 "services/ui/ws/window_server_test_base.h"
6
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/memory/ptr_util.h"
10 #include "base/run_loop.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/test/test_timeouts.h"
13 #include "base/threading/thread_task_runner_handle.h"
14 #include "services/service_manager/public/cpp/connector.h"
15 #include "services/service_manager/public/cpp/interface_registry.h"
16 #include "services/ui/public/cpp/gpu/gpu_service.h"
17 #include "ui/aura/env.h"
18 #include "ui/aura/mus/mus_context_factory.h"
19 #include "ui/aura/mus/window_tree_client.h"
20 #include "ui/aura/mus/window_tree_host_mus.h"
21 #include "ui/display/display.h"
22 #include "ui/display/display_list.h"
23 #include "ui/wm/core/capture_controller.h"
24
25 namespace ui {
26 namespace {
27
28 base::RunLoop* current_run_loop = nullptr;
29
30 void TimeoutRunLoop(const base::Closure& timeout_task, bool* timeout) {
31 CHECK(current_run_loop);
32 *timeout = true;
33 timeout_task.Run();
34 }
35
36 } // namespace
37
38 WindowServerTestBase::WindowServerTestBase() {}
39
40 WindowServerTestBase::~WindowServerTestBase() {}
41
42 // static
43 bool WindowServerTestBase::DoRunLoopWithTimeout() {
44 if (current_run_loop != nullptr)
45 return false;
46
47 bool timeout = false;
48 base::RunLoop run_loop;
49 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
50 FROM_HERE, base::Bind(&TimeoutRunLoop, run_loop.QuitClosure(), &timeout),
51 TestTimeouts::action_timeout());
52
53 current_run_loop = &run_loop;
54 current_run_loop->Run();
55 current_run_loop = nullptr;
56 return !timeout;
57 }
58
59 // static
60 bool WindowServerTestBase::QuitRunLoop() {
61 if (!current_run_loop)
62 return false;
63
64 current_run_loop->Quit();
65 current_run_loop = nullptr;
66 return true;
67 }
68
69 void WindowServerTestBase::DeleteWindowTreeClient(
70 aura::WindowTreeClient* client) {
71 for (auto iter = window_tree_clients_.begin();
72 iter != window_tree_clients_.end(); ++iter) {
73 if (iter->get() == client) {
74 window_tree_clients_.erase(iter);
75 return;
76 }
77 }
78 NOTREACHED();
79 }
80
81 std::unique_ptr<aura::WindowTreeClient>
82 WindowServerTestBase::ReleaseMostRecentClient() {
83 if (window_tree_clients_.empty())
84 return nullptr;
85
86 std::unique_ptr<aura::WindowTreeClient> result =
87 std::move(window_tree_clients_.back());
88 window_tree_clients_.pop_back();
89 return result;
90 }
91
92 void WindowServerTestBase::SetUp() {
93 WindowServerServiceTestBase::SetUp();
94
95 env_ = aura::Env::CreateInstance(aura::Env::Mode::MUS);
96 gpu_service_ = ui::GpuService::Create(connector(), nullptr);
97 compositor_context_factory_ =
98 base::MakeUnique<aura::MusContextFactory>(gpu_service_.get());
99 env_->set_context_factory(compositor_context_factory_.get());
100 display::Screen::SetScreenInstance(&screen_);
101 std::unique_ptr<aura::WindowTreeClient> window_manager_window_tree_client =
102 base::MakeUnique<aura::WindowTreeClient>(connector(), this, this);
103 window_manager_window_tree_client->ConnectAsWindowManager();
104 window_manager_ = window_manager_window_tree_client.get();
105 window_tree_clients_.push_back(std::move(window_manager_window_tree_client));
106
107 // Connecting as the WindowManager results in OnWmNewDisplay() being called
108 // with the display (and root). Wait for it to be called so we have display
109 // and root window information (otherwise we can't really do anything).
110 ASSERT_TRUE(DoRunLoopWithTimeout());
111 }
112
113 void WindowServerTestBase::TearDown() {
114 // WindowTreeHost depends on WindowTreeClient.
115 window_tree_hosts_.clear();
116 window_tree_clients_.clear();
117 env_.reset();
118 gpu_service_.reset();
119 display::Screen::SetScreenInstance(nullptr);
120
121 WindowServerServiceTestBase::TearDown();
122 }
123
124 bool WindowServerTestBase::OnConnect(
125 const service_manager::Identity& remote_identity,
126 service_manager::InterfaceRegistry* registry) {
127 registry->AddInterface<mojom::WindowTreeClient>(this);
128 return true;
129 }
130
131 void WindowServerTestBase::OnEmbed(
132 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) {
133 EXPECT_TRUE(QuitRunLoop());
134 window_tree_hosts_.push_back(std::move(window_tree_host));
135 }
136
137 void WindowServerTestBase::OnLostConnection(aura::WindowTreeClient* client) {
138 window_tree_client_lost_connection_ = true;
139 DeleteWindowTreeClient(client);
140 }
141
142 void WindowServerTestBase::OnEmbedRootDestroyed(
143 aura::WindowTreeHostMus* window_tree_host) {
144 if (!DeleteWindowTreeHost(window_tree_host)) {
145 // Assume a subclass called Embed() and wants us to destroy it.
146 delete window_tree_host;
147 }
148 }
149
150 void WindowServerTestBase::OnPointerEventObserved(const ui::PointerEvent& event,
151 aura::Window* target) {}
152
153 aura::client::CaptureClient* WindowServerTestBase::GetCaptureClient() {
154 return wm_state_.capture_controller();
155 }
156
157 aura::PropertyConverter* WindowServerTestBase::GetPropertyConverter() {
158 return &property_converter_;
159 }
160
161 void WindowServerTestBase::SetWindowManagerClient(
162 aura::WindowManagerClient* client) {
163 window_manager_client_ = client;
164 }
165
166 bool WindowServerTestBase::OnWmSetBounds(aura::Window* window,
167 gfx::Rect* bounds) {
168 return window_manager_delegate_
169 ? window_manager_delegate_->OnWmSetBounds(window, bounds)
170 : true;
171 }
172
173 bool WindowServerTestBase::OnWmSetProperty(
174 aura::Window* window,
175 const std::string& name,
176 std::unique_ptr<std::vector<uint8_t>>* new_data) {
177 return window_manager_delegate_
178 ? window_manager_delegate_->OnWmSetProperty(window, name, new_data)
179 : true;
180 }
181
182 aura::Window* WindowServerTestBase::OnWmCreateTopLevelWindow(
183 ui::mojom::WindowType window_type,
184 std::map<std::string, std::vector<uint8_t>>* properties) {
185 return window_manager_delegate_
186 ? window_manager_delegate_->OnWmCreateTopLevelWindow(window_type,
187 properties)
188 : nullptr;
189 }
190
191 void WindowServerTestBase::OnWmClientJankinessChanged(
192 const std::set<aura::Window*>& client_windows,
193 bool janky) {
194 if (window_manager_delegate_)
195 window_manager_delegate_->OnWmClientJankinessChanged(client_windows, janky);
196 }
197
198 void WindowServerTestBase::OnWmWillCreateDisplay(
199 const display::Display& display) {
200 screen_.display_list().AddDisplay(display,
201 display::DisplayList::Type::PRIMARY);
202 if (window_manager_delegate_)
203 window_manager_delegate_->OnWmWillCreateDisplay(display);
204 }
205
206 void WindowServerTestBase::OnWmNewDisplay(
207 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
208 const display::Display& display) {
209 EXPECT_TRUE(QuitRunLoop());
210 ASSERT_TRUE(window_manager_client_);
211 window_manager_client_->AddActivationParent(window_tree_host->window());
212 window_tree_hosts_.push_back(std::move(window_tree_host));
213
214 if (window_manager_delegate_)
215 window_manager_delegate_->OnWmNewDisplay(nullptr, display);
216 }
217
218 void WindowServerTestBase::OnWmDisplayRemoved(
219 aura::WindowTreeHostMus* window_tree_host) {
220 if (window_manager_delegate_)
221 window_manager_delegate_->OnWmDisplayRemoved(window_tree_host);
222 ASSERT_TRUE(DeleteWindowTreeHost(window_tree_host));
223 }
224
225 void WindowServerTestBase::OnWmDisplayModified(
226 const display::Display& display) {
227 if (window_manager_delegate_)
228 window_manager_delegate_->OnWmDisplayModified(display);
229 }
230
231 ui::mojom::EventResult WindowServerTestBase::OnAccelerator(
232 uint32_t accelerator_id,
233 const ui::Event& event) {
234 return window_manager_delegate_
235 ? window_manager_delegate_->OnAccelerator(accelerator_id, event)
236 : ui::mojom::EventResult::UNHANDLED;
237 }
238
239 void WindowServerTestBase::OnWmPerformMoveLoop(
240 aura::Window* window,
241 ui::mojom::MoveLoopSource source,
242 const gfx::Point& cursor_location,
243 const base::Callback<void(bool)>& on_done) {
244 if (window_manager_delegate_) {
245 window_manager_delegate_->OnWmPerformMoveLoop(window, source,
246 cursor_location, on_done);
247 }
248 }
249
250 void WindowServerTestBase::OnWmCancelMoveLoop(aura::Window* window) {
251 if (window_manager_delegate_)
252 window_manager_delegate_->OnWmCancelMoveLoop(window);
253 }
254
255 void WindowServerTestBase::OnWmSetClientArea(
256 aura::Window* window,
257 const gfx::Insets& insets,
258 const std::vector<gfx::Rect>& additional_client_areas) {
259 if (window_manager_delegate_) {
260 window_manager_delegate_->OnWmSetClientArea(window, insets,
261 additional_client_areas);
262 }
263 }
264
265 void WindowServerTestBase::Create(
266 const service_manager::Identity& remote_identity,
267 mojom::WindowTreeClientRequest request) {
268 window_tree_clients_.push_back(base::MakeUnique<aura::WindowTreeClient>(
269 connector(), this, nullptr, std::move(request)));
270 }
271
272 bool WindowServerTestBase::DeleteWindowTreeHost(
273 aura::WindowTreeHostMus* window_tree_host) {
274 for (auto iter = window_tree_hosts_.begin(); iter != window_tree_hosts_.end();
275 ++iter) {
276 if ((*iter).get() == window_tree_host) {
277 window_tree_hosts_.erase(iter);
278 return true;
279 }
280 }
281 return false;
282 }
283
284 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698