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"
28QVariant dbusVariant(const T& value) { return QVariant::fromValue(QDBusVariant(value)); }
30#define ASSERT_DBUS_CALL(call) \
32 QDBusReply<void> reply = call; \
33 if (!reply.isValid()) QFAIL(reply.error().message().toLatin1()); \
36class AccountsServiceTest : public QObject
41 AccountsServiceTest(QObject* parent = 0)
43 , m_userInterface(nullptr)
44 , m_spy(this, &AccountsServiceTest::propertiesChanged)
45 , m_mousePrimaryButtonSpy(this, &AccountsServiceTest::setMousePrimaryButtonCalled)
47 m_uscInputInterface = new QDBusInterface("com.canonical.Unity.Input",
48 "/com/canonical/Unity/Input",
49 "com.canonical.Unity.Input",
50 QDBusConnection::sessionBus(),
53 QObject::connect(m_uscInputInterface, SIGNAL(setMousePrimaryButtonCalled(int)),
54 this, SIGNAL(setMousePrimaryButtonCalled(int)));
60 QDBusReply<bool> addReply = QDBusInterface("org.freedesktop.Accounts",
61 "/org/freedesktop/Accounts",
62 "org.freedesktop.Accounts").call("AddUser", QTest::currentTestFunction());
63 QVERIFY(addReply.isValid());
64 QCOMPARE(addReply.value(), true);
66 m_userInterface = new QDBusInterface("org.freedesktop.Accounts",
67 QString("/%1").arg(QTest::currentTestFunction()),
68 "org.freedesktop.DBus.Properties", QDBusConnection::sessionBus(), this);
70 QVERIFY(QObject::connect(m_userInterface, SIGNAL(PropertiesChanged(QString, QVariantMap, QStringList)),
71 this, SIGNAL(propertiesChanged(QString, QVariantMap, QStringList))));
75 QDBusReply<bool> reply = QDBusInterface("org.freedesktop.Accounts",
76 "/org/freedesktop/Accounts",
77 "org.freedesktop.Accounts").call("RemoveUser", QTest::currentTestFunction());
78 QVERIFY(reply.isValid());
79 QCOMPARE(reply.value(), true);
81 delete m_userInterface;
83 m_mousePrimaryButtonSpy.clear();
88 // Test various invalid calls
89 AccountsServiceDBusAdaptor session;
90 QCOMPARE(session.getUserPropertyAsync("NOPE", "com.canonical.unity.AccountsService", "demo-edges").value(), QVariant());
91 QCOMPARE(session.getUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "NOPE").value(), QVariant());
94 void testGetSetServiceDBusAdaptor()
96 AccountsServiceDBusAdaptor session;
97 session.setUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges", QVariant(true)).waitForFinished();
98 QCOMPARE(session.getUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges").value(), QVariant(true));
99 session.setUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges", QVariant(false)).waitForFinished();
100 QCOMPARE(session.getUserPropertyAsync(QTest::currentTestFunction(), "com.canonical.unity.AccountsService", "demo-edges").value(), QVariant(false));
103 void testGetSetService()
105 AccountsService session(this, QTest::currentTestFunction());
107 QCOMPARE(session.demoEdges(), false);
108 session.setDemoEdges(true);
109 QCOMPARE(session.demoEdges(), true);
111 QCOMPARE(session.failedLogins(), (uint)0);
112 session.setFailedLogins(5);
113 QCOMPARE(session.failedLogins(), (uint)5);
115 QCOMPARE(session.hereEnabled(), false);
116 session.setHereEnabled(true);
117 QCOMPARE(session.hereEnabled(), true);
120 void testAsynchronousChangeForDemoEdges()
122 AccountsService session(this, QTest::currentTestFunction());
124 QCOMPARE(session.demoEdges(), false);
125 ASSERT_DBUS_CALL(m_userInterface->call("Set",
126 "com.canonical.unity.AccountsService",
129 QTRY_COMPARE(session.demoEdges(), true);
132 void testAsynchronousChangeForFailedLogins()
134 AccountsService session(this, QTest::currentTestFunction());
136 QCOMPARE(session.failedLogins(), (uint)0);
137 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
138 "com.canonical.unity.AccountsService.Private",
141 QTRY_COMPARE(session.failedLogins(), (uint)5);
144 void testAsynchronousChangeForStatsWelcomeScreen()
146 AccountsService session(this, QTest::currentTestFunction());
148 QCOMPARE(session.statsWelcomeScreen(), true);
149 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
150 "com.ubuntu.touch.AccountsService.SecurityPrivacy",
151 "StatsWelcomeScreen",
152 dbusVariant(false)));
153 QTRY_COMPARE(session.statsWelcomeScreen(), false);
156 void testAsynchronousChangeForEnableLauncherWhileLocked()
158 AccountsService session(this, QTest::currentTestFunction());
160 QCOMPARE(session.enableLauncherWhileLocked(), true);
161 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
162 "com.ubuntu.AccountsService.SecurityPrivacy",
163 "EnableLauncherWhileLocked",
164 dbusVariant(false)));
165 QTRY_COMPARE(session.enableLauncherWhileLocked(), false);
168 void testAsynchronousChangeForEnableIndicatorsWhileLocked()
170 AccountsService session(this, QTest::currentTestFunction());
172 QCOMPARE(session.enableIndicatorsWhileLocked(), true);
173 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
174 "com.ubuntu.AccountsService.SecurityPrivacy",
175 "EnableIndicatorsWhileLocked",
176 dbusVariant(false)));
177 QTRY_COMPARE(session.enableIndicatorsWhileLocked(), false);
180 void testAsynchronousChangeForPasswordDisplayHint()
182 AccountsService session(this, QTest::currentTestFunction());
184 QCOMPARE(session.passwordDisplayHint(), AccountsService::Keyboard);
185 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
186 "com.ubuntu.AccountsService.SecurityPrivacy",
187 "PasswordDisplayHint",
188 dbusVariant(AccountsService::Numeric)));
189 QTRY_COMPARE(session.passwordDisplayHint(), AccountsService::Numeric);
192 void testAsynchronousChangeForLicenseAccepted()
194 AccountsService session(this, QTest::currentTestFunction());
196 QCOMPARE(session.hereEnabled(), false);
197 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
198 "com.ubuntu.location.providers.here.AccountsService",
201 QTRY_COMPARE(session.hereEnabled(), true);
204 void testAsynchronousChangeForLicenseBasePath()
206 AccountsService session(this, QTest::currentTestFunction());
208 QCOMPARE(session.hereLicensePath(), QString());
209 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
210 "com.ubuntu.location.providers.here.AccountsService",
213 QTRY_COMPARE(session.hereLicensePath(), QString("/"));
216 void testAsynchronousChangeForBackgroundFile()
218 AccountsService session(this, QTest::currentTestFunction());
220 QCOMPARE(session.backgroundFile(), QString());
221 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
222 "org.freedesktop.Accounts.User",
224 dbusVariant("/test/BackgroundFile")));
225 QTRY_COMPARE(session.backgroundFile(), QString("/test/BackgroundFile"));
228 void testProxyOnStartup()
230 AccountsService session(this, QTest::currentTestFunction());
232 QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
233 QList<QVariant> arguments = m_mousePrimaryButtonSpy.takeFirst();
234 QCOMPARE(arguments.at(0).toInt(), 1);
237 void testProxyOnChange()
239 AccountsService session(this, QTest::currentTestFunction());
240 QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
241 m_mousePrimaryButtonSpy.clear();
243 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
244 "com.ubuntu.AccountsService.Input",
245 "MousePrimaryButton",
246 dbusVariant("left")));
248 QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
249 QList<QVariant> arguments = m_mousePrimaryButtonSpy.takeFirst();
250 QCOMPARE(arguments.at(0).toInt(), 0);
253 void testInvalidPrimaryButton()
255 AccountsService session(this, QTest::currentTestFunction());
256 QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
257 m_mousePrimaryButtonSpy.clear();
259 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
260 "com.ubuntu.AccountsService.Input",
261 "MousePrimaryButton",
262 dbusVariant("NOPE")));
264 QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
265 QList<QVariant> arguments = m_mousePrimaryButtonSpy.takeFirst();
266 QCOMPARE(arguments.at(0).toInt(), 0);
270 void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalid);
271 void setMousePrimaryButtonCalled(int button);
274 QDBusInterface* m_uscInputInterface;
275 QDBusInterface* m_userInterface;
277 QSignalSpy m_mousePrimaryButtonSpy;
280QTEST_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