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

Side by Side 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 unified diff | Download patch
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 #ifndef UI_OZONE_PLATFORM_WAYLAND_FAKE_SERVER_H_
6 #define UI_OZONE_PLATFORM_WAYLAND_FAKE_SERVER_H_
7
8 #include <wayland-server-core.h>
9
10 #include "base/bind.h"
11 #include "base/message_loop/message_pump_libevent.h"
12 #include "base/threading/thread.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14
15 struct wl_client;
16 struct wl_display;
17 struct wl_event_loop;
18 struct wl_global;
19 struct wl_resource;
20
21 namespace wl {
22
23 class MockSurface {
24 public:
25 MockSurface();
26 ~MockSurface();
27
28 MOCK_METHOD3(Attach, void(wl_resource* buffer, int32_t x, int32_t y));
29 MOCK_METHOD4(Damage,
30 void(int32_t x, int32_t y, int32_t width, int32_t height));
31 MOCK_METHOD0(Commit, void());
32
33 private:
34 DISALLOW_COPY_AND_ASSIGN(MockSurface);
35 };
36
37 class MockXdgShell {
38 public:
39 MockXdgShell();
40 ~MockXdgShell();
41
42 MOCK_METHOD1(UseUnstableVersion, void(int32_t version));
43 MOCK_METHOD1(Pong, void(uint32_t serial));
44
45 private:
46 DISALLOW_COPY_AND_ASSIGN(MockXdgShell);
47 };
48
49 class MockXdgSurface {
50 public:
51 MockXdgSurface();
52 ~MockXdgSurface();
53
54 MOCK_METHOD1(SetParent, void(wl_resource* parent));
55 MOCK_METHOD1(SetTitle, void(const char* title));
56 MOCK_METHOD1(SetAppId, void(const char* app_id));
57 MOCK_METHOD1(AckConfigure, void(uint32_t serial));
58 MOCK_METHOD0(SetMaximized, void());
59 MOCK_METHOD0(UnsetMaximized, void());
60 MOCK_METHOD0(SetMinimized, void());
61
62 private:
63 DISALLOW_COPY_AND_ASSIGN(MockXdgSurface);
64 };
65
66 struct FakeXdgSurface;
67
68 struct FakeSurface {
69 FakeSurface(wl_resource* resource);
70 ~FakeSurface();
71
72 wl_resource* resource;
73 MockSurface* mock = nullptr;
74 FakeXdgSurface* xdg_surface = nullptr;
75
76 static FakeSurface* FromResource(wl_resource* resource);
77 };
78
79 struct FakeXdgSurface {
80 FakeXdgSurface(wl_resource* resource, FakeSurface* surface);
81 ~FakeXdgSurface();
82
83 wl_resource* resource;
84 MockXdgSurface* mock = nullptr;
85 FakeSurface* surface;
86 };
87
88 struct GlobalDeleter {
89 void operator()(wl_global* global);
90 };
91
92 class Global {
93 public:
94 Global(const wl_interface* interface,
95 const void* implementation,
96 uint32_t version,
97 void* data);
98 virtual ~Global();
99
100 bool Initialize(wl_display* display);
101
102 // The first bound resource to this global, which is usually all that is
103 // useful when testing a simple client.
104 wl_resource* resource() { return resource_; }
105
106 static void Bind(wl_client* client,
107 void* data,
108 uint32_t version,
109 uint32_t id);
110
111 private:
112 scoped_ptr<wl_global, GlobalDeleter> global_;
113
114 const wl_interface* interface_;
115 const void* implementation_;
116 const uint32_t version_;
117 void* data_;
118 wl_resource* resource_ = nullptr;
119
120 DISALLOW_COPY_AND_ASSIGN(Global);
121 };
122
123 struct DisplayDeleter {
124 void operator()(wl_display* display);
125 };
126
127 class FakeServer : public base::Thread, base::MessagePumpLibevent::Watcher {
128 public:
129 FakeServer(MockXdgShell* xdg_shell_mock = nullptr);
130 ~FakeServer() override;
131
132 // Start the fake Wayland server. If this succeeds, the WAYLAND_SOCKET
133 // environment variable will be set to the string representation of a file
134 // descriptor that a client can connect to. The caller is responsible for
135 // ensuring that this file descriptor gets closed (for example, by calling
136 // wl_display_connect).
137 bool Start();
138
139 void Flush();
140
141 template <typename T>
142 T* GetObject(uint32_t id) {
143 return T::FromResource(wl_client_get_object(client_, id));
144 }
145
146 wl_resource* xdg_shell() { return xdg_shell_.resource(); }
147
148 private:
149 scoped_ptr<base::MessagePump> CreateMessagePump();
150
151 // base::MessagePumpLibevent::Watcher
152 void OnFileCanReadWithoutBlocking(int fd) override;
153 void OnFileCanWriteWithoutBlocking(int fd) override;
154
155 scoped_ptr<wl_display, DisplayDeleter> display_;
156 wl_client* client_ = nullptr;
157 wl_event_loop* event_loop_ = nullptr;
158
159 Global compositor_;
160 Global xdg_shell_;
161
162 base::MessagePumpLibevent::FileDescriptorWatcher controller_;
163
164 DISALLOW_COPY_AND_ASSIGN(FakeServer);
165 };
166
167 } // namespace wl
168
169 #endif // UI_OZONE_PLATFORM_WAYLAND_FAKE_SERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698