diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -18,7 +18,7 @@ # KSldTest ####################################### add_executable(ksldTest ksldtest.cpp) -target_link_libraries(ksldTest Qt5::Test KScreenLocker) +target_link_libraries(ksldTest Qt5::Test Qt5::Widgets KF5::IdleTime KScreenLocker) add_test(ksmserver-ksldTest ksldTest) ecm_mark_as_test(ksldTest) diff --git a/autotests/ksldtest.cpp b/autotests/ksldtest.cpp --- a/autotests/ksldtest.cpp +++ b/autotests/ksldtest.cpp @@ -19,6 +19,8 @@ *********************************************************************/ // own #include "../ksldapp.h" +// KDE Frameworks +#include // Qt #include #include @@ -31,6 +33,7 @@ private Q_SLOTS: void initTestCase(); void testEstablishGrab(); + void testActivateOnTimeout(); }; void KSldTest::initTestCase() @@ -89,5 +92,37 @@ QVERIFY(ksld.establishGrab()); } +void KSldTest::testActivateOnTimeout() +{ + // this time verifies that the screen gets locked on idle timeout, requires the system to be idle + ScreenLocker::KSldApp ksld; + ksld.initialize(); + + // we need to modify the idle timeout of KSLD, it's in minutes we cannot wait that long + if (ksld.idleId() != 0) { + // remove old Idle id + KIdleTime::instance()->removeIdleTimeout(ksld.idleId()); + } + ksld.setIdleId(KIdleTime::instance()->addIdleTimeout(5000)); + + QSignalSpy lockStateChangedSpy(&ksld, &ScreenLocker::KSldApp::lockStateChanged); + QVERIFY(lockStateChangedSpy.isValid()); + + // let's wait the double of the idle timeout + QVERIFY(lockStateChangedSpy.wait(10000)); + QCOMPARE(ksld.lockState(), ScreenLocker::KSldApp::AcquiringLock); + + // let's simulate unlock to get rid of started greeter process + const auto children = ksld.children(); + for (auto it = children.begin(); it != children.end(); ++it) { + if (qstrcmp((*it)->metaObject()->className(), "LogindIntegration") != 0) { + continue; + } + QMetaObject::invokeMethod(*it, "requestUnlock"); + break; + } + QVERIFY(lockStateChangedSpy.wait()); +} + QTEST_MAIN(KSldTest) #include "ksldtest.moc" diff --git a/ksldapp.h b/ksldapp.h --- a/ksldapp.h +++ b/ksldapp.h @@ -104,6 +104,21 @@ bool event(QEvent *event) override; + /** + * For testing + * @internal + **/ + int idleId() const { + return m_idleId; + } + /** + * For testing + * @internal + **/ + void setIdleId(int idleId) { + m_idleId = idleId; + } + Q_SIGNALS: void locked(); void unlocked();