From 037b3ba66e3a2007b6b29c291ab9df72e37ec821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 8 Feb 2016 12:36:39 +0100 Subject: [PATCH] [autotests] Add test case for effects key handling during screen lock Verifies that no key events are forwarded to the Effects during a locked screen. --- autotests/wayland/lockscreen.cpp | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/autotests/wayland/lockscreen.cpp b/autotests/wayland/lockscreen.cpp index bf043a4e00..60629fe4e1 100644 --- a/autotests/wayland/lockscreen.cpp +++ b/autotests/wayland/lockscreen.cpp @@ -60,6 +60,7 @@ private Q_SLOTS: void testPointerAxis(); void testScreenEdge(); void testEffects(); + void testEffectsKeyboard(); void testMoveWindow(); void testPointerShortcut(); void testAxisShortcut_data(); @@ -87,9 +88,13 @@ public: void windowInputMouseEvent(QEvent*) override { emit inputEvent(); } + void grabbedKeyboardEvent(QKeyEvent *e) override { + emit keyEvent(e->text()); + } Q_SIGNALS: void inputEvent(); + void keyEvent(const QString&); }; #define LOCK \ @@ -118,6 +123,12 @@ Q_SIGNALS: #define RELEASE \ waylandServer()->backend()->pointerButtonReleased(BTN_LEFT, timestamp++) +#define KEYPRESS( key ) \ + waylandServer()->backend()->keyboardKeyPressed(key, timestamp++) + +#define KEYRELEASE( key ) \ + waylandServer()->backend()->keyboardKeyReleased(key, timestamp++) + void LockScreenTest::unlock() { using namespace ScreenLocker; @@ -454,6 +465,44 @@ void LockScreenTest::testEffects() effects->stopMouseInterception(effect.data()); } +void LockScreenTest::testEffectsKeyboard() +{ + QScopedPointer effect(new HelperEffect); + QSignalSpy inputSpy(effect.data(), &HelperEffect::keyEvent); + QVERIFY(inputSpy.isValid()); + effects->grabKeyboard(effect.data()); + + quint32 timestamp = 1; + KEYPRESS(KEY_A); + QCOMPARE(inputSpy.count(), 1); + QCOMPARE(inputSpy.first().first().toString(), QStringLiteral("a")); + KEYRELEASE(KEY_A); + QCOMPARE(inputSpy.count(), 2); + QCOMPARE(inputSpy.first().first().toString(), QStringLiteral("a")); + QCOMPARE(inputSpy.at(1).first().toString(), QStringLiteral("a")); + + LOCK + KEYPRESS(KEY_B); + QCOMPARE(inputSpy.count(), 2); + KEYRELEASE(KEY_B); + QCOMPARE(inputSpy.count(), 2); + + UNLOCK + KEYPRESS(KEY_C); + QCOMPARE(inputSpy.count(), 3); + QCOMPARE(inputSpy.first().first().toString(), QStringLiteral("a")); + QCOMPARE(inputSpy.at(1).first().toString(), QStringLiteral("a")); + QCOMPARE(inputSpy.at(2).first().toString(), QStringLiteral("c")); + KEYRELEASE(KEY_C); + QCOMPARE(inputSpy.count(), 4); + QCOMPARE(inputSpy.first().first().toString(), QStringLiteral("a")); + QCOMPARE(inputSpy.at(1).first().toString(), QStringLiteral("a")); + QCOMPARE(inputSpy.at(2).first().toString(), QStringLiteral("c")); + QCOMPARE(inputSpy.at(3).first().toString(), QStringLiteral("c")); + + effects->ungrabKeyboard(); +} + void LockScreenTest::testMoveWindow() { using namespace KWayland::Client;