From 246824aa61df286506a9cc0ec3acee9db040db73 Mon Sep 17 00:00:00 2001 From: Kristen McWilliam Date: Tue, 19 Mar 2024 18:00:12 +0000 Subject: [PATCH] autotests: add test for global keyboard shortcut Adds an integration test that verifies the screen locks when the global keyboard shortcut is invoked. --- autotests/integration/lockscreen.cpp | 45 ++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/autotests/integration/lockscreen.cpp b/autotests/integration/lockscreen.cpp index f443e39438..4f3917d31d 100644 --- a/autotests/integration/lockscreen.cpp +++ b/autotests/integration/lockscreen.cpp @@ -67,7 +67,8 @@ private Q_SLOTS: void testPointerShortcut(); void testAxisShortcut_data(); void testAxisShortcut(); - void testKeyboardShortcut(); + void testKeyboardLockShortcut(); + void testKeyboardShortcutsDisabledWhenLocked(); void testTouch(); private: @@ -691,7 +692,10 @@ void LockScreenTest::testAxisShortcut() #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 QSKIP("Can't test shortcuts without shortcuts"); @@ -738,6 +742,43 @@ void LockScreenTest::testKeyboardShortcut() 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 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(); + QVERIFY(window); + QVERIFY(window->isLockScreen()); + QTRY_COMPARE(ScreenLocker::KSldApp::self()->lockState(), ScreenLocker::KSldApp::Locked); + QVERIFY(waylandServer()->isScreenLocked()); + + UNLOCK; +} + void LockScreenTest::testTouch() { auto touch = m_seat->createTouch(m_seat);