Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Flohack74 committed Jul 10, 2022
1 parent 216e82b commit b343b25
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 38 deletions.
30 changes: 17 additions & 13 deletions qml/Greeter/Greeter.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -571,22 +579,14 @@ Showable {
Biometryd.available &&
AccountsService.enableFingerprintIdentification

function startFingerprintReader() {
function startOperation() {
if (idEnabled) {
var identifier = Biometryd.defaultDevice.identifier;
operation = identifier.identifyUser();
operation.start(biometryd);
}
}

Timer {
id: fpRetryTimer
running: false
repeat: false
onTriggered: startFingerprintReader()
interval: failedFingerprintReaderRetryDelay
}

function cancelOperation() {
if (operation) {
operation.cancel();
Expand All @@ -596,7 +596,11 @@ Showable {

function restartOperation() {
cancelOperation();
fpRetryTimer.running = true;
if (failedFingerprintReaderRetryDelay > 0) {
fpRetryTimer.running = true;
} else {
startOperation();
}
}

function failOperation(reason) {
Expand All @@ -608,7 +612,7 @@ Showable {
d.showFingerprintMessage(msg);
}

Component.onCompleted: startFingerprintReader()
Component.onCompleted: startOperation()
Component.onDestruction: cancelOperation()
onIdEnabledChanged: restartOperation()

Expand All @@ -632,7 +636,7 @@ Showable {
onFailed: {
if (!d.secureFingerprint) {
failOperation("fingerprint reader is locked");
} else {
} else if (reason !== "ERROR_CANCELED") {
AccountsService.failedFingerprintLogins++;
failOperation(reason);
}
Expand Down
57 changes: 32 additions & 25 deletions tests/qmltests/Greeter/tst_Greeter.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand All @@ -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);
Expand All @@ -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");
}
}

Expand All @@ -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("Try again"));
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();

Expand All @@ -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() {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
}
}

0 comments on commit b343b25

Please sign in to comment.