autotests: add test for global keyboard shortcut

Adds an integration test that verifies the screen locks when the global keyboard shortcut is invoked.
wilder/Plasma/6.2
Kristen McWilliam 2 years ago committed by Vlad Zahorodnii
parent 60d36c0753
commit 246824aa61
  1. 45
      autotests/integration/lockscreen.cpp

@ -67,7 +67,8 @@ private Q_SLOTS:
void testPointerShortcut(); void testPointerShortcut();
void testAxisShortcut_data(); void testAxisShortcut_data();
void testAxisShortcut(); void testAxisShortcut();
void testKeyboardShortcut(); void testKeyboardLockShortcut();
void testKeyboardShortcutsDisabledWhenLocked();
void testTouch(); void testTouch();
private: private:
@ -691,7 +692,10 @@ void LockScreenTest::testAxisShortcut()
#undef PERFORM #undef PERFORM
} }
void LockScreenTest::testKeyboardShortcut() /**
* This test verifies that keyboard shortcuts are disabled when the screen is locked
*/
void LockScreenTest::testKeyboardShortcutsDisabledWhenLocked()
{ {
#if !KWIN_BUILD_GLOBALSHORTCUTS #if !KWIN_BUILD_GLOBALSHORTCUTS
QSKIP("Can't test shortcuts without shortcuts"); QSKIP("Can't test shortcuts without shortcuts");
@ -738,6 +742,43 @@ void LockScreenTest::testKeyboardShortcut()
KEYRELEASE(KEY_LEFTALT); KEYRELEASE(KEY_LEFTALT);
} }
/**
* This test verifies that the global keyboard shortcut to lock the screen works
*/
void LockScreenTest::testKeyboardLockShortcut()
{
#if !KWIN_BUILD_GLOBALSHORTCUTS
QSKIP("Can't test shortcuts without shortcuts");
return;
#endif
QList<QKeySequence> shortcuts = KGlobalAccel::self()->globalShortcut("ksmserver", "Lock Session");
// Verify the shortcut is Meta + L, the default
QCOMPARE(shortcuts.first().toString(), QString("Meta+L"));
// Verify the screen is not locked
QVERIFY(!waylandServer()->isScreenLocked());
QSignalSpy windowAddedSpy(workspace(), &Workspace::windowAdded);
// Trigger the shortcut
quint32 timestamp = 1;
KEYPRESS(KEY_LEFTMETA);
KEYPRESS(KEY_L);
KEYRELEASE(KEY_L);
KEYRELEASE(KEY_LEFTMETA);
// Verify the screen gets locked
QVERIFY(windowAddedSpy.wait());
Window *window = windowAddedSpy.first().first().value<Window *>();
QVERIFY(window);
QVERIFY(window->isLockScreen());
QTRY_COMPARE(ScreenLocker::KSldApp::self()->lockState(), ScreenLocker::KSldApp::Locked);
QVERIFY(waylandServer()->isScreenLocked());
UNLOCK;
}
void LockScreenTest::testTouch() void LockScreenTest::testTouch()
{ {
auto touch = m_seat->createTouch(m_seat); auto touch = m_seat->createTouch(m_seat);

Loading…
Cancel
Save