From 87d1f87cc087966008a4356519322d009ea64078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 2 Feb 2016 13:50:13 +0100 Subject: [PATCH] [autotest] Extend lockscreen test * verifies that pointer axis isn't passed to windows * verifies that screen edge is not activated while screen is locked --- autotests/wayland/lockscreen.cpp | 104 +++++++++++++++++++++++++++++++ screenedge.h | 2 +- 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/autotests/wayland/lockscreen.cpp b/autotests/wayland/lockscreen.cpp index 0822f29f9f..9bcca92012 100644 --- a/autotests/wayland/lockscreen.cpp +++ b/autotests/wayland/lockscreen.cpp @@ -21,6 +21,7 @@ along with this program. If not, see . #include "abstract_backend.h" #include "abstract_client.h" #include "cursor.h" +#include "screenedge.h" #include "screens.h" #include "wayland_server.h" #include "workspace.h" @@ -55,6 +56,8 @@ private Q_SLOTS: void cleanup(); void testPointer(); void testPointerButton(); + void testPointerAxis(); + void testScreenEdge(); private: void unlock(); @@ -333,6 +336,107 @@ void LockScreenTest::testPointerButton() QVERIFY(buttonChangedSpy.wait()); } +void LockScreenTest::testPointerAxis() +{ + using namespace KWayland::Client; + + QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); + QVERIFY(clientAddedSpy.isValid()); + + QScopedPointer surface(m_compositor->createSurface()); + QVERIFY(!surface.isNull()); + + QScopedPointer pointer(m_seat->createPointer()); + QVERIFY(!pointer.isNull()); + QSignalSpy axisChangedSpy(pointer.data(), &Pointer::axisChanged); + QVERIFY(axisChangedSpy.isValid()); + + QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QVERIFY(!shellSurface.isNull()); + QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); + QVERIFY(sizeChangeSpy.isValid()); + // let's render + QImage img(QSize(100, 50), QImage::Format_ARGB32); + img.fill(Qt::blue); + surface->attachBuffer(m_shm->createBuffer(img)); + surface->damage(QRect(0, 0, 100, 50)); + surface->commit(Surface::CommitFlag::None); + + m_connection->flush(); + QVERIFY(clientAddedSpy.wait()); + AbstractClient *c = workspace()->activeClient(); + QVERIFY(c); + QCOMPARE(clientAddedSpy.first().first().value(), c); + + // first move cursor into the center of the window + quint32 timestamp = 1; + waylandServer()->backend()->pointerMotion(c->geometry().center(), timestamp++); + // and simulate axis + waylandServer()->backend()->pointerAxisHorizontal(5.0, timestamp++); + QVERIFY(axisChangedSpy.wait()); + + 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()); + + // and simulate axis + waylandServer()->backend()->pointerAxisHorizontal(5.0, timestamp++); + QVERIFY(!axisChangedSpy.wait(100)); + waylandServer()->backend()->pointerAxisVertical(5.0, timestamp++); + QVERIFY(!axisChangedSpy.wait(100)); + + // and unlock + QCOMPARE(lockStateChangedSpy.count(), 1); + unlock(); + if (lockStateChangedSpy.count() < 2) { + QVERIFY(lockStateChangedSpy.wait()); + } + QCOMPARE(lockStateChangedSpy.count(), 2); + QVERIFY(!waylandServer()->isScreenLocked()); + + // and move axis again + waylandServer()->backend()->pointerAxisHorizontal(5.0, timestamp++); + QVERIFY(axisChangedSpy.wait()); + waylandServer()->backend()->pointerAxisVertical(5.0, timestamp++); + QVERIFY(axisChangedSpy.wait()); +} + +void LockScreenTest::testScreenEdge() +{ + QSignalSpy screenEdgeSpy(ScreenEdges::self(), &ScreenEdges::approaching); + QVERIFY(screenEdgeSpy.isValid()); + QCOMPARE(screenEdgeSpy.count(), 0); + + quint32 timestamp = 1; + waylandServer()->backend()->pointerMotion(QPoint(5, 5), timestamp++); + QCOMPARE(screenEdgeSpy.count(), 1); + + 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(4, 4), timestamp++); + QCOMPARE(screenEdgeSpy.count(), 1); + + // 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(screenEdgeSpy.count(), 2); +} + } WAYLANTEST_MAIN(KWin::LockScreenTest) diff --git a/screenedge.h b/screenedge.h index 21ef049123..0024b6240e 100644 --- a/screenedge.h +++ b/screenedge.h @@ -199,7 +199,7 @@ private Q_SLOTS: * * @todo change way how Effects/Scripts can reserve an edge and are notified. */ -class ScreenEdges : public QObject +class KWIN_EXPORT ScreenEdges : public QObject { Q_OBJECT Q_PROPERTY(bool desktopSwitching READ isDesktopSwitching)