Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
vm_tools: Adds tests for xdg_surface
Browse files Browse the repository at this point in the history
+ Adds tests for xdg_surface

BUG=b:255439799
TEST=meson build && ninja -C build && build/sommelier_test

Change-Id: I69a4be34e638a0800d67cff03354ce595be51187
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/4520016
Commit-Queue: Justin Huang <[email protected]>
Reviewed-by: Chloe Pelling <[email protected]>
Tested-by: Justin Huang <[email protected]>
  • Loading branch information
Justin Huang authored and Chromeos LUCI committed May 19, 2023
1 parent b588b2e commit 0a530c8
Showing 1 changed file with 116 additions and 7 deletions.
123 changes: 116 additions & 7 deletions sommelier-xdg-shell-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class XdgShellTest : public WaylandTestBase {
class XdgWmBaseTest : public XdgShellTest {
public:
void SetUp() override {
sommelier_xdg_wm_base = nullptr;
EXPECT_CALL(mock_xdg_wm_base_shim_, add_listener(_, _, _))
.WillOnce([this](struct xdg_wm_base* xdg_wm_base,
const xdg_wm_base_listener* listener,
Expand All @@ -75,8 +74,8 @@ class XdgWmBaseTest : public XdgShellTest {

protected:
// Sommelier's xdg_wm_base instance.
struct sl_host_xdg_shell* sommelier_xdg_wm_base;
wl_surface* client_surface;
struct sl_host_xdg_shell* sommelier_xdg_wm_base = nullptr;
wl_surface* client_surface = nullptr;
};

TEST_F(XdgWmBaseTest, CreatePositioner_ForwardsCorrectly) {
Expand Down Expand Up @@ -113,8 +112,6 @@ class XdgPositionerTest : public XdgShellTest {
void SetUp() override {
WaylandTestBase::SetUp();

sommelier_positioner = nullptr;

EXPECT_CALL(mock_xdg_wm_base_shim_, create_positioner(_))
.WillOnce([](struct xdg_wm_base* xdg_wm_base) {
return xdg_wm_base_create_positioner(xdg_wm_base);
Expand All @@ -134,8 +131,8 @@ class XdgPositionerTest : public XdgShellTest {
}

protected:
struct xdg_positioner* sommelier_positioner;
struct xdg_positioner* client_positioner;
struct xdg_positioner* sommelier_positioner = nullptr;
struct xdg_positioner* client_positioner = nullptr;
};

TEST_F(XdgPositionerTest, SetSize_ForwardsUnscaled) {
Expand Down Expand Up @@ -240,5 +237,117 @@ TEST_F(XdgPositionerTest, SetOffset_AppliesXdgScaleWithDirectScale) {
xdg_positioner_set_offset(client_positioner, 100, 100);
}

class XdgSurfaceTest : public XdgShellTest {
public:
void SetUp() override {
EXPECT_CALL(mock_xdg_wm_base_shim_, get_xdg_surface(_, _))
.WillOnce([](struct xdg_wm_base* xdg_wm_base, wl_surface* wl_surface) {
return xdg_wm_base_get_xdg_surface(xdg_wm_base, wl_surface);
});
EXPECT_CALL(mock_xdg_surface_shim_, add_listener(_, _, _))
.WillOnce([this](struct xdg_surface* xdg_surface,
const xdg_surface_listener* listener,
void* user_data) {
sommelier_xdg_surface =
static_cast<struct sl_host_xdg_surface*>(user_data);
xdg_surface_add_listener(xdg_surface, listener, user_data);
return 0;
});

WaylandTestBase::SetUp();

client_xdg_surface = client->CreateXdgSurface();
Pump();
}

protected:
struct sl_host_xdg_surface* sommelier_xdg_surface = nullptr;
struct xdg_surface* client_xdg_surface = nullptr;
};

TEST_F(XdgSurfaceTest, GetToplevel_CreatesToplevel) {
EXPECT_CALL(mock_xdg_surface_shim_,
get_toplevel(sommelier_xdg_surface->proxy));

xdg_surface_get_toplevel(client_xdg_surface);
}

TEST_F(XdgSurfaceTest, GetPopup_CreatesPopup) {
struct sl_host_xdg_positioner* sommelier_positioner = nullptr;

EXPECT_CALL(mock_xdg_wm_base_shim_, create_positioner(_))
.WillOnce([](struct xdg_wm_base* xdg_wm_base) {
return xdg_wm_base_create_positioner(xdg_wm_base);
});

// Capture the positioner object for verification below.
EXPECT_CALL(mock_xdg_positioner_shim_, set_user_data(_, _))
.WillOnce([&sommelier_positioner](struct xdg_positioner* xdg_positioner,
void* user_data) {
sommelier_positioner =
static_cast<struct sl_host_xdg_positioner*>(user_data);
xdg_positioner_set_user_data(xdg_positioner, user_data);
});

struct xdg_positioner* positioner = client->CreatePositioner();
Pump();

EXPECT_CALL(mock_xdg_surface_shim_, get_popup(sommelier_xdg_surface->proxy,
sommelier_xdg_surface->proxy,
sommelier_positioner->proxy));

xdg_surface_get_popup(client_xdg_surface, client_xdg_surface, positioner);
}

TEST_F(XdgSurfaceTest, SetWindowGeometry_ForwardsUnscaled) {
EXPECT_CALL(
mock_xdg_surface_shim_,
set_window_geometry(sommelier_xdg_surface->proxy, 100, 100, 100, 100));
xdg_surface_set_window_geometry(client_xdg_surface, 100, 100, 100, 100);
}

TEST_F(XdgSurfaceTest, SetWindowGeometry_AppliesCtxScale) {
ctx.scale = 2.0;
EXPECT_CALL(
mock_xdg_surface_shim_,
set_window_geometry(sommelier_xdg_surface->proxy, 50, 50, 50, 50));
xdg_surface_set_window_geometry(client_xdg_surface, 100, 100, 100, 100);
}

TEST_F(XdgSurfaceTest, SetWindowGeometry_UnscaledWithDirectScale) {
ctx.use_direct_scale = true;
EXPECT_CALL(
mock_xdg_surface_shim_,
set_window_geometry(sommelier_xdg_surface->proxy, 100, 100, 100, 100));
xdg_surface_set_window_geometry(client_xdg_surface, 100, 100, 100, 100);
}

TEST_F(XdgSurfaceTest, SetWindowGeometry_AppliesXdgScaleWithDirectScale) {
ctx.use_direct_scale = true;
ctx.xdg_scale_x = 2.0;
ctx.xdg_scale_y = 4.0;
EXPECT_CALL(
mock_xdg_surface_shim_,
set_window_geometry(sommelier_xdg_surface->proxy, 50, 25, 50, 25));
xdg_surface_set_window_geometry(client_xdg_surface, 100, 100, 100, 100);
}

TEST_F(XdgSurfaceTest, AckConfigure_ForwardsCorrectly) {
EXPECT_CALL(mock_xdg_surface_shim_, ack_configure(_, kFakeSerial));
xdg_surface_ack_configure(client_xdg_surface, kFakeSerial);
}

TEST_F(XdgSurfaceTest, Configure_SendsCorrectly) {
EXPECT_CALL(mock_xdg_surface_shim_,
get_user_data(sommelier_xdg_surface->proxy))
.WillOnce([](struct xdg_surface* xdg_surface) {
return xdg_surface_get_user_data(xdg_surface);
});
EXPECT_CALL(mock_xdg_surface_shim_, send_configure(_, kFakeSerial));

HostEventHandler(sommelier_xdg_surface->proxy)
->configure(nullptr, sommelier_xdg_surface->proxy, kFakeSerial);
}

} // namespace sommelier
} // namespace vm_tools

0 comments on commit 0a530c8

Please sign in to comment.