on xenial help sign in
Don't crash because we blocked a method from returning while deleting qml objects; instead just delay signal emission
3ddfbeeMichael Terry
tests/mocks/LightDM/Greeter.cpp+11
@@ -19,6 +19,7 @@
19#include "Greeter.h"
19#include "Greeter.h"
20#include "GreeterPrivate.h"
20#include "GreeterPrivate.h"
21#include <QtCore/QCoreApplication>
21#include <QtCore/QCoreApplication>
22+#include <QTimer>
22
23
23namespace QLightDM
24namespace QLightDM
24{
25{
@@ -164,4 +165,14 @@ void Greeter::respond(const QString &response)
164 d->handleRespond(response);
165 d->handleRespond(response);
165}
166}
166
167
168+void Greeter::sendAuthenticationComplete()
169+{
170+ if (qgetenv("UNITY_TESTING").isEmpty()) {
171+ // simulate PAM's delay
172+ QTimer::singleShot(1000, this, SIGNAL(authenticationComplete()));
173+ } else {
174+ Q_EMIT authenticationComplete();
175+ }
176+}
177+
167}
178}
tests/mocks/LightDM/Greeter.h+3
@@ -96,6 +96,9 @@ Q_SIGNALS:
96 void authenticationComplete();
96 void authenticationComplete();
97 void autologinTimerExpired();
97 void autologinTimerExpired();
98
98
99+protected:
100+ void sendAuthenticationComplete();
101+
99private:
102private:
100 GreeterPrivate *d_ptr;
103 GreeterPrivate *d_ptr;
101 Q_DECLARE_PRIVATE(Greeter)
104 Q_DECLARE_PRIVATE(Greeter)
tests/mocks/LightDM/full/GreeterPrivate.cpp+3−13
@@ -19,9 +19,6 @@
19#include "../Greeter.h"
19#include "../Greeter.h"
20#include "../GreeterPrivate.h"
20#include "../GreeterPrivate.h"
21
21
22−#include <QEventLoop>
23−#include <QTimer>
24−
25namespace QLightDM
22namespace QLightDM
26{
23{
27
24
@@ -72,13 +69,6 @@ void GreeterPrivate::handleRespond(const QString &response)
72{
69{
73 Q_Q(Greeter);
70 Q_Q(Greeter);
74
71
75− if (qgetenv("UNITY_TESTING").isEmpty()) {
76− // simulate PAM's delay
77− QEventLoop loop;
78− QTimer::singleShot(1000, &loop, SLOT(quit()));
79− loop.exec();
80− }
81−
82 if (authenticationUser == "no-response")
72 if (authenticationUser == "no-response")
83 return;
73 return;
84 else if (authenticationUser == "two-factor") {
74 else if (authenticationUser == "two-factor") {
@@ -88,11 +78,11 @@ void GreeterPrivate::handleRespond(const QString &response)
88 Q_EMIT q->showPrompt("otp", Greeter::PromptTypeQuestion);
78 Q_EMIT q->showPrompt("otp", Greeter::PromptTypeQuestion);
89 } else {
79 } else {
90 authenticated = false;
80 authenticated = false;
91− Q_EMIT q->authenticationComplete();
81+ q->sendAuthenticationComplete();
92 }
82 }
93 } else {
83 } else {
94 authenticated = (response == "otp");
84 authenticated = (response == "otp");
95− Q_EMIT q->authenticationComplete();
85+ q->sendAuthenticationComplete();
96 }
86 }
97 return;
87 return;
98 }
88 }
@@ -102,7 +92,7 @@ void GreeterPrivate::handleRespond(const QString &response)
102 } else {
92 } else {
103 authenticated = (response == "password");
93 authenticated = (response == "password");
104 }
94 }
105− Q_EMIT q->authenticationComplete();
95+ q->sendAuthenticationComplete();
106}
96}
107
97
108}
98}
tests/mocks/LightDM/single-passphrase/GreeterPrivate.cpp+1−11
@@ -19,9 +19,6 @@
19#include "../Greeter.h"
19#include "../Greeter.h"
20#include "../GreeterPrivate.h"
20#include "../GreeterPrivate.h"
21
21
22−#include <QEventLoop>
23−#include <QTimer>
24−
25namespace QLightDM
22namespace QLightDM
26{
23{
27
24
@@ -42,15 +39,8 @@ void GreeterPrivate::handleRespond(const QString &response)
42{
39{
43 Q_Q(Greeter);
40 Q_Q(Greeter);
44
41
45− if (qgetenv("UNITY_TESTING").isEmpty()) {
46− // simulate PAM's delay
47− QEventLoop loop;
48− QTimer::singleShot(1000, &loop, SLOT(quit()));
49− loop.exec();
50− }
51−
52 authenticated = (response == "password");
42 authenticated = (response == "password");
53− Q_EMIT q->authenticationComplete();
43+ q->sendAuthenticationComplete();
54}
44}
55
45
56}
46}
tests/mocks/LightDM/single-pin/GreeterPrivate.cpp+1−11
@@ -19,9 +19,6 @@
19#include "../Greeter.h"
19#include "../Greeter.h"
20#include "../GreeterPrivate.h"
20#include "../GreeterPrivate.h"
21
21
22−#include <QEventLoop>
23−#include <QTimer>
24−
25namespace QLightDM
22namespace QLightDM
26{
23{
27
24
@@ -42,15 +39,8 @@ void GreeterPrivate::handleRespond(const QString &response)
42{
39{
43 Q_Q(Greeter);
40 Q_Q(Greeter);
44
41
45− if (qgetenv("UNITY_TESTING").isEmpty()) {
46− // simulate PAM's delay
47− QEventLoop loop;
48− QTimer::singleShot(1000, &loop, SLOT(quit()));
49− loop.exec();
50− }
51−
52 authenticated = (response == "1234");
42 authenticated = (response == "1234");
53− Q_EMIT q->authenticationComplete();
43+ q->sendAuthenticationComplete();
54}
44}
55
45
56}
46}