on 1cf027f help sign in
240 lines 9.9 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);
60 QDBusReply<void> resetReply = m_userInterface->call("Reset");
61 QVERIFY(resetReply.isValid());
63 QVERIFY(QObject::connect(m_userInterface, SIGNAL(PropertiesChanged(QString, QVariantMap, QStringList)),
64 this, SIGNAL(propertiesChanged(QString, QVariantMap, QStringList))));
65 }
67 void cleanup() {
68 QDBusReply<bool> reply = QDBusInterface("org.freedesktop.Accounts",
69 "/org/freedesktop/Accounts",
70 "org.freedesktop.Accounts").call("RemoveUser", QTest::currentTestFunction());
71 QVERIFY(reply.isValid());
72 QCOMPARE(reply.value(), true);
74 delete m_userInterface;
75 m_spy.clear();
76 }
78 void testInvalids()
79 {
80 // Test various invalid calls
81 AccountsServiceDBusAdaptor session;
82 QCOMPARE(session.getUserProperty("NOPE", "com.canonical.unity.AccountsService", "demo-edges"), QVariant());
83 QCOMPARE(session.getUserProperty(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "NOPE"), QVariant());
84 }
86 void testGetSetServiceDBusAdaptor()
87 {
88 AccountsServiceDBusAdaptor session;
89 session.setUserProperty(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges", QVariant(true));
90 QCOMPARE(session.getUserProperty(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges"), QVariant(true));
91 session.setUserProperty(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges", QVariant(false));
92 QCOMPARE(session.getUserProperty(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges"), QVariant(false));
93 }
95 void testGetSetService()
96 {
97 AccountsService session;
98 session.setUser(QTest::currentTestFunction());
100 QCOMPARE(session.demoEdges(), false);
101 session.setDemoEdges(true);
102 QCOMPARE(session.demoEdges(), true);
104 QCOMPARE(session.failedLogins(), (uint)0);
105 session.setFailedLogins(5);
106 QCOMPARE(session.failedLogins(), (uint)5);
108 QCOMPARE(session.hereEnabled(), false);
109 session.setHereEnabled(true);
110 QCOMPARE(session.hereEnabled(), true);
111 }
113 void testAsynchornousChangeForDemoEdges()
114 {
115 AccountsService session;
116 session.setUser(QTest::currentTestFunction());
118 QCOMPARE(session.demoEdges(), false);
119 ASSERT_DBUS_CALL(m_userInterface->call("Set",
120 "com.canonical.unity.AccountsService",
121 "demo-edges",
122 dbusVariant(true)));
123 QTRY_COMPARE(session.demoEdges(), true);
124 }
126 void testAsynchornousChangeForFailedLogins()
127 {
128 AccountsService session;
129 session.setUser(QTest::currentTestFunction());
131 QCOMPARE(session.failedLogins(), (uint)0);
132 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
133 "com.canonical.unity.AccountsService.Private",
134 "FailedLogins",
135 dbusVariant(5)));
136 QTRY_COMPARE(session.failedLogins(), (uint)5);
137 }
139 void testAsynchornousChangeForStatsWelcomeScreen()
140 {
141 AccountsService session;
142 session.setUser(QTest::currentTestFunction());
144 QCOMPARE(session.statsWelcomeScreen(), true);
145 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
146 "com.ubuntu.touch.AccountsService.SecurityPrivacy",
147 "StatsWelcomeScreen",
148 dbusVariant(false)));
149 QTRY_COMPARE(session.statsWelcomeScreen(), false);
150 }
152 void testAsynchornousChangeForStatsEnableLauncherWhileLocked()
153 {
154 AccountsService session;
155 session.setUser(QTest::currentTestFunction());
157 QCOMPARE(session.enableLauncherWhileLocked(), true);
158 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
159 "com.ubuntu.AccountsService.SecurityPrivacy",
160 "EnableLauncherWhileLocked",
161 dbusVariant(false)));
162 QTRY_COMPARE(session.enableLauncherWhileLocked(), false);
163 }
165 void testAsynchornousChangeForStatsEnableIndicatorsWhileLocked()
166 {
167 AccountsService session;
168 session.setUser(QTest::currentTestFunction());
170 QCOMPARE(session.enableIndicatorsWhileLocked(), true);
171 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
172 "com.ubuntu.AccountsService.SecurityPrivacy",
173 "EnableIndicatorsWhileLocked",
174 dbusVariant(false)));
175 QTRY_COMPARE(session.enableIndicatorsWhileLocked(), false);
176 }
178 void testAsynchornousChangeForStatsPasswordDisplayHint()
179 {
180 AccountsService session;
181 session.setUser(QTest::currentTestFunction());
183 QCOMPARE(session.passwordDisplayHint(), AccountsService::Keyboard);
184 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
185 "com.ubuntu.AccountsService.SecurityPrivacy",
186 "PasswordDisplayHint",
187 dbusVariant(AccountsService::Numeric)));
188 QTRY_COMPARE(session.passwordDisplayHint(), AccountsService::Numeric);
189 }
191 void testAsynchornousChangeForStatsLicenseAccepted()
192 {
193 AccountsService session;
194 session.setUser(QTest::currentTestFunction());
196 QCOMPARE(session.hereEnabled(), false);
197 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
198 "com.ubuntu.location.providers.here.AccountsService",
199 "LicenseAccepted",
200 dbusVariant(true)));
201 QTRY_COMPARE(session.hereEnabled(), true);
202 }
204 void testAsynchornousChangeForLicenseBasePath()
205 {
206 AccountsService session;
207 session.setUser(QTest::currentTestFunction());
209 QCOMPARE(session.hereLicensePath(), QString());
210 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
211 "com.ubuntu.location.providers.here.AccountsService",
212 "LicenseBasePath",
213 dbusVariant("/")));
214 QTRY_COMPARE(session.hereLicensePath(), QString("/"));
215 }
217 void testAsynchornousChangeForStatsBackgroundFile()
218 {
219 AccountsService session;
220 session.setUser(QTest::currentTestFunction());
222 QCOMPARE(session.backgroundFile(), QString());
223 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
224 "org.freedesktop.Accounts.User",
225 "BackgroundFile",
226 dbusVariant("/test/BackgroundFile")));
227 QTRY_COMPARE(session.backgroundFile(), QString("/test/BackgroundFile"));
228 }
230Q_SIGNALS:
231 void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalid);
233private:
234 QDBusInterface* m_userInterface;
235 QSignalSpy m_spy;
236};
238QTEST_MAIN(AccountsServiceTest)
240#include "client.moc"