[autotests/integration] Test case for screen locked with mod-only-shortcuts

Currently expected failures as modifier only shortcuts don't check
for locked screen yet.
This commit is contained in:
Martin Gräßlin 2016-08-16 08:19:45 +02:00
parent 4651aa1d79
commit 440d49da00
3 changed files with 67 additions and 0 deletions

View file

@ -143,6 +143,18 @@ ShellClient *renderAndWaitForShown(KWayland::Client::Surface *surface, const QSi
* Waits for the @p client to be destroyed.
**/
bool waitForWindowDestroyed(AbstractClient *client);
/**
* Locks the screen and waits till the screen is locked.
* @returns @c true if the screen could be locked, @c false otherwise
**/
bool lockScreen();
/**
* Unlocks the screen and waits till the screen is unlocked.
* @returns @c true if the screen could be unlocked, @c false otherwise
**/
bool unlockScreen();
}
}

View file

@ -228,6 +228,21 @@ void ModifierOnlyShortcutTest::testTrigger()
kwinApp()->platform()->pointerAxisHorizontal(5.0, timestamp++);
kwinApp()->platform()->keyboardKeyReleased(modifier, timestamp++);
QCOMPARE(triggeredSpy.count(), 2);
// now try to lock the screen while modifier key is pressed
kwinApp()->platform()->keyboardKeyPressed(modifier, timestamp++);
QVERIFY(Test::lockScreen());
kwinApp()->platform()->keyboardKeyReleased(modifier, timestamp++);
QEXPECT_FAIL("", "Screen locking does not quit trigger yet", Continue);
QCOMPARE(triggeredSpy.count(), 2);
// now trigger while screen is locked, should also not work
kwinApp()->platform()->keyboardKeyPressed(modifier, timestamp++);
kwinApp()->platform()->keyboardKeyReleased(modifier, timestamp++);
QEXPECT_FAIL("", "Screen locking does not prevent trigger yet", Continue);
QCOMPARE(triggeredSpy.count(), 2);
QVERIFY(Test::unlockScreen());
}
WAYLANDTEST_MAIN(ModifierOnlyShortcutTest)

View file

@ -34,6 +34,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KWayland/Client/surface.h>
#include <KWayland/Client/xdgshell.h>
//screenlocker
#include <KScreenLocker/KsldApp>
#include <QThread>
using namespace KWayland::Client;
@ -362,5 +365,42 @@ bool waitForWindowDestroyed(AbstractClient *client)
return destroyedSpy.wait();
}
bool lockScreen()
{
if (waylandServer()->isScreenLocked()) {
return false;
}
QSignalSpy lockStateChangedSpy(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged);
if (!lockStateChangedSpy.isValid()) {
return false;
}
ScreenLocker::KSldApp::self()->lock(ScreenLocker::EstablishLock::Immediate);
if (lockStateChangedSpy.count() != 1) {
return false;
}
return waylandServer()->isScreenLocked();
}
bool unlockScreen()
{
QSignalSpy lockStateChangedSpy(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::lockStateChanged);
if (!lockStateChangedSpy.isValid()) {
return false;
}
using namespace ScreenLocker;
const auto children = KSldApp::self()->children();
for (auto it = children.begin(); it != children.end(); ++it) {
if (qstrcmp((*it)->metaObject()->className(), "LogindIntegration") != 0) {
continue;
}
QMetaObject::invokeMethod(*it, "requestUnlock");
break;
}
if (waylandServer()->isScreenLocked()) {
lockStateChangedSpy.wait();
}
return !waylandServer()->isScreenLocked();
}
}
}