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 testMarkDemoEdgeCompleted()
122 AccountsService session(this, QTest::currentTestFunction());
123 QSignalSpy changedSpy(&session, &AccountsService::demoEdgesCompletedChanged);
125 QCOMPARE(changedSpy.count(), 0);
126 QCOMPARE(session.demoEdgesCompleted(), QStringList());
128 session.markDemoEdgeCompleted("testedge");
129 QCOMPARE(changedSpy.count(), 1);
130 QCOMPARE(session.demoEdgesCompleted(), QStringList() << "testedge");
132 session.markDemoEdgeCompleted("testedge");
133 QCOMPARE(changedSpy.count(), 1);
134 QCOMPARE(session.demoEdgesCompleted(), QStringList() << "testedge");
136 session.markDemoEdgeCompleted("testedge2");
137 QCOMPARE(changedSpy.count(), 2);
138 QCOMPARE(session.demoEdgesCompleted(), QStringList() << "testedge" << "testedge2");
141 void testAsynchronousChangeForDemoEdgesCompleted()
143 AccountsService session(this, QTest::currentTestFunction());
144 QSignalSpy changedSpy(&session, &AccountsService::demoEdgesCompletedChanged);
146 QCOMPARE(changedSpy.count(), 0);
147 QCOMPARE(session.demoEdgesCompleted(), QStringList());
149 ASSERT_DBUS_CALL(m_userInterface->call("Set",
150 "com.canonical.unity.AccountsService",
151 "DemoEdgesCompleted",
152 dbusVariant(QStringList() << "testedge")));
153 QTRY_COMPARE(changedSpy.count(), 1);
154 QCOMPARE(session.demoEdgesCompleted(), QStringList() << "testedge");
157 void testAsynchronousChangeForDemoEdges()
159 AccountsService session(this, QTest::currentTestFunction());
161 QCOMPARE(session.demoEdges(), false);
162 ASSERT_DBUS_CALL(m_userInterface->call("Set",
163 "com.canonical.unity.AccountsService",
166 QTRY_COMPARE(session.demoEdges(), true);
169 void testAsynchronousChangeForFailedLogins()
171 AccountsService session(this, QTest::currentTestFunction());
173 QCOMPARE(session.failedLogins(), (uint)0);
174 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
175 "com.canonical.unity.AccountsService.Private",
178 QTRY_COMPARE(session.failedLogins(), (uint)5);
181 void testAsynchronousChangeForStatsWelcomeScreen()
183 AccountsService session(this, QTest::currentTestFunction());
185 QCOMPARE(session.statsWelcomeScreen(), true);
186 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
187 "com.ubuntu.touch.AccountsService.SecurityPrivacy",
188 "StatsWelcomeScreen",
189 dbusVariant(false)));
190 QTRY_COMPARE(session.statsWelcomeScreen(), false);
193 void testAsynchronousChangeForEnableLauncherWhileLocked()
195 AccountsService session(this, QTest::currentTestFunction());
197 QCOMPARE(session.enableLauncherWhileLocked(), true);
198 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
199 "com.ubuntu.AccountsService.SecurityPrivacy",
200 "EnableLauncherWhileLocked",
201 dbusVariant(false)));
202 QTRY_COMPARE(session.enableLauncherWhileLocked(), false);
205 void testAsynchronousChangeForEnableIndicatorsWhileLocked()
207 AccountsService session(this, QTest::currentTestFunction());
209 QCOMPARE(session.enableIndicatorsWhileLocked(), true);
210 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
211 "com.ubuntu.AccountsService.SecurityPrivacy",
212 "EnableIndicatorsWhileLocked",
213 dbusVariant(false)));
214 QTRY_COMPARE(session.enableIndicatorsWhileLocked(), false);
217 void testAsynchronousChangeForPasswordDisplayHint()
219 AccountsService session(this, QTest::currentTestFunction());
221 QCOMPARE(session.passwordDisplayHint(), AccountsService::Keyboard);
222 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
223 "com.ubuntu.AccountsService.SecurityPrivacy",
224 "PasswordDisplayHint",
225 dbusVariant(AccountsService::Numeric)));
226 QTRY_COMPARE(session.passwordDisplayHint(), AccountsService::Numeric);
229 void testAsynchronousChangeForLicenseAccepted()
231 AccountsService session(this, QTest::currentTestFunction());
233 QCOMPARE(session.hereEnabled(), false);
234 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
235 "com.ubuntu.location.providers.here.AccountsService",
238 QTRY_COMPARE(session.hereEnabled(), true);
241 void testAsynchronousChangeForLicenseBasePath()
243 AccountsService session(this, QTest::currentTestFunction());
245 QCOMPARE(session.hereLicensePath(), QString());
246 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
247 "com.ubuntu.location.providers.here.AccountsService",
250 QTRY_COMPARE(session.hereLicensePath(), QString("/"));
253 void testAsynchronousChangeForBackgroundFile()
255 AccountsService session(this, QTest::currentTestFunction());
257 QCOMPARE(session.backgroundFile(), QString());
258 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
259 "org.freedesktop.Accounts.User",
261 dbusVariant("/test/BackgroundFile")));
262 QTRY_COMPARE(session.backgroundFile(), QString("/test/BackgroundFile"));
265 void testProxyOnStartup()
267 AccountsService session(this, QTest::currentTestFunction());
269 QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
270 QList<QVariant> arguments = m_mousePrimaryButtonSpy.takeFirst();
271 QCOMPARE(arguments.at(0).toInt(), 1);
274 void testProxyOnChange()
276 AccountsService session(this, QTest::currentTestFunction());
277 QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
278 m_mousePrimaryButtonSpy.clear();
280 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
281 "com.ubuntu.AccountsService.Input",
282 "MousePrimaryButton",
283 dbusVariant("left")));
285 QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
286 QList<QVariant> arguments = m_mousePrimaryButtonSpy.takeFirst();
287 QCOMPARE(arguments.at(0).toInt(), 0);
290 void testInvalidPrimaryButton()
292 AccountsService session(this, QTest::currentTestFunction());
293 QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
294 m_mousePrimaryButtonSpy.clear();
296 ASSERT_DBUS_CALL(m_userInterface->asyncCall("Set",
297 "com.ubuntu.AccountsService.Input",
298 "MousePrimaryButton",
299 dbusVariant("NOPE")));
301 QTRY_COMPARE(m_mousePrimaryButtonSpy.count(), 1);
302 QList<QVariant> arguments = m_mousePrimaryButtonSpy.takeFirst();
303 QCOMPARE(arguments.at(0).toInt(), 0);
307 void propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalid);
308 void setMousePrimaryButtonCalled(int button);
311 QDBusInterface* m_uscInputInterface;
312 QDBusInterface* m_userInterface;
314 QSignalSpy m_mousePrimaryButtonSpy;
317QTEST_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