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

Side by Side Diff: ui/ozone/platform/wayland/fake_server.cc

Issue 1739193004: ozone/platform/wayland: Use more realistic event processing and request flushing in tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wayland-test2
Patch Set: Use watching_ instead of base::MessageLoopForUI::IsCurrent() Created 4 years, 9 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/ozone/platform/wayland/fake_server.h ('k') | ui/ozone/platform/wayland/wayland_display.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ozone/platform/wayland/fake_server.h" 5 #include "ui/ozone/platform/wayland/fake_server.h"
6 6
7 #include <sys/socket.h> 7 #include <sys/socket.h>
8 #include <wayland-server.h> 8 #include <wayland-server.h>
9 #include <xdg-shell-unstable-v5-server-protocol.h> 9 #include <xdg-shell-unstable-v5-server-protocol.h>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/files/scoped_file.h" 12 #include "base/files/scoped_file.h"
13 #include "base/run_loop.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 15
15 namespace wl { 16 namespace wl {
16 namespace { 17 namespace {
17 18
18 const uint32_t kCompositorVersion = 4; 19 const uint32_t kCompositorVersion = 4;
19 const uint32_t kXdgShellVersion = 1; 20 const uint32_t kXdgShellVersion = 1;
20 21
21 void DestroyResource(wl_client* client, wl_resource* resource) { 22 void DestroyResource(wl_client* client, wl_resource* resource) {
22 wl_resource_destroy(resource); 23 wl_resource_destroy(resource);
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 void DisplayDeleter::operator()(wl_display* display) { 268 void DisplayDeleter::operator()(wl_display* display) {
268 wl_display_destroy(display); 269 wl_display_destroy(display);
269 } 270 }
270 271
271 FakeServer::FakeServer() 272 FakeServer::FakeServer()
272 : Thread("fake_wayland_server"), 273 : Thread("fake_wayland_server"),
273 pause_event_(false, false), 274 pause_event_(false, false),
274 resume_event_(false, false) {} 275 resume_event_(false, false) {}
275 276
276 FakeServer::~FakeServer() { 277 FakeServer::~FakeServer() {
278 Resume();
277 Stop(); 279 Stop();
278 } 280 }
279 281
280 bool FakeServer::Start() { 282 bool FakeServer::Start() {
281 display_.reset(wl_display_create()); 283 display_.reset(wl_display_create());
282 if (!display_) 284 if (!display_)
283 return false; 285 return false;
284 event_loop_ = wl_display_get_event_loop(display_.get()); 286 event_loop_ = wl_display_get_event_loop(display_.get());
285 287
286 int fd[2]; 288 int fd[2];
(...skipping 18 matching lines...) Expand all
305 options.message_pump_factory = 307 options.message_pump_factory =
306 base::Bind(&FakeServer::CreateMessagePump, base::Unretained(this)); 308 base::Bind(&FakeServer::CreateMessagePump, base::Unretained(this));
307 if (!base::Thread::StartWithOptions(options)) 309 if (!base::Thread::StartWithOptions(options))
308 return false; 310 return false;
309 311
310 setenv("WAYLAND_SOCKET", base::UintToString(client_fd.release()).c_str(), 1); 312 setenv("WAYLAND_SOCKET", base::UintToString(client_fd.release()).c_str(), 1);
311 313
312 return true; 314 return true;
313 } 315 }
314 316
315 void FakeServer::Flush() {
316 wl_display_flush_clients(display_.get());
317 }
318
319 void FakeServer::Pause() { 317 void FakeServer::Pause() {
320 task_runner()->PostTask( 318 task_runner()->PostTask(
321 FROM_HERE, base::Bind(&FakeServer::DoPause, base::Unretained(this))); 319 FROM_HERE, base::Bind(&FakeServer::DoPause, base::Unretained(this)));
322 pause_event_.Wait(); 320 pause_event_.Wait();
323 } 321 }
324 322
325 void FakeServer::Resume() { 323 void FakeServer::Resume() {
324 if (display_)
325 wl_display_flush_clients(display_.get());
326 resume_event_.Signal(); 326 resume_event_.Signal();
327 } 327 }
328 328
329 void FakeServer::DoPause() { 329 void FakeServer::DoPause() {
330 base::RunLoop().RunUntilIdle();
330 pause_event_.Signal(); 331 pause_event_.Signal();
331 resume_event_.Wait(); 332 resume_event_.Wait();
332 } 333 }
333 334
334 scoped_ptr<base::MessagePump> FakeServer::CreateMessagePump() { 335 scoped_ptr<base::MessagePump> FakeServer::CreateMessagePump() {
335 auto pump = make_scoped_ptr(new base::MessagePumpLibevent); 336 auto pump = make_scoped_ptr(new base::MessagePumpLibevent);
336 pump->WatchFileDescriptor(wl_event_loop_get_fd(event_loop_), true, 337 pump->WatchFileDescriptor(wl_event_loop_get_fd(event_loop_), true,
337 base::MessagePumpLibevent::WATCH_READ, &controller_, 338 base::MessagePumpLibevent::WATCH_READ, &controller_,
338 this); 339 this);
339 return std::move(pump); 340 return std::move(pump);
340 } 341 }
341 342
342 void FakeServer::OnFileCanReadWithoutBlocking(int fd) { 343 void FakeServer::OnFileCanReadWithoutBlocking(int fd) {
343 wl_event_loop_dispatch(event_loop_, 0); 344 wl_event_loop_dispatch(event_loop_, 0);
344 wl_display_flush_clients(display_.get()); 345 wl_display_flush_clients(display_.get());
345 } 346 }
346 347
347 void FakeServer::OnFileCanWriteWithoutBlocking(int fd) {} 348 void FakeServer::OnFileCanWriteWithoutBlocking(int fd) {}
348 349
349 } // namespace wl 350 } // namespace wl
OLDNEW
« no previous file with comments | « ui/ozone/platform/wayland/fake_server.h ('k') | ui/ozone/platform/wayland/wayland_display.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698