[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.
This commit is contained in:
Martin Gräßlin 2016-02-02 14:41:28 +01:00
parent 87d1f87cc0
commit 1baba74611

View file

@ -26,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "wayland_server.h"
#include "workspace.h"
#include "shell_client.h"
#include <kwineffects.h>
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/compositor.h>
@ -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<HelperEffect> 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)