From 757c21364d186f1bdef5cbe3802228e831958636 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 24 Sep 2024 23:15:06 +0000 Subject: [PATCH] autotests: Add some xdg-toplevel size hints tests (cherry picked from commit 8d21c7abefc75cc58edd2e0e877f96c5b08bed44) Co-authored-by: Vlad Zahorodnii --- autotests/integration/xdgshellwindow_test.cpp | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/autotests/integration/xdgshellwindow_test.cpp b/autotests/integration/xdgshellwindow_test.cpp index bba9643521..8e36e728d5 100644 --- a/autotests/integration/xdgshellwindow_test.cpp +++ b/autotests/integration/xdgshellwindow_test.cpp @@ -16,6 +16,7 @@ #include "virtualdesktops.h" #include "wayland/clientconnection.h" #include "wayland/display.h" +#include "wayland/surface.h" #include "wayland_server.h" #include "window.h" #include "workspace.h" @@ -108,6 +109,10 @@ private Q_SLOTS: void testCloseModal(); void testCloseInactiveModal(); void testClosePopupOnParentUnmapped(); + void testMinimumSize(); + void testNoMinimumSize(); + void testMaximumSize(); + void testNoMaximumSize(); }; void TestXdgShellWindow::testXdgPopupReactive_data() @@ -2347,5 +2352,89 @@ void TestXdgShellWindow::testClosePopupOnParentUnmapped() QVERIFY(childClosedSpy.wait()); } +void TestXdgShellWindow::testMinimumSize() +{ + // NOTE: a minimum size of 20px is forced by the compositor + + auto surface = Test::createSurface(); + auto shellSurface = Test::createXdgToplevelSurface(surface.get(), [](Test::XdgToplevel *toplevel) { + toplevel->set_min_size(200, 250); + }); + Window *window = Test::renderAndWaitForShown(surface.get(), QSize(300, 300), Qt::cyan); + QCOMPARE(window->minSize(), QSizeF(200, 250)); + + QSignalSpy committedSpy(window->surface(), &SurfaceInterface::committed); + + shellSurface->set_min_size(100, 100); + surface->commit(KWayland::Client::Surface::CommitFlag::None); + QVERIFY(committedSpy.wait()); + QCOMPARE(window->minSize(), QSizeF(100, 100)); + + shellSurface->set_min_size(0, 100); + surface->commit(KWayland::Client::Surface::CommitFlag::None); + QVERIFY(committedSpy.wait()); + QCOMPARE(window->minSize(), QSizeF(20, 100)); + + shellSurface->set_min_size(100, 0); + surface->commit(KWayland::Client::Surface::CommitFlag::None); + QVERIFY(committedSpy.wait()); + QCOMPARE(window->minSize(), QSizeF(100, 20)); + + shellSurface->set_min_size(0, 0); + surface->commit(KWayland::Client::Surface::CommitFlag::None); + QVERIFY(committedSpy.wait()); + QCOMPARE(window->minSize(), QSizeF(20, 20)); +} + +void TestXdgShellWindow::testNoMinimumSize() +{ + // NOTE: a minimum size of 20px is forced by the compositor + + auto surface = Test::createSurface(); + auto shellSurface = Test::createXdgToplevelSurface(surface.get()); + Window *window = Test::renderAndWaitForShown(surface.get(), QSize(300, 300), Qt::cyan); + QCOMPARE(window->minSize(), QSizeF(20, 20)); +} + +void TestXdgShellWindow::testMaximumSize() +{ + auto surface = Test::createSurface(); + auto shellSurface = Test::createXdgToplevelSurface(surface.get(), [](Test::XdgToplevel *toplevel) { + toplevel->set_max_size(300, 350); + }); + Window *window = Test::renderAndWaitForShown(surface.get(), QSize(200, 200), Qt::cyan); + QCOMPARE(window->maxSize(), QSizeF(300, 350)); + + QSignalSpy committedSpy(window->surface(), &SurfaceInterface::committed); + + shellSurface->set_max_size(400, 400); + surface->commit(KWayland::Client::Surface::CommitFlag::None); + QVERIFY(committedSpy.wait()); + QCOMPARE(window->maxSize(), QSizeF(400, 400)); + + shellSurface->set_max_size(0, 400); + surface->commit(KWayland::Client::Surface::CommitFlag::None); + QVERIFY(committedSpy.wait()); + QCOMPARE(window->maxSize(), QSizeF(INT_MAX, 400)); + + shellSurface->set_max_size(400, 0); + surface->commit(KWayland::Client::Surface::CommitFlag::None); + QVERIFY(committedSpy.wait()); + QCOMPARE(window->maxSize(), QSizeF(400, INT_MAX)); + + shellSurface->set_max_size(0, 0); + surface->commit(KWayland::Client::Surface::CommitFlag::None); + QVERIFY(committedSpy.wait()); + QCOMPARE(window->maxSize(), QSizeF(INT_MAX, INT_MAX)); +} + +void TestXdgShellWindow::testNoMaximumSize() +{ + auto surface = Test::createSurface(); + auto shellSurface = Test::createXdgToplevelSurface(surface.get()); + Window *window = Test::renderAndWaitForShown(surface.get(), QSize(300, 300), Qt::cyan); + QCOMPARE(window->maxSize(), QSizeF(INT_MAX, INT_MAX)); +} + WAYLANDTEST_MAIN(TestXdgShellWindow) #include "xdgshellwindow_test.moc"