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>
27class GreeterDBusTest : public QObject
32 void PropertiesChangedRelay(const QString &interface, const QVariantMap &changed, const QStringList &invalidated);
38 // Qt doesn't like us connecting to PropertiesChanged using normal
39 // SIGNAL method, because QtDBus doesn't know about PropertiesChanged.
40 // So we connect the hard way for the benefit of any tests that want
42 QDBusConnection::sessionBus().connect(
43 "com.canonical.UnityGreeter",
45 "org.freedesktop.DBus.Properties",
48 SIGNAL(PropertiesChangedRelay(const QString&, const QVariantMap&, const QStringList&)));
49 QDBusConnection::sessionBus().connect(
50 "com.canonical.UnityGreeter",
52 "org.freedesktop.DBus.Properties",
55 SIGNAL(PropertiesChangedRelay(const QString&, const QVariantMap&, const QStringList&)));
60 view = new QQuickView();
61 view->setSource(QUrl::fromLocalFile(CURRENT_SOURCE_DIR "/greeter.qml"));
62 greeter = dynamic_cast<Greeter*>(view->rootObject()->property("greeter").value<QObject*>());
64 QVERIFY(greeter->authenticationUser() == "");
66 QTest::qWaitForWindowExposed(view);
68 dbusMain = new QDBusInterface("com.canonical.UnityGreeter",
70 "com.canonical.UnityGreeter",
71 QDBusConnection::sessionBus(), view);
72 QVERIFY(dbusMain->isValid());
74 dbusList = new QDBusInterface("com.canonical.UnityGreeter",
76 "com.canonical.UnityGreeter.List",
77 QDBusConnection::sessionBus(), view);
78 QVERIFY(dbusList->isValid());
86 void testGetActiveEntry()
88 greeter->authenticate("has-password");
90 QDBusReply<QString> reply = dbusList->call("GetActiveEntry");
91 QVERIFY(reply.isValid());
92 QVERIFY(reply.value() == "has-password");
95 void testSetActiveEntry()
97 QSignalSpy spy(greeter, &Greeter::requestAuthenticationUser);
98 QDBusReply<void> reply = dbusList->call("SetActiveEntry", "has-password");
99 QVERIFY(reply.isValid());
102 QCOMPARE(spy.count(), 1);
103 QList<QVariant> arguments = spy.takeFirst();
104 QVERIFY(arguments.at(0).toString() == "has-password");
107 void testEntrySelectedSignal()
109 QSignalSpy spy(dbusList, SIGNAL(EntrySelected(QString)));
110 greeter->authenticate("has-password");
113 QCOMPARE(spy.count(), 1);
114 QList<QVariant> arguments = spy.takeFirst();
115 QVERIFY(arguments.at(0).toString() == "has-password");
118 void testActiveEntryGet()
120 greeter->authenticate("has-password");
121 QVERIFY(dbusList->property("ActiveEntry").toString() == "has-password");
124 void testActiveEntrySet()
126 QSignalSpy spy(greeter, &Greeter::requestAuthenticationUser);
127 QVERIFY(dbusList->setProperty("ActiveEntry", "has-password"));
130 QCOMPARE(spy.count(), 1);
131 QList<QVariant> arguments = spy.takeFirst();
132 QVERIFY(arguments.at(0).toString() == "has-password");
135 void testActiveEntryChanged()
137 QSignalSpy spy(this, &GreeterDBusTest::PropertiesChangedRelay);
138 greeter->authenticate("has-password");
141 QVERIFY(spy.count() > 0);
142 QList<QVariant> arguments = spy.takeFirst();
143 QVERIFY(arguments.at(0).toString() == "com.canonical.UnityGreeter.List");
144 QVERIFY(arguments.at(1).toMap().contains("ActiveEntry"));
145 QVERIFY(arguments.at(1).toMap()["ActiveEntry"] == "has-password");
148 void testEntryIsLockedGet()
150 QVERIFY(dbusList->property("EntryIsLocked").toBool());
152 greeter->authenticate("no-password");
153 QTRY_VERIFY(!dbusList->property("EntryIsLocked").toBool());
155 greeter->authenticate("has-password");
156 QTRY_VERIFY(dbusList->property("EntryIsLocked").toBool());
159 void testEntryIsLockedChanged()
161 QSignalSpy spy(this, &GreeterDBusTest::PropertiesChangedRelay);
162 greeter->authenticate("no-password");
164 // Two property changed signals will be emitted, one for the IsLocked
165 // property, one for the ActiveEntry; the first will be IsLocked.
167 if (spy.count() < 2) {
170 QCOMPARE(spy.count(), 2);
172 QList<QVariant> arguments = spy.takeLast();
173 QVERIFY(arguments.at(0).toString() == "com.canonical.UnityGreeter.List");
174 QVERIFY(arguments.at(1).toMap().contains("EntryIsLocked"));
175 QVERIFY(arguments.at(1).toMap()["EntryIsLocked"] == false);
180 QVERIFY(!greeter->isActive());
181 QVERIFY(!dbusMain->property("IsActive").toBool());
183 QSignalSpy spy(this, &GreeterDBusTest::PropertiesChangedRelay);
184 greeter->setIsActive(true);
187 QVERIFY(greeter->isActive());
188 QVERIFY(dbusMain->property("IsActive").toBool());
190 QCOMPARE(spy.count(), 1);
191 QList<QVariant> arguments = spy.takeFirst();
192 QCOMPARE(arguments.at(0).toString(), QString("com.canonical.UnityGreeter"));
193 QVERIFY(arguments.at(1).toMap().contains("IsActive"));
194 QVERIFY(arguments.at(1).toMap()["IsActive"].toBool());
197 void testShowGreeter()
199 // Just confirm the call exists and doesn't fail
200 QDBusReply<void> reply = dbusMain->call("ShowGreeter");
201 QVERIFY(reply.isValid());
207 QDBusInterface *dbusMain;
208 QDBusInterface *dbusList;
211QTEST_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