Merge lp:~mardy/unity-webapps-qml/oa-capture into lp:unity-webapps-qml

Proposed by Alberto Mardegan
Status: Needs review
Proposed branch: lp:~mardy/unity-webapps-qml/oa-capture
Merge into: lp:unity-webapps-qml
Diff against target: 706 lines (+552/-4)
14 files modified
.bzrignore (+32/-0)
common-project-config.pri (+12/-0)
debian/control (+2/-0)
debian/unity-webapps-qml.install (+1/-0)
src/Ubuntu/UnityWebApps/UnityWebApps.qml (+8/-1)
src/Ubuntu/UnityWebApps/plugin/com.canonical.webcredentials.capture.gschema.xml (+11/-0)
src/Ubuntu/UnityWebApps/plugin/online-accounts-capturer.cpp (+148/-0)
src/Ubuntu/UnityWebApps/plugin/online-accounts-capturer.h (+60/-0)
src/Ubuntu/UnityWebApps/plugin/plugin.pro (+15/-2)
src/Ubuntu/UnityWebApps/plugin/qml-plugin.cpp (+12/-0)
tests/unit/test_online_accounts_capturer/capture-test.provider (+8/-0)
tests/unit/test_online_accounts_capturer/test_online_accounts_capturer.cpp (+196/-0)
tests/unit/test_online_accounts_capturer/test_online_accounts_capturer.pro (+44/-0)
tests/unit/unit.pro (+3/-1)
To merge this branch: bzr merge lp:~mardy/unity-webapps-qml/oa-capture
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Alexandre Abreu (community) Approve
WebApps Pending
Review via email: mp+209905@code.launchpad.net

Commit message

Send username and cookies to Online Accounts

This is the reimplementation in Qt of this:
http://bazaar.launchpad.net/~online-accounts/webaccounts-browser-extension/trunk/view/head:/lib/webaccounts/login-handler.c

Description of the change

Send username and cookies to Online Accounts

This is the reimplementation in Qt of this:
http://bazaar.launchpad.net/~online-accounts/webaccounts-browser-extension/trunk/view/head:/lib/webaccounts/login-handler.c

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
David Barth (dbarth) wrote :

Hmmm, no unit tests?

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

L97: please do not enforce the getCookies bit. It works only in the context of the webapp-container but not in other (app related) contexts where the component is uses, e.g. html5 apps. Any binding injection will fail bc of this. I'd rather see a more flexible handling & validate at runtime L110 if getcookies() is there,

L226: validate username isEmpty()?

review: Needs Fixing
90. By Alberto Mardegan

Add unit tests

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

Don't enforce the presence of getCookies()

Revision history for this message
Alberto Mardegan (mardy) wrote :

Updated: added unit tests, remove the hard check on getCookies().

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alexandre Abreu (abreu-alexandre) :
review: Approve
92. By Alberto Mardegan

Merge from trunk

[ Alexandre Abreu ]
* Add some missing files striclty for doc generation for the runtime-
  api
* There is currently an issue on Ubuntu Desktop with webapps running
  in the container and bamf/unity that when a local desktop file
  exists (and a webapp icon has been pinned to the launcher through
  its global /usr/share desktop file), the webapp icons are duplicated
  in the launcher. Various fixes have been made to mitigate the issue
  in bamf but it seems to still be around. This is voluntarily
  discarded for now and left around to get to the bottom of the issue
  in a timely fashion. (LP: #1300864)
[ Alexandre Abreu ]
* Fixes to the runtime-api: have inputMethodName return its value,.
  have the client register listeners for property changed, .
[ Ubuntu daily release ]
* New rebuild forced
[ Alexandre Abreu ]
* Add application api (LP: #1278485)
[ Alexandre Abreu ]
* Add integration with oxide (LP: #1290535)
[ Justin McPherson ]
* Add integration with oxide (LP: #1290535)
[ Ubuntu daily release ]
* New rebuild forced
[ Alexandre Abreu ]
* Add support for the new content hub api
[ Alexandre Abreu ]
* Fix desktop file generation: dont do useless generation when not
  needed,. use the proper webapps-runner w/ the --chrome option. make
  sure that the webapp 'domain' is available (LP: #1288805)
* Make sure that priviledged APIs are only injected in the proper
  context (LP: #1293702)
* New rebuild forced
[ Ubuntu daily release ]
* New rebuild forced
[ Alexandre Abreu ]
* Fix issue with the callback order for content hub's high level api.
  The order is reversed
[ Alexandre Abreu ]
* Fix online accounts inline docs
[ Alberto Mardegan ]
* API cleanups Add a getAccounts() method, and remove the
  getAccountsInfoFor() and getAccessTokenFor() methods.

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

From trunk

[ Alexandre Abreu ]
Update the oxide bits to account for oxide moving to 1.0

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

Unmerged revisions

93. By Alberto Mardegan

From trunk

[ Alexandre Abreu ]
Update the oxide bits to account for oxide moving to 1.0

92. By Alberto Mardegan

Merge from trunk

[ Alexandre Abreu ]
* Add some missing files striclty for doc generation for the runtime-
  api
* There is currently an issue on Ubuntu Desktop with webapps running
  in the container and bamf/unity that when a local desktop file
  exists (and a webapp icon has been pinned to the launcher through
  its global /usr/share desktop file), the webapp icons are duplicated
  in the launcher. Various fixes have been made to mitigate the issue
  in bamf but it seems to still be around. This is voluntarily
  discarded for now and left around to get to the bottom of the issue
  in a timely fashion. (LP: #1300864)
[ Alexandre Abreu ]
* Fixes to the runtime-api: have inputMethodName return its value,.
  have the client register listeners for property changed, .
[ Ubuntu daily release ]
* New rebuild forced
[ Alexandre Abreu ]
* Add application api (LP: #1278485)
[ Alexandre Abreu ]
* Add integration with oxide (LP: #1290535)
[ Justin McPherson ]
* Add integration with oxide (LP: #1290535)
[ Ubuntu daily release ]
* New rebuild forced
[ Alexandre Abreu ]
* Add support for the new content hub api
[ Alexandre Abreu ]
* Fix desktop file generation: dont do useless generation when not
  needed,. use the proper webapps-runner w/ the --chrome option. make
  sure that the webapp 'domain' is available (LP: #1288805)
* Make sure that priviledged APIs are only injected in the proper
  context (LP: #1293702)
* New rebuild forced
[ Ubuntu daily release ]
* New rebuild forced
[ Alexandre Abreu ]
* Fix issue with the callback order for content hub's high level api.
  The order is reversed
[ Alexandre Abreu ]
* Fix online accounts inline docs
[ Alberto Mardegan ]
* API cleanups Add a getAccounts() method, and remove the
  getAccountsInfoFor() and getAccessTokenFor() methods.

91. By Alberto Mardegan

Don't enforce the presence of getCookies()

90. By Alberto Mardegan

Add unit tests

89. By Alberto Mardegan

Install GSettings schema

88. By Alberto Mardegan

Send website username and cookies to OA

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file '.bzrignore'
2--- .bzrignore 1970-01-01 00:00:00 +0000
3+++ .bzrignore 2014-04-08 07:15:18 +0000
4@@ -0,0 +1,32 @@
5+*.log
6+*.moc
7+Makefile
8+moc_*.cpp
9+debian/files
10+debian/qtdeclarative5-ubuntu-webapps-api/
11+debian/*.debhelper
12+debian/*.substvars
13+debian/tmp/
14+debian/unity-webapps-qml/
15+debian/unity-webapps-qml-autopilot/
16+debian/unity-webapps-qml-doc/
17+debian/unity-webapps-qml-examples/
18+docs/html/images/
19+docs/html/qml-ubuntu-unitywebapps0-*.html
20+docs/html/scripts/
21+docs/html/style/
22+docs/html/unity-webapps-qml-component.index
23+examples/api-bindings/alarm/main.qml
24+examples/api-bindings/content-hub/main.qml
25+examples/api-bindings/content-hub-exporter/main.qml
26+examples/api-bindings/online-accounts/main.qml
27+src/Ubuntu/UnityWebApps/qmldir
28+src/Ubuntu/UnityWebApps/unity-webapps-api.js
29+tests/integration/autopilot/build/
30+tests/integration/autopilot/unity_webapps_qml.egg-info/
31+tests/unit/test_js/test_js
32+tests/unit/test_online_accounts_capturer/test_online_accounts_capturer
33+tests/unit/test_plugin/tst_plugin
34+tests/unit/test_qml/test_qml
35+tools/qml-launcher/unity-webapps-qml-launcher
36+
37
38=== modified file 'common-project-config.pri'
39--- common-project-config.pri 2013-07-09 19:02:23 +0000
40+++ common-project-config.pri 2014-04-08 07:15:18 +0000
41@@ -13,3 +13,15 @@
42
43 include(coverage.pri)
44
45+INSTALL_PREFIX = /usr # default installation prefix
46+
47+# default prefix can be overriden by defining PREFIX when running qmake
48+isEmpty(PREFIX) {
49+ message("====")
50+ message("==== NOTE: To override the installation path run: `qmake PREFIX=/custom/path'")
51+ message("==== (current installation path is `$${INSTALL_PREFIX}')")
52+} else {
53+ INSTALL_PREFIX = $${PREFIX}
54+ message("====")
55+ message("==== install prefix set to `$${INSTALL_PREFIX}'")
56+}
57
58=== modified file 'debian/control'
59--- debian/control 2014-04-03 14:17:12 +0000
60+++ debian/control 2014-04-08 07:15:18 +0000
61@@ -4,6 +4,8 @@
62 Maintainer: Ubuntu Desktop Team <ubuntu-desktop@lists.ubuntu.com>
63 Build-Depends: debhelper (>= 9),
64 gdb,
65+ libaccounts-qt5-dev,
66+ libgsettings-qt-dev,
67 libmessaging-menu-dev,
68 libnotify-dev,
69 libqt5webkit5-dev,
70
71=== modified file 'debian/unity-webapps-qml.install'
72--- debian/unity-webapps-qml.install 2013-08-27 04:45:47 +0000
73+++ debian/unity-webapps-qml.install 2014-04-08 07:15:18 +0000
74@@ -1,3 +1,4 @@
75 usr/bin/unity-webapps-qml-launcher
76 usr/lib/*/qt5/qml/Ubuntu/UnityWebApps/*
77 usr/share/applications/unitywebappsqmllauncher.desktop
78+usr/share/glib-2.0/schemas/*
79
80=== modified file 'src/Ubuntu/UnityWebApps/UnityWebApps.qml'
81--- src/Ubuntu/UnityWebApps/UnityWebApps.qml 2014-03-26 15:52:46 +0000
82+++ src/Ubuntu/UnityWebApps/UnityWebApps.qml 2014-04-08 07:15:18 +0000
83@@ -81,9 +81,10 @@
84
85 \code
86 method getUnityWebappsProxies()
87+ method getCookies()
88 \endcode
89
90- that should return a BindeeExports:
91+ the getUnityWebappsProxies() method should return a list of BindeeExports:
92
93 \code
94 interface BindeeExports {
95@@ -493,6 +494,12 @@
96 var url = params.__unity_webapps_hidden && params.__unity_webapps_hidden.url
97 ? params.__unity_webapps_hidden.url : "";
98 base.init(webappName, url, isLocal, params);
99+
100+ // Online Accounts capture:
101+ if ('login' in params && (typeof bindee.getCookies === 'function')) {
102+ UbuntuUnityWebApps.OnlineAccounts.capture(params.login, params.domain,
103+ bindee.getCookies());
104+ }
105 });
106 }
107 else {
108
109=== added file 'src/Ubuntu/UnityWebApps/plugin/com.canonical.webcredentials.capture.gschema.xml'
110--- src/Ubuntu/UnityWebApps/plugin/com.canonical.webcredentials.capture.gschema.xml 1970-01-01 00:00:00 +0000
111+++ src/Ubuntu/UnityWebApps/plugin/com.canonical.webcredentials.capture.gschema.xml 2014-04-08 07:15:18 +0000
112@@ -0,0 +1,11 @@
113+<schemalist>
114+ <schema id="com.canonical.webcredentials.capture" path="/com/canonical/webcredentials/capture/" gettext-domain="webcredentials-browser-extension">
115+ <key name="dontask-accounts" type="as">
116+ <summary>A list of accounts (in the form domain:account) which we will not propose to create locally.</summary>
117+ <default>[]</default>
118+ <description>
119+ This key lists all those accounts for which the creation of a local account has been already asked, and won't be asked again.
120+ </description>
121+ </key>
122+ </schema>
123+</schemalist>
124
125=== added file 'src/Ubuntu/UnityWebApps/plugin/online-accounts-capturer.cpp'
126--- src/Ubuntu/UnityWebApps/plugin/online-accounts-capturer.cpp 1970-01-01 00:00:00 +0000
127+++ src/Ubuntu/UnityWebApps/plugin/online-accounts-capturer.cpp 2014-04-08 07:15:18 +0000
128@@ -0,0 +1,148 @@
129+/*
130+ * Copyright 2014 Canonical Ltd.
131+ *
132+ * This file is part of unity-webapps-qml.
133+ *
134+ * unity-webapps-qml is free software; you can redistribute it and/or modify
135+ * it under the terms of the GNU General Public License as published by
136+ * the Free Software Foundation; version 3.
137+ *
138+ * unity-webapps-qml is distributed in the hope that it will be useful,
139+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
140+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
141+ * GNU General Public License for more details.
142+ *
143+ * You should have received a copy of the GNU General Public License
144+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
145+ */
146+
147+#include <Accounts/Manager>
148+#include <Accounts/Provider>
149+#include <QDBusConnection>
150+#include <QDBusMessage>
151+#include <QDBusMetaType>
152+#include <QDebug>
153+#include <QGSettings>
154+#include <QRegExp>
155+#include "online-accounts-capturer.h"
156+
157+#define OA_CAPTURE_SERVICE "com.canonical.webcredentials.capture"
158+#define OA_CAPTURE_OBJECT_PATH "/com/canonical/webcredentials/capture"
159+#define OA_CAPTURE_INTERFACE OA_CAPTURE_SERVICE
160+
161+#define OA_CAPTURE_DCONF_SCHEMA "com.canonical.webcredentials.capture"
162+
163+using namespace OnlineAccounts;
164+
165+static QString accountId(const QString &domain, const QString &username)
166+{
167+ return QString(QStringLiteral("%1:%2")).arg(domain).arg(username);
168+}
169+
170+Capturer::Capturer(QObject *parent):
171+ QObject(parent),
172+ m_manager(new Accounts::Manager(this))
173+{
174+ qRegisterMetaType<Cookies>("Cookies");
175+ qDBusRegisterMetaType<Cookies>();
176+}
177+
178+Capturer::~Capturer()
179+{
180+}
181+
182+Accounts::Provider Capturer::providerForDomain(const QString &domain)
183+{
184+ Q_FOREACH(const Accounts::Provider &provider, m_manager->providerList()) {
185+ QRegExp domainsRegExp(provider.domainsRegExp());
186+ if (domainsRegExp.exactMatch(domain)) {
187+ return provider;
188+ }
189+ }
190+
191+ /* If not found, return an invalid one */
192+ return Accounts::Provider();
193+}
194+
195+bool Capturer::accountIsBlacklisted(const QString &domain,
196+ const QString &username)
197+{
198+ QGSettings settings(OA_CAPTURE_DCONF_SCHEMA);
199+
200+ QStringList blacklistedAccounts =
201+ settings.get("dontask-accounts").toStringList();
202+
203+ return blacklistedAccounts.contains(accountId(domain, username));
204+}
205+
206+void Capturer::blacklistAccount(const QString &domain, const QString &username)
207+{
208+ QGSettings settings(OA_CAPTURE_DCONF_SCHEMA);
209+
210+ QStringList blacklistedAccounts =
211+ settings.get("dontask-accounts").toStringList();
212+ blacklistedAccounts.append(accountId(domain, username));
213+ settings.set("dontask-accounts", blacklistedAccounts);
214+}
215+
216+bool Capturer::accountExists(const Accounts::Provider &provider,
217+ const QString &username)
218+{
219+ Q_FOREACH(Accounts::AccountId id, m_manager->accountList()) {
220+ Accounts::Account *account = m_manager->account(id);
221+ if (!account) continue;
222+
223+ if (account->providerName() != provider.name()) continue;
224+
225+ /* Here we assume that the account username is used as display name; we
226+ * might need to revisit this later. */
227+ if (account->displayName() == username) return true;
228+ }
229+
230+ return false;
231+}
232+
233+void Capturer::capture(const QString &login, const QString &domain,
234+ const Cookies &cookies)
235+{
236+ if (login.isEmpty() || domain.isEmpty()) {
237+ qDebug() << "Insufficient info: domain =" << domain << ", login =" << login;
238+ return;
239+ }
240+
241+ Accounts::Provider provider = providerForDomain(domain);
242+ if (!provider.isValid()) {
243+ qDebug() << "No provider support for domain" << domain;
244+ return;
245+ }
246+
247+ if (accountIsBlacklisted(domain, login)) {
248+ qDebug() << "Account" << login << "on" << domain << "is blacklisted";
249+ return;
250+ }
251+
252+ /* If an account for the same provider with the same username already
253+ * exists, stop processing here. */
254+ if (accountExists(provider, login)) {
255+ qDebug() << "Account already exists:" << login;
256+ return;
257+ }
258+
259+ QDBusMessage message =
260+ QDBusMessage::createMethodCall(OA_CAPTURE_SERVICE,
261+ OA_CAPTURE_OBJECT_PATH,
262+ OA_CAPTURE_INTERFACE,
263+ "LoginCaptured");
264+ QList<QVariant> arguments;
265+ arguments << provider.name();
266+ arguments << login;
267+ arguments << QStringLiteral(""); // password, we don't use it
268+ arguments << QVariant::fromValue(cookies);
269+ message.setArguments(arguments);
270+
271+ QDBusConnection connection = QDBusConnection::sessionBus();
272+ connection.call(message, QDBus::NoBlock);
273+
274+ /* Don't propose to create this account ever again */
275+ blacklistAccount(domain, login);
276+}
277
278=== added file 'src/Ubuntu/UnityWebApps/plugin/online-accounts-capturer.h'
279--- src/Ubuntu/UnityWebApps/plugin/online-accounts-capturer.h 1970-01-01 00:00:00 +0000
280+++ src/Ubuntu/UnityWebApps/plugin/online-accounts-capturer.h 2014-04-08 07:15:18 +0000
281@@ -0,0 +1,60 @@
282+/*
283+ * Copyright 2014 Canonical Ltd.
284+ *
285+ * This file is part of unity-webapps-qml.
286+ *
287+ * unity-webapps-qml is free software; you can redistribute it and/or modify
288+ * it under the terms of the GNU General Public License as published by
289+ * the Free Software Foundation; version 3.
290+ *
291+ * unity-webapps-qml is distributed in the hope that it will be useful,
292+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
293+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
294+ * GNU General Public License for more details.
295+ *
296+ * You should have received a copy of the GNU General Public License
297+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
298+ */
299+
300+#ifndef __UNITY_WEBAPPS_ONLINE_ACCOUNTS_CAPTURER_H__
301+#define __UNITY_WEBAPPS_ONLINE_ACCOUNTS_CAPTURER_H__
302+
303+#include <QMap>
304+#include <QObject>
305+#include <QString>
306+
307+namespace Accounts {
308+ class Manager;
309+ class Provider;
310+};
311+
312+namespace OnlineAccounts {
313+
314+typedef QMap<QString, QString> Cookies;
315+
316+class Capturer: public QObject
317+{
318+ Q_OBJECT
319+
320+public:
321+ Capturer(QObject *parent = 0);
322+ ~Capturer();
323+
324+ Q_INVOKABLE void capture(const QString &login, const QString &domain,
325+ const Cookies &cookies);
326+private:
327+ Accounts::Provider providerForDomain(const QString &domain);
328+ bool accountIsBlacklisted(const QString &domain, const QString &username);
329+ void blacklistAccount(const QString &domain, const QString &username);
330+ bool accountExists(const Accounts::Provider &provider,
331+ const QString &username);
332+
333+private:
334+ Accounts::Manager *m_manager;
335+};
336+
337+};
338+
339+Q_DECLARE_METATYPE(OnlineAccounts::Cookies);
340+
341+#endif // __UNITY_WEBAPPS_ONLINE_ACCOUNTS_CAPTURER_H__
342
343=== modified file 'src/Ubuntu/UnityWebApps/plugin/plugin.pro'
344--- src/Ubuntu/UnityWebApps/plugin/plugin.pro 2014-03-25 20:56:01 +0000
345+++ src/Ubuntu/UnityWebApps/plugin/plugin.pro 2014-04-08 07:15:18 +0000
346@@ -5,7 +5,10 @@
347
348 unix {
349 CONFIG += link_pkgconfig
350- PKGCONFIG += libnotify \
351+ PKGCONFIG += \
352+ accounts-qt5 \
353+ gsettings-qt \
354+ libnotify \
355 messaging-menu \
356 glib-2.0 \
357 gio-2.0 \
358@@ -23,10 +26,14 @@
359 plugin \
360 qt
361
362-QT += core qml
363+QT += \
364+ core \
365+ dbus \
366+ qml
367
368
369 SOURCES += \
370+ online-accounts-capturer.cpp \
371 qml-plugin.cpp \
372 unity-webapps-api.cpp \
373 unity-webapps-api-notifications.cpp \
374@@ -45,6 +52,7 @@
375 application-signal-to-qt-bridge.cpp
376
377 HEADERS += \
378+ online-accounts-capturer.h \
379 qml-plugin.h \
380 unity-webapps-api.h \
381 unity-webapps-api-notifications.h \
382@@ -70,5 +78,10 @@
383 PLUGIN_INSTALL_PATH = $$[QT_INSTALL_QML]/$$replace(API_URI, \\., /)
384 target.path = $${PLUGIN_INSTALL_PATH}
385
386+gsettings_schemas.files = \
387+ com.canonical.webcredentials.capture.gschema.xml
388+gsettings_schemas.path = $${INSTALL_PREFIX}/share/glib-2.0/schemas
389+INSTALLS += gsettings_schemas
390+
391 INSTALLS += target
392
393
394=== modified file 'src/Ubuntu/UnityWebApps/plugin/qml-plugin.cpp'
395--- src/Ubuntu/UnityWebApps/plugin/qml-plugin.cpp 2014-03-21 20:07:16 +0000
396+++ src/Ubuntu/UnityWebApps/plugin/qml-plugin.cpp 2014-04-08 07:15:18 +0000
397@@ -16,6 +16,7 @@
398 * along with this program. If not, see <http://www.gnu.org/licenses/>.
399 */
400
401+#include "online-accounts-capturer.h"
402 #include "qml-plugin.h"
403
404 #include <QtQml/QQmlEngine>
405@@ -36,6 +37,14 @@
406
407 #include <qqml.h>
408
409+static QObject *createOnlineAccountsInstance(QQmlEngine *engine, QJSEngine *scriptEngine)
410+{
411+ Q_UNUSED(engine);
412+ Q_UNUSED(scriptEngine);
413+
414+ return new OnlineAccounts::Capturer();
415+}
416+
417 static QObject *createApplicationApi(QQmlEngine *engine, QJSEngine *scriptEngine)
418 {
419 Q_UNUSED(engine);
420@@ -58,6 +67,9 @@
421 qmlRegisterType<UnityWebappsAppModelFilterProxy> (uri, 0, 1, "UnityWebappsAppModelFilterProxy");
422 qmlRegisterType<UnityWebappsCallback> (uri, 0, 1, "UnityWebappsCallback");
423 qmlRegisterType<UnityWebappsAppInfos> (uri, 0, 1, "UnityWebappsAppInfos");
424+ // Online Accounts capture
425+ qmlRegisterSingletonType<OnlineAccounts::Capturer>(uri, 0, 1, "OnlineAccounts",
426+ createOnlineAccountsInstance);
427
428 // TODO bump version
429 qmlRegisterType<AbstractItemModelAdaptor> (uri, 0, 1, "AbstractItemModelAdaptor");
430
431=== added directory 'tests/unit/test_online_accounts_capturer'
432=== added file 'tests/unit/test_online_accounts_capturer/capture-test.provider'
433--- tests/unit/test_online_accounts_capturer/capture-test.provider 1970-01-01 00:00:00 +0000
434+++ tests/unit/test_online_accounts_capturer/capture-test.provider 2014-04-08 07:15:18 +0000
435@@ -0,0 +1,8 @@
436+<?xml version="1.0" encoding="UTF-8"?>
437+<provider id="capture-test">
438+ <name>Capture test</name>
439+ <description>Something meaningful</description>
440+ <icon>whocares</icon>
441+ <translations>account-plugins</translations>
442+ <domains>.*mysite\.com</domains>
443+</provider>
444
445=== added file 'tests/unit/test_online_accounts_capturer/test_online_accounts_capturer.cpp'
446--- tests/unit/test_online_accounts_capturer/test_online_accounts_capturer.cpp 1970-01-01 00:00:00 +0000
447+++ tests/unit/test_online_accounts_capturer/test_online_accounts_capturer.cpp 2014-04-08 07:15:18 +0000
448@@ -0,0 +1,196 @@
449+/*
450+ * Copyright 2014 Canonical Ltd.
451+ *
452+ * This file is part of unity-webapps-qml.
453+ *
454+ * unity-webapps-qml is free software; you can redistribute it and/or modify
455+ * it under the terms of the GNU General Public License as published by
456+ * the Free Software Foundation; version 3.
457+ *
458+ * unity-webapps-qml is distributed in the hope that it will be useful,
459+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
460+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
461+ * GNU General Public License for more details.
462+ *
463+ * You should have received a copy of the GNU General Public License
464+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
465+ */
466+
467+#include <Accounts/Account>
468+#include <Accounts/Manager>
469+#include <QDir>
470+#include <QDBusConnection>
471+#include <QDBusMessage>
472+#include <QGSettings>
473+#include <QMap>
474+#include <QTest>
475+#include <QVariant>
476+#include "online-accounts-capturer.h"
477+
478+using namespace OnlineAccounts;
479+
480+static QDBusMessage *capturedMessage = 0;
481+
482+QDBusMessage QDBusConnection::call(const QDBusMessage &message,
483+ QDBus::CallMode mode,
484+ int timeout) const
485+{
486+ Q_UNUSED(mode);
487+ Q_UNUSED(timeout);
488+ delete capturedMessage;
489+ capturedMessage = new QDBusMessage(message);
490+ return message;
491+}
492+
493+/* Mock QGSettings */
494+static struct QGSettingsData {
495+ void init(const QByteArray &schema_id, const QByteArray &path) {
496+ m_schemaId = schema_id;
497+ m_path = path;
498+ }
499+
500+ QVariantMap m_data;
501+ QByteArray m_schemaId;
502+ QByteArray m_path;
503+} gsettingsData;
504+
505+QGSettings::QGSettings(const QByteArray &schema_id, const QByteArray &path,
506+ QObject *parent):
507+ QObject(parent)
508+{
509+ gsettingsData.init(schema_id, path);
510+}
511+
512+QGSettings::~QGSettings()
513+{
514+}
515+
516+QVariant QGSettings::get(const QString &key) const
517+{
518+ return gsettingsData.m_data.value(key);
519+}
520+
521+void QGSettings::set(const QString &key, const QVariant &value)
522+{
523+ gsettingsData.m_data.insert(key, value);
524+}
525+
526+
527+class CapturerTest: public QObject
528+{
529+ Q_OBJECT
530+
531+public:
532+ CapturerTest();
533+
534+ void clearDb();
535+ QDBusMessage *dbusMessage() const { return capturedMessage; }
536+
537+private Q_SLOTS:
538+ void initTestCase();
539+ void cleanup();
540+ void testNoData();
541+ void testUnsupportedDomain();
542+ void testBlacklisted();
543+ void testExisting();
544+ void testCall();
545+
546+private:
547+ Capturer *m_capturer;
548+};
549+
550+CapturerTest::CapturerTest():
551+ QObject(),
552+ m_capturer(0)
553+{
554+}
555+
556+void CapturerTest::initTestCase()
557+{
558+ qputenv("ACCOUNTS", "/tmp/");
559+ qputenv("AG_PROVIDERS", TEST_DATA_DIR);
560+
561+ m_capturer = new Capturer(this);
562+}
563+
564+void CapturerTest::cleanup()
565+{
566+ delete capturedMessage;
567+ capturedMessage = 0;
568+
569+ gsettingsData.m_data.clear();
570+}
571+
572+void CapturerTest::clearDb()
573+{
574+ QDir dbroot(QString::fromLatin1(qgetenv("ACCOUNTS")));
575+ dbroot.remove("accounts.db");
576+}
577+
578+void CapturerTest::testNoData()
579+{
580+ m_capturer->capture(QString(), QString(), Cookies());
581+ QVERIFY(!dbusMessage());
582+
583+ m_capturer->capture("username", QString(), Cookies());
584+ QVERIFY(!dbusMessage());
585+
586+ m_capturer->capture("username", "", Cookies());
587+ QVERIFY(!dbusMessage());
588+
589+ m_capturer->capture(QString(), "domain", Cookies());
590+ QVERIFY(!dbusMessage());
591+
592+ m_capturer->capture("", "domain", Cookies());
593+ QVERIFY(!dbusMessage());
594+}
595+
596+void CapturerTest::testUnsupportedDomain()
597+{
598+ m_capturer->capture("John", "whatasite.com", Cookies());
599+ QVERIFY(!dbusMessage());
600+}
601+
602+void CapturerTest::testBlacklisted()
603+{
604+ QStringList blacklist;
605+ blacklist << "something" << "www.mysite.com:John" << "somethingelse";
606+ gsettingsData.m_data.insert("dontask-accounts", blacklist);
607+ m_capturer->capture("John", "www.mysite.com", Cookies());
608+ QVERIFY(!dbusMessage());
609+}
610+
611+void CapturerTest::testExisting()
612+{
613+ // Create the account
614+ Accounts::Manager *manager = new Accounts::Manager(this);
615+ Accounts::Account *account = manager->createAccount("capture-test");
616+ account->setDisplayName("Adam");
617+ account->syncAndBlock();
618+ delete manager;
619+
620+ m_capturer->capture("Adam", "www.mysite.com", Cookies());
621+ QVERIFY(!dbusMessage());
622+}
623+
624+void CapturerTest::testCall()
625+{
626+ Cookies cookies;
627+ cookies.insert("first", "number one");
628+ cookies.insert("second", "number two");
629+ m_capturer->capture("New User", "www.mysite.com", cookies);
630+
631+ QDBusMessage *message = dbusMessage();
632+ QVERIFY(message != 0);
633+
634+ QList<QVariant> arguments = message->arguments();
635+ QCOMPARE(arguments.count(), 4);
636+
637+ QCOMPARE(arguments[0].toString(), QString("capture-test"));
638+ QCOMPARE(arguments[1].toString(), QString("New User"));
639+ QVERIFY(arguments[2].toString().isEmpty()); // no password
640+ QCOMPARE(arguments[3].value<Cookies>(), cookies);
641+}
642+
643+QTEST_MAIN(CapturerTest);
644+#include "test_online_accounts_capturer.moc"
645
646=== added file 'tests/unit/test_online_accounts_capturer/test_online_accounts_capturer.pro'
647--- tests/unit/test_online_accounts_capturer/test_online_accounts_capturer.pro 1970-01-01 00:00:00 +0000
648+++ tests/unit/test_online_accounts_capturer/test_online_accounts_capturer.pro 2014-04-08 07:15:18 +0000
649@@ -0,0 +1,44 @@
650+include(../../../common-project-config.pri)
651+
652+TEMPLATE = app
653+TARGET = test_online_accounts_capturer
654+
655+QT += \
656+ core \
657+ dbus \
658+ testlib
659+
660+CONFIG += \
661+ debug \
662+ link_pkgconfig \
663+ no_keywords
664+
665+PKGCONFIG += \
666+ accounts-qt5 \
667+ gsettings-qt
668+
669+MODULE_DIR = $${TOP_SRC_DIR}/src/Ubuntu/UnityWebApps/plugin
670+
671+INCLUDEPATH += \
672+ $${MODULE_DIR}
673+
674+SOURCES += \
675+ $${MODULE_DIR}/online-accounts-capturer.cpp \
676+ test_online_accounts_capturer.cpp
677+
678+HEADERS += \
679+ $${MODULE_DIR}/online-accounts-capturer.h
680+
681+DATA_PATH = $${PWD}
682+
683+OTHER_FILES += \
684+ capture-test.provider
685+
686+DEFINES += \
687+ TEST_DATA_DIR=\\\"$$DATA_PATH\\\"
688+
689+# make check target
690+check.target = check
691+check.commands = "./$${TARGET}"
692+check.depends = $${TARGET}
693+QMAKE_EXTRA_TARGETS += check
694
695=== modified file 'tests/unit/unit.pro'
696--- tests/unit/unit.pro 2014-01-21 19:58:04 +0000
697+++ tests/unit/unit.pro 2014-04-08 07:15:18 +0000
698@@ -1,6 +1,8 @@
699 TEMPLATE=subdirs
700
701-SUBDIRS = test_plugin \
702+SUBDIRS = \
703+ test_online_accounts_capturer \
704+ test_plugin \
705 test_qml \
706 test_js
707

Subscribers

People subscribed via source and target branches

to all changes: