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

Unified Diff: ui/ozone/platform/wayland/fake_server.h

Issue 1673063002: ozone/platform/wayland: Add some tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
Index: ui/ozone/platform/wayland/fake_server.h
diff --git a/ui/ozone/platform/wayland/fake_server.h b/ui/ozone/platform/wayland/fake_server.h
new file mode 100644
index 0000000000000000000000000000000000000000..634bf6fb1e7d4d65a5efec04314a7c565fd0ba33
--- /dev/null
+++ b/ui/ozone/platform/wayland/fake_server.h
@@ -0,0 +1,169 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_OZONE_PLATFORM_WAYLAND_FAKE_SERVER_H_
+#define UI_OZONE_PLATFORM_WAYLAND_FAKE_SERVER_H_
+
+#include <wayland-server-core.h>
+
+#include "base/bind.h"
+#include "base/message_loop/message_pump_libevent.h"
+#include "base/threading/thread.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+struct wl_client;
+struct wl_display;
+struct wl_event_loop;
+struct wl_global;
+struct wl_resource;
+
+namespace wl {
+
+class MockSurface {
+ public:
+ MockSurface();
+ ~MockSurface();
+
+ MOCK_METHOD3(Attach, void(wl_resource* buffer, int32_t x, int32_t y));
+ MOCK_METHOD4(Damage,
+ void(int32_t x, int32_t y, int32_t width, int32_t height));
+ MOCK_METHOD0(Commit, void());
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockSurface);
+};
+
+class MockXdgShell {
+ public:
+ MockXdgShell();
+ ~MockXdgShell();
+
+ MOCK_METHOD1(UseUnstableVersion, void(int32_t version));
+ MOCK_METHOD1(Pong, void(uint32_t serial));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockXdgShell);
+};
+
+class MockXdgSurface {
+ public:
+ MockXdgSurface();
+ ~MockXdgSurface();
+
+ MOCK_METHOD1(SetParent, void(wl_resource* parent));
+ MOCK_METHOD1(SetTitle, void(const char* title));
+ MOCK_METHOD1(SetAppId, void(const char* app_id));
+ MOCK_METHOD1(AckConfigure, void(uint32_t serial));
+ MOCK_METHOD0(SetMaximized, void());
+ MOCK_METHOD0(UnsetMaximized, void());
+ MOCK_METHOD0(SetMinimized, void());
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockXdgSurface);
+};
+
+struct FakeXdgSurface;
+
+struct FakeSurface {
+ FakeSurface(wl_resource* resource);
+ ~FakeSurface();
+
+ wl_resource* resource;
+ MockSurface* mock = nullptr;
+ FakeXdgSurface* xdg_surface = nullptr;
+
+ static FakeSurface* FromResource(wl_resource* resource);
+};
+
+struct FakeXdgSurface {
+ FakeXdgSurface(wl_resource* resource, FakeSurface* surface);
+ ~FakeXdgSurface();
+
+ wl_resource* resource;
+ MockXdgSurface* mock = nullptr;
+ FakeSurface* surface;
+};
+
+struct GlobalDeleter {
+ void operator()(wl_global* global);
+};
+
+class Global {
+ public:
+ Global(const wl_interface* interface,
+ const void* implementation,
+ uint32_t version,
+ void* data);
+ virtual ~Global();
+
+ bool Initialize(wl_display* display);
+
+ // The first bound resource to this global, which is usually all that is
+ // useful when testing a simple client.
+ wl_resource* resource() { return resource_; }
+
+ static void Bind(wl_client* client,
+ void* data,
+ uint32_t version,
+ uint32_t id);
+
+ private:
+ scoped_ptr<wl_global, GlobalDeleter> global_;
+
+ const wl_interface* interface_;
+ const void* implementation_;
+ const uint32_t version_;
+ void* data_;
+ wl_resource* resource_ = nullptr;
+
+ DISALLOW_COPY_AND_ASSIGN(Global);
+};
+
+struct DisplayDeleter {
+ void operator()(wl_display* display);
+};
+
+class FakeServer : public base::Thread, base::MessagePumpLibevent::Watcher {
+ public:
+ FakeServer(MockXdgShell* xdg_shell_mock = nullptr);
+ ~FakeServer() override;
+
+ // Start the fake Wayland server. If this succeeds, the WAYLAND_SOCKET
+ // environment variable will be set to the string representation of a file
+ // descriptor that a client can connect to. The caller is responsible for
+ // ensuring that this file descriptor gets closed (for example, by calling
+ // wl_display_connect).
+ bool Start();
+
+ void Flush();
+
+ template <typename T>
+ T* GetObject(uint32_t id) {
+ return T::FromResource(wl_client_get_object(client_, id));
+ }
+
+ wl_resource* xdg_shell() { return xdg_shell_.resource(); }
+
+ private:
+ scoped_ptr<base::MessagePump> CreateMessagePump();
+
+ // base::MessagePumpLibevent::Watcher
+ void OnFileCanReadWithoutBlocking(int fd) override;
+ void OnFileCanWriteWithoutBlocking(int fd) override;
+
+ scoped_ptr<wl_display, DisplayDeleter> display_;
+ wl_client* client_ = nullptr;
+ wl_event_loop* event_loop_ = nullptr;
+
+ Global compositor_;
+ Global xdg_shell_;
+
+ base::MessagePumpLibevent::FileDescriptorWatcher controller_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeServer);
+};
+
+} // namespace wl
+
+#endif // UI_OZONE_PLATFORM_WAYLAND_FAKE_SERVER_H_

Powered by Google App Engine
This is Rietveld 408576698