From 1baba74611050b4cb7f4e05741968dd8d46f431d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 2 Feb 2016 14:41:28 +0100 Subject: [PATCH] [autotests] Verify that Effects don't get pointer events on locked screen Interesting approach I would not have expected to work. A dummy Effect class is created in the test and an instance is passed to EffectsHandler's startMouseInterception. It doesn't verify whether it's an Effect it knows or has created, so it's totally happy with the dummy. It shows that motion and press/release are passed to the Effect when screen is not locked and doesn't while the screen is locked. --- autotests/wayland/lockscreen.cpp | 70 ++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/autotests/wayland/lockscreen.cpp b/autotests/wayland/lockscreen.cpp index 9bcca92012..bb43eb2a62 100644 --- a/autotests/wayland/lockscreen.cpp +++ b/autotests/wayland/lockscreen.cpp @@ -26,6 +26,7 @@ along with this program. If not, see . #include "wayland_server.h" #include "workspace.h" #include "shell_client.h" +#include #include #include @@ -58,6 +59,7 @@ private Q_SLOTS: void testPointerButton(); void testPointerAxis(); void testScreenEdge(); + void testEffects(); private: void unlock(); @@ -70,6 +72,22 @@ private: QThread *m_thread = nullptr; }; +class HelperEffect : public Effect +{ + Q_OBJECT +public: + HelperEffect() {} + ~HelperEffect() {} + + void windowInputMouseEvent(QEvent*) override { + emit inputEvent(); + } + +Q_SIGNALS: + void inputEvent(); +}; + + void LockScreenTest::unlock() { using namespace ScreenLocker; @@ -437,6 +455,58 @@ void LockScreenTest::testScreenEdge() QCOMPARE(screenEdgeSpy.count(), 2); } +void LockScreenTest::testEffects() +{ + QScopedPointer effect(new HelperEffect); + QSignalSpy inputSpy(effect.data(), &HelperEffect::inputEvent); + QVERIFY(inputSpy.isValid()); + effects->startMouseInterception(effect.data(), Qt::ArrowCursor); + + quint32 timestamp = 1; + QCOMPARE(inputSpy.count(), 0); + waylandServer()->backend()->pointerMotion(QPoint(5, 5), timestamp++); + QCOMPARE(inputSpy.count(), 1); + // simlate click + waylandServer()->backend()->pointerButtonPressed(BTN_LEFT, timestamp++); + QCOMPARE(inputSpy.count(), 2); + waylandServer()->backend()->pointerButtonReleased(BTN_LEFT, timestamp++); + QCOMPARE(inputSpy.count(), 3); + + QVERIFY(!waylandServer()->isScreenLocked()); + QSignalSpy lockStateChangedSpy(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged); + QVERIFY(lockStateChangedSpy.isValid()); + ScreenLocker::KSldApp::self()->lock(ScreenLocker::EstablishLock::Immediate); + QCOMPARE(lockStateChangedSpy.count(), 1); + QVERIFY(waylandServer()->isScreenLocked()); + + waylandServer()->backend()->pointerMotion(QPoint(6, 6), timestamp++); + QCOMPARE(inputSpy.count(), 3); + // simlate click + waylandServer()->backend()->pointerButtonPressed(BTN_LEFT, timestamp++); + QCOMPARE(inputSpy.count(), 3); + waylandServer()->backend()->pointerButtonReleased(BTN_LEFT, timestamp++); + QCOMPARE(inputSpy.count(), 3); + + // and unlock + QCOMPARE(lockStateChangedSpy.count(), 1); + unlock(); + if (lockStateChangedSpy.count() < 2) { + QVERIFY(lockStateChangedSpy.wait()); + } + QCOMPARE(lockStateChangedSpy.count(), 2); + QVERIFY(!waylandServer()->isScreenLocked()); + + waylandServer()->backend()->pointerMotion(QPoint(5, 5), timestamp++); + QCOMPARE(inputSpy.count(), 4); + // simlate click + waylandServer()->backend()->pointerButtonPressed(BTN_LEFT, timestamp++); + QCOMPARE(inputSpy.count(), 5); + waylandServer()->backend()->pointerButtonReleased(BTN_LEFT, timestamp++); + QCOMPARE(inputSpy.count(), 6); + + effects->stopMouseInterception(effect.data()); +} + } WAYLANTEST_MAIN(KWin::LockScreenTest)