on xenial help sign in
Expanded mocks and tests
commit5c22355108feea57012b47b63c3007fabb51c6d9 authorMichael Terry <michael.terry@canonical.com> dateThu 26 May 2016, 16:59 (10 years ago) parentb9e5bc7
10 files changed+158−46
debian/control+1−1 qml/Components/Lockscreen.qml+1−1 tests/mocks/AccountsService/AccountsService.cpp+12 tests/mocks/AccountsService/AccountsService.h+8 tests/mocks/Biometryd/CMakeLists.txt+4 tests/mocks/Biometryd/MockObserver.cpp−26 tests/mocks/Biometryd/MockObserver.h−2 tests/mocks/Biometryd/plugin.cpp+14 tests/qmltests/Components/tst_Lockscreen.qml+20−1 tests/qmltests/Greeter/tst_Greeter.qml+98−15
debian/control+1−1
@@ -190,7 +190,7 @@ Package: unity8-private
190190Architecture: any
191191Multi-Arch: same
192192Pre-Depends: ${misc:Pre-Depends},
193−Depends: accountsservice-ubuntu-schemas (>= 0.0.5),
193+Depends: accountsservice-ubuntu-schemas (>= 0.0.6),
194194 gsettings-ubuntu-schemas (>= 0.0.2+14.10.20140815),
195195 libhardware2,
196196 pay-service,
qml/Components/Lockscreen.qml+1−1
@@ -94,8 +94,8 @@ Showable {
9494 function showText(text) {
9595 // Programmatically enters the given text into the lockscreen
9696 if (pinPadLoader.item) {
97− pinPadLoader.waiting = true;
9897 pinPadLoader.item.showText(text);
98+ pinPadLoader.waiting = true;
9999 }
100100 }
101101
tests/mocks/AccountsService/AccountsService.cpp+12
@@ -20,6 +20,7 @@
2020
2121AccountsService::AccountsService(QObject* parent)
2222 : QObject(parent),
23+ m_enableFingerprintIdentification(false),
2324 m_enableLauncherWhileLocked(true),
2425 m_enableIndicatorsWhileLocked(true),
2526 m_backgroundFile(qmlDirectory() + "/graphics/phone_background.jpg"),
@@ -74,6 +75,17 @@ void AccountsService::setDemoEdgesCompleted(const QStringList &demoEdgesComplete
7475 Q_EMIT demoEdgesCompletedChanged();
7576}
7677
78+bool AccountsService::enableFingerprintIdentification() const
79+{
80+ return m_enableFingerprintIdentification;
81+}
82+
83+void AccountsService::setEnableFingerprintIdentification(bool enableFingerprintIdentification)
84+{
85+ m_enableFingerprintIdentification = enableFingerprintIdentification;
86+ Q_EMIT enableFingerprintIdentificationChanged();
87+}
88+
7789bool AccountsService::enableLauncherWhileLocked() const
7890{
7991 return m_enableLauncherWhileLocked;
tests/mocks/AccountsService/AccountsService.h+8
@@ -38,6 +38,10 @@ class AccountsService: public QObject
3838 READ demoEdgesCompleted
3939 WRITE setDemoEdgesCompleted // only available in mock
4040 NOTIFY demoEdgesCompletedChanged)
41+ Q_PROPERTY (bool enableFingerprintIdentification
42+ READ enableFingerprintIdentification
43+ WRITE setEnableFingerprintIdentification // only available in mock
44+ NOTIFY enableFingerprintIdentificationChanged)
4145 Q_PROPERTY (bool enableLauncherWhileLocked
4246 READ enableLauncherWhileLocked
4347 WRITE setEnableLauncherWhileLocked // only available in mock
@@ -94,6 +98,8 @@ public:
9498 QStringList demoEdgesCompleted() const;
9599 void setDemoEdgesCompleted(const QStringList &demoEdges);
96100 Q_INVOKABLE void markDemoEdgeCompleted(const QString &edge);
101+ bool enableFingerprintIdentification() const;
102+ void setEnableFingerprintIdentification(bool enableFingerprintIdentification);
97103 bool enableLauncherWhileLocked() const;
98104 void setEnableLauncherWhileLocked(bool enableLauncherWhileLocked);
99105 bool enableIndicatorsWhileLocked() const;
@@ -121,6 +127,7 @@ Q_SIGNALS:
121127 void userChanged();
122128 void demoEdgesChanged();
123129 void demoEdgesCompletedChanged();
130+ void enableFingerprintIdentificationChanged();
124131 void enableLauncherWhileLockedChanged();
125132 void enableIndicatorsWhileLockedChanged();
126133 void backgroundFileChanged();
@@ -134,6 +141,7 @@ Q_SIGNALS:
134141 void keymapsChanged();
135142
136143private:
144+ bool m_enableFingerprintIdentification;
137145 bool m_enableLauncherWhileLocked;
138146 bool m_enableIndicatorsWhileLocked;
139147 QString m_backgroundFile;
tests/mocks/Biometryd/CMakeLists.txt+4
@@ -4,7 +4,11 @@ include_directories(
44
55set(MOCK_BIOMETRYD_SOURCES
66 plugin.cpp
7+ MockBiometryd.cpp
8+ MockDevice.cpp
9+ MockIdentifier.cpp
710 MockObserver.cpp
11+ MockOperation.cpp
812)
913
1014add_library(MockBiometryd MODULE ${MOCK_BIOMETRYD_SOURCES})
tests/mocks/Biometryd/MockObserver.cpp−26
@@ -16,33 +16,7 @@
1616
1717#include "MockObserver.h"
1818
19−class Result : public QObject
20−{
21− Q_OBJECT
22− Q_PROPERTY(unsigned int uid READ uid CONSTANT)
23−
24−public:
25− explicit Result(unsigned int uid, QObject *parent = 0)
26− : QObject(parent), m_uid(uid)
27− {}
28−
29− unsigned int uid() const { return m_uid; }
30−
31−private:
32− unsigned int m_uid;
33−};
34−
3519MockObserver::MockObserver(QObject *parent)
3620 : QObject(parent)
3721{
3822}
39−
40−void MockObserver::mockIdentification(int uid, const QString &error)
41−{
42− if (error.isEmpty())
43− Q_EMIT succeeded(QVariant::fromValue(new Result(uid, this)));
44− else
45− Q_EMIT failed(error);
46−}
47−
48−#include "MockObserver.moc"
tests/mocks/Biometryd/MockObserver.h−2
@@ -29,8 +29,6 @@ class MockObserver : public QObject
2929public:
3030 explicit MockObserver(QObject *parent = 0);
3131
32− Q_INVOKABLE void mockIdentification(int uid, const QString &error); // only in mock
33−
3432Q_SIGNALS:
3533 void succeeded(const QVariant &result);
3634 void failed(const QString &reason);
tests/mocks/Biometryd/plugin.cpp+14
@@ -15,13 +15,27 @@
1515 */
1616
1717#include "plugin.h"
18+#include "MockBiometryd.h"
19+#include "MockDevice.h"
20+#include "MockIdentifier.h"
1821#include "MockObserver.h"
22+#include "MockOperation.h"
1923
2024#include <QtQml>
2125
26+static QObject *biometryd_provider(QQmlEngine *, QJSEngine *)
27+{
28+ return new MockBiometryd();
29+}
30+
2231void BackendPlugin::registerTypes(const char *uri)
2332{
2433 Q_ASSERT(uri == QLatin1String("Biometryd"));
2534
2635 qmlRegisterType<MockObserver>(uri, 0, 0, "Observer");
36+ qmlRegisterSingletonType<MockBiometryd>(uri, 0, 0, "Biometryd", biometryd_provider);
37+
38+ qRegisterMetaType<MockDevice*>();
39+ qRegisterMetaType<MockIdentifier*>();
40+ qRegisterMetaType<MockOperation*>();
2741}
tests/qmltests/Components/tst_Lockscreen.qml+20−1
@@ -173,6 +173,7 @@ Rectangle {
173173 function cleanup() {
174174 lockscreen.clear(false);
175175 delayMinutesTextField.text = "0"
176+ enteredLabel.text = "";
176177
177178 // Reset sizing
178179 root.width = units.gu(80)
@@ -247,7 +248,6 @@ Rectangle {
247248 }
248249
249250 function test_unlock(data) {
250− enteredLabel.text = ""
251251 minPinLengthTextField.text = data.minPinLength
252252 maxPinLengthTextField.text = data.maxPinLength
253253 pinPadCheckBox.checked = data.alphanumeric
@@ -462,6 +462,25 @@ Rectangle {
462462 compare(label.text, "Device Locked")
463463 }
464464
465+ function test_showText_data() {
466+ return [
467+ { tag: "alphanumeric", alphanumeric: true },
468+ { tag: "pinPad", alphanumeric: false },
469+ ]
470+ }
471+
472+ function test_showText(data) {
473+ pinPadCheckBox.checked = data.alphanumeric;
474+ waitForLockscreenReady();
475+
476+ lockscreen.showText("test");
477+
478+ var pinPadLoader = findChild(lockscreen, "pinPadLoader");
479+ verify(pinPadLoader.waiting);
480+ compare(enteredLabel.text, ""); // no entered signal should occur
481+ compare(lockscreen.passphrase, "test");
482+ }
483+
465484 function test_resize_data() {
466485 return [
467486 { tag: "small", width: units.gu(40), height: units.gu(76) },
tests/qmltests/Greeter/tst_Greeter.qml+98−15
@@ -20,6 +20,7 @@ import ".."
2020import "../../../qml/Greeter"
2121import Ubuntu.Components 1.3
2222import AccountsService 0.1
23+import Biometryd 0.0
2324import GSettings 1.0
2425import IntegratedLightDM 0.1 as LightDM
2526import Unity.Test 0.1 as UT
@@ -149,6 +150,8 @@ Item {
149150 teaseSpy.clear();
150151 sessionStartedSpy.clear();
151152 activeChangedSpy.clear();
153+ Biometryd.reset(false);
154+ AccountsService.enableFingerprintIdentification = false;
152155 viewShowMessageSpy.clear();
153156 viewShowPromptSpy.clear();
154157 viewShowLastChanceSpy.clear();
@@ -562,49 +565,129 @@ Item {
562565 }
563566
564567 function test_fingerprintSuccess() {
568+ Biometryd.reset(true);
569+ AccountsService.enableFingerprintIdentification = true;
570+ var index = selectUser("has-password");
571+
565572 var biometryd = findInvisibleChild(greeter, "biometryd");
566− selectUser("has-password");
567− biometryd.mockIdentification(0, "");
568− verify(greeter.forcedUnlock);
573+ verify(biometryd.operation);
574+ verify(biometryd.operation.running);
575+
576+ biometryd.operation.mockSuccess(LightDM.Users.data(index, LightDM.UserRoles.UidRole));
577+ verify(!greeter.active);
569578 }
570579
571580 function test_fingerprintFailureMessage() {
581+ Biometryd.reset(true);
582+ AccountsService.enableFingerprintIdentification = true;
583+ var index = selectUser("has-password");
584+
572585 var biometryd = findInvisibleChild(greeter, "biometryd");
573− selectUser("has-password");
574− biometryd.mockIdentification(0, "error");
586+ verify(biometryd.operation);
587+ verify(biometryd.operation.running);
588+
589+ biometryd.operation.mockFailure("error");
575590 compare(viewShowErrorMessageSpy.count, 1);
576591 compare(viewShowErrorMessageSpy.signalArguments[0][0], i18n.tr("Try again"));
577592 }
578593
579594 function test_fingerprintTooManyFailures() {
580− var biometryd = findInvisibleChild(greeter, "biometryd");
595+ Biometryd.reset(true);
596+ AccountsService.enableFingerprintIdentification = true;
581597 selectUser("has-password");
582− biometryd.mockIdentification(0, "error");
583− biometryd.mockIdentification(0, "error");
598+
599+ var biometryd = findInvisibleChild(greeter, "biometryd");
600+ biometryd.operation.mockFailure("error");
601+ biometryd.operation.mockFailure("error");
584602 compare(viewTryToUnlockSpy.count, 0);
585603
586− biometryd.mockIdentification(0, "error");
604+ biometryd.operation.mockFailure("error");
587605 compare(viewTryToUnlockSpy.count, 1);
588606
589607 compare(viewShowErrorMessageSpy.count, 3);
590608 }
591609
592610 function test_fingerprintFailureCountReset() {
593− var biometryd = findInvisibleChild(greeter, "biometryd");
611+ Biometryd.reset(true);
612+ AccountsService.enableFingerprintIdentification = true;
594613 selectUser("has-password");
595− biometryd.mockIdentification(0, "error");
596− biometryd.mockIdentification(0, "error");
614+
615+ var biometryd = findInvisibleChild(greeter, "biometryd");
616+ biometryd.operation.mockFailure("error");
617+ biometryd.operation.mockFailure("error");
597618 compare(viewTryToUnlockSpy.count, 0);
598619
599620 greeter.forceShow();
600− biometryd.mockIdentification(0, "error");
601− biometryd.mockIdentification(0, "error");
621+ biometryd.operation.mockFailure("error");
622+ biometryd.operation.mockFailure("error");
602623 compare(viewTryToUnlockSpy.count, 0);
603624
604− biometryd.mockIdentification(0, "error");
625+ biometryd.operation.mockFailure("error");
605626 compare(viewTryToUnlockSpy.count, 1);
606627
607628 compare(viewShowErrorMessageSpy.count, 5);
608629 }
630+
631+ function test_fingerprintWrongUid() {
632+ Biometryd.reset(true);
633+ AccountsService.enableFingerprintIdentification = true;
634+ selectUser("has-password");
635+
636+ var biometryd = findInvisibleChild(greeter, "biometryd");
637+ biometryd.operation.mockSuccess(0);
638+
639+ verify(greeter.active);
640+ compare(viewShowErrorMessageSpy.count, 1);
641+ compare(viewShowErrorMessageSpy.signalArguments[0][0], i18n.tr("Try again"));
642+ }
643+
644+ function test_fingerprintNotEnabled() {
645+ Biometryd.reset(true);
646+ selectUser("has-password");
647+
648+ var biometryd = findInvisibleChild(greeter, "biometryd");
649+ verify(!biometryd.operation);
650+
651+ AccountsService.enableFingerprintIdentification = true;
652+ verify(biometryd.operation);
653+ verify(biometryd.operation.running);
654+
655+ AccountsService.enableFingerprintIdentification = false;
656+ verify(!biometryd.operation);
657+ }
658+
659+ function test_fingerprintReaderNotPresent() {
660+ AccountsService.enableFingerprintIdentification = true;
661+ selectUser("has-password");
662+
663+ verify(!Biometryd.defaultDevice);
664+
665+ var biometryd = findInvisibleChild(greeter, "biometryd");
666+ verify(!biometryd.operation);
667+
668+ Biometryd.reset(true);
669+ verify(biometryd.operation);
670+ verify(biometryd.operation.running);
671+
672+ Biometryd.reset(false);
673+ verify(!biometryd.operation);
674+ }
675+
676+ function test_fingerprintGreeterNotActive() {
677+ Biometryd.reset(true);
678+ AccountsService.enableFingerprintIdentification = true;
679+ selectUser("has-password");
680+
681+ var biometryd = findInvisibleChild(greeter, "biometryd");
682+ verify(biometryd.operation);
683+ verify(biometryd.operation.running);
684+
685+ greeter.hideNow();
686+ verify(!biometryd.operation);
687+
688+ greeter.showNow();
689+ verify(biometryd.operation);
690+ verify(biometryd.operation.running);
691+ }
609692 }
610693}