From 47a538e61c0cd52920151f9db8666ac36023d169 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Fri, 19 Jul 2024 17:31:48 -0400 Subject: [PATCH] ButtonRebindsFilter: Add test for mouse button binding This was missed when it was first implemented, but now there's tests for checking the mouse binding functionality in the buttons rebind plugin. --- autotests/integration/buttonrebind_test.cpp | 46 ++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/autotests/integration/buttonrebind_test.cpp b/autotests/integration/buttonrebind_test.cpp index cc6f14c8ef..1c3d4f6bf1 100644 --- a/autotests/integration/buttonrebind_test.cpp +++ b/autotests/integration/buttonrebind_test.cpp @@ -13,6 +13,7 @@ #include "workspace.h" #include +#include #include #include @@ -32,6 +33,9 @@ private Q_SLOTS: void testKey_data(); void testKey(); + void testMouse_data(); + void testMouse(); + private: quint32 timestamp = 1; }; @@ -39,7 +43,7 @@ private: void TestButtonRebind::init() { QVERIFY(Test::setupWaylandConnection(Test::AdditionalWaylandInterface::Seat)); - QVERIFY(Test::waitForWaylandKeyboard()); + QVERIFY(Test::waitForWaylandPointer()); } void TestButtonRebind::cleanup() @@ -104,5 +108,45 @@ void TestButtonRebind::testKey() Test::pointerButtonReleased(0x119, timestamp++); } +void TestButtonRebind::testMouse_data() +{ + QTest::addColumn("mouseButton"); + + QTest::newRow("left button") << BTN_LEFT; + QTest::newRow("middle button") << BTN_MIDDLE; + QTest::newRow("right button") << BTN_RIGHT; +} + +void TestButtonRebind::testMouse() +{ + KConfigGroup buttonGroup = KSharedConfig::openConfig(QStringLiteral("kcminputrc"))->group(QStringLiteral("ButtonRebinds")).group(QStringLiteral("Mouse")); + QFETCH(int, mouseButton); + buttonGroup.writeEntry("ExtraButton7", QStringList{"MouseButton", QString::number(mouseButton)}, KConfig::Notify); + buttonGroup.sync(); + + std::unique_ptr surface = Test::createSurface(); + std::unique_ptr shellSurface = Test::createXdgToplevelSurface(surface.get()); + auto window = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue); + + std::unique_ptr pointer(Test::waylandSeat()->createPointer()); + QSignalSpy enteredSpy(pointer.get(), &KWayland::Client::Pointer::entered); + QSignalSpy buttonChangedSpy(pointer.get(), &KWayland::Client::Pointer::buttonStateChanged); + + const QRectF startGeometry = window->frameGeometry(); + input()->pointer()->warp(startGeometry.center()); + + QVERIFY(enteredSpy.wait()); + + // 0x119 is Qt::ExtraButton7 + Test::pointerButtonPressed(0x119, timestamp++); + + QVERIFY(buttonChangedSpy.wait()); + + QCOMPARE(buttonChangedSpy.count(), 1); + QCOMPARE(buttonChangedSpy.at(0).at(2).value(), mouseButton); + + Test::pointerButtonReleased(0x119, timestamp++); +} + WAYLANDTEST_MAIN(TestButtonRebind) #include "buttonrebind_test.moc"