From 75261ab9f65dad452a00d7ddf1334c5ec68417cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 8 Feb 2016 15:03:21 +0100 Subject: [PATCH] [autotests] Test case for key events on internal windows --- autotests/wayland/internal_window.cpp | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/autotests/wayland/internal_window.cpp b/autotests/wayland/internal_window.cpp index 7b56843233..cedfce3973 100644 --- a/autotests/wayland/internal_window.cpp +++ b/autotests/wayland/internal_window.cpp @@ -44,6 +44,7 @@ private Q_SLOTS: void testEnterLeave(); void testPointerPressRelease(); void testPointerAxis(); + void testKeyboard(); }; class HelperWindow : public QRasterWindow @@ -60,6 +61,8 @@ Q_SIGNALS: void mousePressed(); void mouseReleased(); void wheel(); + void keyPressed(); + void keyReleased(); protected: void paintEvent(QPaintEvent *event) override; @@ -68,6 +71,8 @@ protected: void mousePressEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; void wheelEvent(QWheelEvent *event) override; + void keyPressEvent(QKeyEvent *event) override; + void keyReleaseEvent(QKeyEvent *event) override; }; HelperWindow::HelperWindow() @@ -118,6 +123,18 @@ void HelperWindow::wheelEvent(QWheelEvent *event) emit wheel(); } +void HelperWindow::keyPressEvent(QKeyEvent *event) +{ + Q_UNUSED(event) + emit keyPressed(); +} + +void HelperWindow::keyReleaseEvent(QKeyEvent *event) +{ + Q_UNUSED(event) + emit keyReleased(); +} + void InternalWindowTest::initTestCase() { qRegisterMetaType(); @@ -220,6 +237,31 @@ void InternalWindowTest::testPointerAxis() QTRY_COMPARE(wheelSpy.count(), 2); } +void InternalWindowTest::testKeyboard() +{ + QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); + QVERIFY(clientAddedSpy.isValid()); + HelperWindow win; + win.setGeometry(0, 0, 100, 100); + win.show(); + QSignalSpy pressSpy(&win, &HelperWindow::keyPressed); + QVERIFY(pressSpy.isValid()); + QSignalSpy releaseSpy(&win, &HelperWindow::keyReleased); + QVERIFY(releaseSpy.isValid()); + QVERIFY(clientAddedSpy.wait()); + QCOMPARE(clientAddedSpy.count(), 1); + + quint32 timestamp = 1; + waylandServer()->backend()->pointerMotion(QPoint(50, 50), timestamp++); + + waylandServer()->backend()->keyboardKeyPressed(KEY_A, timestamp++); + QTRY_COMPARE(pressSpy.count(), 1); + QCOMPARE(releaseSpy.count(), 0); + waylandServer()->backend()->keyboardKeyReleased(KEY_A, timestamp++); + QTRY_COMPARE(releaseSpy.count(), 1); + QCOMPARE(pressSpy.count(), 1); +} + } WAYLANTEST_MAIN(KWin::InternalWindowTest)