Merge lp:~online-accounts/ubuntu-system-settings-online-accounts/master into lp:ubuntu-system-settings-online-accounts

Proposed by Alberto Mardegan on 2015-02-18
Status: Merged
Approved by: David Barth on 2015-03-20
Approved revision: 234
Merged at revision: 242
Proposed branch: lp:~online-accounts/ubuntu-system-settings-online-accounts/master
Merge into: lp:ubuntu-system-settings-online-accounts
Diff against target: 1002 lines (+687/-31)
19 files modified
.bzrignore (+1/-0)
click-hooks/main.cpp (+28/-6)
debian/changelog (+10/-0)
online-accounts-service/mir-helper-stub.cpp (+9/-0)
online-accounts-service/mir-helper.h (+2/-0)
online-accounts-service/ui-proxy.cpp (+14/-16)
online-accounts-ui/browser-request.cpp (+2/-0)
online-accounts-ui/signonui-request.cpp (+9/-0)
system-settings-plugin/online-accounts.settings (+2/-6)
system-settings-plugin/plugin.cpp (+116/-0)
system-settings-plugin/plugin.h (+36/-0)
system-settings-plugin/system-settings-plugin.pro (+24/-1)
tests/click-hooks/click-hooks.pro (+5/-1)
tests/click-hooks/tst_online_accounts_hooks.cpp (+63/-0)
tests/online-accounts-service/tst_ui_proxy.cpp (+39/-0)
tests/online-accounts-service/tst_ui_proxy.pro (+1/-0)
tests/system-settings-plugin/system-settings-plugin.pro (+32/-0)
tests/system-settings-plugin/tst_plugin.cpp (+292/-0)
tests/tests.pro (+2/-1)
To merge this branch: bzr merge lp:~online-accounts/ubuntu-system-settings-online-accounts/master
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve on 2015-02-23
Online Accounts 2015-02-18 Pending
Review via email: mp+250095@code.launchpad.net

Commit message

Merge from upstream

- Add account data as search keywords (LP: #1373279)
- Delete accounts when their plugin is removed (LP: #1413542)
- More fixes for plugin confinement (LP: #1219644)
- Fail initialization if trust session cannot be setup (LP: #1420847)

Description of the change

Merge from upstream

- Add account data as search keywords (LP: #1373279)
- Delete accounts when their plugin is removed (LP: #1413542)
- More fixes for plugin confinement (LP: #1219644)
- Fail initialization if trust session cannot be setup (LP: #1420847)

To post a comment you must log in.
232. By Alberto Mardegan on 2015-02-18

From trunk

[ CI Train Bot ]
* Fix tests with Qt 5.4
[ Timo Jyrinki ]
* Use qt_gl_set_global_share_context with Qt 5.4 (LP: #1398372) (LP:
  #1398372)

233. By Alberto Mardegan on 2015-02-18

fix version

234. By Alberto Mardegan on 2015-02-23

Disconnect from signal

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2014-12-11 12:51:46 +0000
+++ .bzrignore 2015-02-23 09:45:54 +0000
@@ -57,3 +57,4 @@
57/tests/online-accounts-ui/tst_notification57/tests/online-accounts-ui/tst_notification
58/tests/online-accounts-ui/tst_signonui_request58/tests/online-accounts-ui/tst_signonui_request
59/tests/plugin/tst_application_manager59/tests/plugin/tst_application_manager
60/tests/system-settings-plugin/tst_plugin
6061
=== modified file 'click-hooks/main.cpp'
--- click-hooks/main.cpp 2015-01-21 15:11:36 +0000
+++ click-hooks/main.cpp 2015-02-23 09:45:54 +0000
@@ -217,7 +217,20 @@
217 }217 }
218}218}
219219
220static void removeStaleFiles(const QStringList &fileTypes,220static void removeStaleAccounts(Accounts::Manager *manager,
221 const QString &providerName)
222{
223 Q_FOREACH(Accounts::AccountId id, manager->accountList()) {
224 Accounts::Account *account = manager->account(id);
225 if (account->providerName() == providerName) {
226 account->remove();
227 account->syncAndBlock();
228 }
229 }
230}
231
232static void removeStaleFiles(Accounts::Manager *manager,
233 const QStringList &fileTypes,
221 const QString &localShare,234 const QString &localShare,
222 const QDir &hooksDirIn)235 const QDir &hooksDirIn)
223{236{
@@ -245,8 +258,13 @@
245 * means that the click package was removed, and we must remove our258 * means that the click package was removed, and we must remove our
246 * copy as well. */259 * copy as well. */
247 QString hookFileName = profile + "." + fileType;260 QString hookFileName = profile + "." + fileType;
248 if (!hooksDirIn.exists(hookFileName)) {261 if (hooksDirIn.exists(hookFileName)) continue;
249 QFile::remove(fileInfo.filePath());262
263 QFile::remove(fileInfo.filePath());
264 /* If this is a provider, we must also remove any accounts
265 * associated with it */
266 if (fileType == QStringLiteral("provider")) {
267 removeStaleAccounts(manager, fileInfo.completeBaseName());
250 }268 }
251 }269 }
252 }270 }
@@ -256,6 +274,12 @@
256{274{
257 QCoreApplication app(argc, argv);275 QCoreApplication app(argc, argv);
258276
277 Accounts::Manager::Options managerOptions;
278 if (qgetenv("DBUS_SESSION_BUS_ADDRESS").isEmpty()) {
279 managerOptions |= Accounts::Manager::DisableNotifications;
280 }
281 Accounts::Manager *manager = new Accounts::Manager(managerOptions);
282
259 /* Go through the hook files in ~/.local/share/online-accounts-hooks/ and283 /* Go through the hook files in ~/.local/share/online-accounts-hooks/ and
260 * check if they have already been processed into a file under284 * check if they have already been processed into a file under
261 * ~/.local/share/accounts/{providers,services,service-types,applications}/;285 * ~/.local/share/accounts/{providers,services,service-types,applications}/;
@@ -274,7 +298,7 @@
274 QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);298 QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
275 QDir hooksDirIn(localShare + "/" HOOK_FILES_SUBDIR);299 QDir hooksDirIn(localShare + "/" HOOK_FILES_SUBDIR);
276300
277 removeStaleFiles(fileTypes, localShare, hooksDirIn);301 removeStaleFiles(manager, fileTypes, localShare, hooksDirIn);
278302
279 Q_FOREACH(const QFileInfo &fileInfo, hooksDirIn.entryInfoList()) {303 Q_FOREACH(const QFileInfo &fileInfo, hooksDirIn.entryInfoList()) {
280 const QString fileType = fileInfo.suffix();304 const QString fileType = fileInfo.suffix();
@@ -320,8 +344,6 @@
320 /* To ensure that all the installed services are parsed into344 /* To ensure that all the installed services are parsed into
321 * libaccounts' DB, we enumerate them now.345 * libaccounts' DB, we enumerate them now.
322 */346 */
323 Accounts::Manager *manager =
324 new Accounts::Manager(Accounts::Manager::DisableNotifications);
325 manager->serviceList();347 manager->serviceList();
326 delete manager;348 delete manager;
327349
328350
=== modified file 'debian/changelog'
--- debian/changelog 2015-02-11 06:39:10 +0000
+++ debian/changelog 2015-02-23 09:45:54 +0000
@@ -1,3 +1,13 @@
1ubuntu-system-settings-online-accounts (0.6+15.04.20150211-0ubuntu2) UNRELEASED; urgency=medium
2
3 * Merge from upstream
4 - Add account data as search keywords (LP: #1373279)
5 - Delete accounts when their plugin is removed (LP: #1413542)
6 - More fixes for plugin confinement (LP: #1219644)
7 - Fail initialization if trust session cannot be setup (LP: #1420847)
8
9 -- Alberto Mardegan <alberto.mardegan@canonical.com> Wed, 18 Feb 2015 09:34:01 +0200
10
1ubuntu-system-settings-online-accounts (0.6+15.04.20150211-0ubuntu1) vivid; urgency=medium11ubuntu-system-settings-online-accounts (0.6+15.04.20150211-0ubuntu1) vivid; urgency=medium
212
3 [ CI Train Bot ]13 [ CI Train Bot ]
414
=== modified file 'online-accounts-service/mir-helper-stub.cpp'
--- online-accounts-service/mir-helper-stub.cpp 2014-11-25 13:34:16 +0000
+++ online-accounts-service/mir-helper-stub.cpp 2015-02-23 09:45:54 +0000
@@ -40,7 +40,11 @@
4040
41QString PromptSession::requestSocket()41QString PromptSession::requestSocket()
42{42{
43#ifdef BUILDING_TESTS
44 return QString::fromUtf8(qgetenv("TEST_MIR_HELPER_SOCKET"));
45#else
43 return QString();46 return QString();
47#endif
44}48}
4549
46MirHelper::MirHelper(QObject *parent):50MirHelper::MirHelper(QObject *parent):
@@ -65,5 +69,10 @@
65PromptSessionP MirHelper::createPromptSession(pid_t initiatorPid)69PromptSessionP MirHelper::createPromptSession(pid_t initiatorPid)
66{70{
67 Q_UNUSED(initiatorPid);71 Q_UNUSED(initiatorPid);
72#ifdef BUILDING_TESTS
73 return qgetenv("TEST_MIR_HELPER_FAIL_CREATE").isEmpty() ?
74 PromptSessionP(new PromptSession(0)) : PromptSessionP();
75#else
68 return PromptSessionP();76 return PromptSessionP();
77#endif
69}78}
7079
=== modified file 'online-accounts-service/mir-helper.h'
--- online-accounts-service/mir-helper.h 2014-11-21 13:50:15 +0000
+++ online-accounts-service/mir-helper.h 2015-02-23 09:45:54 +0000
@@ -27,6 +27,7 @@
27namespace OnlineAccountsUi {27namespace OnlineAccountsUi {
2828
29class PromptSessionPrivate;29class PromptSessionPrivate;
30class MirHelper;
30class MirHelperPrivate;31class MirHelperPrivate;
3132
32class PromptSession: public QObject33class PromptSession: public QObject
@@ -45,6 +46,7 @@
45 explicit PromptSession(PromptSessionPrivate *priv);46 explicit PromptSession(PromptSessionPrivate *priv);
4647
47private:48private:
49 friend class MirHelper;
48 friend class MirHelperPrivate;50 friend class MirHelperPrivate;
49 PromptSessionPrivate *d_ptr;51 PromptSessionPrivate *d_ptr;
50 Q_DECLARE_PRIVATE(PromptSession)52 Q_DECLARE_PRIVATE(PromptSession)
5153
=== modified file 'online-accounts-service/ui-proxy.cpp'
--- online-accounts-service/ui-proxy.cpp 2015-02-03 10:21:46 +0000
+++ online-accounts-service/ui-proxy.cpp 2015-02-23 09:45:54 +0000
@@ -225,6 +225,8 @@
225{225{
226 Q_Q(UiProxy);226 Q_Q(UiProxy);
227227
228 if (!m_clientPid) return false;
229
228 PromptSessionP session =230 PromptSessionP session =
229 MirHelper::instance()->createPromptSession(m_clientPid);231 MirHelper::instance()->createPromptSession(m_clientPid);
230 if (!session) return false;232 if (!session) return false;
@@ -246,15 +248,20 @@
246248
247bool UiProxyPrivate::init()249bool UiProxyPrivate::init()
248{250{
249 m_arguments.clear();251 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
250 if (!m_promptSession) {252 if (env.value("QT_QPA_PLATFORM").startsWith("ubuntu")) {
251 /* the first argument is required to be the desktop file */253 if (!setupPromptSession()) {
252 m_arguments.append("--desktop_file_hint=/usr/share/applications/online-accounts-ui.desktop");254 qWarning() << "Couldn't setup prompt session";
255 return false;
256 }
253 }257 }
254258
255 if (m_clientPid) {259 /* We also create ~/cache/online-accounts-ui/, since the plugin might not
256 setupPromptSession();260 * have permissions to do that. */
257 }261 QString userCacheDir =
262 QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation);
263 QDir cacheDir(userCacheDir + "/online-accounts-ui");
264 if (!cacheDir.exists()) cacheDir.mkpath(".");
258265
259 return true;266 return true;
260}267}
@@ -313,15 +320,6 @@
313 m_arguments.prepend(accountsUi);320 m_arguments.prepend(accountsUi);
314 }321 }
315322
316 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
317 if (env.value("QT_QPA_PLATFORM").startsWith("ubuntu")) {
318 if (!setupPromptSession()) {
319 qWarning() << "Couldn't setup prompt session";
320 setStatus(UiProxy::Error);
321 return;
322 }
323 }
324
325 setStatus(UiProxy::Loading);323 setStatus(UiProxy::Loading);
326 m_process.start(processName, m_arguments);324 m_process.start(processName, m_arguments);
327 if (Q_UNLIKELY(!m_process.waitForStarted())) {325 if (Q_UNLIKELY(!m_process.waitForStarted())) {
328326
=== modified file 'online-accounts-ui/browser-request.cpp'
--- online-accounts-ui/browser-request.cpp 2015-01-09 10:12:03 +0000
+++ online-accounts-ui/browser-request.cpp 2015-02-23 09:45:54 +0000
@@ -265,6 +265,8 @@
265 Q_Q(BrowserRequest);265 Q_Q(BrowserRequest);
266266
267 DEBUG() << "Browser dialog closed";267 DEBUG() << "Browser dialog closed";
268 QObject::disconnect(m_dialog, SIGNAL(finished(int)),
269 this, SLOT(onFinished()));
268270
269 QVariantMap reply;271 QVariantMap reply;
270 QUrl url = m_responseUrl.isEmpty() ? m_currentUrl : m_responseUrl;272 QUrl url = m_responseUrl.isEmpty() ? m_currentUrl : m_responseUrl;
271273
=== modified file 'online-accounts-ui/signonui-request.cpp'
--- online-accounts-ui/signonui-request.cpp 2015-01-14 09:31:14 +0000
+++ online-accounts-ui/signonui-request.cpp 2015-02-23 09:45:54 +0000
@@ -33,6 +33,8 @@
33#include <SignOn/uisessiondata.h>33#include <SignOn/uisessiondata.h>
34#include <SignOn/uisessiondata_priv.h>34#include <SignOn/uisessiondata_priv.h>
35#include <sys/apparmor.h>35#include <sys/apparmor.h>
36#include <sys/types.h>
37#include <unistd.h>
3638
37using namespace SignOnUi;39using namespace SignOnUi;
3840
@@ -135,6 +137,13 @@
135 if (profile == "unconfined" &&137 if (profile == "unconfined" &&
136 parameters.contains(SSOUI_KEY_PID)) {138 parameters.contains(SSOUI_KEY_PID)) {
137 pid_t pid = parameters.value(SSOUI_KEY_PID).toUInt();139 pid_t pid = parameters.value(SSOUI_KEY_PID).toUInt();
140 if (pid == getpid()) {
141 /* If the request was initiated by our own process, we might not
142 * have the rights to call the aa_* functions (we might be
143 * confined). */
144 return QString();
145 }
146
138 char *con = NULL, *mode = NULL;147 char *con = NULL, *mode = NULL;
139 int ret = aa_gettaskcon(pid, &con, &mode);148 int ret = aa_gettaskcon(pid, &con, &mode);
140 if (Q_LIKELY(ret >= 0)) {149 if (Q_LIKELY(ret >= 0)) {
141150
=== modified file 'system-settings-plugin/online-accounts.settings'
--- system-settings-plugin/online-accounts.settings 2014-09-24 19:05:32 +0000
+++ system-settings-plugin/online-accounts.settings 2015-02-23 09:45:54 +0000
@@ -14,14 +14,10 @@
14 "access",14 "access",
15 "authorize",15 "authorize",
16 "revoke",16 "revoke",
17 "web",17 "web"
18 "facebook",
19 "twitter",
20 "flickr",
21 "google",
22 "gmail"
23 ],18 ],
24 "has-dynamic-keywords": true,19 "has-dynamic-keywords": true,
25 "has-dynamic-visibility": false,20 "has-dynamic-visibility": false,
21 "plugin": "online-accounts",
26 "page-component": "MainPage.qml"22 "page-component": "MainPage.qml"
27}23}
2824
=== added file 'system-settings-plugin/plugin.cpp'
--- system-settings-plugin/plugin.cpp 1970-01-01 00:00:00 +0000
+++ system-settings-plugin/plugin.cpp 2015-02-23 09:45:54 +0000
@@ -0,0 +1,116 @@
1/*
2 * Copyright (C) 2015 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "plugin.h"
20
21#include <Accounts/Account>
22#include <Accounts/Manager>
23#include <Accounts/Provider>
24#include <Accounts/Service>
25#include <QDebug>
26#include <QStringList>
27#include <SystemSettings/ItemBase>
28#include <libintl.h>
29
30using namespace SystemSettings;
31
32class Item: public ItemBase
33{
34 Q_OBJECT
35
36public:
37 Item(const QVariantMap &staticData, QObject *parent = 0);
38 ~Item();
39
40private:
41 void computeKeywords();
42};
43
44Item::Item(const QVariantMap &staticData, QObject *parent):
45 ItemBase(staticData, parent)
46{
47 computeKeywords();
48}
49
50Item::~Item()
51{
52}
53
54static QStringList translations(const QString &text, const QString &domain)
55{
56 /* Return a list of keywords based on a translatable name:
57 * - the untranslated text (lowercase, split into words)
58 * - the translated text (lowercase, split into words)
59 */
60 QStringList keys;
61 keys = text.toLower().split(" ", QString::SkipEmptyParts);
62 if (!domain.isEmpty()) {
63 QByteArray baText = text.toUtf8();
64 QByteArray baDomain = domain.toUtf8();
65 QString translated = QString::fromUtf8(dgettext(baDomain.constData(),
66 baText.constData()));
67 if (translated != text) {
68 keys.append(translated.toLower().split(" ",
69 QString::SkipEmptyParts));
70 }
71 }
72 return keys;
73}
74
75void Item::computeKeywords()
76{
77 Accounts::Manager *manager = new Accounts::Manager;
78
79 QStringList keywords;
80
81 /* List available providers, and add their names to the search keywords */
82 Q_FOREACH(const Accounts::Provider &provider, manager->providerList()) {
83 keywords.append(provider.name().toLower());
84 keywords.append(translations(provider.displayName(),
85 provider.trCatalog()));
86 }
87
88 /* Same for services */
89 Q_FOREACH(const Accounts::Service &service, manager->serviceList()) {
90 keywords.append(service.name().toLower());
91 keywords.append(translations(service.displayName(),
92 service.trCatalog()));
93 }
94
95 /* Also add the account display names */
96 Q_FOREACH(Accounts::AccountId id, manager->accountList()) {
97 Accounts::Account *account = manager->account(id);
98 if (Q_UNLIKELY(!account)) continue;
99 QString name = account->displayName().toLower();
100 if (!name.isEmpty()) {
101 keywords.append(name);
102 }
103 }
104
105 delete manager;
106
107 setKeywords(keywords);
108}
109
110ItemBase *Plugin::createItem(const QVariantMap &staticData,
111 QObject *parent)
112{
113 return new Item(staticData, parent);
114}
115
116#include "plugin.moc"
0117
=== added file 'system-settings-plugin/plugin.h'
--- system-settings-plugin/plugin.h 1970-01-01 00:00:00 +0000
+++ system-settings-plugin/plugin.h 2015-02-23 09:45:54 +0000
@@ -0,0 +1,36 @@
1/*
2 * Copyright (C) 2015 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 3, as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranties of
12 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef ONLINE_ACCOUNTS_SYSTEM_SETTINGS_PLUGIN_H
20#define ONLINE_ACCOUNTS_SYSTEM_SETTINGS_PLUGIN_H
21
22#include <QObject>
23#include <SystemSettings/PluginInterface>
24
25class Plugin: public QObject, public SystemSettings::PluginInterface2
26{
27 Q_OBJECT
28 Q_PLUGIN_METADATA(IID "com.ubuntu.SystemSettings.PluginInterface/2.0")
29 Q_INTERFACES(SystemSettings::PluginInterface2)
30
31public:
32 SystemSettings::ItemBase *createItem(const QVariantMap &staticData,
33 QObject *parent = 0);
34};
35
36#endif // ONLINE_ACCOUNTS_SYSTEM_SETTINGS_PLUGIN_H
037
=== modified file 'system-settings-plugin/system-settings-plugin.pro'
--- system-settings-plugin/system-settings-plugin.pro 2014-08-13 13:11:06 +0000
+++ system-settings-plugin/system-settings-plugin.pro 2015-02-23 09:45:54 +0000
@@ -1,7 +1,27 @@
1include(../common-project-config.pri)1include(../common-project-config.pri)
2include($${TOP_SRC_DIR}/common-vars.pri)2include($${TOP_SRC_DIR}/common-vars.pri)
33
4TEMPLATE=aux4TEMPLATE=lib
5TARGET = online-accounts
6
7CONFIG += \
8 link_pkgconfig \
9 plugin \
10 qt
11
12QT += \
13 core \
14 qml
15
16PKGCONFIG += \
17 SystemSettings \
18 accounts-qt5
19
20SOURCES += \
21 plugin.cpp
22
23HEADERS += \
24 plugin.h
525
6QML_SOURCES = \26QML_SOURCES = \
7 AccountEditPage.qml \27 AccountEditPage.qml \
@@ -19,6 +39,9 @@
19settings.path = $${PLUGIN_MANIFEST_DIR}39settings.path = $${PLUGIN_MANIFEST_DIR}
20INSTALLS += settings40INSTALLS += settings
2141
42target.path = $${PLUGIN_MODULE_DIR}
43INSTALLS += target
44
22image.files = settings-accounts.svg45image.files = settings-accounts.svg
23image.path = $${PLUGIN_MANIFEST_DIR}/icons46image.path = $${PLUGIN_MANIFEST_DIR}/icons
24INSTALLS += image47INSTALLS += image
2548
=== modified file 'tests/click-hooks/click-hooks.pro'
--- tests/click-hooks/click-hooks.pro 2014-05-16 09:42:06 +0000
+++ tests/click-hooks/click-hooks.pro 2015-02-23 09:45:54 +0000
@@ -3,13 +3,17 @@
3TARGET = tst_online_accounts_hooks3TARGET = tst_online_accounts_hooks
44
5CONFIG += \5CONFIG += \
6 debug6 debug \
7 link_pkgconfig
78
8QT += \9QT += \
9 core \10 core \
10 testlib \11 testlib \
11 xml12 xml
1213
14PKGCONFIG += \
15 accounts-qt5
16
13DEFINES += \17DEFINES += \
14 DEBUG_ENABLED \18 DEBUG_ENABLED \
15 HOOK_PROCESS=\\\"../../click-hooks/online-accounts-hooks\\\"19 HOOK_PROCESS=\\\"../../click-hooks/online-accounts-hooks\\\"
1620
=== modified file 'tests/click-hooks/tst_online_accounts_hooks.cpp'
--- tests/click-hooks/tst_online_accounts_hooks.cpp 2014-11-04 12:26:46 +0000
+++ tests/click-hooks/tst_online_accounts_hooks.cpp 2015-02-23 09:45:54 +0000
@@ -18,6 +18,8 @@
18 * with this program. If not, see <http://www.gnu.org/licenses/>.18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */19 */
2020
21#include <Accounts/Account>
22#include <Accounts/Manager>
21#include <QDebug>23#include <QDebug>
22#include <QDir>24#include <QDir>
23#include <QDomDocument>25#include <QDomDocument>
@@ -42,6 +44,7 @@
42 void testValidHooks_data();44 void testValidHooks_data();
43 void testValidHooks();45 void testValidHooks();
44 void testRemoval();46 void testRemoval();
47 void testAccountRemoval();
45 void testUpdate();48 void testUpdate();
46 void testDesktopEntry_data();49 void testDesktopEntry_data();
47 void testDesktopEntry();50 void testDesktopEntry();
@@ -139,6 +142,8 @@
139{142{
140 qputenv("XDG_DATA_HOME", TEST_DIR);143 qputenv("XDG_DATA_HOME", TEST_DIR);
141 qputenv("OAH_CLICK_DIR", m_packageDir.path().toUtf8());144 qputenv("OAH_CLICK_DIR", m_packageDir.path().toUtf8());
145 qputenv("ACCOUNTS", TEST_DIR);
146
142 // The hook must be able to run without a D-Bus session147 // The hook must be able to run without a D-Bus session
143 qunsetenv("DBUS_SESSION_BUS_ADDRESS");148 qunsetenv("DBUS_SESSION_BUS_ADDRESS");
144149
@@ -377,6 +382,64 @@
377 QVERIFY(m_installDir.exists(noProfile));382 QVERIFY(m_installDir.exists(noProfile));
378}383}
379384
385void OnlineAccountsHooksTest::testAccountRemoval()
386{
387 clearHooksDir();
388 clearInstallDir();
389
390 Accounts::Manager *manager =
391 new Accounts::Manager(Accounts::Manager::DisableNotifications);
392
393 QString stillInstalled("providers/com.ubuntu.test_StillInstalled.provider");
394 writeInstalledFile(stillInstalled,
395 "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
396 "<provider>\n"
397 " <profile>com-ubuntu.test_StillInstalled_2.0</profile>\n"
398 "</provider>");
399 QVERIFY(m_installDir.exists(stillInstalled));
400
401 writeHookFile("com-ubuntu.test_StillInstalled_2.0.provider",
402 "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
403 "<provider>\n"
404 "</provider>");
405
406 Accounts::Account *account =
407 manager->createAccount("com.ubuntu.test_StillInstalled");
408 account->setDisplayName("Still alive");
409 account->syncAndBlock();
410 Accounts::AccountId idPreserved = account->id();
411 QVERIFY(idPreserved > 0);
412
413 QString myProvider("providers/com.ubuntu.test_MyProvider.provider");
414 writeInstalledFile(myProvider,
415 "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
416 "<provider>\n"
417 " <profile>com-ubuntu.test_MyProvider_3.0</profile>\n"
418 "</provider>");
419 QVERIFY(m_installDir.exists(myProvider));
420
421 account = manager->createAccount("com.ubuntu.test_MyProvider");
422 account->setDisplayName("Must die");
423 account->syncAndBlock();
424 Accounts::AccountId idRemoved = account->id();
425 QVERIFY(idRemoved > 0);
426
427 delete manager;
428
429 QVERIFY(runHookProcess());
430
431 QVERIFY(m_installDir.exists(stillInstalled));
432 QVERIFY(!m_installDir.exists(myProvider));
433
434 manager = new Accounts::Manager(Accounts::Manager::DisableNotifications);
435 account = manager->account(idPreserved);
436 QVERIFY(account != 0);
437 account = manager->account(idRemoved);
438 QVERIFY(account == 0);
439
440 delete manager;
441}
442
380void OnlineAccountsHooksTest::testUpdate()443void OnlineAccountsHooksTest::testUpdate()
381{444{
382 clearHooksDir();445 clearHooksDir();
383446
=== modified file 'tests/online-accounts-service/tst_ui_proxy.cpp'
--- tests/online-accounts-service/tst_ui_proxy.cpp 2014-12-03 13:42:09 +0000
+++ tests/online-accounts-service/tst_ui_proxy.cpp 2015-02-23 09:45:54 +0000
@@ -204,6 +204,8 @@
204 void testRequestDelay();204 void testRequestDelay();
205 void testHandler();205 void testHandler();
206 void testWrapper();206 void testWrapper();
207 void testTrustSessionError_data();
208 void testTrustSessionError();
207209
208private:210private:
209 QDBusConnection m_connection;211 QDBusConnection m_connection;
@@ -477,6 +479,43 @@
477 delete proxy;479 delete proxy;
478}480}
479481
482void UiProxyTest::testTrustSessionError_data()
483{
484 QTest::addColumn<int>("clientPid");
485 QTest::addColumn<QString>("envVar");
486 QTest::addColumn<bool>("expectSuccess");
487
488 QTest::newRow("PID 0") << 0 << "" << false;
489
490 QTest::newRow("fail creation") << 4 <<
491 "TEST_MIR_HELPER_FAIL_CREATE=1" << false;
492
493 QTest::newRow("return empty socket") << 4 <<
494 "" << false;
495
496 QTest::newRow("success") << 4 <<
497 "TEST_MIR_HELPER_SOCKET=something" << true;
498}
499
500void UiProxyTest::testTrustSessionError()
501{
502 QFETCH(int, clientPid);
503 QFETCH(QString, envVar);
504 QFETCH(bool, expectSuccess);
505
506 qputenv("QT_QPA_PLATFORM", "ubuntu-something");
507
508 QStringList envVarSplit = envVar.split('=');
509 QByteArray envVarKey = envVarSplit.value(0, "").toUtf8();
510 QByteArray envVarValue = envVarSplit.value(1, "").toUtf8();
511 qputenv(envVarKey.constData(), envVarValue);
512 UiProxy *proxy = new UiProxy(clientPid, this);
513 QCOMPARE(proxy->init(), expectSuccess);
514 delete proxy;
515
516 qunsetenv(envVarKey.constData());
517}
518
480QTEST_MAIN(UiProxyTest);519QTEST_MAIN(UiProxyTest);
481520
482#include "tst_ui_proxy.moc"521#include "tst_ui_proxy.moc"
483522
=== modified file 'tests/online-accounts-service/tst_ui_proxy.pro'
--- tests/online-accounts-service/tst_ui_proxy.pro 2014-12-08 16:22:39 +0000
+++ tests/online-accounts-service/tst_ui_proxy.pro 2015-02-23 09:45:54 +0000
@@ -13,6 +13,7 @@
13 testlib13 testlib
1414
15DEFINES += \15DEFINES += \
16 BUILDING_TESTS \
16 INSTALL_BIN_DIR=\\\"$${INSTALL_PREFIX}/bin\\\"17 INSTALL_BIN_DIR=\\\"$${INSTALL_PREFIX}/bin\\\"
1718
18PKGCONFIG += \19PKGCONFIG += \
1920
=== added directory 'tests/system-settings-plugin'
=== added file 'tests/system-settings-plugin/system-settings-plugin.pro'
--- tests/system-settings-plugin/system-settings-plugin.pro 1970-01-01 00:00:00 +0000
+++ tests/system-settings-plugin/system-settings-plugin.pro 2015-02-23 09:45:54 +0000
@@ -0,0 +1,32 @@
1include(../../common-project-config.pri)
2
3TARGET = tst_plugin
4
5CONFIG += \
6 debug \
7 link_pkgconfig
8
9QT += \
10 core \
11 qml \
12 testlib
13
14PKGCONFIG += \
15 SystemSettings \
16 accounts-qt5
17
18SYSTEM_SETTINGS_PLUGIN_DIR = $${TOP_SRC_DIR}/system-settings-plugin
19
20INCLUDEPATH += \
21 $${SYSTEM_SETTINGS_PLUGIN_DIR}
22
23SOURCES += \
24 $${SYSTEM_SETTINGS_PLUGIN_DIR}/plugin.cpp \
25 tst_plugin.cpp
26
27HEADERS += \
28 $${SYSTEM_SETTINGS_PLUGIN_DIR}/plugin.h
29
30check.commands = "xvfb-run -s '-screen 0 640x480x24' -a dbus-test-runner -t ./$${TARGET}"
31check.depends = $${TARGET}
32QMAKE_EXTRA_TARGETS += check
033
=== added file 'tests/system-settings-plugin/tst_plugin.cpp'
--- tests/system-settings-plugin/tst_plugin.cpp 1970-01-01 00:00:00 +0000
+++ tests/system-settings-plugin/tst_plugin.cpp 2015-02-23 09:45:54 +0000
@@ -0,0 +1,292 @@
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
5 *
6 * This file is part of online-accounts-ui
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <Accounts/Account>
22#include <Accounts/Manager>
23
24#include <QDebug>
25#include <QDir>
26#include <QDomDocument>
27#include <QDomElement>
28#include <QFile>
29#include <QSignalSpy>
30#include <QTemporaryDir>
31#include <QTest>
32
33#include <SystemSettings/ItemBase>
34
35#include "plugin.h"
36
37namespace QTest {
38template<>
39char *toString(const QSet<QString> &set)
40{
41 QByteArray ba = "QSet<QString>(";
42 QStringList list = set.toList();
43 ba += list.join(", ");
44 ba += ")";
45 return qstrdup(ba.data());
46}
47} // QTest namespace
48
49/* mocking libintl { */
50static QHash<QString,QHash<QByteArray,QByteArray> > m_translations;
51extern "C" {
52char *dgettext(const char *domainname, const char *msgid)
53{
54 return (char *)m_translations[domainname].value(msgid).data();
55}
56char *dcgettext(const char *__domainname, const char *__msgid, int __category)
57{
58 Q_UNUSED(__category);
59 return dgettext(__domainname, __msgid);
60}
61} // extern C
62/* } mocking libintl */
63
64class PluginTest: public QObject
65{
66 Q_OBJECT
67
68 struct FileData {
69 FileData() {}
70 FileData(const QString &name, const QString &domain):
71 name(name), domain(domain) {}
72 QString name;
73 QString domain;
74 };
75
76public:
77 PluginTest();
78
79private Q_SLOTS:
80 void testKeywords_data();
81 void testKeywords();
82
83private:
84 void setDataDir(const QTemporaryDir &dir);
85 void writeProvider(const QString &id, const QString &name,
86 const QString &domain);
87 void writeService(const QString &id, const QString &name,
88 const QString &domain);
89 void writeLibaccountsFile(const QString &type, const QString &id,
90 const QString &name, const QString &domain);
91 void createAccount(const QString &name);
92
93private:
94 QHash<QString,FileData> m_providersData;
95 QHash<QString,FileData> m_servicesData;
96 QDir m_dataDir;
97};
98
99PluginTest::PluginTest():
100 QObject(0)
101{
102 m_providersData["provider_noname"] = FileData("", "");
103 m_providersData["provider_nodomain"] = FileData("Happy", "");
104 m_providersData["provider_translated"] = FileData("Joyful", "translations1");
105
106 m_servicesData["service_nodomain"] = FileData("Sad", "");
107 m_servicesData["service_translated"] = FileData("Depressed", "translations1");
108 m_servicesData["service_translated2"] = FileData("Depressed", "translations2");
109
110 m_translations["translations1"]["Happy"] = "Contento";
111 m_translations["translations1"]["Joyful"] = "Gioioso";
112 m_translations["translations1"]["Sad"] = "Triste";
113 m_translations["translations1"]["Depressed"] = "Depresso1";
114 m_translations["translations1"]["Black"] = "Nero";
115 m_translations["translations1"]["White"] = "Bianco";
116
117 m_translations["translations2"]["Depressed"] = "Depresso2";
118}
119
120void PluginTest::setDataDir(const QTemporaryDir &dir)
121{
122 QVERIFY(dir.isValid());
123
124 m_dataDir = QDir(dir.path());
125
126 QByteArray dataPath = dir.path().toUtf8();
127 qputenv("ACCOUNTS", dataPath);
128 qputenv("AG_PROVIDERS", dataPath);
129 qputenv("AG_SERVICES", dataPath);
130}
131
132void PluginTest::writeProvider(const QString &id, const QString &name,
133 const QString &domain)
134{
135 writeLibaccountsFile("provider", id, name, domain);
136}
137
138void PluginTest::writeService(const QString &id, const QString &name,
139 const QString &domain)
140{
141 writeLibaccountsFile("service", id, name, domain);
142}
143
144void PluginTest::writeLibaccountsFile(const QString &type, const QString &id,
145 const QString &name, const QString &domain)
146{
147 QDomDocument doc;
148 QDomElement root = doc.createElement(type);
149 root.setAttribute("id", id);
150 doc.appendChild(root);
151
152 QDomElement nameTag = doc.createElement("name");
153 nameTag.appendChild(doc.createTextNode(name));
154 root.appendChild(nameTag);
155
156 QDomElement domainTag = doc.createElement("translations");
157 domainTag.appendChild(doc.createTextNode(domain));
158 root.appendChild(domainTag);
159
160 if (type == "service") {
161 QDomElement typeTag = doc.createElement("type");
162 typeTag.appendChild(doc.createTextNode("something"));
163 root.appendChild(typeTag);
164 }
165
166 QFile file(m_dataDir.filePath(id + "." + type));
167 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
168 qWarning() << "Could not write file" << file.fileName();
169 return;
170 }
171
172 file.write(doc.toString().toUtf8());
173}
174
175void PluginTest::createAccount(const QString &name)
176{
177 Accounts::Manager *manager = new Accounts::Manager;
178
179 Accounts::Account *account = manager->createAccount("any");
180 account->setDisplayName(name);
181 account->syncAndBlock();
182
183 delete manager;
184}
185
186void PluginTest::testKeywords_data()
187{
188 QTest::addColumn<QStringList>("providers");
189 QTest::addColumn<QStringList>("services");
190 QTest::addColumn<QStringList>("accountNames");
191 QTest::addColumn<QStringList>("keywords");
192
193 QTest::newRow("provider, no name") <<
194 (QStringList() << "provider_noname") <<
195 QStringList() <<
196 QStringList() <<
197 (QStringList() << "provider_noname");
198
199 QTest::newRow("provider, untranslated") <<
200 (QStringList() << "provider_nodomain") <<
201 QStringList() <<
202 QStringList() <<
203 (QStringList() << "provider_nodomain" << "happy");
204
205 QTest::newRow("provider, translated") <<
206 (QStringList() << "provider_translated") <<
207 QStringList() <<
208 QStringList() <<
209 (QStringList() << "provider_translated" << "joyful" << "gioioso");
210
211 QTest::newRow("service, untranslated") <<
212 QStringList() <<
213 (QStringList() << "service_nodomain") <<
214 QStringList() <<
215 (QStringList() << "service_nodomain" << "sad");
216
217 QTest::newRow("service, translated 1") <<
218 QStringList() <<
219 (QStringList() << "service_translated") <<
220 QStringList() <<
221 (QStringList() << "service_translated" << "depressed" << "depresso1");
222
223 QTest::newRow("service, translated 2") <<
224 QStringList() <<
225 (QStringList() << "service_translated2") <<
226 QStringList() <<
227 (QStringList() << "service_translated2" << "depressed" << "depresso2");
228
229 QTest::newRow("one account, one word") <<
230 QStringList() <<
231 QStringList() <<
232 (QStringList() << "tom@example.com") <<
233 (QStringList() << "tom@example.com");
234
235 QTest::newRow("one account, many words") <<
236 QStringList() <<
237 QStringList() <<
238 (QStringList() << "My little sweet account") <<
239 (QStringList() << "my little sweet account");
240
241 QTest::newRow("combined") <<
242 (QStringList() << "provider_translated" << "provider_nodomain") <<
243 (QStringList() << "service_translated" << "service_translated2") <<
244 (QStringList() << "john@invalid" << "harry@mysite.com") <<
245 (QStringList() << "provider_translated" << "joyful" << "gioioso" <<
246 "provider_nodomain" << "happy" <<
247 "service_translated" << "depressed" << "depresso1" <<
248 "service_translated2" << "depressed" << "depresso2" <<
249 "john@invalid" << "harry@mysite.com");
250}
251
252void PluginTest::testKeywords()
253{
254 QFETCH(QStringList, providers);
255 QFETCH(QStringList, services);
256 QFETCH(QStringList, accountNames);
257 QFETCH(QStringList, keywords);
258
259 QTemporaryDir dataDir;
260
261 setDataDir(dataDir);
262
263 /* Create the needed files */
264 Q_FOREACH(const QString &providerId, providers) {
265 writeProvider(providerId,
266 m_providersData[providerId].name,
267 m_providersData[providerId].domain);
268 }
269
270 Q_FOREACH(const QString &serviceId, services) {
271 writeService(serviceId,
272 m_servicesData[serviceId].name,
273 m_servicesData[serviceId].domain);
274 }
275
276 /* create the accounts */
277 Q_FOREACH(const QString &displayName, accountNames) {
278 createAccount(displayName);
279 }
280
281 /* Now do the actual test */
282 Plugin plugin;
283
284 SystemSettings::ItemBase *item = plugin.createItem(QVariantMap());
285 QStringList pluginKeywords = item->keywords();
286
287 QCOMPARE(pluginKeywords.toSet(), keywords.toSet());
288}
289
290QTEST_MAIN(PluginTest);
291
292#include "tst_plugin.moc"
0293
=== modified file 'tests/tests.pro'
--- tests/tests.pro 2014-10-03 14:56:11 +0000
+++ tests/tests.pro 2015-02-23 09:45:54 +0000
@@ -5,4 +5,5 @@
5 client \5 client \
6 online-accounts-service \6 online-accounts-service \
7 online-accounts-ui \7 online-accounts-ui \
8 plugin8 plugin \
9 system-settings-plugin

Subscribers

People subscribed via source and target branches

to all changes: