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

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: tweak 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 display::Screen::SetScreenInstance(nullptr);
msw 2016/12/08 01:20:11 Is this needed here and in TearDown? Ditto for win
sky 2016/12/08 04:59:45 Nope. Done.
42 window_tree_clients_.clear();
43 }
44
45 // static
46 bool WindowServerTestBase::DoRunLoopWithTimeout() {
47 if (current_run_loop != nullptr)
48 return false;
49
50 bool timeout = false;
51 base::RunLoop run_loop;
52 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
53 FROM_HERE, base::Bind(&TimeoutRunLoop, run_loop.QuitClosure(), &timeout),
54 TestTimeouts::action_timeout());
55
56 current_run_loop = &run_loop;
57 current_run_loop->Run();
58 current_run_loop = nullptr;
59 return !timeout;
60 }
61
62 // static
63 bool WindowServerTestBase::QuitRunLoop() {
64 if (!current_run_loop)
65 return false;
66
67 current_run_loop->Quit();
68 current_run_loop = nullptr;
69 return true;
70 }
71
72 void WindowServerTestBase::DeleteWindowTreeClient(
73 aura::WindowTreeClient* client) {
74 for (auto iter = window_tree_clients_.begin();
75 iter != window_tree_clients_.end(); ++iter) {
76 if (iter->get() == client) {
77 window_tree_clients_.erase(iter);
78 return;
79 }
80 }
81 NOTREACHED();
82 }
83
84 std::unique_ptr<aura::WindowTreeClient>
85 WindowServerTestBase::ReleaseMostRecentClient() {
86 if (window_tree_clients_.empty())
87 return nullptr;
88
89 std::unique_ptr<aura::WindowTreeClient> result =
90 std::move(window_tree_clients_.back());
91 window_tree_clients_.pop_back();
92 return result;
93 }
94
95 void WindowServerTestBase::SetUp() {
96 WindowServerServiceTestBase::SetUp();
97
98 env_ = aura::Env::CreateInstance(aura::Env::Mode::MUS);
99 gpu_service_ = ui::GpuService::Create(connector(), nullptr);
100 compositor_context_factory_ =
101 base::MakeUnique<aura::MusContextFactory>(gpu_service_.get());
102 env_->set_context_factory(compositor_context_factory_.get());
103 display::Screen::SetScreenInstance(&screen_);
104 std::unique_ptr<aura::WindowTreeClient> window_manager_window_tree_client =
105 base::MakeUnique<aura::WindowTreeClient>(connector(), this, this);
106 window_manager_window_tree_client->ConnectAsWindowManager();
107 window_manager_ = window_manager_window_tree_client.get();
108 window_tree_clients_.push_back(std::move(window_manager_window_tree_client));
109
110 ASSERT_TRUE(DoRunLoopWithTimeout()); // RunLoop should be quit by OnEmbed().
msw 2016/12/08 01:20:11 nit: maybe explain why OnEmbed is called? (eg. it'
sky 2016/12/08 04:59:45 Done.
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(
msw 2016/12/08 01:20:11 optional nit: share code with WindowServerTestBase
sky 2016/12/08 04:59:45 Done.
143 aura::WindowTreeHostMus* window_tree_host) {
144 for (auto iter = window_tree_hosts_.begin(); iter != window_tree_hosts_.end();
145 ++iter) {
146 if (iter->get() == window_tree_host) {
147 window_tree_hosts_.erase(iter);
148 return;
149 }
150 }
151 // Assume a subclass called Embed() and wants us to destroy it.
152 delete window_tree_host;
153 }
154
155 void WindowServerTestBase::OnPointerEventObserved(const ui::PointerEvent& event,
156 aura::Window* target) {}
157
158 aura::client::CaptureClient* WindowServerTestBase::GetCaptureClient() {
159 return wm_state_.capture_controller();
160 }
161
162 aura::PropertyConverter* WindowServerTestBase::GetPropertyConverter() {
163 return &property_converter_;
164 }
165
166 void WindowServerTestBase::SetWindowManagerClient(
167 aura::WindowManagerClient* client) {
168 window_manager_client_ = client;
169 }
170
171 bool WindowServerTestBase::OnWmSetBounds(aura::Window* window,
172 gfx::Rect* bounds) {
173 return window_manager_delegate_
174 ? window_manager_delegate_->OnWmSetBounds(window, bounds)
175 : true;
176 }
177
178 bool WindowServerTestBase::OnWmSetProperty(
179 aura::Window* window,
180 const std::string& name,
181 std::unique_ptr<std::vector<uint8_t>>* new_data) {
182 return window_manager_delegate_
183 ? window_manager_delegate_->OnWmSetProperty(window, name, new_data)
184 : true;
185 }
186
187 aura::Window* WindowServerTestBase::OnWmCreateTopLevelWindow(
188 ui::mojom::WindowType window_type,
189 std::map<std::string, std::vector<uint8_t>>* properties) {
190 return window_manager_delegate_
191 ? window_manager_delegate_->OnWmCreateTopLevelWindow(window_type,
192 properties)
193 : nullptr;
194 }
195
196 void WindowServerTestBase::OnWmClientJankinessChanged(
197 const std::set<aura::Window*>& client_windows,
198 bool janky) {
199 if (window_manager_delegate_)
200 window_manager_delegate_->OnWmClientJankinessChanged(client_windows, janky);
201 }
202
203 void WindowServerTestBase::OnWmWillCreateDisplay(
204 const display::Display& display) {
205 screen_.display_list().AddDisplay(display,
206 display::DisplayList::Type::PRIMARY);
207 if (window_manager_delegate_)
208 window_manager_delegate_->OnWmWillCreateDisplay(display);
209 }
210
211 void WindowServerTestBase::OnWmNewDisplay(
212 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
213 const display::Display& display) {
214 EXPECT_TRUE(QuitRunLoop());
215 ASSERT_TRUE(window_manager_client_);
216 window_manager_client_->AddActivationParent(window_tree_host->window());
217 window_tree_hosts_.push_back(std::move(window_tree_host));
218
219 if (window_manager_delegate_)
220 window_manager_delegate_->OnWmNewDisplay(nullptr, display);
221 }
222
223 void WindowServerTestBase::OnWmDisplayRemoved(
224 aura::WindowTreeHostMus* window_tree_host) {
225 if (window_manager_delegate_)
226 window_manager_delegate_->OnWmDisplayRemoved(window_tree_host);
227 for (auto iter = window_tree_hosts_.begin(); iter != window_tree_hosts_.end();
228 ++iter) {
229 if ((*iter).get() == window_tree_host) {
230 window_tree_hosts_.erase(iter);
231 return;
232 }
233 }
234 NOTREACHED();
235 }
236
237 void WindowServerTestBase::OnWmDisplayModified(
238 const display::Display& display) {
239 if (window_manager_delegate_)
240 window_manager_delegate_->OnWmDisplayModified(display);
241 }
242
243 ui::mojom::EventResult WindowServerTestBase::OnAccelerator(
244 uint32_t accelerator_id,
245 const ui::Event& event) {
246 return window_manager_delegate_
247 ? window_manager_delegate_->OnAccelerator(accelerator_id, event)
248 : ui::mojom::EventResult::UNHANDLED;
249 }
250
251 void WindowServerTestBase::OnWmPerformMoveLoop(
252 aura::Window* window,
253 ui::mojom::MoveLoopSource source,
254 const gfx::Point& cursor_location,
255 const base::Callback<void(bool)>& on_done) {
256 if (window_manager_delegate_) {
257 window_manager_delegate_->OnWmPerformMoveLoop(window, source,
258 cursor_location, on_done);
259 }
260 }
261
262 void WindowServerTestBase::OnWmCancelMoveLoop(aura::Window* window) {
263 if (window_manager_delegate_)
264 window_manager_delegate_->OnWmCancelMoveLoop(window);
265 }
266
267 void WindowServerTestBase::OnWmSetClientArea(
268 aura::Window* window,
269 const gfx::Insets& insets,
270 const std::vector<gfx::Rect>& additional_client_areas) {}
msw 2016/12/08 01:20:11 Should this also call through to the delegate?
sky 2016/12/08 04:59:45 Done.
271
272 void WindowServerTestBase::Create(
273 const service_manager::Identity& remote_identity,
274 mojom::WindowTreeClientRequest request) {
275 window_tree_clients_.push_back(base::MakeUnique<aura::WindowTreeClient>(
276 connector(), this, nullptr, std::move(request)));
277 }
278
279 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698