on 480ed37 help sign in
120 lines 3.5 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
17#include "Greeter.h"
19#include <QDBusInterface>
20#include <QDBusReply>
21#include <QSignalSpy>
22#include <QQuickItem>
23#include <QQuickView>
24#include <QtTestGui>
26class GreeterDBusTest : public QObject
28 Q_OBJECT
30private Q_SLOTS:
32 void init()
33 {
34 view = new QQuickView();
35 view->setSource(QUrl::fromLocalFile(CURRENT_SOURCE_DIR "/greeter.qml"));
36 greeter = dynamic_cast<Greeter*>(view->rootObject()->property("greeter").value<QObject*>());
37 QVERIFY(greeter);
38 QVERIFY(greeter->authenticationUser() == "");
39 view->show();
40 QTest::qWaitForWindowExposed(view);
42 dbusList = new QDBusInterface("com.canonical.UnityGreeter",
43 "/list",
44 "com.canonical.UnityGreeter.List",
45 QDBusConnection::sessionBus(), view);
46 QVERIFY(dbusList->isValid());
47 }
49 void cleanup()
50 {
51 delete view;
52 }
54 void testGetActiveEntry()
55 {
56 greeter->authenticate("has-password");
58 QDBusReply<QString> reply = dbusList->call("GetActiveEntry");
59 QVERIFY(reply.isValid());
60 QVERIFY(reply.value() == "has-password");
61 }
63 void testSetActiveEntry()
64 {
65 QSignalSpy spy(greeter, SIGNAL(requestAuthenticationUser(QString)));
66 QDBusReply<void> reply = dbusList->call("SetActiveEntry", "has-password");
67 QVERIFY(reply.isValid());
68 spy.wait();
70 QCOMPARE(spy.count(), 1);
71 QList<QVariant> arguments = spy.takeFirst();
72 QVERIFY(arguments.at(0).toString() == "has-password");
73 }
75 void testEntrySelectedSignal()
76 {
77 QSignalSpy spy(dbusList, SIGNAL(EntrySelected(QString)));
78 greeter->authenticate("has-password");
79 spy.wait();
81 QCOMPARE(spy.count(), 1);
82 QList<QVariant> arguments = spy.takeFirst();
83 QVERIFY(arguments.at(0).toString() == "has-password");
84 }
86 void testActiveEntryGet()
87 {
88 greeter->authenticate("has-password");
89 QVERIFY(dbusList->property("ActiveEntry").toString() == "has-password");
90 }
92 void testActiveEntrySet()
93 {
94 QSignalSpy spy(greeter, SIGNAL(requestAuthenticationUser(QString)));
95 QVERIFY(dbusList->setProperty("ActiveEntry", "has-password"));
96 spy.wait();
98 QCOMPARE(spy.count(), 1);
99 QList<QVariant> arguments = spy.takeFirst();
100 QVERIFY(arguments.at(0).toString() == "has-password");
101 }
103 void testEntryIsLockedGet()
104 {
105 greeter->authenticate("has-password");
106 QVERIFY(dbusList->property("EntryIsLocked").toBool());
108 greeter->authenticate("no-password");
109 QVERIFY(!dbusList->property("EntryIsLocked").toBool());
110 }
112private:
113 QQuickView *view;
114 Greeter *greeter;
115 QDBusInterface *dbusList;
116};
118QTEST_MAIN(GreeterDBusTest)
120#include "dbus.moc"