2 * Copyright 2013 Canonical Ltd.
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.
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.
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/>
17 * Authored by: Michael Terry <michael.terry@canonical.com>
20#include "AccountsService.h"
21#include "AccountsServiceDBusAdaptor.h"
26#include <QDBusMetaType>
28using StringMap = QMap<QString,QString>;
29using StringMapList = QList<StringMap>;
30Q_DECLARE_METATYPE(StringMapList)
33QVariant dbusVariant(const T& value) { return QVariant::fromValue(QDBusVariant(value)); }
35#define ASSERT_DBUS_CALL(call) \
37 QDBusReply<void> reply = call; \
38 if (!reply.isValid()) QFAIL(reply.error().message().toLatin1()); \
41class AccountsServiceTest : public QObject
46 AccountsServiceTest(QObject* parent = 0)
48 , m_userInterface(nullptr)
49 , m_spy(this, &AccountsServiceTest::propertiesChanged)
50 , m_mousePrimaryButtonSpy(this, &AccountsServiceTest::setMousePrimaryButtonCalled)
52 m_uscInputInterface = new QDBusInterface("com.canonical.Unity.Input",
53 "/com/canonical/Unity/Input",
54 "com.canonical.Unity.Input",
55 QDBusConnection::sessionBus(),
58 QObject::connect(m_uscInputInterface, SIGNAL(setMousePrimaryButtonCalled(int)),
59 this, SIGNAL(setMousePrimaryButtonCalled(int)));
61 qDBusRegisterMetaType<StringMap>();
62 qDBusRegisterMetaType<StringMapList>();
68 QDBusReply<bool> addReply = QDBusInterface("org.freedesktop.Accounts",
69 "/org/freedesktop/Accounts",
70 "org.freedesktop.Accounts").call("AddUser", QTest::currentTestFunction());
71 QVERIFY(addReply.isValid());
72 QCOMPARE(addReply.value(), true);
74 m_userInterface = new QDBusInterface("org.freedesktop.Accounts",
75 QString("/%1").arg(QTest::currentTestFunction()),
76 "org.freedesktop.DBus.Properties", QDBusConnection::sessionBus(), this);
78 QVERIFY(QObject::connect(m_userInterface, SIGNAL(PropertiesChanged(QString, QVariantMap, QStringList)),
79 this, SIGNAL(propertiesChanged(QString, QVariantMap, QStringList))));
83 QDBusReply<bool> reply = QDBusInterface("org.freedesktop.Accounts",
84 "/org/freedesktop/Accounts",
85 "org.freedesktop.Accounts").call("RemoveUser", QTest::currentTestFunction());
86 QVERIFY(reply.isValid());
87 QCOMPARE(reply.value(), true);
89 delete m_userInterface;
91 m_mousePrimaryButtonSpy.clear();
96 // Test various invalid calls
97 AccountsServiceDBusAdaptor session;
98 QCOMPARE(session.getUserPropertyAsync("NOPE", "com.canonical.unity.AccountsService", "demo-edges").value(), QVariant());
99 QCOMPARE(session.getUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "NOPE").value(), QVariant());
102 void testGetSetServiceDBusAdaptor()
104 AccountsServiceDBusAdaptor session;
105 session.setUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges", QVariant(true)).waitForFinished();
106 QCOMPARE(session.getUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges").value(), QVariant(true));
107 session.setUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges", QVariant(false)).waitForFinished();
108 QCOMPARE(session.getUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges").value(), QVariant(false));
111 void testGetSetService()
113 AccountsService session(this, QTest::currentTestFunction());
115 QCOMPARE(session.demoEdges(), false);
116 session.setDemoEdges(true);
117 QCOMPARE(session.demoEdges(), true);
119 QCOMPARE(session.failedLogins(), (uint)0);
120 session.setFailedLogins(5);
121 QCOMPARE(session.failedLogins(), (uint)5);
123 QCOMPARE(session.hereEnabled(), false);
124 session.setHereEnabled(true);
125 QCOMPARE(session.hereEnabled(), true);
128 void testMarkDemoEdgeCompleted()
130 AccountsService session(this, QTest::currentTestFunction());
131 QSignalSpy changedSpy(&session, &AccountsService::demoEdgesCompletedChanged);
133 QCOMPARE(changedSpy.count(), 0);
134 QCOMPARE(session.demoEdgesCompleted(), QStringList());
136 session.markDemoEdgeCompleted("testedge");
137 QCOMPARE(changedSpy.count(), 1);
138 QCOMPARE(session.demoEdgesCompleted(), QStringList() << "testedge");
140 session.markDemoEdgeCompleted("testedge");
141 QCOMPARE(changedSpy.count(), 1);
142 QCOMPARE(session.demoEdgesCompleted(), QStringList() << "testedge");
144 session.markDemoEdgeCompleted("testedge2");
145 QCOMPARE(changedSpy.count(), 2);
146 QCOMPARE(session.demoEdgesCompleted(), QStringList() << "testedge" << "testedge2");
149 void testAsynchronousChangeForDemoEdgesCompleted()
151 AccountsService session(this, QTest::currentTestFunction());
152 QSignalSpy changedSpy(&session, &AccountsService::demoEdgesCompletedChanged);
154 QCOMPARE(changedSpy.count(), 0);
155 QCOMPARE(session.demoEdgesCompleted(), QStringList());
157 ASSERT_DBUS_CALL(m_userInterface->call("Set",
158 "com.canonical.unity.AccountsService",
159 "DemoEdgesCompleted",
160 dbusVariant(QStringList() << "testedge")));
161 QTRY_COMPARE(changedSpy.count(), 1);
162 QCOMPARE(session.demoEdgesCompleted(), QStringList() << "testedge");
165 void testAsynchronousChangeForDemoEdges()
167 AccountsService session(this, QTest::currentTestFunction());
169 QCOMPARE(session.demoEdges(), false);
170 ASSERT_DBUS_CALL(m_userInterface->call("Set",
171 "com.canonical.unity.AccountsService",
174 QTRY_COMPARE(session.demoEdges(), true);
177 void testAsynchronousChangeForFailedLogins()
179 AccountsService session(this, QTest::currentTestFunction());
181 QCOMPARE(session.failedLogins(), (uint)0);
182 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
183 "com.canonical.unity.AccountsService.Private",
186 QTRY_COMPARE(session.failedLogins(), (uint)5);
189 void testAsynchronousChangeForStatsWelcomeScreen()
191 AccountsService session(this, QTest::currentTestFunction());
193 QCOMPARE(session.statsWelcomeScreen(), true);
194 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
195 "com.ubuntu.touch.AccountsService.SecurityPrivacy",
196 "StatsWelcomeScreen",
197 dbusVariant(false)));
198 QTRY_COMPARE(session.statsWelcomeScreen(), false);
201 void testAsynchronousChangeForEnableLauncherWhileLocked()
203 AccountsService session(this, QTest::currentTestFunction());
205 QCOMPARE(session.enableLauncherWhileLocked(), true);
206 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
207 "com.ubuntu.AccountsService.SecurityPrivacy",
208 "EnableLauncherWhileLocked",
209 dbusVariant(false)));
210 QTRY_COMPARE(session.enableLauncherWhileLocked(), false);
213 void testAsynchronousChangeForEnableIndicatorsWhileLocked()
215 AccountsService session(this, QTest::currentTestFunction());
217 QCOMPARE(session.enableIndicatorsWhileLocked(), true);
218 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
219 "com.ubuntu.AccountsService.SecurityPrivacy",
220 "EnableIndicatorsWhileLocked",
221 dbusVariant(false)));
222 QTRY_COMPARE(session.enableIndicatorsWhileLocked(), false);
225 void testAsynchronousChangeForPasswordDisplayHint()
227 AccountsService session(this, QTest::currentTestFunction());
229 QCOMPARE(session.passwordDisplayHint(), AccountsService::Keyboard);
230 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
231 "com.ubuntu.AccountsService.SecurityPrivacy",
232 "PasswordDisplayHint",
233 dbusVariant(AccountsService::Numeric)));
234 QTRY_COMPARE(session.passwordDisplayHint(), AccountsService::Numeric);
237 void testAsynchronousChangeForLicenseAccepted()
239 AccountsService session(this, QTest::currentTestFunction());
241 QCOMPARE(session.hereEnabled(), false);
242 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
243 "com.ubuntu.location.providers.here.AccountsService",
246 QTRY_COMPARE(session.hereEnabled(), true);
249 void testAsynchronousChangeForLicenseBasePath()
251 AccountsService session(this, QTest::currentTestFunction());
253 QCOMPARE(session.hereLicensePath(), QString());
254 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
255 "com.ubuntu.location.providers.here.AccountsService",
258 QTRY_COMPARE(session.hereLicensePath(), QString("/"));
261 void testAsynchronousChangeForBackgroundFile()
263 AccountsService session(this, QTest::currentTestFunction());
265 QCOMPARE(session.backgroundFile(), QString());
266 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
267 "org.freedesktop.Accounts.User",
269 dbusVariant("/test/BackgroundFile")));
270 QTRY_COMPARE(session.backgroundFile(), QString("/test/BackgroundFile"));
273 void testProxyOnStartup()
275 AccountsService session(this, QTest::currentTestFunction());
277 QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
278 QList<QVariant> arguments = m_mousePrimaryButtonSpy.takeFirst();
279 QCOMPARE(arguments.at(0).toInt(), 1);
282 void testProxyOnChange()
284 AccountsService session(this, QTest::currentTestFunction());
285 QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
286 m_mousePrimaryButtonSpy.clear();
288 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
289 "com.ubuntu.AccountsService.Input",
290 "MousePrimaryButton",
291 dbusVariant("left")));
293 QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
294 QList<QVariant> arguments = m_mousePrimaryButtonSpy.takeFirst();
295 QCOMPARE(arguments.at(0).toInt(), 0);
298 void testInvalidPrimaryButton()
300 AccountsService session(this, QTest::currentTestFunction());
301 QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
302 m_mousePrimaryButtonSpy.clear();
304 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
305 "com.ubuntu.AccountsService.Input",
306 "MousePrimaryButton",
307 dbusVariant("NOPE")));
309 QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
310 QList<QVariant> arguments = m_mousePrimaryButtonSpy.takeFirst();
311 QCOMPARE(arguments.at(0).toInt(), 0);
314 void testAsynchronousChangeForKeymaps()
316 AccountsService session(this, QTest::currentTestFunction());
318 QCOMPARE(session.keymaps(), {"us"});
320 StringMapList inputSources;
322 map1.insert("xkb", "cz+qwerty");
323 inputSources.append(map1);
325 map2.insert("xkb", "fr");
326 inputSources.append(map2);
328 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
329 "org.freedesktop.Accounts.User",
331 QVariant::fromValue(QDBusVariant(QVariant::fromValue(inputSources)))));
332 QStringList result = {"cz+qwerty", "fr"};
333 QTRY_COMPARE(session.keymaps(), result);
337 void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalid);
338 void setMousePrimaryButtonCalled(int button);
341 QDBusInterface* m_uscInputInterface;
342 QDBusInterface* m_userInterface;
344 QSignalSpy m_mousePrimaryButtonSpy;
347QTEST_MAIN(AccountsServiceTest)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list