~xnox/unity8/cross-compile

« back to all changes in this revision

Viewing changes to tests/plugins/LightDM/dbus.cpp

  • Committer: Tarmac
  • Author(s): Michael Terry
  • Date: 2013-12-04 19:29:59 UTC
  • mfrom: (567.4.6 greeter-dbus-api)
  • Revision ID: tarmac-20131204192959-6p1va2xnvkoxegk8
Add the DBus greeter API from the desktop greeter into the unity8 greeter.

Approved by PS Jenkins bot, Albert Astals Cid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 */
 
16
 
 
17
#include "Greeter.h"
 
18
 
 
19
#include <QDBusInterface>
 
20
#include <QDBusReply>
 
21
#include <QSignalSpy>
 
22
#include <QQuickItem>
 
23
#include <QQuickView>
 
24
#include <QtTestGui>
 
25
 
 
26
class GreeterDBusTest : public QObject
 
27
{
 
28
    Q_OBJECT
 
29
 
 
30
Q_SIGNALS:
 
31
    void PropertiesChangedRelay(const QString &interface, const QVariantMap &changed, const QStringList &invalidated);
 
32
 
 
33
private Q_SLOTS:
 
34
 
 
35
    void initTestCase()
 
36
    {
 
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
 
40
        // to watch.
 
41
        QDBusConnection::sessionBus().connect(
 
42
            "com.canonical.UnityGreeter",
 
43
            "/list",
 
44
            "org.freedesktop.DBus.Properties",
 
45
            "PropertiesChanged",
 
46
            this,
 
47
            SIGNAL(PropertiesChangedRelay(const QString&, const QVariantMap&, const QStringList&)));
 
48
    }
 
49
 
 
50
    void init()
 
51
    {
 
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*>());
 
55
        QVERIFY(greeter);
 
56
        QVERIFY(greeter->authenticationUser() == "");
 
57
        view->show();
 
58
        QTest::qWaitForWindowExposed(view);
 
59
 
 
60
        dbusList = new QDBusInterface("com.canonical.UnityGreeter",
 
61
                                      "/list",
 
62
                                      "com.canonical.UnityGreeter.List",
 
63
                                      QDBusConnection::sessionBus(), view);
 
64
        QVERIFY(dbusList->isValid());
 
65
    }
 
66
 
 
67
    void cleanup()
 
68
    {
 
69
        delete view;
 
70
    }
 
71
 
 
72
    void testGetActiveEntry()
 
73
    {
 
74
        greeter->authenticate("has-password");
 
75
 
 
76
        QDBusReply<QString> reply = dbusList->call("GetActiveEntry");
 
77
        QVERIFY(reply.isValid());
 
78
        QVERIFY(reply.value() == "has-password");
 
79
    }
 
80
 
 
81
    void testSetActiveEntry()
 
82
    {
 
83
        QSignalSpy spy(greeter, SIGNAL(requestAuthenticationUser(QString)));
 
84
        QDBusReply<void> reply = dbusList->call("SetActiveEntry", "has-password");
 
85
        QVERIFY(reply.isValid());
 
86
        spy.wait();
 
87
 
 
88
        QCOMPARE(spy.count(), 1);
 
89
        QList<QVariant> arguments = spy.takeFirst();
 
90
        QVERIFY(arguments.at(0).toString() == "has-password");
 
91
    }
 
92
 
 
93
    void testEntrySelectedSignal()
 
94
    {
 
95
        QSignalSpy spy(dbusList, SIGNAL(EntrySelected(QString)));
 
96
        greeter->authenticate("has-password");
 
97
        spy.wait();
 
98
 
 
99
        QCOMPARE(spy.count(), 1);
 
100
        QList<QVariant> arguments = spy.takeFirst();
 
101
        QVERIFY(arguments.at(0).toString() == "has-password");
 
102
    }
 
103
 
 
104
    void testActiveEntryGet()
 
105
    {
 
106
        greeter->authenticate("has-password");
 
107
        QVERIFY(dbusList->property("ActiveEntry").toString() == "has-password");
 
108
    }
 
109
 
 
110
    void testActiveEntrySet()
 
111
    {
 
112
        QSignalSpy spy(greeter, SIGNAL(requestAuthenticationUser(QString)));
 
113
        QVERIFY(dbusList->setProperty("ActiveEntry", "has-password"));
 
114
        spy.wait();
 
115
 
 
116
        QCOMPARE(spy.count(), 1);
 
117
        QList<QVariant> arguments = spy.takeFirst();
 
118
        QVERIFY(arguments.at(0).toString() == "has-password");
 
119
    }
 
120
 
 
121
    void testActiveEntryChanged()
 
122
    {
 
123
        QSignalSpy spy(this, SIGNAL(PropertiesChangedRelay(QString, QVariantMap, QStringList)));
 
124
        greeter->authenticate("has-password");
 
125
        spy.wait();
 
126
 
 
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");
 
132
    }
 
133
 
 
134
    void testEntryIsLockedGet()
 
135
    {
 
136
        QVERIFY(dbusList->property("EntryIsLocked").toBool());
 
137
 
 
138
        greeter->authenticate("no-password");
 
139
        QVERIFY(!dbusList->property("EntryIsLocked").toBool());
 
140
 
 
141
        greeter->authenticate("has-password");
 
142
        QVERIFY(dbusList->property("EntryIsLocked").toBool());
 
143
    }
 
144
 
 
145
    void testEntryIsLockedChanged()
 
146
    {
 
147
        QSignalSpy spy(this, SIGNAL(PropertiesChangedRelay(QString, QVariantMap, QStringList)));
 
148
        greeter->authenticate("no-password");
 
149
        spy.wait();
 
150
 
 
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);
 
156
    }
 
157
 
 
158
private:
 
159
    QQuickView *view;
 
160
    Greeter *greeter;
 
161
    QDBusInterface *dbusList;
 
162
};
 
163
 
 
164
QTEST_MAIN(GreeterDBusTest)
 
165
 
 
166
#include "dbus.moc"