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 <QDBusInterface>
26class GreeterDBusTest : public QObject
31 void PropertiesChangedRelay(const QString &interface, const QVariantMap &changed, const QStringList &invalidated);
37 // Qt doesn't like us connecting to PropertiesChanged using normal
38 // SIGNAL method, because QtDBus doesn't know about PropertiesChanged.
39 // So we connect the hard way for the benefit of any tests that want
41 QDBusConnection::sessionBus().connect(
42 "com.canonical.UnityGreeter",
44 "org.freedesktop.DBus.Properties",
47 SIGNAL(PropertiesChangedRelay(const QString&, const QVariantMap&, const QStringList&)));
48 QDBusConnection::sessionBus().connect(
49 "com.canonical.UnityGreeter",
51 "org.freedesktop.DBus.Properties",
54 SIGNAL(PropertiesChangedRelay(const QString&, const QVariantMap&, const QStringList&)));
59 view = new QQuickView();
60 view->setSource(QUrl::fromLocalFile(CURRENT_SOURCE_DIR "/greeter.qml"));
61 greeter = dynamic_cast<Greeter*>(view->rootObject()->property("greeter").value<QObject*>());
63 QVERIFY(greeter->authenticationUser() == "");
65 QTest::qWaitForWindowExposed(view);
67 dbusMain = new QDBusInterface("com.canonical.UnityGreeter",
69 "com.canonical.UnityGreeter",
70 QDBusConnection::sessionBus(), view);
71 QVERIFY(dbusMain->isValid());
73 dbusList = new QDBusInterface("com.canonical.UnityGreeter",
75 "com.canonical.UnityGreeter.List",
76 QDBusConnection::sessionBus(), view);
77 QVERIFY(dbusList->isValid());
85 void testGetActiveEntry()
87 greeter->authenticate("has-password");
89 QDBusReply<QString> reply = dbusList->call("GetActiveEntry");
90 QVERIFY(reply.isValid());
91 QVERIFY(reply.value() == "has-password");
94 void testSetActiveEntry()
96 QSignalSpy spy(greeter, SIGNAL(requestAuthenticationUser(QString)));
97 QDBusReply<void> reply = dbusList->call("SetActiveEntry", "has-password");
98 QVERIFY(reply.isValid());
101 QCOMPARE(spy.count(), 1);
102 QList<QVariant> arguments = spy.takeFirst();
103 QVERIFY(arguments.at(0).toString() == "has-password");
106 void testEntrySelectedSignal()
108 QSignalSpy spy(dbusList, SIGNAL(EntrySelected(QString)));
109 greeter->authenticate("has-password");
112 QCOMPARE(spy.count(), 1);
113 QList<QVariant> arguments = spy.takeFirst();
114 QVERIFY(arguments.at(0).toString() == "has-password");
117 void testActiveEntryGet()
119 greeter->authenticate("has-password");
120 QVERIFY(dbusList->property("ActiveEntry").toString() == "has-password");
123 void testActiveEntrySet()
125 QSignalSpy spy(greeter, SIGNAL(requestAuthenticationUser(QString)));
126 QVERIFY(dbusList->setProperty("ActiveEntry", "has-password"));
129 QCOMPARE(spy.count(), 1);
130 QList<QVariant> arguments = spy.takeFirst();
131 QVERIFY(arguments.at(0).toString() == "has-password");
134 void testActiveEntryChanged()
136 QSignalSpy spy(this, SIGNAL(PropertiesChangedRelay(QString, QVariantMap, QStringList)));
137 greeter->authenticate("has-password");
140 QCOMPARE(spy.count(), 1);
141 QList<QVariant> arguments = spy.takeFirst();
142 QVERIFY(arguments.at(0).toString() == "com.canonical.UnityGreeter.List");
143 QVERIFY(arguments.at(1).toMap().contains("ActiveEntry"));
144 QVERIFY(arguments.at(1).toMap()["ActiveEntry"] == "has-password");
147 void testEntryIsLockedGet()
149 QVERIFY(dbusList->property("EntryIsLocked").toBool());
151 greeter->authenticate("no-password");
152 QVERIFY(!dbusList->property("EntryIsLocked").toBool());
154 greeter->authenticate("has-password");
155 QVERIFY(dbusList->property("EntryIsLocked").toBool());
158 void testEntryIsLockedChanged()
160 QSignalSpy spy(this, SIGNAL(PropertiesChangedRelay(QString, QVariantMap, QStringList)));
161 greeter->authenticate("no-password");
164 QCOMPARE(spy.count(), 2); // once for locked, once for user; first will be locked mode
165 QList<QVariant> arguments = spy.takeFirst();
166 QVERIFY(arguments.at(0).toString() == "com.canonical.UnityGreeter.List");
167 QVERIFY(arguments.at(1).toMap().contains("EntryIsLocked"));
168 QVERIFY(arguments.at(1).toMap()["EntryIsLocked"] == false);
173 QVERIFY(!greeter->isActive());
174 QVERIFY(!dbusMain->property("IsActive").toBool());
176 QSignalSpy spy(this, SIGNAL(PropertiesChangedRelay(QString, QVariantMap, QStringList)));
177 greeter->setIsActive(true);
180 QVERIFY(greeter->isActive());
181 QVERIFY(dbusMain->property("IsActive").toBool());
183 QCOMPARE(spy.count(), 1);
184 QList<QVariant> arguments = spy.takeFirst();
185 QCOMPARE(arguments.at(0).toString(), QString("com.canonical.UnityGreeter"));
186 QVERIFY(arguments.at(1).toMap().contains("IsActive"));
187 QVERIFY(arguments.at(1).toMap()["IsActive"].toBool());
190 void testShowGreeter()
192 // Just confirm the call exists and doesn't fail
193 QDBusReply<void> reply = dbusMain->call("ShowGreeter");
194 QVERIFY(reply.isValid());
200 QDBusInterface *dbusMain;
201 QDBusInterface *dbusList;
204QTEST_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