Commit fc50a615 authored by Alexander Dunaev's avatar Alexander Dunaev Committed by Commit Bot

The test harness for Ozone/Wayland unit tests is restructured.

Mock and test classes are moved into separate files and renamed appropriately.
The new files are moved into a separate source set that will later be used by
other tests.  Use of the SetImplementation call is revised; the 'deprecated'
version that doesn't take ownership is considered to be legitimate and renamed.
Additional test and mock classes that model environment of the Wayland buffer
manager are introduced.

Bug: 926155
Change-Id: Ia1056a3d1051b12fdc49fd3a11c5fdeb7a558dbd
Reviewed-on: https://chromium-review.googlesource.com/c/1443115Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Reviewed-by: default avatarMaksim Sisov <msisov@igalia.com>
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Cr-Commit-Position: refs/heads/master@{#627044}
parent 87c33c5d
...@@ -147,12 +147,75 @@ source_set("wayland") { ...@@ -147,12 +147,75 @@ source_set("wayland") {
] ]
} }
source_set("wayland_unittests") { source_set("test_support") {
testonly = true testonly = true
sources = [ sources = [
"fake_server.cc", "fake_server.cc",
"fake_server.h", "fake_server.h",
"test/constants.h",
"test/global_object.cc",
"test/global_object.h",
"test/mock_buffer.cc",
"test/mock_buffer.h",
"test/mock_surface.cc",
"test/mock_surface.h",
"test/mock_xdg_popup.cc",
"test/mock_xdg_popup.h",
"test/mock_xdg_shell.cc",
"test/mock_xdg_shell.h",
"test/mock_xdg_surface.cc",
"test/mock_xdg_surface.h",
"test/mock_zwp_linux_buffer_params.cc",
"test/mock_zwp_linux_buffer_params.h",
"test/mock_zwp_linux_dmabuf.cc",
"test/mock_zwp_linux_dmabuf.h",
"test/mock_zwp_text_input.cc",
"test/mock_zwp_text_input.h",
"test/server_object.cc",
"test/server_object.h",
"test/test_compositor.cc",
"test/test_compositor.h",
"test/test_data_device.cc",
"test/test_data_device.h",
"test/test_data_device_manager.cc",
"test/test_data_device_manager.h",
"test/test_data_offer.cc",
"test/test_data_offer.h",
"test/test_data_source.cc",
"test/test_data_source.h",
"test/test_keyboard.cc",
"test/test_keyboard.h",
"test/test_output.cc",
"test/test_output.h",
"test/test_pointer.cc",
"test/test_pointer.h",
"test/test_positioner.cc",
"test/test_positioner.h",
"test/test_seat.cc",
"test/test_seat.h",
"test/test_touch.cc",
"test/test_touch.h",
"test/test_zwp_text_input_manager.cc",
"test/test_zwp_text_input_manager.h",
]
deps = [
"//base:base",
"//testing/gmock",
"//third_party/wayland:wayland_server",
"//third_party/wayland-protocols:linux_dmabuf_protocol",
"//third_party/wayland-protocols:text_input_protocol",
"//third_party/wayland-protocols:xdg_shell_protocol",
"//ui/gfx/geometry:geometry",
]
}
source_set("wayland_unittests") {
testonly = true
sources = [
"wayland_buffer_manager_unittest.cc",
"wayland_connection_unittest.cc", "wayland_connection_unittest.cc",
"wayland_data_device_unittest.cc", "wayland_data_device_unittest.cc",
"wayland_input_method_context_unittest.cc", "wayland_input_method_context_unittest.cc",
...@@ -167,10 +230,13 @@ source_set("wayland_unittests") { ...@@ -167,10 +230,13 @@ source_set("wayland_unittests") {
] ]
deps = [ deps = [
":test_support",
":wayland", ":wayland",
"//build/config/linux/libdrm",
"//testing/gmock", "//testing/gmock",
"//testing/gtest", "//testing/gtest",
"//third_party/wayland:wayland_server", "//third_party/wayland:wayland_server",
"//third_party/wayland-protocols:linux_dmabuf_protocol",
"//third_party/wayland-protocols:text_input_protocol", "//third_party/wayland-protocols:text_input_protocol",
"//third_party/wayland-protocols:xdg_shell_protocol", "//third_party/wayland-protocols:xdg_shell_protocol",
"//ui/base", "//ui/base",
......
This diff is collapsed.
This diff is collapsed.
// Copyright 2019 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_TEST_CONSTANTS_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_CONSTANTS_H_
namespace wl {
constexpr char kSampleClipboardText[] = "This is a sample text for clipboard.";
constexpr char kSampleTextForDragAndDrop[] =
"This is a sample text for drag-and-drop.";
constexpr char kTextMimeTypeUtf8[] = "text/plain;charset=utf-8";
constexpr char kTextMimeTypeText[] = "text/plain";
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_CONSTANTS_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/global_object.h"
#include <algorithm>
#include <wayland-server-core.h>
#include "ui/ozone/platform/wayland/test/server_object.h"
namespace wl {
void GlobalObject::Deleter::operator()(wl_global* global) {
wl_global_destroy(global);
}
GlobalObject::GlobalObject(const wl_interface* interface,
const void* implementation,
uint32_t version)
: interface_(interface),
implementation_(implementation),
version_(version) {}
GlobalObject::~GlobalObject() {}
bool GlobalObject::Initialize(wl_display* display) {
global_.reset(wl_global_create(display, interface_, version_, this, &Bind));
return global_ != nullptr;
}
void GlobalObject::DestroyGlobal() {
global_.reset();
}
// static
void GlobalObject::Bind(wl_client* client,
void* data,
uint32_t version,
uint32_t id) {
auto* global = static_cast<GlobalObject*>(data);
wl_resource* resource = wl_resource_create(
client, global->interface_, std::min(version, global->version_), id);
if (!resource) {
wl_client_post_no_memory(client);
return;
}
if (!global->resource_)
global->resource_ = resource;
wl_resource_set_implementation(resource, global->implementation_, global,
&GlobalObject::OnResourceDestroyed);
global->OnBind();
}
// static
void GlobalObject::OnResourceDestroyed(wl_resource* resource) {
auto* global = GetUserDataAs<GlobalObject>(resource);
if (global->resource_ == resource)
global->resource_ = nullptr;
}
} // namespace wl
// Copyright 2019 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_TEST_GLOBAL_OBJECT_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_GLOBAL_OBJECT_H_
#include <memory>
#include "base/macros.h"
struct wl_client;
struct wl_display;
struct wl_global;
struct wl_interface;
struct wl_resource;
namespace wl {
// Base class for managing the lifecycle of global objects.
// Represents a global object used to emit global events to all clients.
class GlobalObject {
public:
GlobalObject(const wl_interface* interface,
const void* implementation,
uint32_t version);
virtual ~GlobalObject();
// Creates a global object.
bool Initialize(wl_display* display);
// Can be used by clients to explicitly destroy global objects and send
// global_remove event.
void DestroyGlobal();
// Called from Bind() to send additional information to clients.
virtual void OnBind() {}
// The first resource bound to this global, which is usually all that is
// useful when testing a simple client.
wl_resource* resource() const { return resource_; }
// Sends the global event to clients.
static void Bind(wl_client* client,
void* data,
uint32_t version,
uint32_t id);
static void OnResourceDestroyed(wl_resource* resource);
private:
struct Deleter {
void operator()(wl_global* global);
};
std::unique_ptr<wl_global, Deleter> global_;
const wl_interface* interface_;
const void* implementation_;
const uint32_t version_;
wl_resource* resource_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(GlobalObject);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_GLOBAL_OBJECT_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/mock_buffer.h"
namespace wl {
const struct wl_buffer_interface kMockWlBufferImpl = {&DestroyResource};
MockBuffer::MockBuffer(wl_resource* resource, std::vector<base::ScopedFD>&& fds)
: ServerObject(resource), fds_(std::move(fds)) {}
MockBuffer::~MockBuffer() {
for (auto& fd : fds_) {
LOG(WARNING) << "Will close FD: " << fd.get();
fd.reset();
}
}
} // namespace wl
// Copyright 2019 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_TEST_MOCK_BUFFER_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_BUFFER_H_
#include <linux-dmabuf-unstable-v1-server-protocol.h>
#include "base/files/scoped_file.h"
#include "base/macros.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/ozone/platform/wayland/test/server_object.h"
struct wl_client;
struct wl_resource;
namespace wl {
extern const struct wl_buffer_interface kMockWlBufferImpl;
// Manage wl_buffer object.
class MockBuffer : public ServerObject {
public:
MockBuffer(wl_resource* resource, std::vector<base::ScopedFD>&& fds);
~MockBuffer() override;
MOCK_METHOD2(Destroy, void(wl_client* client, wl_resource* resource));
private:
std::vector<base::ScopedFD> fds_;
DISALLOW_COPY_AND_ASSIGN(MockBuffer);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_BUFFER_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/mock_surface.h"
namespace wl {
namespace {
void Attach(wl_client* client,
wl_resource* resource,
wl_resource* buffer_resource,
int32_t x,
int32_t y) {
GetUserDataAs<MockSurface>(resource)->Attach(buffer_resource, x, y);
}
void Damage(wl_client* client,
wl_resource* resource,
int32_t x,
int32_t y,
int32_t width,
int32_t height) {
GetUserDataAs<MockSurface>(resource)->Damage(x, y, width, height);
}
void Commit(wl_client* client, wl_resource* resource) {
GetUserDataAs<MockSurface>(resource)->Commit();
}
} // namespace
const struct wl_surface_interface kMockSurfaceImpl = {
&DestroyResource, // destroy
&Attach, // attach
&Damage, // damage
nullptr, // frame
nullptr, // set_opaque_region
nullptr, // set_input_region
&Commit, // commit
nullptr, // set_buffer_transform
nullptr, // set_buffer_scale
nullptr, // damage_buffer
};
MockSurface::MockSurface(wl_resource* resource) : ServerObject(resource) {}
MockSurface::~MockSurface() {
if (xdg_surface_ && xdg_surface_->resource())
wl_resource_destroy(xdg_surface_->resource());
}
MockSurface* MockSurface::FromResource(wl_resource* resource) {
if (!ResourceHasImplementation(resource, &wl_surface_interface,
&kMockSurfaceImpl))
return nullptr;
return GetUserDataAs<MockSurface>(resource);
}
} // namespace wl
// Copyright 2019 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_TEST_MOCK_SURFACE_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_SURFACE_H_
#include <wayland-server-protocol-core.h>
#include "base/macros.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/ozone/platform/wayland/test/mock_xdg_surface.h"
#include "ui/ozone/platform/wayland/test/server_object.h"
struct wl_resource;
namespace wl {
extern const struct wl_surface_interface kMockSurfaceImpl;
// Manage client surface
class MockSurface : public ServerObject {
public:
explicit MockSurface(wl_resource* resource);
~MockSurface() override;
static MockSurface* FromResource(wl_resource* resource);
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());
void set_xdg_surface(std::unique_ptr<MockXdgSurface> xdg_surface) {
xdg_surface_ = std::move(xdg_surface);
}
MockXdgSurface* xdg_surface() const { return xdg_surface_.get(); }
private:
std::unique_ptr<MockXdgSurface> xdg_surface_;
DISALLOW_COPY_AND_ASSIGN(MockSurface);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_SURFACE_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/mock_xdg_popup.h"
namespace wl {
namespace {
void Grab(struct wl_client* client,
struct wl_resource* resource,
struct wl_resource* seat,
uint32_t serial) {
GetUserDataAs<MockXdgPopup>(resource)->Grab(serial);
}
} // namespace
const struct xdg_popup_interface kXdgPopupImpl = {
&DestroyResource, // destroy
};
const struct zxdg_popup_v6_interface kZxdgPopupV6Impl = {
&DestroyResource, // destroy
&Grab, // grab
};
MockXdgPopup::MockXdgPopup(wl_resource* resource) : ServerObject(resource) {}
MockXdgPopup::~MockXdgPopup() {}
} // namespace wl
// Copyright 2019 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_TEST_MOCK_XDG_POPUP_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_XDG_POPUP_H_
#include <xdg-shell-unstable-v5-server-protocol.h>
#include <xdg-shell-unstable-v6-server-protocol.h>
#include "base/macros.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/ozone/platform/wayland/test/server_object.h"
struct wl_resource;
namespace wl {
extern const struct xdg_popup_interface kXdgPopupImpl;
extern const struct zxdg_popup_v6_interface kZxdgPopupV6Impl;
class MockXdgPopup : public ServerObject {
public:
MockXdgPopup(wl_resource* resource);
~MockXdgPopup() override;
MOCK_METHOD1(Grab, void(uint32_t serial));
private:
DISALLOW_COPY_AND_ASSIGN(MockXdgPopup);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_XDG_POPUP_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/mock_xdg_shell.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/ozone/platform/wayland/test/mock_xdg_popup.h"
#include "ui/ozone/platform/wayland/test/server_object.h"
#include "ui/ozone/platform/wayland/test/test_positioner.h"
namespace wl {
namespace {
constexpr uint32_t kXdgShellVersion = 1;
void GetXdgSurfaceImpl(wl_client* client,
wl_resource* resource,
uint32_t id,
wl_resource* surface_resource,
const struct wl_interface* interface,
const void* implementation) {
auto* surface = GetUserDataAs<MockSurface>(surface_resource);
if (surface->xdg_surface()) {
uint32_t xdg_error = implementation == &kMockXdgSurfaceImpl
? XDG_SHELL_ERROR_ROLE
: ZXDG_SHELL_V6_ERROR_ROLE;
wl_resource_post_error(resource, xdg_error, "surface already has a role");
return;
}
wl_resource* xdg_surface_resource = wl_resource_create(
client, interface, wl_resource_get_version(resource), id);
if (!xdg_surface_resource) {
wl_client_post_no_memory(client);
return;
}
surface->set_xdg_surface(
std::make_unique<MockXdgSurface>(xdg_surface_resource, implementation));
}
void UseUnstableVersion(wl_client* client,
wl_resource* resource,
int32_t version) {
GetUserDataAs<MockXdgShell>(resource)->UseUnstableVersion(version);
}
void GetXdgSurface(wl_client* client,
wl_resource* resource,
uint32_t id,
wl_resource* surface_resource) {
GetXdgSurfaceImpl(client, resource, id, surface_resource,
&xdg_surface_interface, &kMockXdgSurfaceImpl);
}
void GetXdgPopup(struct wl_client* client,
struct wl_resource* resource,
uint32_t id,
struct wl_resource* surface,
struct wl_resource* parent,
struct wl_resource* seat,
uint32_t serial,
int32_t x,
int32_t y) {
auto* mock_surface = GetUserDataAs<MockSurface>(surface);
if (mock_surface->resource() &&
ResourceHasImplementation(mock_surface->resource(), &xdg_popup_interface,
&kXdgPopupImpl)) {
wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE,
"surface has already assigned a role");
return;
}
wl_resource* popup_resource = wl_resource_create(
client, &xdg_popup_interface, wl_resource_get_version(resource), id);
if (!popup_resource) {
wl_client_post_no_memory(client);
return;
}
SetImplementation(popup_resource, &kXdgPopupImpl,
std::make_unique<MockXdgPopup>(popup_resource));
}
void Pong(wl_client* client, wl_resource* resource, uint32_t serial) {
GetUserDataAs<MockXdgShell>(resource)->Pong(serial);
}
void CreatePositioner(wl_client* client,
struct wl_resource* resource,
uint32_t id) {
wl_resource* positioner_resource =
wl_resource_create(client, &zxdg_positioner_v6_interface,
wl_resource_get_version(resource), id);
if (!positioner_resource) {
wl_client_post_no_memory(client);
return;
}
SetImplementation(positioner_resource, &kTestZxdgPositionerV6Impl,
std::make_unique<TestPositioner>(positioner_resource));
}
void GetXdgSurfaceV6(wl_client* client,
wl_resource* resource,
uint32_t id,
wl_resource* surface_resource) {
GetXdgSurfaceImpl(client, resource, id, surface_resource,
&zxdg_surface_v6_interface, &kMockZxdgSurfaceV6Impl);
}
void PongV6(wl_client* client, wl_resource* resource, uint32_t serial) {
GetUserDataAs<MockZxdgShellV6>(resource)->Pong(serial);
}
} // namespace
const struct xdg_shell_interface kMockXdgShellImpl = {
&DestroyResource, // destroy
&UseUnstableVersion, // use_unstable_version
&GetXdgSurface, // get_xdg_surface
&GetXdgPopup, // get_xdg_popup
&Pong, // pong
};
const struct zxdg_shell_v6_interface kMockZxdgShellV6Impl = {
&DestroyResource, // destroy
&CreatePositioner, // create_positioner
&GetXdgSurfaceV6, // get_xdg_surface
&PongV6, // pong
};
MockXdgShell::MockXdgShell()
: GlobalObject(&xdg_shell_interface, &kMockXdgShellImpl, kXdgShellVersion) {
}
MockXdgShell::~MockXdgShell() {}
MockZxdgShellV6::MockZxdgShellV6()
: GlobalObject(&zxdg_shell_v6_interface,
&kMockZxdgShellV6Impl,
kXdgShellVersion) {}
MockZxdgShellV6::~MockZxdgShellV6() {}
} // namespace wl
// Copyright 2019 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_TEST_MOCK_XDG_SHELL_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_XDG_SHELL_H_
#include <xdg-shell-unstable-v5-server-protocol.h>
#include <xdg-shell-unstable-v6-server-protocol.h>
#include "base/macros.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/ozone/platform/wayland/test/global_object.h"
namespace wl {
extern const struct xdg_shell_interface kMockXdgShellImpl;
extern const struct zxdg_shell_v6_interface kMockZxdgShellV6Impl;
// Manage xdg_shell object.
class MockXdgShell : public GlobalObject {
public:
MockXdgShell();
~MockXdgShell() override;
MOCK_METHOD1(UseUnstableVersion, void(int32_t version));
MOCK_METHOD1(Pong, void(uint32_t serial));
private:
DISALLOW_COPY_AND_ASSIGN(MockXdgShell);
};
// Manage zxdg_shell_v6 object.
class MockZxdgShellV6 : public GlobalObject {
public:
MockZxdgShellV6();
~MockZxdgShellV6() override;
MOCK_METHOD1(Pong, void(uint32_t serial));
private:
DISALLOW_COPY_AND_ASSIGN(MockZxdgShellV6);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_XDG_SHELL_H_
// Copyright 2019 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.
#include <xdg-shell-unstable-v6-server-protocol.h>
#include "ui/ozone/platform/wayland/test/mock_xdg_popup.h"
#include "ui/ozone/platform/wayland/test/mock_xdg_surface.h"
#include "ui/ozone/platform/wayland/test/test_positioner.h"
namespace wl {
void SetTitle(wl_client* client, wl_resource* resource, const char* title) {
GetUserDataAs<MockXdgSurface>(resource)->SetTitle(title);
}
void SetAppId(wl_client* client, wl_resource* resource, const char* app_id) {
GetUserDataAs<MockXdgSurface>(resource)->SetAppId(app_id);
}
void Move(wl_client* client,
wl_resource* resource,
wl_resource* seat,
uint32_t serial) {
GetUserDataAs<MockXdgSurface>(resource)->Move(serial);
}
void Resize(wl_client* client,
wl_resource* resource,
wl_resource* seat,
uint32_t serial,
uint32_t edges) {
GetUserDataAs<MockXdgSurface>(resource)->Resize(serial, edges);
}
void AckConfigure(wl_client* client, wl_resource* resource, uint32_t serial) {
GetUserDataAs<MockXdgSurface>(resource)->AckConfigure(serial);
}
void SetWindowGeometry(wl_client* client,
wl_resource* resource,
int32_t x,
int32_t y,
int32_t width,
int32_t height) {
GetUserDataAs<MockXdgSurface>(resource)->SetWindowGeometry(x, y, width,
height);
}
void SetMaximized(wl_client* client, wl_resource* resource) {
GetUserDataAs<MockXdgSurface>(resource)->SetMaximized();
}
void UnsetMaximized(wl_client* client, wl_resource* resource) {
GetUserDataAs<MockXdgSurface>(resource)->UnsetMaximized();
}
void SetFullscreen(wl_client* client,
wl_resource* resource,
wl_resource* output) {
GetUserDataAs<MockXdgSurface>(resource)->SetFullscreen();
}
void UnsetFullscreen(wl_client* client, wl_resource* resource) {
GetUserDataAs<MockXdgSurface>(resource)->UnsetFullscreen();
}
void SetMinimized(wl_client* client, wl_resource* resource) {
GetUserDataAs<MockXdgSurface>(resource)->SetMinimized();
}
void GetTopLevel(wl_client* client, wl_resource* resource, uint32_t id) {
auto* surface = GetUserDataAs<MockXdgSurface>(resource);
if (surface->xdg_toplevel()) {
wl_resource_post_error(resource, ZXDG_SURFACE_V6_ERROR_ALREADY_CONSTRUCTED,
"surface has already been constructed");
return;
}
wl_resource* xdg_toplevel_resource =
wl_resource_create(client, &zxdg_toplevel_v6_interface, 1, id);
if (!xdg_toplevel_resource) {
wl_client_post_no_memory(client);
return;
}
surface->set_xdg_toplevel(
std::make_unique<MockXdgTopLevel>(xdg_toplevel_resource));
}
void GetZXdgPopupV6(struct wl_client* client,
struct wl_resource* resource,
uint32_t id,
struct wl_resource* parent,
struct wl_resource* positioner_resource) {
auto* mock_xdg_surface = GetUserDataAs<MockXdgSurface>(resource);
wl_resource* current_resource = mock_xdg_surface->resource();
if (current_resource &&
(ResourceHasImplementation(current_resource, &zxdg_popup_v6_interface,
&kZxdgPopupV6Impl) ||
ResourceHasImplementation(current_resource,
&zxdg_positioner_v6_interface,
&kTestZxdgPositionerV6Impl))) {
wl_resource_post_error(resource, ZXDG_SURFACE_V6_ERROR_ALREADY_CONSTRUCTED,
"surface has already been constructed");
return;
}
auto* positioner = GetUserDataAs<TestPositioner>(positioner_resource);
if (positioner->size().width() == 0 ||
positioner->anchor_rect().width() == 0) {
wl_resource_post_error(resource, ZXDG_SHELL_V6_ERROR_INVALID_POSITIONER,
"Positioner object is not complete");
return;
}
wl_resource* popup_resource = wl_resource_create(
client, &zxdg_popup_v6_interface, wl_resource_get_version(resource), id);
if (!popup_resource) {
wl_client_post_no_memory(client);
return;
}
SetImplementation(popup_resource, &kZxdgPopupV6Impl,
std::make_unique<MockXdgPopup>(popup_resource));
}
const struct xdg_surface_interface kMockXdgSurfaceImpl = {
&DestroyResource, // destroy
nullptr, // set_parent
&SetTitle, // set_title
&SetAppId, // set_app_id
nullptr, // show_window_menu
&Move, // move
&Resize, // resize
&AckConfigure, // ack_configure
&SetWindowGeometry, // set_window_geometry
&SetMaximized, // set_maximized
&UnsetMaximized, // set_unmaximized
&SetFullscreen, // set_fullscreen
&UnsetFullscreen, // unset_fullscreen
&SetMinimized, // set_minimized
};
const struct zxdg_surface_v6_interface kMockZxdgSurfaceV6Impl = {
&DestroyResource, // destroy
&GetTopLevel, // get_toplevel
&GetZXdgPopupV6, // get_popup
&SetWindowGeometry, // set_window_geometry
&AckConfigure, // ack_configure
};
const struct zxdg_toplevel_v6_interface kMockZxdgToplevelV6Impl = {
&DestroyResource, // destroy
nullptr, // set_parent
&SetTitle, // set_title
&SetAppId, // set_app_id
nullptr, // show_window_menu
&Move, // move
&Resize, // resize
nullptr, // set_max_size
nullptr, // set_min_size
&SetMaximized, // set_maximized
&UnsetMaximized, // set_unmaximized
&SetFullscreen, // set_fullscreen
&UnsetFullscreen, // unset_fullscreen
&SetMinimized, // set_minimized
};
MockXdgSurface::MockXdgSurface(wl_resource* resource,
const void* implementation)
: ServerObject(resource) {
SetImplementationUnretained(resource, implementation, this);
}
MockXdgSurface::~MockXdgSurface() {}
MockXdgTopLevel::MockXdgTopLevel(wl_resource* resource)
: MockXdgSurface(resource, &kMockZxdgSurfaceV6Impl) {
SetImplementationUnretained(resource, &kMockZxdgToplevelV6Impl, this);
}
MockXdgTopLevel::~MockXdgTopLevel() {}
} // namespace wl
// Copyright 2019 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_TEST_MOCK_XDG_SURFACE_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_XDG_SURFACE_H_
#include <xdg-shell-unstable-v5-server-protocol.h>
#include <xdg-shell-unstable-v6-server-protocol.h>
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/ozone/platform/wayland/test/server_object.h"
struct wl_resource;
namespace wl {
extern const struct xdg_surface_interface kMockXdgSurfaceImpl;
extern const struct zxdg_surface_v6_interface kMockZxdgSurfaceV6Impl;
extern const struct zxdg_toplevel_v6_interface kMockZxdgToplevelV6Impl;
class MockXdgTopLevel;
// Manage xdg_surface, zxdg_surface_v6 and zxdg_toplevel for providing desktop
// UI.
class MockXdgSurface : public ServerObject {
public:
MockXdgSurface(wl_resource* resource, const void* implementation);
~MockXdgSurface() override;
// These mock methods are shared between xdg_surface and zxdg_toplevel
// surface.
MOCK_METHOD1(SetParent, void(wl_resource* parent));
MOCK_METHOD1(SetTitle, void(const char* title));
MOCK_METHOD1(SetAppId, void(const char* app_id));
MOCK_METHOD1(Move, void(uint32_t serial));
MOCK_METHOD2(Resize, void(uint32_t serial, uint32_t edges));
MOCK_METHOD1(AckConfigure, void(uint32_t serial));
MOCK_METHOD4(SetWindowGeometry,
void(int32_t x, int32_t y, int32_t width, int32_t height));
MOCK_METHOD0(SetMaximized, void());
MOCK_METHOD0(UnsetMaximized, void());
MOCK_METHOD0(SetFullscreen, void());
MOCK_METHOD0(UnsetFullscreen, void());
MOCK_METHOD0(SetMinimized, void());
void set_xdg_toplevel(std::unique_ptr<MockXdgTopLevel> xdg_toplevel) {
xdg_toplevel_ = std::move(xdg_toplevel);
}
MockXdgTopLevel* xdg_toplevel() const { return xdg_toplevel_.get(); }
private:
// Used when xdg v6 is used.
std::unique_ptr<MockXdgTopLevel> xdg_toplevel_;
DISALLOW_COPY_AND_ASSIGN(MockXdgSurface);
};
// Manage zxdg_toplevel for providing desktop UI.
class MockXdgTopLevel : public MockXdgSurface {
public:
explicit MockXdgTopLevel(wl_resource* resource);
~MockXdgTopLevel() override;
// TODO(msisov): mock other zxdg_toplevel specific methods once
// implementation
// is done. example: MOCK_METHOD2(SetMaxSize, void(int32_t width, int32_t
// height());
private:
DISALLOW_COPY_AND_ASSIGN(MockXdgTopLevel);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_XDG_SURFACE_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/mock_zwp_linux_buffer_params.h"
#include "ui/ozone/platform/wayland/test/mock_buffer.h"
namespace wl {
namespace {
void Add(wl_client* client,
wl_resource* resource,
int32_t fd,
uint32_t plane_idx,
uint32_t offset,
uint32_t stride,
uint32_t modifier_hi,
uint32_t modifier_lo) {
auto* buffer_params = GetUserDataAs<MockZwpLinuxBufferParamsV1>(resource);
buffer_params->fds_.emplace_back(fd);
buffer_params->Add(client, resource, fd, plane_idx, offset, stride,
modifier_hi, modifier_lo);
}
void Create(wl_client* client,
wl_resource* resource,
int32_t width,
int32_t height,
uint32_t format,
uint32_t flags) {
auto* buffer_params = GetUserDataAs<MockZwpLinuxBufferParamsV1>(resource);
wl_resource* buffer_resource =
wl_resource_create(client, &wl_buffer_interface, 1, 0);
SetImplementation(buffer_resource, &kMockWlBufferImpl,
std::make_unique<MockBuffer>(
buffer_resource, std::move(buffer_params->fds_)));
zwp_linux_buffer_params_v1_send_created(resource, buffer_resource);
GetUserDataAs<MockZwpLinuxBufferParamsV1>(resource)->Create(
client, resource, width, height, format, flags);
}
void CreateImmed(wl_client* client,
wl_resource* resource,
uint32_t buffer_id,
int32_t width,
int32_t height,
uint32_t format,
uint32_t flags) {
GetUserDataAs<MockZwpLinuxBufferParamsV1>(resource)->CreateImmed(
client, resource, buffer_id, width, height, format, flags);
}
} // namespace
const struct zwp_linux_buffer_params_v1_interface
kMockZwpLinuxBufferParamsV1Impl = {&DestroyResource, &Add, &Create,
&CreateImmed};
MockZwpLinuxBufferParamsV1::MockZwpLinuxBufferParamsV1(wl_resource* resource)
: ServerObject(resource) {}
MockZwpLinuxBufferParamsV1::~MockZwpLinuxBufferParamsV1() {}
} // namespace wl
// Copyright 2019 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_TEST_MOCK_ZWP_LINUX_BUFFER_PARAMS_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_ZWP_LINUX_BUFFER_PARAMS_H_
#include <linux-dmabuf-unstable-v1-server-protocol.h>
#include "base/files/scoped_file.h"
#include "base/macros.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/ozone/platform/wayland/test/server_object.h"
struct wl_client;
struct wl_resource;
namespace wl {
extern const struct zwp_linux_buffer_params_v1_interface
kMockZwpLinuxBufferParamsV1Impl;
// Manage zwp_linux_buffer_params_v1
class MockZwpLinuxBufferParamsV1 : public ServerObject {
public:
MockZwpLinuxBufferParamsV1(wl_resource* resource);
~MockZwpLinuxBufferParamsV1();
MOCK_METHOD2(Destroy, void(wl_client* client, wl_resource* resource));
MOCK_METHOD8(Add,
void(wl_client* client,
wl_resource* resource,
int32_t fd,
uint32_t plane_idx,
uint32_t offset,
uint32_t stride,
uint32_t modifier_hi,
uint32_t modifier_lo));
MOCK_METHOD6(Create,
void(wl_client* client,
wl_resource* resource,
int32_t width,
int32_t height,
uint32_t format,
uint32_t flags));
MOCK_METHOD7(CreateImmed,
void(wl_client* client,
wl_resource* resource,
uint32_t buffer_id,
int32_t width,
int32_t height,
uint32_t format,
uint32_t flags));
std::vector<base::ScopedFD> fds_;
private:
DISALLOW_COPY_AND_ASSIGN(MockZwpLinuxBufferParamsV1);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_ZWP_LINUX_BUFFER_PARAMS_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/mock_zwp_linux_dmabuf.h"
#include <linux-dmabuf-unstable-v1-server-protocol.h>
#include <wayland-server-core.h>
#include "ui/ozone/platform/wayland/test/mock_buffer.h"
#include "ui/ozone/platform/wayland/test/mock_zwp_linux_buffer_params.h"
namespace wl {
namespace {
constexpr uint32_t kLinuxDmabufVersion = 1;
void CreateParams(wl_client* client, wl_resource* resource, uint32_t id) {
wl_resource* buffer_params_resource =
wl_resource_create(client, &zwp_linux_buffer_params_v1_interface,
wl_resource_get_version(resource), id);
SetImplementation(
buffer_params_resource, &kMockZwpLinuxBufferParamsV1Impl,
std::make_unique<MockZwpLinuxBufferParamsV1>(buffer_params_resource));
GetUserDataAs<MockZwpLinuxDmabufV1>(resource)->CreateParams(client, resource,
id);
}
} // namespace
const struct zwp_linux_dmabuf_v1_interface kMockZwpLinuxDmabufV1Impl = {
&DestroyResource, // destroy
&CreateParams, // create_params
};
MockZwpLinuxDmabufV1::MockZwpLinuxDmabufV1()
: GlobalObject(&zwp_linux_dmabuf_v1_interface,
&kMockZwpLinuxDmabufV1Impl,
kLinuxDmabufVersion) {}
MockZwpLinuxDmabufV1::~MockZwpLinuxDmabufV1() {}
} // namespace wl
// Copyright 2019 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_TEST_MOCK_ZWP_LINUX_DMABUF_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_ZWP_LINUX_DMABUF_H_
#include <linux-dmabuf-unstable-v1-server-protocol.h>
#include "base/macros.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/ozone/platform/wayland/test/global_object.h"
struct wl_client;
struct wl_resource;
namespace wl {
extern const struct zwp_linux_dmabuf_v1_interface kMockZwpLinuxDmabufV1Impl;
// Manage zwp_linux_dmabuf_v1 object.
class MockZwpLinuxDmabufV1 : public GlobalObject {
public:
MockZwpLinuxDmabufV1();
~MockZwpLinuxDmabufV1() override;
MOCK_METHOD2(Destroy, void(wl_client* client, wl_resource* resource));
MOCK_METHOD3(CreateParams,
void(wl_client* client,
wl_resource* resource,
uint32_t params_id));
private:
DISALLOW_COPY_AND_ASSIGN(MockZwpLinuxDmabufV1);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_ZWP_LINUX_DMABUF_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/mock_zwp_text_input.h"
namespace wl {
namespace {
void TextInputV1Activate(wl_client* client,
wl_resource* resource,
wl_resource* seat,
wl_resource* surface) {
GetUserDataAs<MockZwpTextInput>(resource)->Activate(surface);
}
void TextInputV1Deactivate(wl_client* client,
wl_resource* resource,
wl_resource* seat) {
GetUserDataAs<MockZwpTextInput>(resource)->Deactivate();
}
void TextInputV1ShowInputPanel(wl_client* client, wl_resource* resource) {
GetUserDataAs<MockZwpTextInput>(resource)->ShowInputPanel();
}
void TextInputV1HideInputPanel(wl_client* client, wl_resource* resource) {
GetUserDataAs<MockZwpTextInput>(resource)->HideInputPanel();
}
void TextInputV1Reset(wl_client* client, wl_resource* resource) {
GetUserDataAs<MockZwpTextInput>(resource)->Reset();
}
void TextInputV1SetCursorRectangle(wl_client* client,
wl_resource* resource,
int32_t x,
int32_t y,
int32_t width,
int32_t height) {
GetUserDataAs<MockZwpTextInput>(resource)->SetCursorRect(x, y, width, height);
}
} // namespace
const struct zwp_text_input_v1_interface kMockZwpTextInputV1Impl = {
&TextInputV1Activate, // activate
&TextInputV1Deactivate, // deactivate
&TextInputV1ShowInputPanel, // show_input_panel
&TextInputV1HideInputPanel, // hide_input_panel
&TextInputV1Reset, // reset
nullptr, // set_surrounding_text
nullptr, // set_content_type
&TextInputV1SetCursorRectangle, // set_cursor_rectangle
nullptr, // set_preferred_language
nullptr, // commit_state
nullptr, // invoke_action
};
MockZwpTextInput::MockZwpTextInput(wl_resource* resource)
: ServerObject(resource) {}
MockZwpTextInput::~MockZwpTextInput() {}
} // namespace wl
// Copyright 2019 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_TEST_MOCK_ZWP_TEXT_INPUT_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_ZWP_TEXT_INPUT_H_
#include <text-input-unstable-v1-server-protocol.h>
#include "base/macros.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/ozone/platform/wayland/test/server_object.h"
struct wl_resource;
namespace wl {
extern const struct zwp_text_input_v1_interface kMockZwpTextInputV1Impl;
// Manage zwp_text_input_v1.
class MockZwpTextInput : public ServerObject {
public:
MockZwpTextInput(wl_resource* resource);
~MockZwpTextInput() override;
MOCK_METHOD0(Reset, void());
MOCK_METHOD1(Activate, void(wl_resource* window));
MOCK_METHOD0(Deactivate, void());
MOCK_METHOD0(ShowInputPanel, void());
MOCK_METHOD0(HideInputPanel, void());
MOCK_METHOD4(SetCursorRect,
void(int32_t x, int32_t y, int32_t width, int32_t height));
private:
DISALLOW_COPY_AND_ASSIGN(MockZwpTextInput);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_ZWP_TEXT_INPUT_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/server_object.h"
namespace wl {
bool ResourceHasImplementation(wl_resource* resource,
const wl_interface* interface,
const void* impl) {
return wl_resource_instance_of(resource, interface, impl);
}
void DestroyResource(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
ServerObject::ServerObject(wl_resource* resource) : resource_(resource) {}
ServerObject::~ServerObject() {
if (resource_)
wl_resource_destroy(resource_);
}
// static
void ServerObject::OnResourceDestroyed(wl_resource* resource) {
auto* obj = GetUserDataAs<ServerObject>(resource);
obj->resource_ = nullptr;
}
} // namespace wl
// Copyright 2019 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_TEST_SERVER_OBJECT_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_SERVER_OBJECT_H_
#include <memory>
#include "base/macros.h"
#include <wayland-server-core.h>
struct wl_client;
struct wl_resource;
namespace wl {
// Base class for managing the life cycle of server objects.
class ServerObject {
public:
explicit ServerObject(wl_resource* resource);
virtual ~ServerObject();
wl_resource* resource() const { return resource_; }
static void OnResourceDestroyed(wl_resource* resource);
private:
wl_resource* resource_;
DISALLOW_COPY_AND_ASSIGN(ServerObject);
};
template <class T>
T* GetUserDataAs(wl_resource* resource) {
return static_cast<T*>(wl_resource_get_user_data(resource));
}
template <class T>
std::unique_ptr<T> TakeUserDataAs(wl_resource* resource) {
std::unique_ptr<T> user_data(GetUserDataAs<T>(resource));
// Make sure ServerObject doesn't try to destroy the resource twice.
ServerObject::OnResourceDestroyed(resource);
wl_resource_set_user_data(resource, nullptr);
return user_data;
}
template <class T>
void DestroyUserData(wl_resource* resource) {
TakeUserDataAs<T>(resource);
}
template <class T>
void SetImplementation(wl_resource* resource,
const void* implementation,
std::unique_ptr<T> user_data) {
wl_resource_set_implementation(resource, implementation, user_data.release(),
DestroyUserData<T>);
}
// Does not transfer ownership of the user_data. Use with caution. The only
// legitimate purpose is setting more than one implementation to the same user
// data.
template <class T>
void SetImplementationUnretained(wl_resource* resource,
const void* implementation,
T* user_data) {
wl_resource_set_implementation(resource, implementation, user_data,
&ServerObject::OnResourceDestroyed);
}
bool ResourceHasImplementation(wl_resource* resource,
const wl_interface* interface,
const void* impl);
void DestroyResource(wl_client* client, wl_resource* resource);
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_SERVER_OBJECT_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/test_compositor.h"
#include <wayland-server-core.h>
#include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/ozone/platform/wayland/test/server_object.h"
namespace wl {
namespace {
constexpr uint32_t kCompositorVersion = 4;
void CreateSurface(wl_client* client, wl_resource* resource, uint32_t id) {
auto* compositor = GetUserDataAs<TestCompositor>(resource);
wl_resource* surface_resource = wl_resource_create(
client, &wl_surface_interface, wl_resource_get_version(resource), id);
if (!surface_resource) {
wl_client_post_no_memory(client);
return;
}
SetImplementation(surface_resource, &kMockSurfaceImpl,
std::make_unique<MockSurface>(surface_resource));
compositor->AddSurface(GetUserDataAs<MockSurface>(surface_resource));
}
} // namespace
const struct wl_compositor_interface kTestCompositorImpl = {
&CreateSurface, // create_surface
nullptr, // create_region
};
TestCompositor::TestCompositor()
: GlobalObject(&wl_compositor_interface,
&kTestCompositorImpl,
kCompositorVersion) {}
TestCompositor::~TestCompositor() {}
void TestCompositor::AddSurface(MockSurface* surface) {
surfaces_.push_back(surface);
}
} // namespace wl
// Copyright 2019 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_TEST_TEST_COMPOSITOR_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_COMPOSITOR_H_
#include <vector>
#include "base/macros.h"
#include "ui/ozone/platform/wayland/test/global_object.h"
namespace wl {
class MockSurface;
// Manage wl_compositor object.
class TestCompositor : public GlobalObject {
public:
TestCompositor();
~TestCompositor() override;
void AddSurface(MockSurface* surface);
private:
std::vector<MockSurface*> surfaces_;
DISALLOW_COPY_AND_ASSIGN(TestCompositor);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_COMPOSITOR_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/test_data_device.h"
#include <wayland-server-core.h>
#include "base/logging.h"
#include "ui/ozone/platform/wayland/test/test_data_offer.h"
namespace wl {
namespace {
void DataDeviceStartDrag(wl_client* client,
wl_resource* resource,
wl_resource* source,
wl_resource* origin,
wl_resource* icon,
uint32_t serial) {
NOTIMPLEMENTED();
}
void DataDeviceSetSelection(wl_client* client,
wl_resource* resource,
wl_resource* data_source,
uint32_t serial) {
GetUserDataAs<TestDataDevice>(resource)->SetSelection(
data_source ? GetUserDataAs<TestDataSource>(data_source) : nullptr,
serial);
}
void DataDeviceRelease(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
} // namespace
const struct wl_data_device_interface kTestDataDeviceImpl = {
&DataDeviceStartDrag, &DataDeviceSetSelection, &DataDeviceRelease};
TestDataDevice::TestDataDevice(wl_client* client, wl_resource* resource)
: ServerObject(resource), client_(client) {}
TestDataDevice::~TestDataDevice() {}
void TestDataDevice::SetSelection(TestDataSource* data_source,
uint32_t serial) {
NOTIMPLEMENTED();
}
TestDataOffer* TestDataDevice::OnDataOffer() {
wl_resource* data_offer_resource =
wl_resource_create(client_, &wl_data_offer_interface,
wl_resource_get_version(resource()), 0);
SetImplementation(data_offer_resource, &kTestDataOfferImpl,
std::make_unique<TestDataOffer>(data_offer_resource));
data_offer_ = GetUserDataAs<TestDataOffer>(data_offer_resource);
wl_data_device_send_data_offer(resource(), data_offer_resource);
return GetUserDataAs<TestDataOffer>(data_offer_resource);
}
void TestDataDevice::OnEnter(uint32_t serial,
wl_resource* surface,
wl_fixed_t x,
wl_fixed_t y,
TestDataOffer* data_offer) {
wl_data_device_send_enter(resource(), serial, surface, x, y,
data_offer->resource());
}
void TestDataDevice::OnLeave() {
wl_data_device_send_leave(resource());
}
void TestDataDevice::OnMotion(uint32_t time, wl_fixed_t x, wl_fixed_t y) {
wl_data_device_send_motion(resource(), time, x, y);
}
void TestDataDevice::OnDrop() {
wl_data_device_send_drop(resource());
}
void TestDataDevice::OnSelection(TestDataOffer* data_offer) {
wl_data_device_send_selection(resource(), data_offer->resource());
}
} // namespace wl
// Copyright 2019 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_TEST_TEST_DATA_DEVICE_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_DEVICE_H_
#include <wayland-server-protocol-core.h>
#include "base/macros.h"
#include "ui/ozone/platform/wayland/test/server_object.h"
struct wl_client;
struct wl_resource;
namespace wl {
extern const struct wl_data_device_interface kTestDataDeviceImpl;
class TestDataOffer;
class TestDataSource;
class TestDataDevice : public ServerObject {
public:
TestDataDevice(wl_client* client, wl_resource* resource);
~TestDataDevice() override;
void SetSelection(TestDataSource* data_source, uint32_t serial);
TestDataOffer* OnDataOffer();
void OnEnter(uint32_t serial,
wl_resource* surface,
wl_fixed_t x,
wl_fixed_t y,
TestDataOffer* data_offer);
void OnLeave();
void OnMotion(uint32_t time, wl_fixed_t x, wl_fixed_t y);
void OnDrop();
void OnSelection(TestDataOffer* data_offer);
private:
TestDataOffer* data_offer_;
wl_client* client_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(TestDataDevice);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_DEVICE_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/test_data_device_manager.h"
#include <wayland-server-core.h>
#include "ui/ozone/platform/wayland/test/test_data_device.h"
#include "ui/ozone/platform/wayland/test/test_data_source.h"
namespace wl {
namespace {
constexpr uint32_t kDataDeviceManagerVersion = 3;
void CreateDataSource(wl_client* client, wl_resource* resource, uint32_t id) {
wl_resource* data_source_resource = wl_resource_create(
client, &wl_data_source_interface, wl_resource_get_version(resource), id);
if (!data_source_resource) {
wl_client_post_no_memory(client);
return;
}
SetImplementation(data_source_resource, &kTestDataSourceImpl,
std::make_unique<TestDataSource>(data_source_resource));
auto* data_device_manager = GetUserDataAs<TestDataDeviceManager>(resource);
data_device_manager->set_data_source(
GetUserDataAs<TestDataSource>(data_source_resource));
}
void GetDataDevice(wl_client* client,
wl_resource* resource,
uint32_t id,
wl_resource* seat_resource) {
wl_resource* data_device_resource = wl_resource_create(
client, &wl_data_device_interface, wl_resource_get_version(resource), id);
if (!data_device_resource) {
wl_client_post_no_memory(client);
return;
}
SetImplementation(
data_device_resource, &kTestDataDeviceImpl,
std::make_unique<TestDataDevice>(client, data_device_resource));
auto* data_device_manager = GetUserDataAs<TestDataDeviceManager>(resource);
data_device_manager->set_data_device(
GetUserDataAs<TestDataDevice>(data_device_resource));
}
} // namespace
const struct wl_data_device_manager_interface kTestDataDeviceManagerImpl = {
&CreateDataSource, &GetDataDevice};
TestDataDeviceManager::TestDataDeviceManager()
: GlobalObject(&wl_data_device_manager_interface,
&kTestDataDeviceManagerImpl,
kDataDeviceManagerVersion) {}
TestDataDeviceManager::~TestDataDeviceManager() {}
} // namespace wl
// Copyright 2019 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_TEST_TEST_DATA_DEVICE_MANAGER_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_DEVICE_MANAGER_H_
#include <wayland-server-protocol-core.h>
#include "base/macros.h"
#include "ui/ozone/platform/wayland/test/global_object.h"
namespace wl {
extern const struct wl_data_device_manager_interface kTestDataDeviceManagerImpl;
class TestDataDevice;
class TestDataSource;
// Manage wl_data_device_manager object.
class TestDataDeviceManager : public GlobalObject {
public:
TestDataDeviceManager();
~TestDataDeviceManager() override;
TestDataDevice* data_device() const { return data_device_; }
void set_data_device(TestDataDevice* data_device) {
data_device_ = data_device;
}
TestDataSource* data_source() const { return data_source_; }
void set_data_source(TestDataSource* data_source) {
data_source_ = data_source;
}
private:
TestDataDevice* data_device_;
TestDataSource* data_source_;
DISALLOW_COPY_AND_ASSIGN(TestDataDeviceManager);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_DEVICE_MANAGER_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/test_data_offer.h"
#include <wayland-server-core.h>
#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "ui/ozone/platform/wayland/test/constants.h"
namespace wl {
namespace {
void WriteDataOnWorkerThread(base::ScopedFD fd, const std::string& utf8_text) {
if (!base::WriteFileDescriptor(fd.get(), utf8_text.data(), utf8_text.size()))
LOG(ERROR) << "Failed to write selection data to clipboard.";
}
void DataOfferAccept(wl_client* client,
wl_resource* resource,
uint32_t serial,
const char* mime_type) {
NOTIMPLEMENTED();
}
void DataOfferReceive(wl_client* client,
wl_resource* resource,
const char* mime_type,
int fd) {
GetUserDataAs<TestDataOffer>(resource)->Receive(mime_type,
base::ScopedFD(fd));
}
void DataOfferDestroy(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
void DataOfferFinish(wl_client* client, wl_resource* resource) {
NOTIMPLEMENTED();
}
void DataOfferSetActions(wl_client* client,
wl_resource* resource,
uint32_t dnd_actions,
uint32_t preferred_action) {
NOTIMPLEMENTED();
}
} // namespace
const struct wl_data_offer_interface kTestDataOfferImpl = {
DataOfferAccept, DataOfferReceive, DataOfferDestroy, DataOfferFinish,
DataOfferSetActions};
TestDataOffer::TestDataOffer(wl_resource* resource)
: ServerObject(resource),
io_thread_("Worker thread"),
write_data_weak_ptr_factory_(this) {
base::Thread::Options options;
options.message_loop_type = base::MessageLoop::TYPE_IO;
io_thread_.StartWithOptions(options);
}
TestDataOffer::~TestDataOffer() {}
void TestDataOffer::Receive(const std::string& mime_type, base::ScopedFD fd) {
DCHECK(fd.is_valid());
std::string text_data;
if (mime_type == kTextMimeTypeUtf8)
text_data = kSampleClipboardText;
else if (mime_type == kTextMimeTypeText)
text_data = kSampleTextForDragAndDrop;
io_thread_.task_runner()->PostTask(
FROM_HERE,
base::BindOnce(&WriteDataOnWorkerThread, std::move(fd), text_data));
}
void TestDataOffer::OnOffer(const std::string& mime_type) {
wl_data_offer_send_offer(resource(), mime_type.c_str());
}
} // namespace wl
// Copyright 2019 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_TEST_TEST_DATA_OFFER_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_OFFER_H_
#include <string>
#include <wayland-server-protocol-core.h>
#include "base/files/scoped_file.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread.h"
#include "ui/ozone/platform/wayland/test/server_object.h"
struct wl_resource;
namespace wl {
extern const struct wl_data_offer_interface kTestDataOfferImpl;
class TestDataOffer : public ServerObject {
public:
explicit TestDataOffer(wl_resource* resource);
~TestDataOffer() override;
void Receive(const std::string& mime_type, base::ScopedFD fd);
void OnOffer(const std::string& mime_type);
private:
// TODO(adunaev): get rid of this in favor of using a task runner.
base::Thread io_thread_;
base::WeakPtrFactory<TestDataOffer> write_data_weak_ptr_factory_;
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_OFFER_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/test_data_source.h"
#include <wayland-server-core.h>
#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/task_runner_util.h"
#include "ui/ozone/platform/wayland/test/constants.h"
namespace wl {
namespace {
std::vector<uint8_t> ReadDataOnWorkerThread(base::ScopedFD fd) {
constexpr size_t kChunkSize = 1024;
std::vector<uint8_t> bytes;
while (true) {
uint8_t chunk[kChunkSize];
ssize_t bytes_read = HANDLE_EINTR(read(fd.get(), chunk, kChunkSize));
if (bytes_read > 0) {
bytes.insert(bytes.end(), chunk, chunk + bytes_read);
continue;
}
if (!bytes_read)
return bytes;
if (bytes_read < 0) {
LOG(ERROR) << "Failed to read selection data from clipboard.";
return std::vector<uint8_t>();
}
}
}
void CreatePipe(base::ScopedFD* read_pipe, base::ScopedFD* write_pipe) {
int raw_pipe[2];
PCHECK(0 == pipe(raw_pipe));
read_pipe->reset(raw_pipe[0]);
write_pipe->reset(raw_pipe[1]);
}
void DataSourceOffer(wl_client* client,
wl_resource* resource,
const char* mime_type) {
GetUserDataAs<TestDataSource>(resource)->Offer(mime_type);
}
void DataSourceDestroy(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
void SetActions(wl_client* client,
wl_resource* resource,
uint32_t dnd_actions) {
NOTIMPLEMENTED();
}
} // namespace
const struct wl_data_source_interface kTestDataSourceImpl = {
DataSourceOffer, DataSourceDestroy, SetActions};
TestDataSource::TestDataSource(wl_resource* resource)
: ServerObject(resource),
io_thread_("Worker thread"),
read_data_weak_ptr_factory_(this) {
base::Thread::Options options;
options.message_loop_type = base::MessageLoop::TYPE_IO;
io_thread_.StartWithOptions(options);
}
TestDataSource::~TestDataSource() {}
void TestDataSource::Offer(const std::string& mime_type) {
NOTIMPLEMENTED();
}
void TestDataSource::ReadData(ReadDataCallback callback) {
base::ScopedFD read_fd;
base::ScopedFD write_fd;
CreatePipe(&read_fd, &write_fd);
wl_data_source_send_send(resource(), kTextMimeTypeUtf8, write_fd.get());
base::PostTaskAndReplyWithResult(
io_thread_.task_runner().get(), FROM_HERE,
base::BindOnce(&ReadDataOnWorkerThread, std::move(read_fd)),
base::BindOnce(&TestDataSource::DataReadCb,
read_data_weak_ptr_factory_.GetWeakPtr(),
std::move(callback)));
}
void TestDataSource::DataReadCb(ReadDataCallback callback,
const std::vector<uint8_t>& data) {
std::move(callback).Run(data);
}
void TestDataSource::OnCancelled() {
wl_data_source_send_cancelled(resource());
}
} // namespace wl
// Copyright 2019 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_TEST_TEST_DATA_SOURCE_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_SOURCE_H_
#include <string>
#include <vector>
#include <wayland-server-protocol-core.h>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread.h"
#include "ui/ozone/platform/wayland/test/server_object.h"
struct wl_resource;
namespace wl {
extern const struct wl_data_source_interface kTestDataSourceImpl;
class TestDataSource : public ServerObject {
public:
explicit TestDataSource(wl_resource* resource);
~TestDataSource() override;
void Offer(const std::string& mime_type);
using ReadDataCallback =
base::OnceCallback<void(const std::vector<uint8_t>&)>;
void ReadData(ReadDataCallback);
void OnCancelled();
private:
void DataReadCb(ReadDataCallback callback, const std::vector<uint8_t>& data);
base::Thread io_thread_;
base::WeakPtrFactory<TestDataSource> read_data_weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(TestDataSource);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_DATA_SOURCE_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/test_keyboard.h"
namespace wl {
const struct wl_pointer_interface kTestKeyboardImpl = {
nullptr, // set_cursor
&DestroyResource, // release
};
TestKeyboard::TestKeyboard(wl_resource* resource) : ServerObject(resource) {}
TestKeyboard::~TestKeyboard() = default;
} // namespace wl
// Copyright 2019 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_TEST_TEST_KEYBOARD_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_KEYBOARD_H_
#include <wayland-server-protocol.h>
#include "base/macros.h"
#include "ui/ozone/platform/wayland/test/server_object.h"
struct wl_resource;
namespace wl {
extern const struct wl_pointer_interface kTestKeyboardImpl;
class TestKeyboard : public ServerObject {
public:
explicit TestKeyboard(wl_resource* resource);
~TestKeyboard() override;
private:
DISALLOW_COPY_AND_ASSIGN(TestKeyboard);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_KEYBOARD_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/test_output.h"
#include <wayland-server-protocol-core.h>
namespace wl {
namespace {
constexpr uint32_t kOutputVersion = 2;
}
TestOutput::TestOutput()
: GlobalObject(&wl_output_interface, nullptr, kOutputVersion) {}
TestOutput::~TestOutput() = default;
// Notify clients of the change for output position.
void TestOutput::OnBind() {
if (rect_.IsEmpty())
return;
const char* kUnknownMake = "unknown";
const char* kUnknownModel = "unknown";
wl_output_send_geometry(resource(), rect_.x(), rect_.y(), 0, 0, 0,
kUnknownMake, kUnknownModel, 0);
wl_output_send_mode(resource(), WL_OUTPUT_MODE_CURRENT, rect_.width(),
rect_.height(), 0);
wl_output_send_done(resource());
}
} // namespace wl
// Copyright 2019 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_TEST_TEST_OUTPUT_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_OUTPUT_H_
#include "base/macros.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/ozone/platform/wayland/test/global_object.h"
namespace wl {
// Handle wl_output object.
class TestOutput : public GlobalObject {
public:
TestOutput();
~TestOutput() override;
void SetRect(const gfx::Rect rect) { rect_ = rect; }
const gfx::Rect GetRect() { return rect_; }
void OnBind() override;
private:
gfx::Rect rect_;
DISALLOW_COPY_AND_ASSIGN(TestOutput);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_OUTPUT_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/test_pointer.h"
namespace wl {
const struct wl_pointer_interface kTestPointerImpl = {
nullptr, // set_cursor
&DestroyResource, // release
};
TestPointer::TestPointer(wl_resource* resource) : ServerObject(resource) {}
TestPointer::~TestPointer() = default;
} // namespace wl
// Copyright 2019 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_TEST_TEST_POINTER_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_POINTER_H_
#include <wayland-server-protocol.h>
#include "base/macros.h"
#include "ui/ozone/platform/wayland/test/server_object.h"
struct wl_resource;
namespace wl {
extern const struct wl_pointer_interface kTestPointerImpl;
class TestPointer : public ServerObject {
public:
explicit TestPointer(wl_resource* resource);
~TestPointer() override;
private:
DISALLOW_COPY_AND_ASSIGN(TestPointer);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_MOCK_POINTER_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/test_positioner.h"
#include <wayland-server-core.h>
namespace wl {
namespace {
void SetSize(struct wl_client* wl_client,
struct wl_resource* resource,
int32_t width,
int32_t height) {
if (width < 1 || height < 1) {
wl_resource_post_error(resource, ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT,
"width and height must be positive and non-zero");
return;
}
GetUserDataAs<TestPositioner>(resource)->set_size(gfx::Size(width, height));
}
void SetAnchorRect(struct wl_client* client,
struct wl_resource* resource,
int32_t x,
int32_t y,
int32_t width,
int32_t height) {
if (width < 1 || height < 1) {
wl_resource_post_error(resource, ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT,
"width and height must be positive and non-zero");
return;
}
GetUserDataAs<TestPositioner>(resource)->set_anchor_rect(
gfx::Rect(x, y, width, height));
}
void SetAnchor(struct wl_client* wl_client,
struct wl_resource* resource,
uint32_t anchor) {
if (((anchor & ZXDG_POSITIONER_V6_ANCHOR_LEFT) &&
(anchor & ZXDG_POSITIONER_V6_ANCHOR_RIGHT)) ||
((anchor & ZXDG_POSITIONER_V6_ANCHOR_TOP) &&
(anchor & ZXDG_POSITIONER_V6_ANCHOR_BOTTOM))) {
wl_resource_post_error(resource, ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT,
"same-axis values are not allowed");
return;
}
GetUserDataAs<TestPositioner>(resource)->set_anchor(anchor);
}
void SetGravity(struct wl_client* client,
struct wl_resource* resource,
uint32_t gravity) {
if (((gravity & ZXDG_POSITIONER_V6_GRAVITY_LEFT) &&
(gravity & ZXDG_POSITIONER_V6_GRAVITY_RIGHT)) ||
((gravity & ZXDG_POSITIONER_V6_GRAVITY_TOP) &&
(gravity & ZXDG_POSITIONER_V6_GRAVITY_BOTTOM))) {
wl_resource_post_error(resource, ZXDG_POSITIONER_V6_ERROR_INVALID_INPUT,
"same-axis values are not allowed");
return;
}
GetUserDataAs<TestPositioner>(resource)->set_gravity(gravity);
}
} // namespace
const struct zxdg_positioner_v6_interface kTestZxdgPositionerV6Impl = {
&DestroyResource, // destroy
&SetSize, // set_size
&SetAnchorRect, // set_anchor_rect
&SetAnchor, // set_anchor
&SetGravity, // set_gravity
nullptr, // set_constraint_adjustment
nullptr, // set_offset
};
TestPositioner::TestPositioner(wl_resource* resource)
: ServerObject(resource) {}
TestPositioner::~TestPositioner() {}
} // namespace wl
// Copyright 2019 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_TEST_TEST_POSITIONER_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_POSITIONER_H_
#include <xdg-shell-unstable-v6-server-protocol.h>
#include "base/macros.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/ozone/platform/wayland/test/server_object.h"
struct wl_resource;
namespace wl {
extern const struct zxdg_positioner_v6_interface kTestZxdgPositionerV6Impl;
// A simple positioner object that provides a collection of rules of a child
// surface relative to a parent surface.
class TestPositioner : public ServerObject {
public:
explicit TestPositioner(wl_resource* resource);
~TestPositioner() override;
void set_size(gfx::Size size) { size_ = size; }
gfx::Size size() const { return size_; }
void set_anchor_rect(gfx::Rect anchor_rect) { anchor_rect_ = anchor_rect; }
gfx::Rect anchor_rect() const { return anchor_rect_; }
void set_anchor(uint32_t anchor) { anchor_ = anchor; }
void set_gravity(uint32_t gravity) { gravity_ = gravity; }
private:
gfx::Rect anchor_rect_;
gfx::Size size_;
uint32_t anchor_;
uint32_t gravity_;
DISALLOW_COPY_AND_ASSIGN(TestPositioner);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_POSITIONER_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/test_seat.h"
#include "ui/ozone/platform/wayland/test/test_keyboard.h"
#include "ui/ozone/platform/wayland/test/test_pointer.h"
#include "ui/ozone/platform/wayland/test/test_touch.h"
namespace wl {
namespace {
constexpr uint32_t kSeatVersion = 4;
void GetPointer(wl_client* client, wl_resource* resource, uint32_t id) {
wl_resource* pointer_resource = wl_resource_create(
client, &wl_pointer_interface, wl_resource_get_version(resource), id);
if (!pointer_resource) {
wl_client_post_no_memory(client);
return;
}
SetImplementation(pointer_resource, &kTestPointerImpl,
std::make_unique<TestPointer>(pointer_resource));
auto* seat = GetUserDataAs<TestSeat>(resource);
seat->set_pointer(GetUserDataAs<TestPointer>(pointer_resource));
}
void GetKeyboard(wl_client* client, wl_resource* resource, uint32_t id) {
wl_resource* keyboard_resource = wl_resource_create(
client, &wl_keyboard_interface, wl_resource_get_version(resource), id);
if (!keyboard_resource) {
wl_client_post_no_memory(client);
return;
}
SetImplementation(keyboard_resource, &kTestKeyboardImpl,
std::make_unique<TestKeyboard>(keyboard_resource));
auto* seat = GetUserDataAs<TestSeat>(resource);
seat->set_keyboard(GetUserDataAs<TestKeyboard>(keyboard_resource));
}
void GetTouch(wl_client* client, wl_resource* resource, uint32_t id) {
wl_resource* touch_resource = wl_resource_create(
client, &wl_touch_interface, wl_resource_get_version(resource), id);
if (!touch_resource) {
wl_client_post_no_memory(client);
return;
}
SetImplementation(touch_resource, &kTestTouchImpl,
std::make_unique<TestTouch>(touch_resource));
auto* seat = GetUserDataAs<TestSeat>(resource);
seat->set_touch(GetUserDataAs<TestTouch>(touch_resource));
}
} // namespace
const struct wl_seat_interface kTestSeatImpl = {
&GetPointer, // get_pointer
&GetKeyboard, // get_keyboard
&GetTouch, // get_touch,
&DestroyResource, // release
};
TestSeat::TestSeat()
: GlobalObject(&wl_seat_interface, &kTestSeatImpl, kSeatVersion) {}
TestSeat::~TestSeat() {}
} // namespace wl
// Copyright 2019 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_TEST_TEST_SEAT_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SEAT_H_
#include <wayland-server-protocol-core.h>
#include "base/macros.h"
#include "ui/ozone/platform/wayland/test/global_object.h"
namespace wl {
extern const struct wl_seat_interface kTestSeatImpl;
class TestKeyboard;
class TestPointer;
class TestTouch;
// Manages a global wl_seat object.
// A seat groups keyboard, pointer, and touch devices. This object is
// published as a global during start up, or when such a device is hot plugged.
// A seat typically has a pointer and maintains a keyboard focus and a pointer
// focus.
// https://people.freedesktop.org/~whot/wayland-doxygen/wayland/Server/structwl__seat__interface.html
class TestSeat : public GlobalObject {
public:
TestSeat();
~TestSeat() override;
void set_pointer(TestPointer* pointer) { pointer_ = pointer; }
TestPointer* pointer() const { return pointer_; }
void set_keyboard(TestKeyboard* keyboard) { keyboard_ = keyboard; }
TestKeyboard* keyboard() const { return keyboard_; }
void set_touch(TestTouch* touch) { touch_ = touch; }
TestTouch* touch() const { return touch_; }
private:
TestPointer* pointer_;
TestKeyboard* keyboard_;
TestTouch* touch_;
DISALLOW_COPY_AND_ASSIGN(TestSeat);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_SEAT_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/test_touch.h"
namespace wl {
const struct wl_pointer_interface kTestTouchImpl = {
nullptr, // set_cursor
&DestroyResource, // release
};
TestTouch::TestTouch(wl_resource* resource) : ServerObject(resource) {}
TestTouch::~TestTouch() = default;
} // namespace wl
// Copyright 2019 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_TEST_TEST_TOUCH_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_TOUCH_H_
#include <wayland-server-protocol.h>
#include "base/macros.h"
#include "ui/ozone/platform/wayland/test/server_object.h"
struct wl_resource;
namespace wl {
extern const struct wl_pointer_interface kTestTouchImpl;
class TestTouch : public ServerObject {
public:
explicit TestTouch(wl_resource* resource);
~TestTouch() override;
private:
DISALLOW_COPY_AND_ASSIGN(TestTouch);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_TOUCH_H_
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/test/test_zwp_text_input_manager.h"
#include <wayland-server-core.h>
#include "ui/ozone/platform/wayland/test/mock_zwp_text_input.h"
namespace wl {
namespace {
constexpr uint32_t kTextInputManagerVersion = 1;
void CreateTextInput(struct wl_client* client,
struct wl_resource* resource,
uint32_t id) {
auto* im = static_cast<TestZwpTextInputManagerV1*>(
wl_resource_get_user_data(resource));
wl_resource* text_resource =
wl_resource_create(client, &zwp_text_input_v1_interface,
wl_resource_get_version(resource), id);
if (!text_resource) {
wl_client_post_no_memory(client);
return;
}
SetImplementation(text_resource, &kMockZwpTextInputV1Impl,
std::make_unique<MockZwpTextInput>(text_resource));
im->set_text_input(GetUserDataAs<MockZwpTextInput>(text_resource));
}
} // namespace
const struct zwp_text_input_manager_v1_interface
kTestZwpTextInputManagerV1Impl = {
&CreateTextInput, // create_text_input
};
TestZwpTextInputManagerV1::TestZwpTextInputManagerV1()
: GlobalObject(&zwp_text_input_manager_v1_interface,
&kTestZwpTextInputManagerV1Impl,
kTextInputManagerVersion) {}
TestZwpTextInputManagerV1::~TestZwpTextInputManagerV1() {}
} // namespace wl
// Copyright 2019 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_TEST_TEST_ZWP_TEXT_INPUT_MANAGER_H_
#define UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZWP_TEXT_INPUT_MANAGER_H_
#include <text-input-unstable-v1-server-protocol.h>
#include "base/macros.h"
#include "ui/ozone/platform/wayland/test/global_object.h"
namespace wl {
extern const struct zwp_text_input_manager_v1_interface
kTestZwpTextInputManagerV1Impl;
class MockZwpTextInput;
// Manage zwp_text_input_manager_v1 object.
class TestZwpTextInputManagerV1 : public GlobalObject {
public:
TestZwpTextInputManagerV1();
~TestZwpTextInputManagerV1() override;
void set_text_input(MockZwpTextInput* text_input) {
text_input_ = text_input;
}
MockZwpTextInput* text_input() const { return text_input_; }
private:
MockZwpTextInput* text_input_;
DISALLOW_COPY_AND_ASSIGN(TestZwpTextInputManagerV1);
};
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_TEST_TEST_ZWP_TEXT_INPUT_MANAGER_H_
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
#include "base/files/file.h" #include "base/files/file.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
...@@ -73,6 +74,8 @@ class WaylandBufferManager { ...@@ -73,6 +74,8 @@ class WaylandBufferManager {
void ClearState(); void ClearState();
private: private:
FRIEND_TEST_ALL_PREFIXES(WaylandBufferManagerTest, ValidateDataFromGpu);
// This is an internal helper representation of a wayland buffer object, which // This is an internal helper representation of a wayland buffer object, which
// the GPU process creates when CreateBuffer is called. It's used for // the GPU process creates when CreateBuffer is called. It's used for
// asynchronous buffer creation and stores |params| parameter to find out, // asynchronous buffer creation and stores |params| parameter to find out,
......
// Copyright 2019 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.
#include "ui/ozone/platform/wayland/wayland_buffer_manager.h"
#include <memory>
#include <drm_fourcc.h>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/ozone/platform/wayland/wayland_test.h"
using testing::_;
namespace ui {
namespace {
constexpr uint32_t kWidth = 1024;
constexpr uint32_t kHeight = 768;
} // namespace
class WaylandBufferManagerTest : public WaylandTest {
public:
WaylandBufferManagerTest() = default;
~WaylandBufferManagerTest() override = default;
protected:
base::File MakeTempFile() {
base::FilePath temp_path;
EXPECT_TRUE(base::CreateTemporaryFile(&temp_path));
return base::File(temp_path, base::File::FLAG_READ |
base::File::FLAG_WRITE |
base::File::FLAG_CREATE_ALWAYS);
}
private:
DISALLOW_COPY_AND_ASSIGN(WaylandBufferManagerTest);
};
TEST_P(WaylandBufferManagerTest, ValidateDataFromGpu) {
struct InputData {
bool has_file = false;
uint32_t width = 0;
uint32_t height = 0;
uint32_t planes_count = 0;
std::vector<uint32_t> strides;
std::vector<uint32_t> offsets;
std::vector<uint64_t> modifiers;
uint32_t format = 0;
uint32_t buffer_id = 0;
};
constexpr uint32_t kExistingBufferId = 1;
constexpr uint32_t kNonExistingBufferId = 2;
// Create a buffer through the connection's interface so it gets
// registered with the given ID.
// This must be the only buffer that is asked to be created.
EXPECT_CALL(*server_.zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
connection_->CreateZwpLinuxDmabuf(MakeTempFile(), kWidth, kHeight, {1}, {2},
DRM_FORMAT_R8, {3}, 1, kExistingBufferId);
Sync();
const InputData kBadInputs[] = {
// All zeros.
{},
// Valid file but zeros everywhereelse.
{true},
// Valid file, invalid size, zeros elsewhere.
{true, kWidth},
{true, 0, kHeight},
// Valid file and size but zeros in other fields.
{true, kWidth, kHeight},
// Vectors have different lengths.
{true, kWidth, kHeight, 1, {1}, {2, 3}, {4, 5, 6}},
// Vectors have same lengths but strides have a zero.
{true, kWidth, kHeight, 1, {0}, {2}, {6}},
// Vectors are valid but buffer format is not.
{true, kWidth, kHeight, 1, {1}, {2}, {6}},
// Everything is correct but the buffer ID is zero.
{true, kWidth, kHeight, 1, {1}, {2}, {6}, DRM_FORMAT_R8},
// Everything is correct but the buffer ID .
{true,
kWidth,
kHeight,
1,
{1},
{2},
{6},
DRM_FORMAT_R8,
kExistingBufferId},
};
WaylandBufferManager* manager = connection_->buffer_manager_for_tests();
ASSERT_TRUE(manager);
auto temp_file = MakeTempFile();
for (const auto& bad : kBadInputs) {
base::File dummy;
EXPECT_FALSE(manager->ValidateDataFromGpu(
bad.has_file ? temp_file : dummy, bad.width, bad.height, bad.strides,
bad.offsets, bad.format, bad.modifiers, bad.planes_count,
bad.buffer_id));
EXPECT_FALSE(manager->error_message().empty());
}
EXPECT_TRUE(manager->ValidateDataFromGpu(temp_file, kWidth, kHeight, {1}, {2},
DRM_FORMAT_R8, {3}, 1,
kNonExistingBufferId));
connection_->DestroyZwpLinuxDmabuf(kExistingBufferId);
}
TEST_P(WaylandBufferManagerTest, CreateAndDestroyBuffer) {
WaylandBufferManager* manager = connection_->buffer_manager_for_tests();
ASSERT_TRUE(manager);
const uint32_t kBufferId1 = 1;
const uint32_t kBufferId2 = 2;
EXPECT_CALL(*server_.zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(2);
EXPECT_TRUE(manager->CreateBuffer(MakeTempFile(), kWidth, kHeight, {1}, {2},
DRM_FORMAT_R8, {3}, 1, kBufferId1));
EXPECT_FALSE(manager->CreateBuffer(MakeTempFile(), kWidth, kHeight, {1}, {2},
DRM_FORMAT_R8, {3}, 1, kBufferId1));
EXPECT_FALSE(manager->DestroyBuffer(kBufferId2));
EXPECT_TRUE(manager->CreateBuffer(MakeTempFile(), kWidth, kHeight, {1}, {2},
DRM_FORMAT_R8, {3}, 1, kBufferId2));
EXPECT_TRUE(manager->DestroyBuffer(kBufferId1));
EXPECT_FALSE(manager->DestroyBuffer(kBufferId1));
EXPECT_TRUE(manager->DestroyBuffer(kBufferId2));
EXPECT_FALSE(manager->DestroyBuffer(kBufferId2));
}
INSTANTIATE_TEST_CASE_P(XdgVersionV5Test,
WaylandBufferManagerTest,
::testing::Values(kXdgShellV5));
INSTANTIATE_TEST_CASE_P(XdgVersionV6Test,
WaylandBufferManagerTest,
::testing::Values(kXdgShellV6));
} // namespace ui
...@@ -81,6 +81,9 @@ class WaylandConnection : public PlatformEventSource, ...@@ -81,6 +81,9 @@ class WaylandConnection : public PlatformEventSource,
zwp_text_input_manager_v1* text_input_manager_v1() { zwp_text_input_manager_v1* text_input_manager_v1() {
return text_input_manager_v1_.get(); return text_input_manager_v1_.get();
} }
WaylandBufferManager* buffer_manager_for_tests() {
return buffer_manager_.get();
}
WaylandWindow* GetWindow(gfx::AcceleratedWidget widget); WaylandWindow* GetWindow(gfx::AcceleratedWidget widget);
WaylandWindow* GetCurrentFocusedWindow(); WaylandWindow* GetCurrentFocusedWindow();
......
...@@ -10,6 +10,12 @@ ...@@ -10,6 +10,12 @@
#include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/events/base_event_utils.h" #include "ui/events/base_event_utils.h"
#include "ui/ozone/platform/wayland/fake_server.h" #include "ui/ozone/platform/wayland/fake_server.h"
#include "ui/ozone/platform/wayland/test/constants.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/ozone/platform/wayland/test/test_data_device.h"
#include "ui/ozone/platform/wayland/test/test_data_device_manager.h"
#include "ui/ozone/platform/wayland/test/test_data_offer.h"
#include "ui/ozone/platform/wayland/test/test_data_source.h"
#include "ui/ozone/platform/wayland/wayland_test.h" #include "ui/ozone/platform/wayland/wayland_test.h"
#include "ui/ozone/public/platform_clipboard.h" #include "ui/ozone/public/platform_clipboard.h"
...@@ -77,7 +83,7 @@ class WaylandDataDeviceManagerTest : public WaylandTest { ...@@ -77,7 +83,7 @@ class WaylandDataDeviceManagerTest : public WaylandTest {
} }
protected: protected:
wl::MockDataDeviceManager* data_device_manager_; wl::TestDataDeviceManager* data_device_manager_;
std::unique_ptr<MockClipboardClient> clipboard_client_; std::unique_ptr<MockClipboardClient> clipboard_client_;
DISALLOW_COPY_AND_ASSIGN(WaylandDataDeviceManagerTest); DISALLOW_COPY_AND_ASSIGN(WaylandDataDeviceManagerTest);
...@@ -104,7 +110,7 @@ TEST_P(WaylandDataDeviceManagerTest, ReadFromClibpard) { ...@@ -104,7 +110,7 @@ TEST_P(WaylandDataDeviceManagerTest, ReadFromClibpard) {
// focused and compositor sends data_device data to it. // focused and compositor sends data_device data to it.
auto* data_offer = data_device_manager_->data_device()->OnDataOffer(); auto* data_offer = data_device_manager_->data_device()->OnDataOffer();
data_offer->OnOffer(wl::kTextMimeTypeUtf8); data_offer->OnOffer(wl::kTextMimeTypeUtf8);
data_device_manager_->data_device()->OnSelection(*data_offer); data_device_manager_->data_device()->OnSelection(data_offer);
Sync(); Sync();
// The client requests to reading clipboard data from the server. // The client requests to reading clipboard data from the server.
...@@ -168,7 +174,7 @@ TEST_P(WaylandDataDeviceManagerTest, ReceiveDrag) { ...@@ -168,7 +174,7 @@ TEST_P(WaylandDataDeviceManagerTest, ReceiveDrag) {
// The server sends an enter event. // The server sends an enter event.
data_device_manager_->data_device()->OnEnter( data_device_manager_->data_device()->OnEnter(
1002, surface_->resource(), wl_fixed_from_int(entered_point.x()), 1002, surface_->resource(), wl_fixed_from_int(entered_point.x()),
wl_fixed_from_int(entered_point.y()), *data_offer); wl_fixed_from_int(entered_point.y()), data_offer);
int64_t time = int64_t time =
(ui::EventTimeForNow() - base::TimeTicks()).InMilliseconds() & UINT32_MAX; (ui::EventTimeForNow() - base::TimeTicks()).InMilliseconds() & UINT32_MAX;
......
...@@ -11,13 +11,15 @@ ...@@ -11,13 +11,15 @@
#include "ui/base/ime/linux/linux_input_method_context.h" #include "ui/base/ime/linux/linux_input_method_context.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/ozone/platform/wayland/fake_server.h" #include "ui/ozone/platform/wayland/fake_server.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/ozone/platform/wayland/test/mock_zwp_text_input.h"
#include "ui/ozone/platform/wayland/wayland_input_method_context.h" #include "ui/ozone/platform/wayland/wayland_input_method_context.h"
#include "ui/ozone/platform/wayland/wayland_input_method_context_factory.h" #include "ui/ozone/platform/wayland/wayland_input_method_context_factory.h"
#include "ui/ozone/platform/wayland/wayland_test.h" #include "ui/ozone/platform/wayland/wayland_test.h"
#include "ui/ozone/platform/wayland/wayland_window.h" #include "ui/ozone/platform/wayland/wayland_window.h"
using ::testing::SaveArg;
using ::testing::_; using ::testing::_;
using ::testing::SaveArg;
namespace ui { namespace ui {
...@@ -69,7 +71,7 @@ class WaylandInputMethodContextTest : public WaylandTest { ...@@ -69,7 +71,7 @@ class WaylandInputMethodContextTest : public WaylandTest {
Sync(); Sync();
zwp_text_input_ = server_.text_input_manager_v1()->text_input.get(); zwp_text_input_ = server_.text_input_manager_v1()->text_input();
window_->set_keyboard_focus(true); window_->set_keyboard_focus(true);
ASSERT_TRUE(connection_->text_input_manager_v1()); ASSERT_TRUE(connection_->text_input_manager_v1());
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/ozone/platform/wayland/fake_server.h" #include "ui/ozone/platform/wayland/fake_server.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/ozone/platform/wayland/test/test_keyboard.h"
#include "ui/ozone/platform/wayland/wayland_test.h" #include "ui/ozone/platform/wayland/wayland_test.h"
#if BUILDFLAG(USE_XKBCOMMON) #if BUILDFLAG(USE_XKBCOMMON)
...@@ -61,7 +63,7 @@ class WaylandKeyboardTest : public WaylandTest { ...@@ -61,7 +63,7 @@ class WaylandKeyboardTest : public WaylandTest {
} }
protected: protected:
wl::MockKeyboard* keyboard_; wl::TestKeyboard* keyboard_;
private: private:
#if BUILDFLAG(USE_XKBCOMMON) #if BUILDFLAG(USE_XKBCOMMON)
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/ozone/platform/wayland/fake_server.h" #include "ui/ozone/platform/wayland/fake_server.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/ozone/platform/wayland/test/test_pointer.h"
#include "ui/ozone/platform/wayland/wayland_test.h" #include "ui/ozone/platform/wayland/wayland_test.h"
#include "ui/ozone/platform/wayland/wayland_window.h" #include "ui/ozone/platform/wayland/wayland_window.h"
#include "ui/ozone/test/mock_platform_window_delegate.h" #include "ui/ozone/test/mock_platform_window_delegate.h"
...@@ -36,7 +38,7 @@ class WaylandPointerTest : public WaylandTest { ...@@ -36,7 +38,7 @@ class WaylandPointerTest : public WaylandTest {
} }
protected: protected:
wl::MockPointer* pointer_; wl::TestPointer* pointer_;
private: private:
DISALLOW_COPY_AND_ASSIGN(WaylandPointerTest); DISALLOW_COPY_AND_ASSIGN(WaylandPointerTest);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/display/display_observer.h" #include "ui/display/display_observer.h"
#include "ui/ozone/platform/wayland/fake_server.h" #include "ui/ozone/platform/wayland/fake_server.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/ozone/platform/wayland/wayland_connection.h" #include "ui/ozone/platform/wayland/wayland_connection.h"
#include "ui/ozone/platform/wayland/wayland_output_manager.h" #include "ui/ozone/platform/wayland/wayland_output_manager.h"
#include "ui/ozone/platform/wayland/wayland_screen.h" #include "ui/ozone/platform/wayland/wayland_screen.h"
...@@ -110,7 +111,7 @@ class WaylandScreenTest : public WaylandTest { ...@@ -110,7 +111,7 @@ class WaylandScreenTest : public WaylandTest {
EXPECT_EQ(display_for_widget.id(), expected_display_id); EXPECT_EQ(display_for_widget.id(), expected_display_id);
} }
wl::MockOutput* output_ = nullptr; wl::TestOutput* output_ = nullptr;
WaylandOutputManager* output_manager_ = nullptr; WaylandOutputManager* output_manager_ = nullptr;
std::unique_ptr<WaylandScreen> platform_screen_; std::unique_ptr<WaylandScreen> platform_screen_;
...@@ -142,7 +143,7 @@ TEST_P(WaylandScreenTest, MultipleOutputsAddedAndRemoved) { ...@@ -142,7 +143,7 @@ TEST_P(WaylandScreenTest, MultipleOutputsAddedAndRemoved) {
platform_screen_->GetPrimaryDisplay().id(); platform_screen_->GetPrimaryDisplay().id();
// Add a second display. // Add a second display.
wl::MockOutput* output2 = server_.CreateAndInitializeOutput(); wl::TestOutput* output2 = server_.CreateAndInitializeOutput();
Sync(); Sync();
...@@ -295,7 +296,7 @@ TEST_P(WaylandScreenTest, GetDisplayMatching) { ...@@ -295,7 +296,7 @@ TEST_P(WaylandScreenTest, GetDisplayMatching) {
const display::Display primary_display = const display::Display primary_display =
platform_screen_->GetPrimaryDisplay(); platform_screen_->GetPrimaryDisplay();
wl::MockOutput* output2 = server_.CreateAndInitializeOutput(); wl::TestOutput* output2 = server_.CreateAndInitializeOutput();
Sync(); Sync();
...@@ -366,7 +367,7 @@ TEST_P(WaylandScreenTest, GetDisplayForAcceleratedWidget) { ...@@ -366,7 +367,7 @@ TEST_P(WaylandScreenTest, GetDisplayForAcceleratedWidget) {
platform_screen_->GetPrimaryDisplay(); platform_screen_->GetPrimaryDisplay();
// Create an additional display. // Create an additional display.
wl::MockOutput* output2 = server_.CreateAndInitializeOutput(); wl::TestOutput* output2 = server_.CreateAndInitializeOutput();
Sync(); Sync();
......
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ui/ozone/platform/wayland/wayland_surface_factory.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/core/SkSurface.h"
#include "ui/ozone/platform/wayland/fake_server.h" #include "ui/ozone/platform/wayland/fake_server.h"
#include "ui/ozone/platform/wayland/wayland_surface_factory.h" #include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/ozone/platform/wayland/wayland_test.h" #include "ui/ozone/platform/wayland/wayland_test.h"
#include "ui/ozone/platform/wayland/wayland_window.h" #include "ui/ozone/platform/wayland/wayland_window.h"
#include "ui/ozone/public/surface_ozone_canvas.h" #include "ui/ozone/public/surface_ozone_canvas.h"
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/platform_window/platform_window_init_properties.h" #include "ui/platform_window/platform_window_init_properties.h"
#if BUILDFLAG(USE_XKBCOMMON) #if BUILDFLAG(USE_XKBCOMMON)
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
#include "ui/events/ozone/layout/xkb/xkb_evdev_codes.h" #include "ui/events/ozone/layout/xkb/xkb_evdev_codes.h"
#endif #endif
namespace wl {
class MockSurface;
} // namespace wl
namespace ui { namespace ui {
const uint32_t kXdgShellV5 = 5; const uint32_t kXdgShellV5 = 5;
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/ozone/platform/wayland/fake_server.h" #include "ui/ozone/platform/wayland/fake_server.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/ozone/platform/wayland/test/test_touch.h"
#include "ui/ozone/platform/wayland/wayland_test.h" #include "ui/ozone/platform/wayland/wayland_test.h"
#include "ui/ozone/platform/wayland/wayland_window.h" #include "ui/ozone/platform/wayland/wayland_window.h"
#include "ui/ozone/test/mock_platform_window_delegate.h" #include "ui/ozone/test/mock_platform_window_delegate.h"
...@@ -51,7 +53,7 @@ class WaylandTouchTest : public WaylandTest { ...@@ -51,7 +53,7 @@ class WaylandTouchTest : public WaylandTest {
EXPECT_EQ(event_type, key_event->type()); EXPECT_EQ(event_type, key_event->type());
} }
wl::MockTouch* touch_; wl::TestTouch* touch_;
private: private:
DISALLOW_COPY_AND_ASSIGN(WaylandTouchTest); DISALLOW_COPY_AND_ASSIGN(WaylandTouchTest);
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include "ui/events/base_event_utils.h" #include "ui/events/base_event_utils.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/ozone/platform/wayland/fake_server.h" #include "ui/ozone/platform/wayland/fake_server.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/ozone/platform/wayland/test/test_pointer.h"
#include "ui/ozone/platform/wayland/wayland_test.h" #include "ui/ozone/platform/wayland/wayland_test.h"
#include "ui/ozone/platform/wayland/wayland_util.h" #include "ui/ozone/platform/wayland/wayland_util.h"
#include "ui/ozone/test/mock_platform_window_delegate.h" #include "ui/ozone/test/mock_platform_window_delegate.h"
...@@ -523,7 +525,7 @@ TEST_P(WaylandWindowTest, HasCaptureUpdatedOnPointerEvents) { ...@@ -523,7 +525,7 @@ TEST_P(WaylandWindowTest, HasCaptureUpdatedOnPointerEvents) {
Sync(); Sync();
wl::MockPointer* pointer = server_.seat()->pointer(); wl::TestPointer* pointer = server_.seat()->pointer();
ASSERT_TRUE(pointer); ASSERT_TRUE(pointer);
wl_pointer_send_enter(pointer->resource(), 1, surface_->resource(), 0, 0); wl_pointer_send_enter(pointer->resource(), 1, surface_->resource(), 0, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment