on d28fa91 help sign in
228 lines 9.7 kB history raw
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Michael Terry <michael.terry@canonical.com>
18 */
20#include "AccountsService.h"
21#include "AccountsServiceDBusAdaptor.h"
22#include <QSignalSpy>
23#include <QTest>
24#include <QDebug>
25#include <QDBusReply>
27template <class T>
28QVariant dbusVariant(const T& value) { return QVariant::fromValue(QDBusVariant(value)); }
30#define ASSERT_DBUS_CALL(call) \
31 { \
32 QDBusReply<void> reply = call; \
33 if (!reply.isValid()) QFAIL(reply.error().message().toLatin1()); \
34 }
36class AccountsServiceTest : public QObject
38 Q_OBJECT
40public:
41 AccountsServiceTest(QObject* parent = 0)
42 : QObject(parent)
43 , m_userInterface(nullptr)
44 , m_spy(this, &AccountsServiceTest::propertiesChanged)
45 {
46 }
48private Q_SLOTS:
50 void init() {
51 QDBusReply<bool> addReply = QDBusInterface("org.freedesktop.Accounts",
52 "/org/freedesktop/Accounts",
53 "org.freedesktop.Accounts").call("AddUser", QTest::currentTestFunction());
54 QVERIFY(addReply.isValid());
55 QCOMPARE(addReply.value(), true);
57 m_userInterface = new QDBusInterface("org.freedesktop.Accounts",
58 QString("/%1").arg(QTest::currentTestFunction()),
59 "org.freedesktop.DBus.Properties", QDBusConnection::sessionBus(), this);
61 QVERIFY(QObject::connect(m_userInterface, SIGNAL(PropertiesChanged(QString, QVariantMap, QStringList)),
62 this, SIGNAL(propertiesChanged(QString, QVariantMap, QStringList))));
63 }
65 void cleanup() {
66 QDBusReply<bool> reply = QDBusInterface("org.freedesktop.Accounts",
67 "/org/freedesktop/Accounts",
68 "org.freedesktop.Accounts").call("RemoveUser", QTest::currentTestFunction());
69 QVERIFY(reply.isValid());
70 QCOMPARE(reply.value(), true);
72 delete m_userInterface;
73 m_spy.clear();
74 }
76 void testInvalids()
77 {
78 // Test various invalid calls
79 AccountsServiceDBusAdaptor session;
80 QCOMPARE(session.getUserPropertyAsync("NOPE", "com.canonical.unity.AccountsService", "demo-edges").value(), QVariant());
81 QCOMPARE(session.getUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "NOPE").value(), QVariant());
82 }
84 void testGetSetServiceDBusAdaptor()
85 {
86 AccountsServiceDBusAdaptor session;
87 session.setUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges", QVariant(true)).waitForFinished();
88 QCOMPARE(session.getUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges").value(), QVariant(true));
89 session.setUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges", QVariant(false)).waitForFinished();
90 QCOMPARE(session.getUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges").value(), QVariant(false));
91 }
93 void testGetSetService()
94 {
95 AccountsService session(this, QTest::currentTestFunction());
97 QCOMPARE(session.demoEdges(), false);
98 session.setDemoEdges(true);
99 QCOMPARE(session.demoEdges(), true);
101 QCOMPARE(session.failedLogins(), (uint)0);
102 session.setFailedLogins(5);
103 QCOMPARE(session.failedLogins(), (uint)5);
105 QCOMPARE(session.hereEnabled(), false);
106 session.setHereEnabled(true);
107 QCOMPARE(session.hereEnabled(), true);
108 }
110 void testAsynchornousChangeForDemoEdges()
111 {
112 AccountsService session(this, QTest::currentTestFunction());
114 QCOMPARE(session.demoEdges(), false);
115 ASSERT_DBUS_CALL(m_userInterface->call("Set",
116 "com.canonical.unity.AccountsService",
117 "demo-edges",
118 dbusVariant(true)));
119 QTRY_COMPARE(session.demoEdges(), true);
120 }
122 void testAsynchornousChangeForFailedLogins()
123 {
124 AccountsService session(this, QTest::currentTestFunction());
126 QCOMPARE(session.failedLogins(), (uint)0);
127 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
128 "com.canonical.unity.AccountsService.Private",
129 "FailedLogins",
130 dbusVariant(5)));
131 QTRY_COMPARE(session.failedLogins(), (uint)5);
132 }
134 void testAsynchornousChangeForStatsWelcomeScreen()
135 {
136 AccountsService session(this, QTest::currentTestFunction());
138 QCOMPARE(session.statsWelcomeScreen(), true);
139 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
140 "com.ubuntu.touch.AccountsService.SecurityPrivacy",
141 "StatsWelcomeScreen",
142 dbusVariant(false)));
143 QTRY_COMPARE(session.statsWelcomeScreen(), false);
144 }
146 void testAsynchornousChangeForStatsEnableLauncherWhileLocked()
147 {
148 AccountsService session(this, QTest::currentTestFunction());
150 QCOMPARE(session.enableLauncherWhileLocked(), true);
151 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
152 "com.ubuntu.AccountsService.SecurityPrivacy",
153 "EnableLauncherWhileLocked",
154 dbusVariant(false)));
155 QTRY_COMPARE(session.enableLauncherWhileLocked(), false);
156 }
158 void testAsynchornousChangeForStatsEnableIndicatorsWhileLocked()
159 {
160 AccountsService session(this, QTest::currentTestFunction());
162 QCOMPARE(session.enableIndicatorsWhileLocked(), true);
163 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
164 "com.ubuntu.AccountsService.SecurityPrivacy",
165 "EnableIndicatorsWhileLocked",
166 dbusVariant(false)));
167 QTRY_COMPARE(session.enableIndicatorsWhileLocked(), false);
168 }
170 void testAsynchornousChangeForStatsPasswordDisplayHint()
171 {
172 AccountsService session(this, QTest::currentTestFunction());
174 QCOMPARE(session.passwordDisplayHint(), AccountsService::Keyboard);
175 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
176 "com.ubuntu.AccountsService.SecurityPrivacy",
177 "PasswordDisplayHint",
178 dbusVariant(AccountsService::Numeric)));
179 QTRY_COMPARE(session.passwordDisplayHint(), AccountsService::Numeric);
180 }
182 void testAsynchornousChangeForStatsLicenseAccepted()
183 {
184 AccountsService session(this, QTest::currentTestFunction());
186 QCOMPARE(session.hereEnabled(), false);
187 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
188 "com.ubuntu.location.providers.here.AccountsService",
189 "LicenseAccepted",
190 dbusVariant(true)));
191 QTRY_COMPARE(session.hereEnabled(), true);
192 }
194 void testAsynchornousChangeForLicenseBasePath()
195 {
196 AccountsService session(this, QTest::currentTestFunction());
198 QCOMPARE(session.hereLicensePath(), QString());
199 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
200 "com.ubuntu.location.providers.here.AccountsService",
201 "LicenseBasePath",
202 dbusVariant("/")));
203 QTRY_COMPARE(session.hereLicensePath(), QString("/"));
204 }
206 void testAsynchornousChangeForStatsBackgroundFile()
207 {
208 AccountsService session(this, QTest::currentTestFunction());
210 QCOMPARE(session.backgroundFile(), QString());
211 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
212 "org.freedesktop.Accounts.User",
213 "BackgroundFile",
214 dbusVariant("/test/BackgroundFile")));
215 QTRY_COMPARE(session.backgroundFile(), QString("/test/BackgroundFile"));
216 }
218Q_SIGNALS:
219 void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalid);
221private:
222 QDBusInterface* m_userInterface;
223 QSignalSpy m_spy;
224};
226QTEST_MAIN(AccountsServiceTest)
228#include "client.moc"