Merge lp:~mardy/signon-ui/lp1135038 into lp:signon-ui
- lp1135038
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Alberto Mardegan |
Approved revision: | 79 |
Merged at revision: | 78 |
Proposed branch: | lp:~mardy/signon-ui/lp1135038 |
Merge into: | lp:signon-ui |
Diff against target: |
672 lines (+367/-51) 12 files modified
.bzrignore (+2/-0) src/inactivity-timer.cpp (+68/-0) src/inactivity-timer.h (+58/-0) src/indicator-service.cpp (+18/-0) src/indicator-service.h (+5/-0) src/main.cpp (+12/-7) src/service.cpp (+15/-42) src/service.h (+3/-2) src/src.pro (+2/-0) tests/unit/tst_inactivity_timer.cpp (+143/-0) tests/unit/tst_inactivity_timer.pro (+37/-0) tests/unit/unit.pro (+4/-0) |
To merge this branch: | bzr merge lp:~mardy/signon-ui/lp1135038 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
David King (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Review via email: mp+153356@code.launchpad.net |
Commit message
Do not quit if some accounts are failing
The inactivity timer should not trigger if there are some account failures (we
even had a comment warning about that!), because signon-ui is also the host for
the com.canonical.
Create a new InactivityTimer to monitor both the Service and IndicatorService
objects.
Description of the change
Do not quit if some accounts are failing
The inactivity timer should not trigger if there are some account failures (we
even had a comment warning about that!), because signon-ui is also the host for
the com.canonical.
Create a new InactivityTimer to monitor both the Service and IndicatorService
objects.
PS Jenkins bot (ps-jenkins) wrote : | # |
- 79. By Alberto Mardegan
-
Use xvfb-run
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:79
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
David King (amigadave) : | # |
Preview Diff
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2012-11-15 08:10:18 +0000 | |||
3 | +++ .bzrignore 2013-03-14 13:21:22 +0000 | |||
4 | @@ -13,6 +13,7 @@ | |||
5 | 13 | core | 13 | core |
6 | 14 | debian/ | 14 | debian/ |
7 | 15 | Makefile | 15 | Makefile |
8 | 16 | Makefile.* | ||
9 | 16 | moc_* | 17 | moc_* |
10 | 17 | qrc_*.cpp | 18 | qrc_*.cpp |
11 | 18 | signon-ui-test | 19 | signon-ui-test |
12 | @@ -20,6 +21,7 @@ | |||
13 | 20 | src/signon_ui_adaptor.* | 21 | src/signon_ui_adaptor.* |
14 | 21 | src/webcredentials_adaptor.* | 22 | src/webcredentials_adaptor.* |
15 | 22 | tests/unit/signon-ui-unittest | 23 | tests/unit/signon-ui-unittest |
16 | 24 | tests/unit/tst_inactivity_timer | ||
17 | 23 | tests/.config/Trolltech.conf | 25 | tests/.config/Trolltech.conf |
18 | 24 | tests/functional/.cache/ | 26 | tests/functional/.cache/ |
19 | 25 | tests/functional/.config/ | 27 | tests/functional/.config/ |
20 | 26 | 28 | ||
21 | === added file 'src/inactivity-timer.cpp' | |||
22 | --- src/inactivity-timer.cpp 1970-01-01 00:00:00 +0000 | |||
23 | +++ src/inactivity-timer.cpp 2013-03-14 13:21:22 +0000 | |||
24 | @@ -0,0 +1,68 @@ | |||
25 | 1 | /* | ||
26 | 2 | * This file is part of signon-ui | ||
27 | 3 | * | ||
28 | 4 | * Copyright (C) 2013 Canonical Ltd. | ||
29 | 5 | * | ||
30 | 6 | * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> | ||
31 | 7 | * | ||
32 | 8 | * This program is free software: you can redistribute it and/or modify it | ||
33 | 9 | * under the terms of the GNU General Public License version 3, as published | ||
34 | 10 | * by the Free Software Foundation. | ||
35 | 11 | * | ||
36 | 12 | * This program is distributed in the hope that it will be useful, but | ||
37 | 13 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
38 | 14 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
39 | 15 | * PURPOSE. See the GNU General Public License for more details. | ||
40 | 16 | * | ||
41 | 17 | * You should have received a copy of the GNU General Public License along | ||
42 | 18 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
43 | 19 | */ | ||
44 | 20 | |||
45 | 21 | #include "inactivity-timer.h" | ||
46 | 22 | |||
47 | 23 | #include "debug.h" | ||
48 | 24 | |||
49 | 25 | using namespace SignOnUi; | ||
50 | 26 | |||
51 | 27 | InactivityTimer::InactivityTimer(int interval, QObject *parent): | ||
52 | 28 | QObject(parent), | ||
53 | 29 | m_interval(interval) | ||
54 | 30 | { | ||
55 | 31 | m_timer.setSingleShot(true); | ||
56 | 32 | QObject::connect(&m_timer, SIGNAL(timeout()), | ||
57 | 33 | this, SLOT(onTimeout())); | ||
58 | 34 | } | ||
59 | 35 | |||
60 | 36 | void InactivityTimer::watchObject(QObject *object) | ||
61 | 37 | { | ||
62 | 38 | connect(object, SIGNAL(isIdleChanged()), SLOT(onIdleChanged())); | ||
63 | 39 | m_watchedObjects.append(object); | ||
64 | 40 | |||
65 | 41 | /* Force an initial check */ | ||
66 | 42 | onIdleChanged(); | ||
67 | 43 | } | ||
68 | 44 | |||
69 | 45 | void InactivityTimer::onIdleChanged() | ||
70 | 46 | { | ||
71 | 47 | if (allObjectsAreIdle()) { | ||
72 | 48 | m_timer.start(m_interval); | ||
73 | 49 | } | ||
74 | 50 | } | ||
75 | 51 | |||
76 | 52 | void InactivityTimer::onTimeout() | ||
77 | 53 | { | ||
78 | 54 | TRACE(); | ||
79 | 55 | if (allObjectsAreIdle()) { | ||
80 | 56 | Q_EMIT timeout(); | ||
81 | 57 | } | ||
82 | 58 | } | ||
83 | 59 | |||
84 | 60 | bool InactivityTimer::allObjectsAreIdle() const | ||
85 | 61 | { | ||
86 | 62 | foreach (const QObject *object, m_watchedObjects) { | ||
87 | 63 | if (!object->property("isIdle").toBool()) { | ||
88 | 64 | return false; | ||
89 | 65 | } | ||
90 | 66 | } | ||
91 | 67 | return true; | ||
92 | 68 | } | ||
93 | 0 | 69 | ||
94 | === added file 'src/inactivity-timer.h' | |||
95 | --- src/inactivity-timer.h 1970-01-01 00:00:00 +0000 | |||
96 | +++ src/inactivity-timer.h 2013-03-14 13:21:22 +0000 | |||
97 | @@ -0,0 +1,58 @@ | |||
98 | 1 | /* | ||
99 | 2 | * This file is part of signon-ui | ||
100 | 3 | * | ||
101 | 4 | * Copyright (C) 2013 Canonical Ltd. | ||
102 | 5 | * | ||
103 | 6 | * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> | ||
104 | 7 | * | ||
105 | 8 | * This program is free software: you can redistribute it and/or modify it | ||
106 | 9 | * under the terms of the GNU General Public License version 3, as published | ||
107 | 10 | * by the Free Software Foundation. | ||
108 | 11 | * | ||
109 | 12 | * This program is distributed in the hope that it will be useful, but | ||
110 | 13 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
111 | 14 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
112 | 15 | * PURPOSE. See the GNU General Public License for more details. | ||
113 | 16 | * | ||
114 | 17 | * You should have received a copy of the GNU General Public License along | ||
115 | 18 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
116 | 19 | */ | ||
117 | 20 | |||
118 | 21 | #ifndef SIGNON_UI_INACTIVITY_TIMER_H | ||
119 | 22 | #define SIGNON_UI_INACTIVITY_TIMER_H | ||
120 | 23 | |||
121 | 24 | #include <QList> | ||
122 | 25 | #include <QObject> | ||
123 | 26 | #include <QTimer> | ||
124 | 27 | |||
125 | 28 | namespace SignOnUi { | ||
126 | 29 | |||
127 | 30 | class InactivityTimer: public QObject | ||
128 | 31 | { | ||
129 | 32 | Q_OBJECT | ||
130 | 33 | |||
131 | 34 | public: | ||
132 | 35 | InactivityTimer(int interval, QObject *parent = 0); | ||
133 | 36 | ~InactivityTimer() {} | ||
134 | 37 | |||
135 | 38 | void watchObject(QObject *object); | ||
136 | 39 | |||
137 | 40 | Q_SIGNALS: | ||
138 | 41 | void timeout(); | ||
139 | 42 | |||
140 | 43 | private Q_SLOTS: | ||
141 | 44 | void onIdleChanged(); | ||
142 | 45 | void onTimeout(); | ||
143 | 46 | |||
144 | 47 | private: | ||
145 | 48 | bool allObjectsAreIdle() const; | ||
146 | 49 | |||
147 | 50 | private: | ||
148 | 51 | QList<QObject*> m_watchedObjects; | ||
149 | 52 | QTimer m_timer; | ||
150 | 53 | int m_interval; | ||
151 | 54 | }; | ||
152 | 55 | |||
153 | 56 | } // namespace | ||
154 | 57 | |||
155 | 58 | #endif // SIGNON_UI_INACTIVITY_TIMER_H | ||
156 | 0 | 59 | ||
157 | === modified file 'src/indicator-service.cpp' | |||
158 | --- src/indicator-service.cpp 2013-01-23 07:48:35 +0000 | |||
159 | +++ src/indicator-service.cpp 2013-03-14 13:21:22 +0000 | |||
160 | @@ -121,14 +121,23 @@ | |||
161 | 121 | 121 | ||
162 | 122 | void IndicatorServicePrivate::RemoveFailures(const QSet<uint> &accountIds) | 122 | void IndicatorServicePrivate::RemoveFailures(const QSet<uint> &accountIds) |
163 | 123 | { | 123 | { |
164 | 124 | Q_Q(IndicatorService); | ||
165 | 124 | m_failures.subtract(accountIds); | 125 | m_failures.subtract(accountIds); |
166 | 125 | notifyPropertyChanged("Failures"); | 126 | notifyPropertyChanged("Failures"); |
167 | 127 | if (q->isIdle()) { | ||
168 | 128 | Q_EMIT q->isIdleChanged(); | ||
169 | 129 | } | ||
170 | 126 | } | 130 | } |
171 | 127 | 131 | ||
172 | 128 | void IndicatorServicePrivate::ReportFailure(uint accountId, | 132 | void IndicatorServicePrivate::ReportFailure(uint accountId, |
173 | 129 | const QVariantMap ¬ification) | 133 | const QVariantMap ¬ification) |
174 | 130 | { | 134 | { |
175 | 135 | Q_Q(IndicatorService); | ||
176 | 136 | bool wasIdle = q->isIdle(); | ||
177 | 131 | m_failures.insert(accountId); | 137 | m_failures.insert(accountId); |
178 | 138 | if (wasIdle) { | ||
179 | 139 | Q_EMIT q->isIdleChanged(); | ||
180 | 140 | } | ||
181 | 132 | 141 | ||
182 | 133 | /* If the original client data is provided, we remember it: it can | 142 | /* If the original client data is provided, we remember it: it can |
183 | 134 | * be used to replay the authentication later. | 143 | * be used to replay the authentication later. |
184 | @@ -249,6 +258,8 @@ | |||
185 | 249 | 258 | ||
186 | 250 | void IndicatorServicePrivate::onReauthenticatorFinished(bool success) | 259 | void IndicatorServicePrivate::onReauthenticatorFinished(bool success) |
187 | 251 | { | 260 | { |
188 | 261 | Q_Q(IndicatorService); | ||
189 | 262 | |||
190 | 252 | Reauthenticator *reauthenticator = | 263 | Reauthenticator *reauthenticator = |
191 | 253 | qobject_cast<Reauthenticator*>(sender()); | 264 | qobject_cast<Reauthenticator*>(sender()); |
192 | 254 | 265 | ||
193 | @@ -277,6 +288,7 @@ | |||
194 | 277 | 288 | ||
195 | 278 | if (m_failures.isEmpty()) { | 289 | if (m_failures.isEmpty()) { |
196 | 279 | ClearErrorStatus(); | 290 | ClearErrorStatus(); |
197 | 291 | Q_EMIT q->isIdleChanged(); | ||
198 | 280 | } | 292 | } |
199 | 281 | } | 293 | } |
200 | 282 | 294 | ||
201 | @@ -342,4 +354,10 @@ | |||
202 | 342 | return d->m_errorStatus; | 354 | return d->m_errorStatus; |
203 | 343 | } | 355 | } |
204 | 344 | 356 | ||
205 | 357 | bool IndicatorService::isIdle() const | ||
206 | 358 | { | ||
207 | 359 | Q_D(const IndicatorService); | ||
208 | 360 | return d->m_failures.isEmpty(); | ||
209 | 361 | } | ||
210 | 362 | |||
211 | 345 | #include "indicator-service.moc" | 363 | #include "indicator-service.moc" |
212 | 346 | 364 | ||
213 | === modified file 'src/indicator-service.h' | |||
214 | --- src/indicator-service.h 2012-03-06 13:54:30 +0000 | |||
215 | +++ src/indicator-service.h 2013-03-14 13:21:22 +0000 | |||
216 | @@ -36,6 +36,7 @@ | |||
217 | 36 | class IndicatorService: public QObject | 36 | class IndicatorService: public QObject |
218 | 37 | { | 37 | { |
219 | 38 | Q_OBJECT | 38 | Q_OBJECT |
220 | 39 | Q_PROPERTY(bool isIdle READ isIdle NOTIFY isIdleChanged) | ||
221 | 39 | 40 | ||
222 | 40 | public: | 41 | public: |
223 | 41 | 42 | ||
224 | @@ -52,6 +53,10 @@ | |||
225 | 52 | 53 | ||
226 | 53 | QSet<uint> failures() const; | 54 | QSet<uint> failures() const; |
227 | 54 | bool errorStatus() const; | 55 | bool errorStatus() const; |
228 | 56 | bool isIdle() const; | ||
229 | 57 | |||
230 | 58 | Q_SIGNALS: | ||
231 | 59 | void isIdleChanged(); | ||
232 | 55 | 60 | ||
233 | 56 | private: | 61 | private: |
234 | 57 | IndicatorServicePrivate *d_ptr; | 62 | IndicatorServicePrivate *d_ptr; |
235 | 58 | 63 | ||
236 | === modified file 'src/main.cpp' | |||
237 | --- src/main.cpp 2013-02-01 17:11:24 +0000 | |||
238 | +++ src/main.cpp 2013-03-14 13:21:22 +0000 | |||
239 | @@ -20,6 +20,7 @@ | |||
240 | 20 | 20 | ||
241 | 21 | #include "debug.h" | 21 | #include "debug.h" |
242 | 22 | #include "i18n.h" | 22 | #include "i18n.h" |
243 | 23 | #include "inactivity-timer.h" | ||
244 | 23 | #include "indicator-service.h" | 24 | #include "indicator-service.h" |
245 | 24 | #include "my-network-proxy-factory.h" | 25 | #include "my-network-proxy-factory.h" |
246 | 25 | #include "service.h" | 26 | #include "service.h" |
247 | @@ -75,24 +76,26 @@ | |||
248 | 75 | QNetworkProxyFactory::setApplicationProxyFactory(proxyFactory); | 76 | QNetworkProxyFactory::setApplicationProxyFactory(proxyFactory); |
249 | 76 | 77 | ||
250 | 77 | Service *service = new Service(); | 78 | Service *service = new Service(); |
251 | 78 | if (daemonTimeout > 0) | ||
252 | 79 | service->setTimeout(daemonTimeout); | ||
253 | 80 | QDBusConnection connection = QDBusConnection::sessionBus(); | 79 | QDBusConnection connection = QDBusConnection::sessionBus(); |
254 | 81 | connection.registerService(QLatin1String(serviceName)); | 80 | connection.registerService(QLatin1String(serviceName)); |
255 | 82 | connection.registerObject(QLatin1String(objectPath), | 81 | connection.registerObject(QLatin1String(objectPath), |
256 | 83 | service, | 82 | service, |
257 | 84 | QDBusConnection::ExportAllContents); | 83 | QDBusConnection::ExportAllContents); |
258 | 85 | /* FIXME: before quitting we should check if the IndicatorService is idle | ||
259 | 86 | * too. However, since this feature is used for unit tests only, for the | ||
260 | 87 | * time being this is fine. | ||
261 | 88 | */ | ||
262 | 89 | QObject::connect(service, SIGNAL(idleTimeout()), &app, SLOT(quit())); | ||
263 | 90 | 84 | ||
264 | 91 | IndicatorService *indicatorService = new IndicatorService(); | 85 | IndicatorService *indicatorService = new IndicatorService(); |
265 | 92 | connection.registerService(QLatin1String(WEBCREDENTIALS_BUS_NAME)); | 86 | connection.registerService(QLatin1String(WEBCREDENTIALS_BUS_NAME)); |
266 | 93 | connection.registerObject(QLatin1String(WEBCREDENTIALS_OBJECT_PATH), | 87 | connection.registerObject(QLatin1String(WEBCREDENTIALS_OBJECT_PATH), |
267 | 94 | indicatorService->serviceObject()); | 88 | indicatorService->serviceObject()); |
268 | 95 | 89 | ||
269 | 90 | InactivityTimer *inactivityTimer = 0; | ||
270 | 91 | if (daemonTimeout > 0) { | ||
271 | 92 | inactivityTimer = new InactivityTimer(daemonTimeout * 1000); | ||
272 | 93 | inactivityTimer->watchObject(service); | ||
273 | 94 | inactivityTimer->watchObject(indicatorService); | ||
274 | 95 | QObject::connect(inactivityTimer, SIGNAL(timeout()), | ||
275 | 96 | &app, SLOT(quit())); | ||
276 | 97 | } | ||
277 | 98 | |||
278 | 96 | int ret = app.exec(); | 99 | int ret = app.exec(); |
279 | 97 | 100 | ||
280 | 98 | connection.unregisterService(QLatin1String(WEBCREDENTIALS_BUS_NAME)); | 101 | connection.unregisterService(QLatin1String(WEBCREDENTIALS_BUS_NAME)); |
281 | @@ -103,6 +106,8 @@ | |||
282 | 103 | connection.unregisterObject(QLatin1String(objectPath)); | 106 | connection.unregisterObject(QLatin1String(objectPath)); |
283 | 104 | delete service; | 107 | delete service; |
284 | 105 | 108 | ||
285 | 109 | delete inactivityTimer; | ||
286 | 110 | |||
287 | 106 | return ret; | 111 | return ret; |
288 | 107 | } | 112 | } |
289 | 108 | 113 | ||
290 | 109 | 114 | ||
291 | === modified file 'src/service.cpp' | |||
292 | --- src/service.cpp 2012-04-03 11:46:12 +0000 | |||
293 | +++ src/service.cpp 2013-03-14 13:21:22 +0000 | |||
294 | @@ -23,7 +23,6 @@ | |||
295 | 23 | #include "debug.h" | 23 | #include "debug.h" |
296 | 24 | #include "request.h" | 24 | #include "request.h" |
297 | 25 | 25 | ||
298 | 26 | #include <QTimer> | ||
299 | 27 | #include <QQueue> | 26 | #include <QQueue> |
300 | 28 | 27 | ||
301 | 29 | using namespace SignOnUi; | 28 | using namespace SignOnUi; |
302 | @@ -41,24 +40,16 @@ | |||
303 | 41 | ServicePrivate(Service *service); | 40 | ServicePrivate(Service *service); |
304 | 42 | ~ServicePrivate(); | 41 | ~ServicePrivate(); |
305 | 43 | 42 | ||
306 | 44 | void setTimeout(int timeout); | ||
307 | 45 | |||
308 | 46 | RequestQueue &queueForWindowId(WId windowId); | 43 | RequestQueue &queueForWindowId(WId windowId); |
309 | 47 | void enqueue(Request *request); | 44 | void enqueue(Request *request); |
310 | 48 | void runQueue(RequestQueue &queue); | 45 | void runQueue(RequestQueue &queue); |
311 | 49 | void cancelUiRequest(const QString &requestId); | 46 | void cancelUiRequest(const QString &requestId); |
312 | 50 | 47 | ||
313 | 51 | private: | ||
314 | 52 | void resetTimer(); | ||
315 | 53 | |||
316 | 54 | private Q_SLOTS: | 48 | private Q_SLOTS: |
317 | 55 | void onRequestCompleted(); | 49 | void onRequestCompleted(); |
318 | 56 | void onTimeout(); | ||
319 | 57 | 50 | ||
320 | 58 | private: | 51 | private: |
321 | 59 | mutable Service *q_ptr; | 52 | mutable Service *q_ptr; |
322 | 60 | QTimer m_timer; | ||
323 | 61 | int m_timeout; | ||
324 | 62 | /* each window Id has a different queue */ | 53 | /* each window Id has a different queue */ |
325 | 63 | QMap<WId,RequestQueue> m_requests; | 54 | QMap<WId,RequestQueue> m_requests; |
326 | 64 | }; | 55 | }; |
327 | @@ -67,41 +58,14 @@ | |||
328 | 67 | 58 | ||
329 | 68 | ServicePrivate::ServicePrivate(Service *service): | 59 | ServicePrivate::ServicePrivate(Service *service): |
330 | 69 | QObject(service), | 60 | QObject(service), |
333 | 70 | q_ptr(service), | 61 | q_ptr(service) |
332 | 71 | m_timeout(0) | ||
334 | 72 | { | 62 | { |
335 | 73 | m_timer.setSingleShot(true); | ||
336 | 74 | QObject::connect(&m_timer, SIGNAL(timeout()), | ||
337 | 75 | this, SLOT(onTimeout())); | ||
338 | 76 | } | 63 | } |
339 | 77 | 64 | ||
340 | 78 | ServicePrivate::~ServicePrivate() | 65 | ServicePrivate::~ServicePrivate() |
341 | 79 | { | 66 | { |
342 | 80 | } | 67 | } |
343 | 81 | 68 | ||
344 | 82 | void ServicePrivate::setTimeout(int timeout) | ||
345 | 83 | { | ||
346 | 84 | m_timeout = timeout * 1000; | ||
347 | 85 | resetTimer(); | ||
348 | 86 | } | ||
349 | 87 | |||
350 | 88 | void ServicePrivate::resetTimer() | ||
351 | 89 | { | ||
352 | 90 | m_timer.stop(); | ||
353 | 91 | if (m_timeout > 0) { | ||
354 | 92 | m_timer.start(m_timeout); | ||
355 | 93 | } | ||
356 | 94 | } | ||
357 | 95 | |||
358 | 96 | void ServicePrivate::onTimeout() | ||
359 | 97 | { | ||
360 | 98 | Q_Q(Service); | ||
361 | 99 | |||
362 | 100 | if (m_requests.isEmpty()) { | ||
363 | 101 | Q_EMIT q->idleTimeout(); | ||
364 | 102 | } | ||
365 | 103 | } | ||
366 | 104 | |||
367 | 105 | RequestQueue &ServicePrivate::queueForWindowId(WId windowId) | 69 | RequestQueue &ServicePrivate::queueForWindowId(WId windowId) |
368 | 106 | { | 70 | { |
369 | 107 | if (!m_requests.contains(windowId)) { | 71 | if (!m_requests.contains(windowId)) { |
370 | @@ -113,13 +77,18 @@ | |||
371 | 113 | 77 | ||
372 | 114 | void ServicePrivate::enqueue(Request *request) | 78 | void ServicePrivate::enqueue(Request *request) |
373 | 115 | { | 79 | { |
375 | 116 | resetTimer(); | 80 | Q_Q(Service); |
376 | 81 | bool wasIdle = q->isIdle(); | ||
377 | 117 | 82 | ||
378 | 118 | WId windowId = request->windowId(); | 83 | WId windowId = request->windowId(); |
379 | 119 | 84 | ||
380 | 120 | RequestQueue &queue = queueForWindowId(windowId); | 85 | RequestQueue &queue = queueForWindowId(windowId); |
381 | 121 | queue.enqueue(request); | 86 | queue.enqueue(request); |
382 | 122 | 87 | ||
383 | 88 | if (wasIdle) { | ||
384 | 89 | Q_EMIT q->isIdleChanged(); | ||
385 | 90 | } | ||
386 | 91 | |||
387 | 123 | runQueue(queue); | 92 | runQueue(queue); |
388 | 124 | } | 93 | } |
389 | 125 | 94 | ||
390 | @@ -140,7 +109,7 @@ | |||
391 | 140 | 109 | ||
392 | 141 | void ServicePrivate::onRequestCompleted() | 110 | void ServicePrivate::onRequestCompleted() |
393 | 142 | { | 111 | { |
395 | 143 | resetTimer(); | 112 | Q_Q(Service); |
396 | 144 | 113 | ||
397 | 145 | Request *request = qobject_cast<Request*>(sender()); | 114 | Request *request = qobject_cast<Request*>(sender()); |
398 | 146 | WId windowId = request->windowId(); | 115 | WId windowId = request->windowId(); |
399 | @@ -160,6 +129,10 @@ | |||
400 | 160 | /* start the next request */ | 129 | /* start the next request */ |
401 | 161 | runQueue(queue); | 130 | runQueue(queue); |
402 | 162 | } | 131 | } |
403 | 132 | |||
404 | 133 | if (q->isIdle()) { | ||
405 | 134 | Q_EMIT q->isIdleChanged(); | ||
406 | 135 | } | ||
407 | 163 | } | 136 | } |
408 | 164 | 137 | ||
409 | 165 | void ServicePrivate::cancelUiRequest(const QString &requestId) | 138 | void ServicePrivate::cancelUiRequest(const QString &requestId) |
410 | @@ -193,10 +166,10 @@ | |||
411 | 193 | { | 166 | { |
412 | 194 | } | 167 | } |
413 | 195 | 168 | ||
415 | 196 | void Service::setTimeout(int timeout) | 169 | bool Service::isIdle() const |
416 | 197 | { | 170 | { |
419 | 198 | Q_D(Service); | 171 | Q_D(const Service); |
420 | 199 | d->setTimeout(timeout); | 172 | return d->m_requests.isEmpty(); |
421 | 200 | } | 173 | } |
422 | 201 | 174 | ||
423 | 202 | QVariantMap Service::queryDialog(const QVariantMap ¶meters) | 175 | QVariantMap Service::queryDialog(const QVariantMap ¶meters) |
424 | 203 | 176 | ||
425 | === modified file 'src/service.h' | |||
426 | --- src/service.h 2012-04-03 11:46:12 +0000 | |||
427 | +++ src/service.h 2013-03-14 13:21:22 +0000 | |||
428 | @@ -32,13 +32,14 @@ | |||
429 | 32 | class Service: public QObject, protected QDBusContext | 32 | class Service: public QObject, protected QDBusContext |
430 | 33 | { | 33 | { |
431 | 34 | Q_OBJECT | 34 | Q_OBJECT |
432 | 35 | Q_PROPERTY(bool isIdle READ isIdle NOTIFY isIdleChanged) | ||
433 | 35 | Q_CLASSINFO("D-Bus Interface", "com.nokia.singlesignonui") | 36 | Q_CLASSINFO("D-Bus Interface", "com.nokia.singlesignonui") |
434 | 36 | 37 | ||
435 | 37 | public: | 38 | public: |
436 | 38 | explicit Service(QObject *parent = 0); | 39 | explicit Service(QObject *parent = 0); |
437 | 39 | ~Service(); | 40 | ~Service(); |
438 | 40 | 41 | ||
440 | 41 | void setTimeout(int timeout); | 42 | bool isIdle() const; |
441 | 42 | 43 | ||
442 | 43 | public Q_SLOTS: | 44 | public Q_SLOTS: |
443 | 44 | QVariantMap queryDialog(const QVariantMap ¶meters); | 45 | QVariantMap queryDialog(const QVariantMap ¶meters); |
444 | @@ -46,7 +47,7 @@ | |||
445 | 46 | Q_NOREPLY void cancelUiRequest(const QString &requestId); | 47 | Q_NOREPLY void cancelUiRequest(const QString &requestId); |
446 | 47 | 48 | ||
447 | 48 | Q_SIGNALS: | 49 | Q_SIGNALS: |
449 | 49 | void idleTimeout(); | 50 | void isIdleChanged(); |
450 | 50 | 51 | ||
451 | 51 | private: | 52 | private: |
452 | 52 | ServicePrivate *d_ptr; | 53 | ServicePrivate *d_ptr; |
453 | 53 | 54 | ||
454 | === modified file 'src/src.pro' | |||
455 | --- src/src.pro 2013-01-23 07:48:35 +0000 | |||
456 | +++ src/src.pro 2013-03-14 13:21:22 +0000 | |||
457 | @@ -34,6 +34,7 @@ | |||
458 | 34 | dialog.h \ | 34 | dialog.h \ |
459 | 35 | errors.h \ | 35 | errors.h \ |
460 | 36 | i18n.h \ | 36 | i18n.h \ |
461 | 37 | inactivity-timer.h \ | ||
462 | 37 | indicator-service.h \ | 38 | indicator-service.h \ |
463 | 38 | network-access-manager.h \ | 39 | network-access-manager.h \ |
464 | 39 | reauthenticator.h \ | 40 | reauthenticator.h \ |
465 | @@ -49,6 +50,7 @@ | |||
466 | 49 | dialog-request.cpp \ | 50 | dialog-request.cpp \ |
467 | 50 | dialog.cpp \ | 51 | dialog.cpp \ |
468 | 51 | i18n.cpp \ | 52 | i18n.cpp \ |
469 | 53 | inactivity-timer.cpp \ | ||
470 | 52 | indicator-service.cpp \ | 54 | indicator-service.cpp \ |
471 | 53 | main.cpp \ | 55 | main.cpp \ |
472 | 54 | my-network-proxy-factory.cpp \ | 56 | my-network-proxy-factory.cpp \ |
473 | 55 | 57 | ||
474 | === added file 'tests/unit/tst_inactivity_timer.cpp' | |||
475 | --- tests/unit/tst_inactivity_timer.cpp 1970-01-01 00:00:00 +0000 | |||
476 | +++ tests/unit/tst_inactivity_timer.cpp 2013-03-14 13:21:22 +0000 | |||
477 | @@ -0,0 +1,143 @@ | |||
478 | 1 | /* | ||
479 | 2 | * This file is part of signon-ui | ||
480 | 3 | * | ||
481 | 4 | * Copyright (C) 2013 Canonical Ltd. | ||
482 | 5 | * | ||
483 | 6 | * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> | ||
484 | 7 | * | ||
485 | 8 | * This program is free software: you can redistribute it and/or modify it | ||
486 | 9 | * under the terms of the GNU General Public License version 3, as published | ||
487 | 10 | * by the Free Software Foundation. | ||
488 | 11 | * | ||
489 | 12 | * This program is distributed in the hope that it will be useful, but | ||
490 | 13 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
491 | 14 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
492 | 15 | * PURPOSE. See the GNU General Public License for more details. | ||
493 | 16 | * | ||
494 | 17 | * You should have received a copy of the GNU General Public License along | ||
495 | 18 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
496 | 19 | */ | ||
497 | 20 | |||
498 | 21 | #include "debug.h" | ||
499 | 22 | #include "inactivity-timer.h" | ||
500 | 23 | |||
501 | 24 | #include <QDebug> | ||
502 | 25 | #include <QObject> | ||
503 | 26 | #include <QSignalSpy> | ||
504 | 27 | #include <QTest> | ||
505 | 28 | |||
506 | 29 | using namespace SignOnUi; | ||
507 | 30 | |||
508 | 31 | class InactivityTest: public QObject | ||
509 | 32 | { | ||
510 | 33 | Q_OBJECT | ||
511 | 34 | |||
512 | 35 | public: | ||
513 | 36 | InactivityTest() {}; | ||
514 | 37 | |||
515 | 38 | private Q_SLOTS: | ||
516 | 39 | void testAlwaysIdle(); | ||
517 | 40 | void testIdleThenBusy(); | ||
518 | 41 | void testStartBusy(); | ||
519 | 42 | }; | ||
520 | 43 | |||
521 | 44 | class TestObject: public QObject | ||
522 | 45 | { | ||
523 | 46 | Q_OBJECT | ||
524 | 47 | Q_PROPERTY(bool isIdle READ isIdle NOTIFY isIdleChanged) | ||
525 | 48 | |||
526 | 49 | public: | ||
527 | 50 | TestObject(): QObject(0), m_isIdle(false) {} | ||
528 | 51 | ~TestObject() {} | ||
529 | 52 | |||
530 | 53 | bool isIdle() const { return m_isIdle; } | ||
531 | 54 | void setIdle(bool idle) { | ||
532 | 55 | if (idle == m_isIdle) return; | ||
533 | 56 | m_isIdle = idle; | ||
534 | 57 | Q_EMIT isIdleChanged(); | ||
535 | 58 | } | ||
536 | 59 | |||
537 | 60 | Q_SIGNALS: | ||
538 | 61 | void isIdleChanged(); | ||
539 | 62 | |||
540 | 63 | private: | ||
541 | 64 | bool m_isIdle; | ||
542 | 65 | }; | ||
543 | 66 | |||
544 | 67 | void InactivityTest::testAlwaysIdle() | ||
545 | 68 | { | ||
546 | 69 | InactivityTimer inactivityTimer(100); | ||
547 | 70 | QSignalSpy timeout(&inactivityTimer, SIGNAL(timeout())); | ||
548 | 71 | |||
549 | 72 | TestObject object1; | ||
550 | 73 | object1.setIdle(true); | ||
551 | 74 | inactivityTimer.watchObject(&object1); | ||
552 | 75 | |||
553 | 76 | TestObject object2; | ||
554 | 77 | object2.setIdle(true); | ||
555 | 78 | inactivityTimer.watchObject(&object2); | ||
556 | 79 | |||
557 | 80 | QCOMPARE(timeout.count(), 0); | ||
558 | 81 | QTest::qWait(150); | ||
559 | 82 | QCOMPARE(timeout.count(), 1); | ||
560 | 83 | } | ||
561 | 84 | |||
562 | 85 | void InactivityTest::testIdleThenBusy() | ||
563 | 86 | { | ||
564 | 87 | InactivityTimer inactivityTimer(100); | ||
565 | 88 | QSignalSpy timeout(&inactivityTimer, SIGNAL(timeout())); | ||
566 | 89 | |||
567 | 90 | TestObject object1; | ||
568 | 91 | object1.setIdle(true); | ||
569 | 92 | inactivityTimer.watchObject(&object1); | ||
570 | 93 | |||
571 | 94 | TestObject object2; | ||
572 | 95 | object2.setIdle(true); | ||
573 | 96 | inactivityTimer.watchObject(&object2); | ||
574 | 97 | |||
575 | 98 | QCOMPARE(timeout.count(), 0); | ||
576 | 99 | |||
577 | 100 | QTest::qWait(30); | ||
578 | 101 | QCOMPARE(timeout.count(), 0); | ||
579 | 102 | object2.setIdle(false); | ||
580 | 103 | |||
581 | 104 | QTest::qWait(100); | ||
582 | 105 | QCOMPARE(timeout.count(), 0); | ||
583 | 106 | object2.setIdle(true); | ||
584 | 107 | QTest::qWait(30); | ||
585 | 108 | QCOMPARE(timeout.count(), 0); | ||
586 | 109 | |||
587 | 110 | QTest::qWait(100); | ||
588 | 111 | QCOMPARE(timeout.count(), 1); | ||
589 | 112 | } | ||
590 | 113 | |||
591 | 114 | void InactivityTest::testStartBusy() | ||
592 | 115 | { | ||
593 | 116 | InactivityTimer inactivityTimer(100); | ||
594 | 117 | QSignalSpy timeout(&inactivityTimer, SIGNAL(timeout())); | ||
595 | 118 | |||
596 | 119 | TestObject object1; | ||
597 | 120 | inactivityTimer.watchObject(&object1); | ||
598 | 121 | |||
599 | 122 | TestObject object2; | ||
600 | 123 | inactivityTimer.watchObject(&object2); | ||
601 | 124 | |||
602 | 125 | QCOMPARE(timeout.count(), 0); | ||
603 | 126 | |||
604 | 127 | QTest::qWait(130); | ||
605 | 128 | QCOMPARE(timeout.count(), 0); | ||
606 | 129 | object2.setIdle(true); | ||
607 | 130 | |||
608 | 131 | QTest::qWait(130); | ||
609 | 132 | QCOMPARE(timeout.count(), 0); | ||
610 | 133 | object1.setIdle(true); | ||
611 | 134 | |||
612 | 135 | QTest::qWait(30); | ||
613 | 136 | QCOMPARE(timeout.count(), 0); | ||
614 | 137 | |||
615 | 138 | QTest::qWait(100); | ||
616 | 139 | QCOMPARE(timeout.count(), 1); | ||
617 | 140 | } | ||
618 | 141 | |||
619 | 142 | QTEST_MAIN(InactivityTest); | ||
620 | 143 | #include "tst_inactivity_timer.moc" | ||
621 | 0 | 144 | ||
622 | === added file 'tests/unit/tst_inactivity_timer.pro' | |||
623 | --- tests/unit/tst_inactivity_timer.pro 1970-01-01 00:00:00 +0000 | |||
624 | +++ tests/unit/tst_inactivity_timer.pro 2013-03-14 13:21:22 +0000 | |||
625 | @@ -0,0 +1,37 @@ | |||
626 | 1 | include(../../common-project-config.pri) | ||
627 | 2 | include($${TOP_SRC_DIR}/common-vars.pri) | ||
628 | 3 | include($${TOP_SRC_DIR}/common-installs-config.pri) | ||
629 | 4 | |||
630 | 5 | TARGET = tst_inactivity_timer | ||
631 | 6 | |||
632 | 7 | CONFIG += \ | ||
633 | 8 | build_all \ | ||
634 | 9 | debug \ | ||
635 | 10 | qtestlib | ||
636 | 11 | |||
637 | 12 | QT += \ | ||
638 | 13 | core | ||
639 | 14 | |||
640 | 15 | SOURCES += \ | ||
641 | 16 | tst_inactivity_timer.cpp \ | ||
642 | 17 | $$TOP_SRC_DIR/src/debug.cpp \ | ||
643 | 18 | $$TOP_SRC_DIR/src/inactivity-timer.cpp | ||
644 | 19 | HEADERS += \ | ||
645 | 20 | $$TOP_SRC_DIR/src/debug.h \ | ||
646 | 21 | $$TOP_SRC_DIR/src/inactivity-timer.h | ||
647 | 22 | |||
648 | 23 | INCLUDEPATH += \ | ||
649 | 24 | . \ | ||
650 | 25 | $$TOP_SRC_DIR/src | ||
651 | 26 | |||
652 | 27 | QMAKE_CXXFLAGS += \ | ||
653 | 28 | -fno-exceptions \ | ||
654 | 29 | -fno-rtti | ||
655 | 30 | |||
656 | 31 | DEFINES += \ | ||
657 | 32 | DEBUG_ENABLED \ | ||
658 | 33 | UNIT_TESTS | ||
659 | 34 | |||
660 | 35 | check.commands = "xvfb-run -a ./$$TARGET" | ||
661 | 36 | check.depends = $$TARGET | ||
662 | 37 | QMAKE_EXTRA_TARGETS += check | ||
663 | 0 | 38 | ||
664 | === renamed file 'tests/unit/unit.pro' => 'tests/unit/tst_signon_ui.pro' | |||
665 | === added file 'tests/unit/unit.pro' | |||
666 | --- tests/unit/unit.pro 1970-01-01 00:00:00 +0000 | |||
667 | +++ tests/unit/unit.pro 2013-03-14 13:21:22 +0000 | |||
668 | @@ -0,0 +1,4 @@ | |||
669 | 1 | TEMPLATE = subdirs | ||
670 | 2 | SUBDIRS = \ | ||
671 | 3 | tst_inactivity_timer.pro \ | ||
672 | 4 | tst_signon_ui.pro |
FAILED: Continuous integration, rev:78 s-jenkins: 8080/job/ signon- ui-ci/14/ s-jenkins: 8080/job/ signon- ui-ci/. /build= pbuilder, distribution= raring, flavor= amd64/14/ console s-jenkins: 8080/job/ signon- ui-ci/. /build= pbuilder, distribution= raring, flavor= i386/14/ console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins: 8080/job/ signon- ui-ci/14/ rebuild
http://