autotests: Use layer-shell based panels

This commit is contained in:
Vlad Zahorodnii 2023-05-19 14:58:32 +03:00
parent f3e4495e44
commit cab0765947
3 changed files with 48 additions and 56 deletions

View file

@ -18,7 +18,6 @@
#include "window.h"
#include "workspace.h"
#include <KWayland/Client/plasmashell.h>
#include <KWayland/Client/plasmawindowmanagement.h>
#include <KWayland/Client/surface.h>
@ -75,8 +74,7 @@ void MinimizeAnimationTest::initTestCase()
void MinimizeAnimationTest::init()
{
QVERIFY(Test::setupWaylandConnection(
Test::AdditionalWaylandInterface::PlasmaShell | Test::AdditionalWaylandInterface::WindowManagement));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::LayerShellV1 | Test::AdditionalWaylandInterface::WindowManagement));
}
void MinimizeAnimationTest::cleanup()
@ -102,27 +100,25 @@ void MinimizeAnimationTest::testMinimizeUnminimize()
// This test verifies that a minimize effect tries to animate a window
// when it's minimized or unminimized.
QSignalSpy plasmaWindowCreatedSpy(Test::waylandWindowManagement(), &KWayland::Client::PlasmaWindowManagement::windowCreated);
// Create a panel at the top of the screen.
const QRect panelRect = QRect(0, 0, 1280, 36);
std::unique_ptr<KWayland::Client::Surface> panelSurface(Test::createSurface());
QVERIFY(panelSurface != nullptr);
std::unique_ptr<Test::XdgToplevel> panelShellSurface(Test::createXdgToplevelSurface(panelSurface.get()));
QVERIFY(panelShellSurface != nullptr);
std::unique_ptr<KWayland::Client::PlasmaShellSurface> plasmaPanelShellSurface(Test::waylandPlasmaShell()->createSurface(panelSurface.get()));
QVERIFY(plasmaPanelShellSurface != nullptr);
plasmaPanelShellSurface->setRole(KWayland::Client::PlasmaShellSurface::Role::Panel);
plasmaPanelShellSurface->setPosition(panelRect.topLeft());
plasmaPanelShellSurface->setPanelBehavior(KWayland::Client::PlasmaShellSurface::PanelBehavior::AlwaysVisible);
Window *panel = Test::renderAndWaitForShown(panelSurface.get(), panelRect.size(), Qt::blue);
std::unique_ptr<KWayland::Client::Surface> panelSurface{Test::createSurface()};
std::unique_ptr<Test::LayerSurfaceV1> panelShellSurface{Test::createLayerSurfaceV1(panelSurface.get(), QStringLiteral("dock"))};
panelShellSurface->set_size(panelRect.width(), panelRect.height());
panelShellSurface->set_exclusive_zone(panelRect.height());
panelShellSurface->set_anchor(Test::LayerSurfaceV1::anchor_top);
panelSurface->commit(KWayland::Client::Surface::CommitFlag::None);
QSignalSpy panelConfigureRequestedSpy(panelShellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
QVERIFY(panelConfigureRequestedSpy.wait());
Window *panel = Test::renderAndWaitForShown(panelSurface.get(), panelConfigureRequestedSpy.last().at(1).toSize(), Qt::blue);
QVERIFY(panel);
QVERIFY(panel->isDock());
QCOMPARE(panel->frameGeometry(), panelRect);
QVERIFY(plasmaWindowCreatedSpy.wait());
QCOMPARE(plasmaWindowCreatedSpy.count(), 1);
// Create the test window.
QSignalSpy plasmaWindowCreatedSpy(Test::waylandWindowManagement(), &KWayland::Client::PlasmaWindowManagement::windowCreated);
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
QVERIFY(surface != nullptr);
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
@ -130,7 +126,7 @@ void MinimizeAnimationTest::testMinimizeUnminimize()
Window *window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::red);
QVERIFY(window);
QVERIFY(plasmaWindowCreatedSpy.wait());
QCOMPARE(plasmaWindowCreatedSpy.count(), 2);
QCOMPARE(plasmaWindowCreatedSpy.count(), 1);
// We have to set the minimized geometry because the squash effect needs it,
// otherwise it won't start animation.

View file

@ -60,10 +60,10 @@ private Q_SLOTS:
void testPlasmaShellSurfaceMovable_data();
void testPlasmaShellSurfaceMovable();
void testNetMove();
void testAdjustClientGeometryOfAutohidingX11Panel_data();
void testAdjustClientGeometryOfAutohidingX11Panel();
void testAdjustClientGeometryOfAutohidingWaylandPanel_data();
void testAdjustClientGeometryOfAutohidingWaylandPanel();
void testAdjustClientGeometryOfHiddenX11Panel_data();
void testAdjustClientGeometryOfHiddenX11Panel();
void testAdjustClientGeometryOfHiddenWaylandPanel_data();
void testAdjustClientGeometryOfHiddenWaylandPanel();
void testResizeForVirtualKeyboard_data();
void testResizeForVirtualKeyboard();
void testResizeForVirtualKeyboardWithMaximize();
@ -94,7 +94,7 @@ void MoveResizeWindowTest::initTestCase()
void MoveResizeWindowTest::init()
{
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::PlasmaShell | Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::PlasmaShell | Test::AdditionalWaylandInterface::LayerShellV1 | Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::waitForWaylandPointer());
m_connection = Test::waylandConnection();
m_compositor = Test::waylandCompositor();
@ -657,7 +657,7 @@ void MoveResizeWindowTest::testNetMove()
QVERIFY(windowClosedSpy.wait());
}
void MoveResizeWindowTest::testAdjustClientGeometryOfAutohidingX11Panel_data()
void MoveResizeWindowTest::testAdjustClientGeometryOfHiddenX11Panel_data()
{
QTest::addColumn<QRect>("panelGeometry");
QTest::addColumn<QPoint>("targetPoint");
@ -670,7 +670,7 @@ void MoveResizeWindowTest::testAdjustClientGeometryOfAutohidingX11Panel_data()
QTest::newRow("right") << QRect(1280 - 20, 0, 20, 100) << QPoint(1280 - 25 - 100, 50) << QPoint(1280 - 20 - 100, 50) << 1u;
}
void MoveResizeWindowTest::testAdjustClientGeometryOfAutohidingX11Panel()
void MoveResizeWindowTest::testAdjustClientGeometryOfHiddenX11Panel()
{
// this test verifies that auto hiding panels are ignored when adjusting client geometry
// see BUG 365892
@ -745,36 +745,37 @@ void MoveResizeWindowTest::testAdjustClientGeometryOfAutohidingX11Panel()
QVERIFY(windowClosedSpy.wait());
}
void MoveResizeWindowTest::testAdjustClientGeometryOfAutohidingWaylandPanel_data()
void MoveResizeWindowTest::testAdjustClientGeometryOfHiddenWaylandPanel_data()
{
QTest::addColumn<uint32_t>("anchor");
QTest::addColumn<QRect>("panelGeometry");
QTest::addColumn<QPoint>("targetPoint");
QTest::addColumn<QPoint>("expectedAdjustedPoint");
QTest::newRow("top") << QRect(0, 0, 100, 20) << QPoint(50, 25) << QPoint(50, 20);
QTest::newRow("bottom") << QRect(0, 1024 - 20, 100, 20) << QPoint(50, 1024 - 25 - 50) << QPoint(50, 1024 - 20 - 50);
QTest::newRow("left") << QRect(0, 0, 20, 100) << QPoint(25, 50) << QPoint(20, 50);
QTest::newRow("right") << QRect(1280 - 20, 0, 20, 100) << QPoint(1280 - 25 - 100, 50) << QPoint(1280 - 20 - 100, 50);
QTest::newRow("top") << uint32_t(Test::LayerSurfaceV1::anchor_top) << QRect(0, 0, 1280, 20) << QPoint(50, 25) << QPoint(50, 20);
QTest::newRow("bottom") << uint32_t(Test::LayerSurfaceV1::anchor_bottom) << QRect(0, 1024 - 20, 1280, 20) << QPoint(50, 1024 - 25 - 50) << QPoint(50, 1024 - 20 - 50);
QTest::newRow("left") << uint32_t(Test::LayerSurfaceV1::anchor_left) << QRect(0, 0, 20, 1024) << QPoint(25, 50) << QPoint(20, 50);
QTest::newRow("right") << uint32_t(Test::LayerSurfaceV1::anchor_right) << QRect(1280 - 20, 0, 20, 1024) << QPoint(1280 - 25 - 100, 50) << QPoint(1280 - 20 - 100, 50);
}
void MoveResizeWindowTest::testAdjustClientGeometryOfAutohidingWaylandPanel()
void MoveResizeWindowTest::testAdjustClientGeometryOfHiddenWaylandPanel()
{
// this test verifies that auto hiding panels are ignored when adjusting client geometry
// this test verifies that hidden panels are ignored when adjusting client geometry
// see BUG 365892
// first create our panel
std::unique_ptr<KWayland::Client::Surface> panelSurface(Test::createSurface());
QVERIFY(panelSurface != nullptr);
std::unique_ptr<Test::XdgToplevel> panelShellSurface(Test::createXdgToplevelSurface(panelSurface.get()));
QVERIFY(panelShellSurface != nullptr);
std::unique_ptr<KWayland::Client::PlasmaShellSurface> plasmaSurface(Test::waylandPlasmaShell()->createSurface(panelSurface.get()));
QVERIFY(plasmaSurface != nullptr);
plasmaSurface->setRole(KWayland::Client::PlasmaShellSurface::Role::Panel);
plasmaSurface->setPanelBehavior(KWayland::Client::PlasmaShellSurface::PanelBehavior::AutoHide);
std::unique_ptr<Test::LayerSurfaceV1> panelShellSurface(Test::createLayerSurfaceV1(panelSurface.get(), QStringLiteral("dock")));
QFETCH(QRect, panelGeometry);
plasmaSurface->setPosition(panelGeometry.topLeft());
QFETCH(uint32_t, anchor);
panelShellSurface->set_anchor(anchor);
panelShellSurface->set_size(panelGeometry.width(), panelGeometry.height());
panelSurface->commit(KWayland::Client::Surface::CommitFlag::None);
// let's render
auto panel = Test::renderAndWaitForShown(panelSurface.get(), panelGeometry.size(), Qt::blue);
QSignalSpy panelConfigureRequestedSpy(panelShellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
QVERIFY(panelConfigureRequestedSpy.wait());
auto panel = Test::renderAndWaitForShown(panelSurface.get(), panelConfigureRequestedSpy.last().at(1).toSize(), Qt::blue);
QVERIFY(panel);
QCOMPARE(panel->frameGeometry(), panelGeometry);
QVERIFY(panel->isDock());
@ -794,16 +795,13 @@ void MoveResizeWindowTest::testAdjustClientGeometryOfAutohidingWaylandPanel()
QTEST(Workspace::self()->adjustWindowPosition(testWindow, targetPoint, false).toPoint(), "expectedAdjustedPoint");
// now let's hide the panel
QSignalSpy panelHiddenSpy(panel, &Window::windowHidden);
plasmaSurface->requestHideAutoHidingPanel();
QVERIFY(panelHiddenSpy.wait());
panel->hideClient();
// now try to snap again
QCOMPARE(Workspace::self()->adjustWindowPosition(testWindow, targetPoint, false), targetPoint);
// and destroy the panel again
QSignalSpy panelClosedSpy(panel, &Window::closed);
plasmaSurface.reset();
panelShellSurface.reset();
panelSurface.reset();
QVERIFY(panelClosedSpy.wait());

View file

@ -22,7 +22,6 @@
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/event_queue.h>
#include <KWayland/Client/keyboard.h>
#include <KWayland/Client/plasmashell.h>
#include <KWayland/Client/pointer.h>
#include <KWayland/Client/registry.h>
#include <KWayland/Client/seat.h>
@ -79,7 +78,7 @@ void TransientPlacementTest::initTestCase()
void TransientPlacementTest::init()
{
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration | Test::AdditionalWaylandInterface::PlasmaShell));
QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Decoration | Test::AdditionalWaylandInterface::LayerShellV1));
workspace()->setActiveOutput(QPoint(640, 512));
input()->pointer()->warp(QPoint(640, 512));
@ -470,18 +469,17 @@ void TransientPlacementTest::testXdgPopupWithPanel()
{
const Output *output = workspace()->activeOutput();
std::unique_ptr<KWayland::Client::Surface> surface{Test::createSurface()};
QVERIFY(surface != nullptr);
std::unique_ptr<Test::XdgToplevel> dockShellSurface{Test::createXdgToplevelSurface(surface.get())};
QVERIFY(dockShellSurface != nullptr);
std::unique_ptr<KWayland::Client::PlasmaShellSurface> plasmaSurface(Test::waylandPlasmaShell()->createSurface(surface.get()));
QVERIFY(plasmaSurface != nullptr);
plasmaSurface->setRole(KWayland::Client::PlasmaShellSurface::Role::Panel);
plasmaSurface->setPosition(QPoint(0, output->geometry().height() - 50));
plasmaSurface->setPanelBehavior(KWayland::Client::PlasmaShellSurface::PanelBehavior::AlwaysVisible);
std::unique_ptr<KWayland::Client::Surface> dockSurface{Test::createSurface()};
std::unique_ptr<Test::LayerSurfaceV1> dockShellSurface{Test::createLayerSurfaceV1(dockSurface.get(), QStringLiteral("dock"))};
dockShellSurface->set_size(1280, 50);
dockShellSurface->set_anchor(Test::LayerSurfaceV1::anchor_bottom);
dockShellSurface->set_exclusive_zone(50);
dockSurface->commit(KWayland::Client::Surface::CommitFlag::None);
// now render and map the window
auto dock = Test::renderAndWaitForShown(surface.get(), QSize(1280, 50), Qt::blue);
QSignalSpy dockConfigureRequestedSpy(dockShellSurface.get(), &Test::LayerSurfaceV1::configureRequested);
QVERIFY(dockConfigureRequestedSpy.wait());
auto dock = Test::renderAndWaitForShown(dockSurface.get(), dockConfigureRequestedSpy.last().at(1).toSize(), Qt::blue);
QVERIFY(dock);
QCOMPARE(dock->windowType(), NET::Dock);
QVERIFY(dock->isDock());