Merge lp:~mardy/ubuntu-system-settings-online-accounts/request-by-service into lp:ubuntu-system-settings-online-accounts

Proposed by Alberto Mardegan
Status: Merged
Approved by: David Barth
Approved revision: 283
Merged at revision: 290
Proposed branch: lp:~mardy/ubuntu-system-settings-online-accounts/request-by-service
Merge into: lp:ubuntu-system-settings-online-accounts
Diff against target: 1016 lines (+596/-25)
28 files modified
.bzrignore (+1/-0)
.qmake.conf (+2/-0)
client/OnlineAccountsClient/setup.cpp (+37/-2)
client/OnlineAccountsClient/setup.h (+11/-0)
client/module/module.pro (+3/-9)
client/module/plugin.cpp (+1/-0)
common-project-config.pri (+4/-2)
common-vars.pri (+1/-1)
coverage.pri (+0/-1)
debian/changelog (+9/-0)
online-accounts-service/request.cpp (+21/-1)
online-accounts-ui/globals.h (+3/-0)
online-accounts-ui/provider-request.cpp (+15/-1)
online-accounts-ui/request.cpp (+2/-7)
tests/client/tst_qml_client.cpp (+58/-1)
tests/online-accounts-service/tst_service.pro (+2/-0)
tests/online-accounts-service/tst_signonui_service.pro (+1/-0)
tests/online-accounts-ui/ProviderRequest.qml (+28/-0)
tests/online-accounts-ui/mock/application-manager-mock.cpp (+71/-0)
tests/online-accounts-ui/mock/application-manager-mock.h (+61/-0)
tests/online-accounts-ui/mock/request-mock.cpp (+13/-0)
tests/online-accounts-ui/mock/request-mock.h (+1/-0)
tests/online-accounts-ui/online-accounts-ui.pro (+1/-0)
tests/online-accounts-ui/qml/qml.pro (+1/-0)
tests/online-accounts-ui/qml/tst_online_accounts_qml.cpp (+2/-0)
tests/online-accounts-ui/tst_provider_request.cpp (+190/-0)
tests/online-accounts-ui/tst_provider_request.pro (+52/-0)
tests/online-accounts-ui/tst_provider_request.qrc (+5/-0)
To merge this branch: bzr merge lp:~mardy/ubuntu-system-settings-online-accounts/request-by-service
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Alexandre Abreu (community) Approve
Review via email: mp+262720@code.launchpad.net

Commit message

Create version 0.2 of the Ubuntu.OnlineAccounts.Client module

Add a new "serviceId" property to the Ubuntu.OnlineAccounts.Client Setup class. Fix shadow builds.

Description of the change

Create version 0.2 of the Ubuntu.OnlineAccounts.Client module

Add a new "serviceId" property to the Ubuntu.OnlineAccounts.Client Setup class, which will be used also by the V2 daemon. Fix shadow builds.

To post a comment you must log in.
Revision history for this message
Alexandre Abreu (abreu-alexandre) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
278. By Alberto Mardegan

fix tests in pbuilder

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
279. By Alberto Mardegan

Fix missing provider ID

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
280. By Alberto Mardegan

Add API to forward client pid

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
281. By Alberto Mardegan

Allow unconfined clients to override requestor PID

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
282. By Alberto Mardegan

fix copypaste

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
283. By Alberto Mardegan

from trunk

* Resync trunk.
* No-change test rebuild for g++5 ABI transition
[ Andreas Pokorny ]
* rebuild for libmirclient9 part of mir release 0.14.0 - removes
  architecture restrictions imposed by previous mir releases.
[ CI Train Bot ]
* Resync trunk. added: po/cy.po
[ Alberto Mardegan ]
* Inject the APP_ID into the child process's environment. (LP:
  #1468792)
[ CI Train Bot ]
* New rebuild forced.
* Resync trunk.
[ Alberto Mardegan ]
* Fix build with Qt 5.5 (LP: #1387537, #1421009, #1448878, #1447175)
* Return the error name to the client (LP: #1441873)
[ CI Train Bot ]
* New rebuild forced.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2015-02-02 15:21:40 +0000
3+++ .bzrignore 2015-08-06 12:32:34 +0000
4@@ -55,6 +55,7 @@
5 /tests/online-accounts-ui/tst_access_model
6 /tests/online-accounts-ui/tst_browser_request
7 /tests/online-accounts-ui/tst_notification
8+/tests/online-accounts-ui/tst_provider_request
9 /tests/online-accounts-ui/tst_signonui_request
10 /tests/plugin/tst_application_manager
11 /tests/system-settings-plugin/tst_plugin
12
13=== added file '.qmake.conf'
14--- .qmake.conf 1970-01-01 00:00:00 +0000
15+++ .qmake.conf 2015-08-06 12:32:34 +0000
16@@ -0,0 +1,2 @@
17+TOP_SRC_DIR = $$PWD
18+TOP_BUILD_DIR = $$shadowed($$PWD)
19
20=== modified file 'client/OnlineAccountsClient/setup.cpp'
21--- client/OnlineAccountsClient/setup.cpp 2015-05-12 12:56:03 +0000
22+++ client/OnlineAccountsClient/setup.cpp 2015-08-06 12:32:34 +0000
23@@ -30,7 +30,6 @@
24 #include <QGuiApplication>
25 #include <QWindow>
26 #include <climits>
27-#include <unistd.h>
28
29 using namespace OnlineAccountsClient;
30 using namespace com::ubuntu;
31@@ -55,8 +54,10 @@
32 private:
33 OnlineAccountsUi m_onlineAccountsUi;
34 QString m_applicationId;
35+ QString m_serviceId;
36 QString m_serviceTypeId;
37 QString m_providerId;
38+ pid_t m_clientPid;
39 mutable Setup *q_ptr;
40 };
41
42@@ -67,6 +68,7 @@
43 m_onlineAccountsUi(OAU_SERVICE_NAME,
44 OAU_OBJECT_PATH,
45 QDBusConnection::sessionBus()),
46+ m_clientPid(0),
47 q_ptr(setup)
48 {
49 m_onlineAccountsUi.setTimeout(INT_MAX);
50@@ -76,7 +78,8 @@
51 {
52 QVariantMap options;
53
54- options.insert(OAU_KEY_PID, uint(getpid()));
55+ options.insert(OAU_KEY_PID,
56+ uint(m_clientPid != 0 ? m_clientPid : getpid()));
57
58 QWindow *window = clientWindow();
59 if (window) {
60@@ -95,6 +98,10 @@
61 options.insert(OAU_KEY_APPLICATION, m_applicationId);
62 }
63
64+ if (!m_serviceId.isEmpty()) {
65+ options.insert(OAU_KEY_SERVICE_ID, m_serviceId);
66+ }
67+
68 if (!m_serviceTypeId.isEmpty()) {
69 options.insert(OAU_KEY_SERVICE_TYPE, m_serviceTypeId);
70 }
71@@ -214,6 +221,25 @@
72 }
73
74 /*!
75+ * \qmlproperty string Setup::serviceId
76+ * If set to a valid service ID, the user will be asked to create an Online
77+ * Account which provides this service.
78+ */
79+void Setup::setServiceId(const QString &serviceId)
80+{
81+ Q_D(Setup);
82+ if (serviceId == d->m_serviceId) return;
83+ d->m_serviceId = serviceId;
84+ Q_EMIT serviceIdChanged();
85+}
86+
87+QString Setup::serviceId() const
88+{
89+ Q_D(const Setup);
90+ return d->m_serviceId;
91+}
92+
93+/*!
94 * \qmlproperty string Setup::serviceTypeId
95 * If set to a valid service type, the user will be asked to create an Online
96 * Account which supports this service type.
97@@ -251,6 +277,15 @@
98 return d->m_providerId;
99 }
100
101+/* At the moment this method is meant to be used by unconfined services, when
102+ * forwarding a request from their client.
103+ */
104+void Setup::setClientPid(pid_t clientPid)
105+{
106+ Q_D(Setup);
107+ d->m_clientPid = clientPid;
108+}
109+
110 /*!
111 * \qmlmethod void Setup::exec()
112 * Launches the Online Accounts panel.
113
114=== modified file 'client/OnlineAccountsClient/setup.h'
115--- client/OnlineAccountsClient/setup.h 2014-09-15 12:16:50 +0000
116+++ client/OnlineAccountsClient/setup.h 2015-08-06 12:32:34 +0000
117@@ -26,6 +26,8 @@
118 #include "global.h"
119 #include <QObject>
120 #include <QVariantMap>
121+#include <sys/types.h>
122+#include <unistd.h>
123
124 namespace OnlineAccountsClient {
125
126@@ -35,6 +37,8 @@
127 Q_OBJECT
128 Q_PROPERTY(QString applicationId READ applicationId \
129 WRITE setApplicationId NOTIFY applicationIdChanged)
130+ Q_PROPERTY(QString serviceId READ serviceId \
131+ WRITE setServiceId NOTIFY serviceIdChanged REVISION 2)
132 Q_PROPERTY(QString serviceTypeId READ serviceTypeId \
133 WRITE setServiceTypeId NOTIFY serviceTypeIdChanged)
134 Q_PROPERTY(QString providerId READ providerId \
135@@ -47,16 +51,23 @@
136 void setApplicationId(const QString &applicationId);
137 QString applicationId() const;
138
139+ void setServiceId(const QString &serviceId);
140+ QString serviceId() const;
141+
142 void setServiceTypeId(const QString &serviceTypeId);
143 QString serviceTypeId() const;
144
145 void setProviderId(const QString &providerId);
146 QString providerId() const;
147
148+ // Intentionally not exposed to QML; see the source code for the reason
149+ void setClientPid(pid_t clientPid);
150+
151 Q_INVOKABLE void exec();
152
153 Q_SIGNALS:
154 void applicationIdChanged();
155+ Q_REVISION(2) void serviceIdChanged();
156 void serviceTypeIdChanged();
157 void providerIdChanged();
158 void finished(QVariantMap reply);
159
160=== modified file 'client/module/module.pro'
161--- client/module/module.pro 2013-08-07 13:30:41 +0000
162+++ client/module/module.pro 2015-08-06 12:32:34 +0000
163@@ -5,9 +5,9 @@
164 TARGET = OnlineAccountsClient
165
166 API_URI = "Ubuntu.OnlineAccounts.Client"
167-API_VER = 0.1
168+API_VER = 0.2
169
170-DESTDIR = $$replace(API_URI, \\., /).$$API_VER
171+DESTDIR = $$replace(API_URI, \\., /)
172 PLUGIN_INSTALL_BASE = $$[QT_INSTALL_QML]/$${DESTDIR}
173
174 CONFIG += \
175@@ -34,13 +34,7 @@
176 QMAKE_SUBSTITUTES += qmldir.in
177 OTHER_FILES += qmldir.in
178
179-copy2build.output = $${DESTDIR}/${QMAKE_FILE_IN}
180-copy2build.input = QMLDIR_FILES
181-copy2build.commands = $$QMAKE_COPY ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT}
182-copy2build.name = COPY ${QMAKE_FILE_IN}
183-copy2build.variable_out = PRE_TARGETDEPS
184-copy2build.CONFIG += no_link
185-QMAKE_EXTRA_COMPILERS += copy2build
186+QMAKE_POST_LINK += $$QMAKE_COPY $${QMLDIR_FILES} $$DESTDIR
187
188 target.path = $${PLUGIN_INSTALL_BASE}
189 INSTALLS += target
190
191=== modified file 'client/module/plugin.cpp'
192--- client/module/plugin.cpp 2013-07-31 11:49:18 +0000
193+++ client/module/plugin.cpp 2015-08-06 12:32:34 +0000
194@@ -31,4 +31,5 @@
195 {
196 qDebug() << Q_FUNC_INFO << uri;
197 qmlRegisterType<Setup>(uri, 0, 1, "Setup");
198+ qmlRegisterType<Setup,2>(uri, 0, 2, "Setup");
199 }
200
201=== modified file 'common-project-config.pri'
202--- common-project-config.pri 2014-08-06 13:49:45 +0000
203+++ common-project-config.pri 2015-08-06 12:32:34 +0000
204@@ -7,8 +7,10 @@
205 # Disable RTTI
206 QMAKE_CXXFLAGS += -fno-exceptions -fno-rtti
207
208-TOP_SRC_DIR = $$PWD
209-TOP_BUILD_DIR = $${TOP_SRC_DIR}/$(BUILD_DIR)
210+!defined(TOP_SRC_DIR, var) {
211+ TOP_SRC_DIR = $$PWD
212+ TOP_BUILD_DIR = $${TOP_SRC_DIR}/$(BUILD_DIR)
213+}
214
215 include(coverage.pri)
216
217
218=== modified file 'common-vars.pri'
219--- common-vars.pri 2015-01-13 13:59:48 +0000
220+++ common-vars.pri 2015-08-06 12:32:34 +0000
221@@ -13,6 +13,6 @@
222 # Project version
223 # remember to update debian/* files if you changes this
224 #-----------------------------------------------------------------------------
225-PROJECT_VERSION = 0.6
226+PROJECT_VERSION = 0.7
227
228 # End of File
229
230=== modified file 'coverage.pri'
231--- coverage.pri 2014-08-29 13:18:54 +0000
232+++ coverage.pri 2015-08-06 12:32:34 +0000
233@@ -2,7 +2,6 @@
234 CONFIG(coverage) {
235 OBJECTS_DIR =
236 MOC_DIR =
237- TOP_SRC_DIR = $$PWD
238
239 LIBS += -lgcov
240 QMAKE_CXXFLAGS += --coverage
241
242=== modified file 'debian/changelog'
243--- debian/changelog 2015-08-04 09:05:45 +0000
244+++ debian/changelog 2015-08-06 12:32:34 +0000
245@@ -1,3 +1,12 @@
246+ubuntu-system-settings-online-accounts (0.7-0ubuntu1) UNRELEASED; urgency=medium
247+
248+ * New release
249+ - Add new "serviceId" property to the Ubuntu.OnlineAccounts.Client Setup
250+ class.
251+ - Support shadow builds
252+
253+ -- Alberto Mardegan <alberto.mardegan@canonical.com> Tue, 23 Jun 2015 17:38:21 +0300
254+
255 ubuntu-system-settings-online-accounts (0.6+15.10.20150804-0ubuntu1) wily; urgency=medium
256
257 * Resync trunk.
258
259=== modified file 'online-accounts-service/request.cpp'
260--- online-accounts-service/request.cpp 2014-12-08 15:18:18 +0000
261+++ online-accounts-service/request.cpp 2015-08-06 12:32:34 +0000
262@@ -23,6 +23,8 @@
263 #include "request.h"
264 #include "utils.h"
265
266+#include <Accounts/Manager>
267+#include <Accounts/Service>
268 #include <SignOn/uisessiondata_priv.h>
269
270 using namespace OnlineAccountsUi;
271@@ -127,6 +129,13 @@
272 if (interface() == OAU_INTERFACE) {
273 return d->m_parameters.value(OAU_KEY_PID, 0).toUInt();
274 } else if (interface() == SIGNONUI_INTERFACE) {
275+ if (d->m_clientApparmorProfile == "unconfined") {
276+ QVariantMap clientData =
277+ d->m_parameters.value(SSOUI_KEY_CLIENT_DATA).toMap();
278+ if (clientData.contains("requestorPid")) {
279+ return clientData.value("requestorPid").toUInt();
280+ }
281+ }
282 return d->m_parameters.value(SSOUI_KEY_PID, 0).toUInt();
283 }
284
285@@ -166,7 +175,18 @@
286 {
287 Q_D(const Request);
288 if (interface() == OAU_INTERFACE) {
289- return d->m_parameters.value(OAU_KEY_PROVIDER, 0).toString();
290+ QString providerId =
291+ d->m_parameters.value(OAU_KEY_PROVIDER).toString();
292+ if (providerId.isEmpty() &&
293+ d->m_parameters.contains(OAU_KEY_SERVICE_ID)) {
294+ Accounts::Manager manager;
295+ QString serviceId = d->m_parameters[OAU_KEY_SERVICE_ID].toString();
296+ Accounts::Service service = manager.service(serviceId);
297+ if (service.isValid()) {
298+ providerId = service.provider();
299+ }
300+ }
301+ return providerId;
302 } else {
303 return QString();
304 }
305
306=== modified file 'online-accounts-ui/globals.h'
307--- online-accounts-ui/globals.h 2015-01-05 14:26:10 +0000
308+++ online-accounts-ui/globals.h 2015-08-06 12:32:34 +0000
309@@ -27,6 +27,7 @@
310
311 #define OAU_KEY_APPLICATION QStringLiteral("application")
312 #define OAU_KEY_PROVIDER QStringLiteral("provider")
313+#define OAU_KEY_SERVICE_ID QStringLiteral("serviceId")
314 #define OAU_KEY_SERVICE_TYPE QStringLiteral("serviceType")
315 #define OAU_KEY_WINDOW_ID QStringLiteral("windowId")
316 #define OAU_KEY_PID QStringLiteral("pid")
317@@ -40,6 +41,8 @@
318 QStringLiteral(OAU_ERROR_PREFIX "InvalidParameters")
319 #define OAU_ERROR_INVALID_APPLICATION \
320 QStringLiteral(OAU_ERROR_PREFIX "InvalidApplication")
321+#define OAU_ERROR_INVALID_SERVICE \
322+ QStringLiteral(OAU_ERROR_PREFIX "InvalidService")
323 #define OAU_ERROR_PROMPT_SESSION \
324 QStringLiteral(OAU_ERROR_PREFIX "NoPromptSession")
325
326
327=== modified file 'online-accounts-ui/provider-request.cpp'
328--- online-accounts-ui/provider-request.cpp 2014-11-26 14:16:20 +0000
329+++ online-accounts-ui/provider-request.cpp 2015-08-06 12:32:34 +0000
330@@ -23,6 +23,7 @@
331 #include "globals.h"
332 #include "provider-request.h"
333
334+#include <OnlineAccountsPlugin/account-manager.h>
335 #include <OnlineAccountsPlugin/application-manager.h>
336 #include <QQmlContext>
337 #include <QQmlEngine>
338@@ -97,7 +98,20 @@
339 return;
340 }
341
342- QString providerId = q->parameters().value(OAU_KEY_PROVIDER).toString();
343+ QString providerId;
344+ QString serviceId = q->parameters().value(OAU_KEY_SERVICE_ID).toString();
345+ if (!serviceId.isEmpty()) {
346+ Accounts::Service service =
347+ AccountManager::instance()->service(serviceId);
348+ if (Q_UNLIKELY(!service.isValid())) {
349+ q->fail(OAU_ERROR_INVALID_SERVICE,
350+ QString("Service %1 not found").arg(serviceId));
351+ return;
352+ }
353+ providerId = service.provider();
354+ } else {
355+ providerId = q->parameters().value(OAU_KEY_PROVIDER).toString();
356+ }
357 QVariantMap providerInfo = appManager->providerInfo(providerId);
358
359 m_view = new QQuickView;
360
361=== modified file 'online-accounts-ui/request.cpp'
362--- online-accounts-ui/request.cpp 2014-11-21 13:50:15 +0000
363+++ online-accounts-ui/request.cpp 2015-08-06 12:32:34 +0000
364@@ -135,13 +135,8 @@
365 * the @parameters argument to figure out which subclass is the most apt to
366 * handle the request. */
367 if (interface == OAU_INTERFACE) {
368- if (parameters.contains(OAU_KEY_PROVIDER)) {
369- return new ProviderRequest(interface, id, clientProfile,
370- parameters, parent);
371- } else {
372- return new PanelRequest(interface, id, clientProfile,
373- parameters, parent);
374- }
375+ return new ProviderRequest(interface, id, clientProfile,
376+ parameters, parent);
377 } else {
378 Q_ASSERT(interface == SIGNONUI_INTERFACE);
379 return SignOnUi::Request::newRequest(id, clientProfile,
380
381=== modified file 'tests/client/tst_qml_client.cpp'
382--- tests/client/tst_qml_client.cpp 2014-09-15 12:16:50 +0000
383+++ tests/client/tst_qml_client.cpp 2015-08-06 12:32:34 +0000
384@@ -63,6 +63,8 @@
385 void initTestCase();
386 void testLoadPlugin();
387 void testProperties();
388+ void testVersions_data();
389+ void testVersions();
390 void testExec();
391 void testExecWithServiceType();
392
393@@ -105,7 +107,7 @@
394 {
395 QQmlEngine engine;
396 QQmlComponent component(&engine);
397- component.setData("import Ubuntu.OnlineAccounts.Client 0.1\n"
398+ component.setData("import Ubuntu.OnlineAccounts.Client 0.2\n"
399 "Setup { providerId: \"hello\" }",
400 QUrl());
401 QObject *object = component.create();
402@@ -120,6 +122,60 @@
403 object->setProperty("serviceTypeId", QString("hi"));
404 QCOMPARE(object->property("serviceTypeId").toString(), QString("hi"));
405
406+ object->setProperty("serviceId", QString("bonjour"));
407+ QCOMPARE(object->property("serviceId").toString(), QString("bonjour"));
408+
409+ delete object;
410+}
411+
412+void SetupTest::testVersions_data()
413+{
414+ QTest::addColumn<QString>("qmlCode");
415+ QTest::addColumn<bool>("mustBuild");
416+
417+ QTest::newRow("0.1, regular") <<
418+ "import Ubuntu.OnlineAccounts.Client 0.1\n"
419+ "Setup {\n"
420+ " providerId: \"hello\"\n"
421+ " serviceTypeId: \"something\"\n"
422+ "}" <<
423+ true;
424+
425+ QTest::newRow("0.1, newer prop") <<
426+ "import Ubuntu.OnlineAccounts.Client 0.1\n"
427+ "Setup {\n"
428+ " providerId: \"hello\"\n"
429+ " serviceTypeId: \"something\"\n"
430+ " serviceId: \"wishful\"\n"
431+ "}" <<
432+ false;
433+
434+ QTest::newRow("0.2, newer prop") <<
435+ "import Ubuntu.OnlineAccounts.Client 0.2\n"
436+ "Setup {\n"
437+ " providerId: \"hello\"\n"
438+ " serviceTypeId: \"something\"\n"
439+ " serviceId: \"yes we can\"\n"
440+ "}" <<
441+ true;
442+}
443+
444+void SetupTest::testVersions()
445+{
446+ QFETCH(QString, qmlCode);
447+ QFETCH(bool, mustBuild);
448+
449+ if (!mustBuild) {
450+ QTest::ignoreMessage(QtWarningMsg,
451+ "QQmlComponent: Component is not ready");
452+ }
453+
454+ QQmlEngine engine;
455+ QQmlComponent component(&engine);
456+ component.setData(qmlCode.toUtf8(), QUrl());
457+ QObject *object = component.create();
458+ QCOMPARE(object != 0, mustBuild);
459+
460 delete object;
461 }
462
463@@ -139,6 +195,7 @@
464 QVERIFY(finished.wait());
465 QCOMPARE(options().contains(OAU_KEY_PROVIDER), false);
466 QCOMPARE(options().contains(OAU_KEY_SERVICE_TYPE), false);
467+ QCOMPARE(options().contains(OAU_KEY_SERVICE_ID), false);
468 }
469
470 void SetupTest::testExecWithServiceType()
471
472=== modified file 'tests/online-accounts-service/tst_service.pro'
473--- tests/online-accounts-service/tst_service.pro 2014-12-08 16:22:39 +0000
474+++ tests/online-accounts-service/tst_service.pro 2015-08-06 12:32:34 +0000
475@@ -12,6 +12,7 @@
476 testlib
477
478 PKGCONFIG += \
479+ accounts-qt5 \
480 signon-plugins-common
481
482 DEFINES += \
483@@ -37,6 +38,7 @@
484 $${ONLINE_ACCOUNTS_SERVICE_DIR}/utils.h \
485
486 INCLUDEPATH += \
487+ $${TOP_BUILD_DIR}/online-accounts-service \
488 $${ONLINE_ACCOUNTS_SERVICE_DIR} \
489 $${COMMON_SRC_DIR}
490
491
492=== modified file 'tests/online-accounts-service/tst_signonui_service.pro'
493--- tests/online-accounts-service/tst_signonui_service.pro 2014-12-08 16:22:39 +0000
494+++ tests/online-accounts-service/tst_signonui_service.pro 2015-08-06 12:32:34 +0000
495@@ -13,6 +13,7 @@
496 testlib
497
498 PKGCONFIG += \
499+ accounts-qt5 \
500 signon-plugins-common
501
502 DEFINES += \
503
504=== added file 'tests/online-accounts-ui/ProviderRequest.qml'
505--- tests/online-accounts-ui/ProviderRequest.qml 1970-01-01 00:00:00 +0000
506+++ tests/online-accounts-ui/ProviderRequest.qml 2015-08-06 12:32:34 +0000
507@@ -0,0 +1,28 @@
508+/*
509+ * Copyright (C) 2015 Canonical Ltd.
510+ *
511+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
512+ *
513+ * This program is free software: you can redistribute it and/or modify it
514+ * under the terms of the GNU General Public License version 3, as published
515+ * by the Free Software Foundation.
516+ *
517+ * This program is distributed in the hope that it will be useful, but
518+ * WITHOUT ANY WARRANTY; without even the implied warranties of
519+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
520+ * PURPOSE. See the GNU General Public License for more details.
521+ *
522+ * You should have received a copy of the GNU General Public License along
523+ * with this program. If not, see <http://www.gnu.org/licenses/>.
524+ */
525+
526+import QtQuick 2.0
527+
528+Item {
529+ id: root
530+
531+ property bool wasDenied: false
532+
533+ signal denied
534+ signal allowed(int accountId)
535+}
536
537=== added file 'tests/online-accounts-ui/mock/application-manager-mock.cpp'
538--- tests/online-accounts-ui/mock/application-manager-mock.cpp 1970-01-01 00:00:00 +0000
539+++ tests/online-accounts-ui/mock/application-manager-mock.cpp 2015-08-06 12:32:34 +0000
540@@ -0,0 +1,71 @@
541+/*
542+ * Copyright (C) 2014 Canonical Ltd.
543+ *
544+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
545+ *
546+ * This file is part of online-accounts-ui
547+ *
548+ * This program is free software: you can redistribute it and/or modify it
549+ * under the terms of the GNU General Public License version 3, as published
550+ * by the Free Software Foundation.
551+ *
552+ * This program is distributed in the hope that it will be useful, but
553+ * WITHOUT ANY WARRANTY; without even the implied warranties of
554+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
555+ * PURPOSE. See the GNU General Public License for more details.
556+ *
557+ * You should have received a copy of the GNU General Public License along
558+ * with this program. If not, see <http://www.gnu.org/licenses/>.
559+ */
560+
561+#include "application-manager-mock.h"
562+
563+#include <QDebug>
564+
565+using namespace OnlineAccountsUi;
566+
567+ApplicationManager *ApplicationManager::m_instance = 0;
568+
569+ApplicationManagerPrivate::ApplicationManagerPrivate(ApplicationManager *q):
570+ QObject(q),
571+ q_ptr(q)
572+{
573+}
574+
575+ApplicationManagerPrivate::~ApplicationManagerPrivate()
576+{
577+}
578+
579+ApplicationManager::ApplicationManager(QObject *parent):
580+ QObject(parent),
581+ d_ptr(new ApplicationManagerPrivate(this))
582+{
583+ m_instance = this;
584+}
585+
586+ApplicationManager::~ApplicationManager()
587+{
588+ m_instance = 0;
589+}
590+
591+ApplicationManager *ApplicationManager::instance()
592+{
593+ if (!m_instance) {
594+ new ApplicationManager;
595+ }
596+ return m_instance;
597+}
598+
599+QVariantMap ApplicationManager::applicationInfo(const QString &applicationId,
600+ const QString &profile)
601+{
602+ Q_D(ApplicationManager);
603+ Q_EMIT d->applicationInfoCalled(applicationId, profile);
604+ return d->m_applicationInfo[applicationId];
605+}
606+
607+QVariantMap ApplicationManager::providerInfo(const QString &providerId) const
608+{
609+ Q_D(const ApplicationManager);
610+ return d->m_providerInfo[providerId];
611+}
612
613=== added file 'tests/online-accounts-ui/mock/application-manager-mock.h'
614--- tests/online-accounts-ui/mock/application-manager-mock.h 1970-01-01 00:00:00 +0000
615+++ tests/online-accounts-ui/mock/application-manager-mock.h 2015-08-06 12:32:34 +0000
616@@ -0,0 +1,61 @@
617+/*
618+ * Copyright (C) 2014 Canonical Ltd.
619+ *
620+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
621+ *
622+ * This file is part of online-accounts-ui
623+ *
624+ * This program is free software: you can redistribute it and/or modify it
625+ * under the terms of the GNU General Public License version 3, as published
626+ * by the Free Software Foundation.
627+ *
628+ * This program is distributed in the hope that it will be useful, but
629+ * WITHOUT ANY WARRANTY; without even the implied warranties of
630+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
631+ * PURPOSE. See the GNU General Public License for more details.
632+ *
633+ * You should have received a copy of the GNU General Public License along
634+ * with this program. If not, see <http://www.gnu.org/licenses/>.
635+ */
636+
637+#ifndef MOCK_APPLICATION_MANAGER_H
638+#define MOCK_APPLICATION_MANAGER_H
639+
640+#include <OnlineAccountsPlugin/application-manager.h>
641+
642+#include <QHash>
643+#include <QObject>
644+
645+namespace OnlineAccountsUi {
646+
647+class ApplicationManagerPrivate: public QObject
648+{
649+ Q_OBJECT
650+ Q_DECLARE_PUBLIC(ApplicationManager)
651+
652+public:
653+ ApplicationManagerPrivate(ApplicationManager *q);
654+ ~ApplicationManagerPrivate();
655+ static ApplicationManagerPrivate *mocked(ApplicationManager *r) { return r->d_ptr; }
656+
657+ void setApplicationInfo(const QString &applicationId,
658+ const QVariantMap &info) {
659+ m_applicationInfo[applicationId] = info;
660+ }
661+
662+ void setProviderInfo(const QString &providerId, const QVariantMap &info) {
663+ m_providerInfo[providerId] = info;
664+ }
665+
666+Q_SIGNALS:
667+ void applicationInfoCalled(QString applicationId, QString profile);
668+
669+public:
670+ QHash<QString,QVariantMap> m_applicationInfo;
671+ QHash<QString,QVariantMap> m_providerInfo;
672+ mutable ApplicationManager *q_ptr;
673+};
674+
675+} // namespace
676+
677+#endif // MOCK_APPLICATION_MANAGER_H
678
679=== modified file 'tests/online-accounts-ui/mock/request-mock.cpp'
680--- tests/online-accounts-ui/mock/request-mock.cpp 2014-08-08 11:37:56 +0000
681+++ tests/online-accounts-ui/mock/request-mock.cpp 2015-08-06 12:32:34 +0000
682@@ -35,6 +35,7 @@
683 m_parameters(parameters),
684 m_clientApparmorProfile(clientProfile),
685 m_window(0),
686+ m_delay(0),
687 m_inProgress(false)
688 {
689 Q_UNUSED(interface);
690@@ -95,6 +96,18 @@
691 return d->m_window;
692 }
693
694+void Request::setDelay(int delay)
695+{
696+ Q_D(Request);
697+ d->m_delay = delay;
698+}
699+
700+int Request::delay() const
701+{
702+ Q_D(const Request);
703+ return d->m_delay;
704+}
705+
706 void Request::start()
707 {
708 Q_D(Request);
709
710=== modified file 'tests/online-accounts-ui/mock/request-mock.h'
711--- tests/online-accounts-ui/mock/request-mock.h 2014-08-08 11:37:56 +0000
712+++ tests/online-accounts-ui/mock/request-mock.h 2015-08-06 12:32:34 +0000
713@@ -53,6 +53,7 @@
714 QVariantMap m_parameters;
715 QString m_clientApparmorProfile;
716 QWindow *m_window;
717+ int m_delay;
718 bool m_inProgress;
719 };
720
721
722=== modified file 'tests/online-accounts-ui/online-accounts-ui.pro'
723--- tests/online-accounts-ui/online-accounts-ui.pro 2014-10-03 14:56:11 +0000
724+++ tests/online-accounts-ui/online-accounts-ui.pro 2015-08-06 12:32:34 +0000
725@@ -4,4 +4,5 @@
726 tst_access_model.pro \
727 tst_browser_request.pro \
728 tst_notification.pro \
729+ tst_provider_request.pro \
730 tst_signonui_request.pro
731
732=== modified file 'tests/online-accounts-ui/qml/qml.pro'
733--- tests/online-accounts-ui/qml/qml.pro 2014-10-24 18:21:11 +0000
734+++ tests/online-accounts-ui/qml/qml.pro 2015-08-06 12:32:34 +0000
735@@ -7,6 +7,7 @@
736 warn_on
737
738 DEFINES += \
739+ SOURCE_MODULE_PATH=\\\"$${PWD}\\\" \
740 TEST_DATA_DIR=\\\"$${PWD}/../data\\\"
741
742 SOURCES += \
743
744=== modified file 'tests/online-accounts-ui/qml/tst_online_accounts_qml.cpp'
745--- tests/online-accounts-ui/qml/tst_online_accounts_qml.cpp 2014-10-24 18:21:11 +0000
746+++ tests/online-accounts-ui/qml/tst_online_accounts_qml.cpp 2015-08-06 12:32:34 +0000
747@@ -16,5 +16,7 @@
748 qputenv("AG_PROVIDERS", TEST_DATA_DIR);
749 qputenv("XDG_DATA_HOME", TEST_DATA_DIR);
750
751+ qputenv("QML2_IMPORT_PATH", SOURCE_MODULE_PATH);
752+
753 return quick_test_main(argc, argv, "online_accounts_qml", QUICK_TEST_SOURCE_DIR);
754 }
755
756=== added file 'tests/online-accounts-ui/tst_provider_request.cpp'
757--- tests/online-accounts-ui/tst_provider_request.cpp 1970-01-01 00:00:00 +0000
758+++ tests/online-accounts-ui/tst_provider_request.cpp 2015-08-06 12:32:34 +0000
759@@ -0,0 +1,190 @@
760+/*
761+ * Copyright (C) 2014 Canonical Ltd.
762+ *
763+ * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
764+ *
765+ * This file is part of online-accounts-ui
766+ *
767+ * This program is free software: you can redistribute it and/or modify it
768+ * under the terms of the GNU General Public License version 3, as published
769+ * by the Free Software Foundation.
770+ *
771+ * This program is distributed in the hope that it will be useful, but
772+ * WITHOUT ANY WARRANTY; without even the implied warranties of
773+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
774+ * PURPOSE. See the GNU General Public License for more details.
775+ *
776+ * You should have received a copy of the GNU General Public License along
777+ * with this program. If not, see <http://www.gnu.org/licenses/>.
778+ */
779+
780+#include "debug.h"
781+#include "globals.h"
782+#include "mock/application-manager-mock.h"
783+#include "mock/request-mock.h"
784+#include "mock/ui-server-mock.h"
785+#include "provider-request.h"
786+
787+#include <QDebug>
788+#include <QJsonDocument>
789+#include <QJsonObject>
790+#include <QQmlContext>
791+#include <QQmlEngine>
792+#include <QQuickView>
793+#include <QSignalSpy>
794+#include <QTest>
795+
796+using namespace OnlineAccountsUi;
797+
798+namespace QTest {
799+template<>
800+char *toString(const QVariantMap &p)
801+{
802+ QJsonDocument doc(QJsonObject::fromVariantMap(p));
803+ QByteArray ba = doc.toJson(QJsonDocument::Compact);
804+ return qstrdup(ba.data());
805+}
806+} // QTest namespace
807+
808+class TestRequest: public ProviderRequest
809+{
810+ Q_OBJECT
811+
812+public:
813+ TestRequest(const QVariantMap &parameters, const QString &profile,
814+ QObject *parent = 0):
815+ ProviderRequest("interface", 0, profile, parameters, parent)
816+ {
817+ }
818+};
819+
820+class ProviderRequestTest: public QObject
821+{
822+ Q_OBJECT
823+
824+public:
825+ ProviderRequestTest();
826+
827+private Q_SLOTS:
828+ void initTestCase();
829+ void testParameters_data();
830+ void testParameters();
831+
832+private:
833+ UiServer m_uiServer;
834+};
835+
836+ProviderRequestTest::ProviderRequestTest():
837+ QObject(),
838+ m_uiServer("fake")
839+{
840+}
841+
842+void ProviderRequestTest::initTestCase()
843+{
844+ qputenv("ACCOUNTS", "/tmp/");
845+ qputenv("AG_APPLICATIONS", TEST_DATA_DIR);
846+ qputenv("AG_SERVICES", TEST_DATA_DIR);
847+ qputenv("AG_SERVICE_TYPES", TEST_DATA_DIR);
848+ qputenv("AG_PROVIDERS", TEST_DATA_DIR);
849+ qputenv("XDG_DATA_HOME", TEST_DATA_DIR);
850+}
851+
852+void ProviderRequestTest::testParameters_data()
853+{
854+ QTest::addColumn<QVariantMap>("parameters");
855+ QTest::addColumn<QString>("profile");
856+ QTest::addColumn<QString>("providerId");
857+ QTest::addColumn<QVariantMap>("providerInfo");
858+ QTest::addColumn<QVariantMap>("applicationInfo");
859+ QTest::addColumn<QString>("errorName");
860+
861+ QTest::newRow("empty") <<
862+ QVariantMap() <<
863+ QString() <<
864+ QString() <<
865+ QVariantMap() <<
866+ QVariantMap() <<
867+ OAU_ERROR_INVALID_APPLICATION;
868+
869+ QVariantMap parameters;
870+ QVariantMap providerInfo;
871+ QVariantMap applicationInfo;
872+
873+ parameters.insert(OAU_KEY_APPLICATION, "Gallery");
874+ parameters.insert(OAU_KEY_PROVIDER, "my provider");
875+ providerInfo.insert("some", "value");
876+ applicationInfo.insert("one", "two");
877+ QTest::newRow("confined app") <<
878+ parameters <<
879+ "my-app" <<
880+ "my provider" <<
881+ providerInfo <<
882+ applicationInfo <<
883+ "";
884+ parameters.clear();
885+ providerInfo.clear();
886+ applicationInfo.clear();
887+
888+ parameters.insert(OAU_KEY_APPLICATION, "Gallery");
889+ parameters.insert(OAU_KEY_SERVICE_ID, "coolmail");
890+ providerInfo.insert("name", "cool");
891+ applicationInfo.insert("one", "two");
892+ QTest::newRow("by service ID") <<
893+ parameters <<
894+ "my-app" <<
895+ "cool" <<
896+ providerInfo <<
897+ applicationInfo <<
898+ "";
899+ parameters.clear();
900+ providerInfo.clear();
901+ applicationInfo.clear();
902+}
903+
904+void ProviderRequestTest::testParameters()
905+{
906+ QFETCH(QVariantMap, parameters);
907+ QFETCH(QString, profile);
908+ QFETCH(QString, providerId);
909+ QFETCH(QVariantMap, providerInfo);
910+ QFETCH(QVariantMap, applicationInfo);
911+ QFETCH(QString, errorName);
912+
913+ TestRequest request(parameters, profile);
914+ RequestPrivate *mockedRequest = RequestPrivate::mocked(&request);
915+ QSignalSpy setWindowCalled(mockedRequest,
916+ SIGNAL(setWindowCalled(QWindow*)));
917+ QSignalSpy failCalled(mockedRequest,
918+ SIGNAL(failCalled(const QString&, const QString&)));
919+
920+ ApplicationManager *appManager = ApplicationManager::instance();
921+ ApplicationManagerPrivate *mockedAppManager =
922+ ApplicationManagerPrivate::mocked(appManager);
923+ mockedAppManager->setApplicationInfo(parameters[OAU_KEY_APPLICATION].toString(),
924+ applicationInfo);
925+ mockedAppManager->setProviderInfo(providerId, providerInfo);
926+ QSignalSpy applicationInfoCalled(mockedAppManager,
927+ SIGNAL(applicationInfoCalled(QString,QString)));
928+
929+ request.start();
930+
931+ if (errorName.isEmpty()) {
932+ QTRY_COMPARE(setWindowCalled.count(), 1);
933+ QQuickView *view = static_cast<QQuickView*>(setWindowCalled.at(0).at(0).value<QWindow*>());
934+ QQmlContext *context = view->engine()->rootContext();
935+
936+ QCOMPARE(applicationInfoCalled.count(), 1);
937+ QCOMPARE(applicationInfoCalled.at(0).at(1).toString(), profile);
938+
939+ QCOMPARE(context->contextProperty("provider").toMap(), providerInfo);
940+ QCOMPARE(context->contextProperty("application").toMap(), applicationInfo);
941+ } else {
942+ QTRY_COMPARE(failCalled.count(), 1);
943+ QCOMPARE(failCalled.at(0).at(0).toString(), errorName);
944+ }
945+}
946+
947+QTEST_MAIN(ProviderRequestTest);
948+
949+#include "tst_provider_request.moc"
950
951=== added file 'tests/online-accounts-ui/tst_provider_request.pro'
952--- tests/online-accounts-ui/tst_provider_request.pro 1970-01-01 00:00:00 +0000
953+++ tests/online-accounts-ui/tst_provider_request.pro 2015-08-06 12:32:34 +0000
954@@ -0,0 +1,52 @@
955+include(online-accounts-ui.pri)
956+
957+TARGET = tst_provider_request
958+
959+CONFIG += \
960+ link_pkgconfig
961+
962+QT += \
963+ gui \
964+ quick
965+
966+PKGCONFIG += \
967+ accounts-qt5
968+
969+INCLUDEPATH += \
970+ $${TOP_SRC_DIR}/plugins
971+QMAKE_LIBDIR = $${TOP_BUILD_DIR}/plugins/OnlineAccountsPlugin
972+LIBS += -lonline-accounts-plugin
973+
974+DEFINES += \
975+ NO_REQUEST_FACTORY \
976+ OAU_PLUGIN_DIR=\\\"/tmp\\\" \
977+ PLUGIN_PRIVATE_MODULE_DIR=\\\"/tmp\\\" \
978+ TEST_DATA_DIR=\\\"$${PWD}/data\\\"
979+
980+
981+SOURCES += \
982+ $${ONLINE_ACCOUNTS_UI_DIR}/access-model.cpp \
983+ $${ONLINE_ACCOUNTS_UI_DIR}/debug.cpp \
984+ $${ONLINE_ACCOUNTS_UI_DIR}/i18n.cpp \
985+ $${ONLINE_ACCOUNTS_UI_DIR}/provider-request.cpp \
986+ mock/application-manager-mock.cpp \
987+ mock/request-mock.cpp \
988+ mock/ui-server-mock.cpp \
989+ tst_provider_request.cpp
990+
991+HEADERS += \
992+ $${ONLINE_ACCOUNTS_UI_DIR}/access-model.h \
993+ $${ONLINE_ACCOUNTS_UI_DIR}/i18n.h \
994+ $${ONLINE_ACCOUNTS_UI_DIR}/provider-request.h \
995+ $${ONLINE_ACCOUNTS_UI_DIR}/request.h \
996+ $${ONLINE_ACCOUNTS_UI_DIR}/ui-server.h \
997+ mock/application-manager-mock.h \
998+ mock/request-mock.h \
999+ mock/ui-server-mock.h
1000+
1001+RESOURCES += \
1002+ tst_provider_request.qrc
1003+
1004+check.commands += "xvfb-run -s '-screen 0 640x480x24' -a dbus-test-runner -t ./$${TARGET}"
1005+check.depends = $${TARGET}
1006+QMAKE_EXTRA_TARGETS += check
1007
1008=== added file 'tests/online-accounts-ui/tst_provider_request.qrc'
1009--- tests/online-accounts-ui/tst_provider_request.qrc 1970-01-01 00:00:00 +0000
1010+++ tests/online-accounts-ui/tst_provider_request.qrc 2015-08-06 12:32:34 +0000
1011@@ -0,0 +1,5 @@
1012+<!DOCTYPE RCC><RCC version="1.0">
1013+<qresource prefix="qml">
1014+ <file>ProviderRequest.qml</file>
1015+</qresource>
1016+</RCC>

Subscribers

People subscribed via source and target branches