2 * Copyright (C) 2013 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU 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 General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19#include <QCoreApplication>
20#include <QDBusInterface>
28class GreeterDBusTest : public QObject
33 void PropertiesChangedRelay(const QString &interface, const QVariantMap &changed, const QStringList &invalidated);
39 // Qt doesn't like us connecting to PropertiesChanged using normal
40 // SIGNAL method, because QtDBus doesn't know about PropertiesChanged.
41 // So we connect the hard way for the benefit of any tests that want
43 QDBusConnection::sessionBus().connect(
44 "com.canonical.UnityGreeter",
46 "org.freedesktop.DBus.Properties",
49 SIGNAL(PropertiesChangedRelay(const QString&, const QVariantMap&, const QStringList&)));
50 QDBusConnection::sessionBus().connect(
51 "com.canonical.UnityGreeter",
53 "org.freedesktop.DBus.Properties",
56 SIGNAL(PropertiesChangedRelay(const QString&, const QVariantMap&, const QStringList&)));
61 view = new QQuickView();
62 view->setSource(QUrl::fromLocalFile(testDataDir() + "/plugins/LightDM/IntegratedLightDM/greeter.qml"));
63 greeter = dynamic_cast<Greeter*>(view->rootObject()->property("greeter").value<QObject*>());
65 QVERIFY(greeter->authenticationUser() == "");
67 QTest::qWaitForWindowExposed(view);
69 dbusMain = new QDBusInterface("com.canonical.UnityGreeter",
71 "com.canonical.UnityGreeter",
72 QDBusConnection::sessionBus(), view);
73 QVERIFY(dbusMain->isValid());
75 dbusList = new QDBusInterface("com.canonical.UnityGreeter",
77 "com.canonical.UnityGreeter.List",
78 QDBusConnection::sessionBus(), view);
79 QVERIFY(dbusList->isValid());
85 delete greeter; // reset singleton
88 void testGetActiveEntry()
90 greeter->authenticate("has-password");
92 QDBusReply<QString> reply = dbusList->call("GetActiveEntry");
93 QVERIFY(reply.isValid());
94 QVERIFY(reply.value() == "has-password");
97 void testSetActiveEntry()
99 QSignalSpy spy(greeter, &Greeter::requestAuthenticationUser);
100 QDBusReply<void> reply = dbusList->call("SetActiveEntry", "has-password");
101 QVERIFY(reply.isValid());
104 QCOMPARE(spy.count(), 1);
105 QList<QVariant> arguments = spy.takeFirst();
106 QVERIFY(arguments.at(0).toString() == "has-password");
109 void testEntrySelectedSignal()
111 QSignalSpy spy(dbusList, SIGNAL(EntrySelected(QString)));
112 greeter->authenticate("has-password");
115 QCOMPARE(spy.count(), 1);
116 QList<QVariant> arguments = spy.takeFirst();
117 QVERIFY(arguments.at(0).toString() == "has-password");
120 void testActiveEntryGet()
122 greeter->authenticate("has-password");
123 QVERIFY(dbusList->property("ActiveEntry").toString() == "has-password");
126 void testActiveEntrySet()
128 QSignalSpy spy(greeter, &Greeter::requestAuthenticationUser);
129 QVERIFY(dbusList->setProperty("ActiveEntry", "has-password"));
132 QCOMPARE(spy.count(), 1);
133 QList<QVariant> arguments = spy.takeFirst();
134 QVERIFY(arguments.at(0).toString() == "has-password");
137 void testActiveEntryChanged()
139 QSignalSpy spy(this, &GreeterDBusTest::PropertiesChangedRelay);
140 greeter->authenticate("has-password");
142 QTRY_COMPARE(spy.count(), 2); // EntryIsLocked then ActiveEntry
144 QList<QVariant> arguments = spy[1];
145 QVERIFY(arguments.at(0).toString() == "com.canonical.UnityGreeter.List");
146 QVERIFY(arguments.at(1).toMap().contains("ActiveEntry"));
147 QVERIFY(arguments.at(1).toMap()["ActiveEntry"] == "has-password");
150 void testEntryIsLockedGet()
152 QVERIFY(dbusList->property("EntryIsLocked").toBool());
154 greeter->authenticate("no-password");
155 QTRY_VERIFY(!dbusList->property("EntryIsLocked").toBool());
157 greeter->authenticate("has-password");
158 QTRY_VERIFY(dbusList->property("EntryIsLocked").toBool());
161 void testEntryIsLockedChanged()
163 QSignalSpy spy(this, &GreeterDBusTest::PropertiesChangedRelay);
164 greeter->authenticate("no-password");
166 // EntryIsLocked=true, ActiveEntry, then EntryIsLocked=false
167 QTRY_COMPARE(spy.count(), 3);
169 QList<QVariant> arguments = spy[2];
170 QVERIFY(arguments.at(0).toString() == "com.canonical.UnityGreeter.List");
171 QVERIFY(arguments.at(1).toMap().contains("EntryIsLocked"));
172 QVERIFY(arguments.at(1).toMap()["EntryIsLocked"] == false);
177 QVERIFY(!greeter->isActive());
178 QVERIFY(!dbusMain->property("IsActive").toBool());
180 QSignalSpy spy(this, &GreeterDBusTest::PropertiesChangedRelay);
181 greeter->setIsActive(true);
184 QVERIFY(greeter->isActive());
185 QVERIFY(dbusMain->property("IsActive").toBool());
187 QCOMPARE(spy.count(), 1);
188 QList<QVariant> arguments = spy.takeFirst();
189 QCOMPARE(arguments.at(0).toString(), QString("com.canonical.UnityGreeter"));
190 QVERIFY(arguments.at(1).toMap().contains("IsActive"));
191 QVERIFY(arguments.at(1).toMap()["IsActive"].toBool());
194 void testShowGreeter()
196 // Just confirm the call exists and doesn't fail
197 QDBusReply<void> reply = dbusMain->call("ShowGreeter");
198 QVERIFY(reply.isValid());
204 QDBusInterface *dbusMain;
205 QDBusInterface *dbusList;
208QTEST_MAIN(GreeterDBusTest)
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