From c55203ad417a1016d800e020252b8c8671ff5f93 Mon Sep 17 00:00:00 2001 From: Florian Leeber Date: Sat, 9 Jul 2022 23:35:30 +0200 Subject: [PATCH] Fix unit tests --- qml/Greeter/Greeter.qml | 30 ++++++++------ tests/qmltests/Greeter/tst_Greeter.qml | 57 +++++++++++++++----------- 2 files changed, 49 insertions(+), 38 deletions(-) diff --git a/qml/Greeter/Greeter.qml b/qml/Greeter/Greeter.qml index ba22f2b24..f154198f9 100644 --- a/qml/Greeter/Greeter.qml +++ b/qml/Greeter/Greeter.qml @@ -64,7 +64,7 @@ Showable { property int failedLoginsDelayAttempts: 7 // number of failed logins property real failedLoginsDelayMinutes: 5 // minutes of forced waiting property int failedFingerprintLoginsDisableAttempts: 5 // number of failed fingerprint logins - property int failedFingerprintReaderRetryDelay: 300 // milliseconds + property int failedFingerprintReaderRetryDelay: 250 // time to wait before retrying a failed fingerprint read [ms] readonly property bool animating: loader.item ? loader.item.animating : false @@ -560,6 +560,14 @@ Showable { onLanguageChanged: LightDMService.infographic.readyForDataChange() } + Timer { + id: fpRetryTimer + running: false + repeat: false + onTriggered: biometryd.startOperation() + interval: failedFingerprintReaderRetryDelay + } + Observer { id: biometryd objectName: "biometryd" @@ -571,7 +579,7 @@ Showable { Biometryd.available && AccountsService.enableFingerprintIdentification - function startFingerprintReader() { + function startOperation() { if (idEnabled) { var identifier = Biometryd.defaultDevice.identifier; operation = identifier.identifyUser(); @@ -579,14 +587,6 @@ Showable { } } - Timer { - id: fpRetryTimer - running: false - repeat: false - onTriggered: startFingerprintReader() - interval: failedFingerprintReaderRetryDelay - } - function cancelOperation() { if (operation) { operation.cancel(); @@ -596,7 +596,11 @@ Showable { function restartOperation() { cancelOperation(); - fpRetryTimer.running = true; + if (failedFingerprintReaderRetryDelay > 0) { + fpRetryTimer.running = true; + } else { + startOperation(); + } } function failOperation(reason) { @@ -608,7 +612,7 @@ Showable { d.showFingerprintMessage(msg); } - Component.onCompleted: startFingerprintReader() + Component.onCompleted: startOperation() Component.onDestruction: cancelOperation() onIdEnabledChanged: restartOperation() @@ -632,7 +636,7 @@ Showable { onFailed: { if (!d.secureFingerprint) { failOperation("fingerprint reader is locked"); - } else { + } else if (reason !== "ERROR_CANCELED") { AccountsService.failedFingerprintLogins++; failOperation(reason); } diff --git a/tests/qmltests/Greeter/tst_Greeter.qml b/tests/qmltests/Greeter/tst_Greeter.qml index baef9683c..9821d1c4c 100644 --- a/tests/qmltests/Greeter/tst_Greeter.qml +++ b/tests/qmltests/Greeter/tst_Greeter.qml @@ -200,11 +200,6 @@ Item { compare(greeter.shown, false); } - function verifyBiometrydOperation() { - verify(biometryd.operation); - verify(biometryd.operation.running); - } - function unlockAndShowGreeter() { // useful to enable "lockscreen mode" in greeter greeter.forcedUnlock = true; @@ -537,7 +532,8 @@ Item { unlockAndShowGreeter(); // turn on lockscreen mode var biometryd = findInvisibleChild(greeter, "biometryd"); - verifyBiometrydOperation(); + verify(biometryd.operation); + verify(biometryd.operation.running); biometryd.operation.mockSuccess(LightDM.Users.data(index, LightDM.UserRoles.UidRole)); verify(!greeter.active); @@ -548,10 +544,12 @@ Item { // don't hide/show greeter, we want to test behavior before lockscreen mode is on var biometryd = findInvisibleChild(greeter, "biometryd"); - verifyBiometrydOperation(); + verify(biometryd.operation); + verify(biometryd.operation.running); biometryd.operation.mockSuccess(LightDM.Users.data(index, LightDM.UserRoles.UidRole)); - viewTryToUnlockSpy.wait(); + viewShowErrorMessageSpy.wait(); + compare(viewShowErrorMessageSpy.signalArguments[0][0], i18n.tr("Enter passphrase to unlock")); verify(greeter.locked); } @@ -560,7 +558,8 @@ Item { unlockAndShowGreeter(); // turn on lockscreen mode var biometryd = findInvisibleChild(greeter, "biometryd"); - verifyBiometrydOperation(); + verify(biometryd.operation); + verify(biometryd.operation.running); greeter.allowFingerprint = false; verify(!biometryd.operation); @@ -571,16 +570,17 @@ Item { unlockAndShowGreeter(); // turn on lockscreen mode var biometryd = findInvisibleChild(greeter, "biometryd"); - verifyBiometrydOperation(); + verify(biometryd.operation); + verify(biometryd.operation.running); biometryd.operation.mockFailure("error"); viewShowErrorMessageSpy.wait(); compare(viewShowErrorMessageSpy.signalArguments[0][0], i18n.tr("Try again")); } - function repeatBiometrydMockFailure(int count) { + function repeatBiometrydMockFailure(operationHost, count) { for (var i = 0; i < count; i++) { - biometryd.operation.mockFailure("error"); + operationHost.operation.mockFailure("error"); } } @@ -589,16 +589,18 @@ Item { unlockAndShowGreeter(); // turn on lockscreen mode var biometryd = findInvisibleChild(greeter, "biometryd"); - repeatBiometrydMockFailure(2); + repeatBiometrydMockFailure(biometryd, 4); compare(viewTryToUnlockSpy.count, 0); - repeatBiometrydMockFailure(3); - viewTryToUnlockSpy.wait(); - viewTryToUnlockSpy.clear(); + repeatBiometrydMockFailure(biometryd, 1); + viewShowErrorMessageSpy.wait(); + compare(viewShowErrorMessageSpy.signalArguments[0][0], i18n.tr("Enter passphrase to unlock")); + viewShowErrorMessageSpy.clear(); // Confirm that we are stuck in this mode until next login biometryd.operation.mockSuccess(LightDM.Users.data(index, LightDM.UserRoles.UidRole)); - viewTryToUnlockSpy.wait(); + viewShowErrorMessageSpy.wait(); + compare(viewShowErrorMessageSpy.signalArguments[0][0], i18n.tr("Enter passphrase to unlock")); unlockAndShowGreeter(); @@ -611,15 +613,16 @@ Item { unlockAndShowGreeter(); // turn on lockscreen mode var biometryd = findInvisibleChild(greeter, "biometryd"); - repeatBiometrydMockFailure(2); + repeatBiometrydMockFailure(biometryd, 4); compare(viewTryToUnlockSpy.count, 0); unlockAndShowGreeter(); - repeatBiometrydMockFailure(2); + repeatBiometrydMockFailure(biometryd, 4); compare(viewTryToUnlockSpy.count, 0); - repeatBiometrydMockFailure(1; - viewTryToUnlockSpy.wait(); + repeatBiometrydMockFailure(biometryd, 1); + viewShowErrorMessageSpy.wait(); + compare(viewShowErrorMessageSpy.signalArguments[0][0], i18n.tr("Try again")); } function test_fingerprintWrongUid() { @@ -643,7 +646,8 @@ Item { verify(!biometryd.operation); AccountsService.enableFingerprintIdentification = true; - verifyBiometrydOperation(); + verify(biometryd.operation); + verify(biometryd.operation.running); AccountsService.enableFingerprintIdentification = false; verify(!biometryd.operation); @@ -660,7 +664,8 @@ Item { verify(!biometryd.operation); Biometryd.available = true; - verifyBiometrydOperation(); + verify(biometryd.operation); + verify(biometryd.operation.running); Biometryd.available = false; verify(!biometryd.operation); @@ -671,13 +676,15 @@ Item { unlockAndShowGreeter(); // turn on lockscreen mode var biometryd = findInvisibleChild(greeter, "biometryd"); - verifyBiometrydOperation(); + verify(biometryd.operation); + verify(biometryd.operation.running); greeter.hideNow(); verify(!biometryd.operation); greeter.showNow(); - verifyBiometrydOperation(); + verify(biometryd.operation); + verify(biometryd.operation.running); } } }