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&)));
52 view = new QQuickView();
53 view->setSource(QUrl::fromLocalFile(CURRENT_SOURCE_DIR "/greeter.qml"));
54 greeter = dynamic_cast<Greeter*>(view->rootObject()->property("greeter").value<QObject*>());
56 QVERIFY(greeter->authenticationUser() == "");
58 QTest::qWaitForWindowExposed(view);
60 dbusList = new QDBusInterface("com.canonical.UnityGreeter",
62 "com.canonical.UnityGreeter.List",
63 QDBusConnection::sessionBus(), view);
64 QVERIFY(dbusList->isValid());
72 void testGetActiveEntry()
74 greeter->authenticate("has-password");
76 QDBusReply<QString> reply = dbusList->call("GetActiveEntry");
77 QVERIFY(reply.isValid());
78 QVERIFY(reply.value() == "has-password");
81 void testSetActiveEntry()
83 QSignalSpy spy(greeter, SIGNAL(requestAuthenticationUser(QString)));
84 QDBusReply<void> reply = dbusList->call("SetActiveEntry", "has-password");
85 QVERIFY(reply.isValid());
88 QCOMPARE(spy.count(), 1);
89 QList<QVariant> arguments = spy.takeFirst();
90 QVERIFY(arguments.at(0).toString() == "has-password");
93 void testEntrySelectedSignal()
95 QSignalSpy spy(dbusList, SIGNAL(EntrySelected(QString)));
96 greeter->authenticate("has-password");
99 QCOMPARE(spy.count(), 1);
100 QList<QVariant> arguments = spy.takeFirst();
101 QVERIFY(arguments.at(0).toString() == "has-password");
104 void testActiveEntryGet()
106 greeter->authenticate("has-password");
107 QVERIFY(dbusList->property("ActiveEntry").toString() == "has-password");
110 void testActiveEntrySet()
112 QSignalSpy spy(greeter, SIGNAL(requestAuthenticationUser(QString)));
113 QVERIFY(dbusList->setProperty("ActiveEntry", "has-password"));
116 QCOMPARE(spy.count(), 1);
117 QList<QVariant> arguments = spy.takeFirst();
118 QVERIFY(arguments.at(0).toString() == "has-password");
121 void testActiveEntryChanged()
123 QSignalSpy spy(this, SIGNAL(PropertiesChangedRelay(QString, QVariantMap, QStringList)));
124 greeter->authenticate("has-password");
127 QCOMPARE(spy.count(), 1);
128 QList<QVariant> arguments = spy.takeFirst();
129 QVERIFY(arguments.at(0).toString() == "com.canonical.UnityGreeter.List");
130 QVERIFY(arguments.at(1).toMap().contains("ActiveEntry"));
131 QVERIFY(arguments.at(1).toMap()["ActiveEntry"] == "has-password");
134 void testEntryIsLockedGet()
136 QVERIFY(dbusList->property("EntryIsLocked").toBool());
138 greeter->authenticate("no-password");
139 QVERIFY(!dbusList->property("EntryIsLocked").toBool());
141 greeter->authenticate("has-password");
142 QVERIFY(dbusList->property("EntryIsLocked").toBool());
145 void testEntryIsLockedChanged()
147 QSignalSpy spy(this, SIGNAL(PropertiesChangedRelay(QString, QVariantMap, QStringList)));
148 greeter->authenticate("no-password");
151 QCOMPARE(spy.count(), 2); // once for locked, once for user; first will be locked mode
152 QList<QVariant> arguments = spy.takeFirst();
153 QVERIFY(arguments.at(0).toString() == "com.canonical.UnityGreeter.List");
154 QVERIFY(arguments.at(1).toMap().contains("EntryIsLocked"));
155 QVERIFY(arguments.at(1).toMap()["EntryIsLocked"] == false);
161 QDBusInterface *dbusList;
164QTEST_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