2 * Copyright 2013-2015 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Ying-Chun Liu (PaulLiu) <paul.liu@canonical.com>
18 * Lukáš Tinkl <lukas.tinkl@canonical.com>
22#include <QDBusConnection>
23#include <QDBusMessage>
24#include <QDBusInterface>
26#include <QDBusVariant>
28#include <QDBusObjectPath>
33#include "dbusunitysessionservice.h"
35enum class Action : unsigned
43class SessionBackendTest : public QObject
50 dbusUnitySession = new QDBusInterface ("com.canonical.Unity",
51 "/com/canonical/Unity/Session",
52 "com.canonical.Unity.Session",
53 QDBusConnection::sessionBus());
57 qputenv("TEST_USER", "testuser");
58 qputenv("TEST_NOPASSWD_USERS", "");
61 void testUnitySessionLogoutRequested_data() {
62 QTest::addColumn<QString>("method");
63 QTest::addColumn<QString>("signal");
65 QTest::newRow("Logout") << "RequestLogout" << "LogoutRequested(bool)";
66 QTest::newRow("Reboot") << "RequestReboot" << "RebootRequested(bool)";
67 QTest::newRow("Shutdown") << "RequestShutdown" << "ShutdownRequested(bool)";
68 QTest::newRow("PromptLock") << "PromptLock" << "LockRequested()";
69 QTest::newRow("Lock") << "Lock" << "LockRequested()";
70 QTest::newRow("LockLightDM") << "Lock" << "Locked()"; // happens when we lock LightDM, only for Lock()
73 void testUnitySessionLogoutRequested() {
74 QFETCH(QString, method);
75 QFETCH(QString, signal);
77 DBusUnitySessionService dbusUnitySessionService;
78 QCoreApplication::processEvents(); // to let the service register on DBus
80 // .. because QSignalSpy checks the signal signature like this: "if (((aSignal[0] - '0') & 0x03) != QSIGNAL_CODE)"
81 QSignalSpy spy(&dbusUnitySessionService, qPrintable(signal.prepend(QSIGNAL_CODE)));
83 QDBusReply<void> reply = dbusUnitySession->call(method);
84 QCOMPARE(reply.isValid(), true);
86 QTRY_COMPARE(spy.count(), 1);
89 void testGnomeSessionWrapperWithoutConfirmation_data() {
90 QTest::addColumn<QString>("method");
91 QTest::addColumn<QString>("signal");
93 QTest::newRow("Reboot") << "RequestReboot" << SIGNAL(RebootCalled(bool));
94 QTest::newRow("Shutdown") << "RequestShutdown" << SIGNAL(PowerOffCalled(bool));
97 void testGnomeSessionWrapperWithoutConfirmation() {
98 QFETCH(QString, method);
99 QFETCH(QString, signal);
101 DBusUnitySessionService dbusUnitySessionService;
102 DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
103 QCoreApplication::processEvents(); // to let the services register on DBus
105 QDBusInterface login1Interface("org.freedesktop.login1",
107 "org.freedesktop.login1.Manager");
108 QSignalSpy spy(&login1Interface, signal.toUtf8().data());
110 QDBusInterface dbusGnomeSessionWrapper("org.gnome.SessionManager",
111 "/org/gnome/SessionManager",
112 "org.gnome.SessionManager",
113 QDBusConnection::sessionBus());
114 QVERIFY(dbusGnomeSessionWrapper.isValid());
116 QDBusReply<void> reply = dbusGnomeSessionWrapper.call(method);
117 QVERIFY(reply.isValid());
118 QTRY_COMPARE(spy.count(), 1);
121 void testGnomeSessionWrapperWithConfirmation_data() {
122 QTest::addColumn<QString>("method");
123 QTest::addColumn<QString>("signal");
125 QTest::newRow("Reboot") << "Reboot" << SIGNAL(RebootRequested(bool));
126 QTest::newRow("Shutdown") << "Shutdown" << SIGNAL(ShutdownRequested(bool));
129 void testGnomeSessionWrapperWithConfirmation() {
130 QFETCH(QString, method);
131 QFETCH(QString, signal);
133 DBusUnitySessionService dbusUnitySessionService;
134 DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
135 QCoreApplication::processEvents(); // to let the services register on DBus
137 QSignalSpy spy(&dbusUnitySessionService, signal.toUtf8().data());
139 QDBusInterface dbusGnomeSessionWrapper("org.gnome.SessionManager",
140 "/org/gnome/SessionManager",
141 "org.gnome.SessionManager",
142 QDBusConnection::sessionBus());
143 QVERIFY(dbusGnomeSessionWrapper.isValid());
145 QDBusReply<void> reply = dbusGnomeSessionWrapper.call(method);
146 QVERIFY(reply.isValid());
147 QCOMPARE(spy.count(), 1);
150 void testGnomeSessionWrapperLogout_data() {
151 QTest::addColumn<int>("mode");
152 QTest::addColumn<QString>("signal");
154 QTest::newRow("Logout") << 0 << SIGNAL(LogoutRequested(bool));
155 QTest::newRow("LogoutNoDialog") << 1 << SIGNAL(LogoutReady());
156 QTest::newRow("LogoutNoInhibits") << 2 << SIGNAL(LogoutReady());
157 QTest::newRow("LogoutNoDialogNoInhibits") << 3 << SIGNAL(LogoutReady());
160 void testGnomeSessionWrapperLogout() {
162 QFETCH(QString, signal);
164 DBusUnitySessionService dbusUnitySessionService;
165 DBusGnomeSessionManagerWrapper dbusGnomeSessionManagerWrapper;
166 QCoreApplication::processEvents(); // to let the services register on DBus
168 QSignalSpy spy(&dbusUnitySessionService, signal.toUtf8().data());
170 QDBusInterface dbusGnomeSessionWrapper("org.gnome.SessionManager",
171 "/org/gnome/SessionManager",
172 "org.gnome.SessionManager",
173 QDBusConnection::sessionBus());
174 QVERIFY(dbusGnomeSessionWrapper.isValid());
176 QDBusReply<void> reply = dbusGnomeSessionWrapper.call("Logout", (quint32)mode);
177 QVERIFY(reply.isValid());
178 QCOMPARE(spy.count(), 1);
181 void testGnomeSessionDialogWrapper_data() {
182 QTest::addColumn<uint>("method");
183 QTest::addColumn<QString>("signal");
185 QTest::newRow("Logout") << (uint)Action::LOGOUT << "LogoutRequested(bool)";
186 QTest::newRow("Shutdown") << (uint)Action::SHUTDOWN << "ShutdownRequested(bool)";
187 QTest::newRow("Reboot") << (uint)Action::REBOOT << "RebootRequested(bool)";
190 void testGnomeSessionDialogWrapper() {
191 QFETCH(uint, method);
192 QFETCH(QString, signal);
194 DBusUnitySessionService dbusUnitySessionService;
195 QCoreApplication::processEvents(); // to let the service register on DBus
197 // Spy on the given signal on the /com/canonical/Unity/Session object
198 // as proof we are actually calling the actual method.
199 // .. because QSignalSpy checks the signal signature like this: "if (((aSignal[0] - '0') & 0x03) != QSIGNAL_CODE)"
200 QSignalSpy spy(&dbusUnitySessionService, qPrintable(signal.prepend(QSIGNAL_CODE)));
202 DBusGnomeSessionManagerDialogWrapper dbusGnomeSessionManagerDialogWrapper;
203 QCoreApplication::processEvents(); // to let the service register on DBus
205 QDBusInterface dbusGnomeSessionWrapper("com.canonical.Unity",
206 "/org/gnome/SessionManager/EndSessionDialog",
207 "org.gnome.SessionManager.EndSessionDialog",
208 QDBusConnection::sessionBus());
210 QCOMPARE(dbusGnomeSessionWrapper.isValid(), true);
212 // Set the QVariant as a QList<QDBusObjectPath> type
215 inhibitors.setValue(var);
217 QDBusReply<void> reply = dbusGnomeSessionWrapper.call("Open", method, (unsigned)0, (unsigned)0, inhibitors);
218 QCOMPARE(reply.isValid(), true);
220 // Make sure we see the signal being emitted.
221 QCOMPARE(spy.count(), 1);
224 void testUnlockFromLogind() {
225 DBusUnitySessionService dbusUnitySessionService;
226 QCoreApplication::processEvents(); // to let the service register on DBus
228 QDBusInterface iface("org.freedesktop.login1", "/logindsession", "org.freedesktop.login1.Session");
229 QVERIFY(iface.isValid());
231 QSignalSpy spy(&dbusUnitySessionService, SIGNAL(Unlocked()));
232 QCOMPARE(iface.call("MockEmitUnlock").errorMessage(), QString());
233 QTRY_COMPARE(spy.count(), 1);
236 void testUserName() {
237 DBusUnitySessionService dbusUnitySessionService;
238 QCOMPARE(dbusUnitySessionService.UserName(), QString("testuser"));
241 void testRealName() {
242 DBusUnitySessionService dbusUnitySessionService;
243 QCoreApplication::processEvents(); // to let the service register on DBus
245 QDBusInterface accIface("org.freedesktop.Accounts", "/org/freedesktop/Accounts", "org.freedesktop.Accounts", QDBusConnection::systemBus());
246 if (accIface.isValid()) {
247 QDBusReply<QDBusObjectPath> userPath = accIface.asyncCall("FindUserById", static_cast<qint64>(geteuid()));
248 if (userPath.isValid()) {
249 QDBusInterface userAccIface("org.freedesktop.Accounts", userPath.value().path(), "org.freedesktop.Accounts.User", QDBusConnection::systemBus());
250 QCOMPARE(dbusUnitySessionService.RealName(), userAccIface.property("RealName").toString());
256 DBusUnitySessionService dbusUnitySessionService;
258 qputenv("TEST_USER", "testuser");
259 QVERIFY(dbusUnitySessionService.CanLock());
261 qputenv("TEST_USER", "guest-abcdef"); // guest-* can't lock
262 QVERIFY(!dbusUnitySessionService.CanLock());
264 qputenv("TEST_USER", "testuser");
265 qputenv("TEST_NOPASSWD_USERS", "testuser"); // nopasswdlogin can't lock
266 QVERIFY(!dbusUnitySessionService.CanLock());
269 void testPromptLockRespectsCanLock() {
270 DBusUnitySessionService dbusUnitySessionService;
272 QSignalSpy spy(&dbusUnitySessionService, SIGNAL(lockRequested()));
273 QVERIFY(dbusUnitySessionService.CanLock());
274 dbusUnitySessionService.PromptLock();
275 QCOMPARE(spy.count(), 1);
278 qputenv("TEST_USER", "guest-abcdef");
279 QVERIFY(!dbusUnitySessionService.CanLock());
280 dbusUnitySessionService.PromptLock();
281 QCOMPARE(spy.count(), 0);
285 QDBusInterface *dbusUnitySession;
288QTEST_GUILESS_MAIN(SessionBackendTest)
289#include "sessionbackendtest.moc"
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