~dandrader/unity8/miral

« back to all changes in this revision

Viewing changes to tests/plugins/Unity/Launcher/launchermodeltest.cpp

  • Committer: CI Train Bot
  • Author(s): Michael Terry
  • Date: 2015-11-12 20:39:05 UTC
  • mfrom: (2004.5.2 async)
  • Revision ID: ci-train-bot@canonical.com-20151112203905-tdbo0utd7jcrqw00
Make a few DBus calls asynchronous, for a smoother UX.

The calls I've changed here are neither hugely important nor frequent calls. But every little bit helps.

- Made a few sync calls async.

- Made a few sync calls more obviously sync. We had several instances of asyncCall()'s return value -- a QDBusPendingReply -- being assigned to a QDBusReply variable, which makes it wait for the call to finish. In cases where it didn't make sense to rewrite logic to be async, I've merely changed the method to be call() instead of asyncCall() for clarity.

- I removed the API in our AccountsService plugin for even making sync calls. This won't stop future developers from from writing sync code, but might give them pause.

- I removed some test mocks for our AccountsService plugin interface and changed those tests to use our actual AS plugin against a mock AS server. In truth, this change was because I had a devil of a time crafting a fake reply that included a custom complex type. But it's a good change anyway. Exercises more of our code in tests and reduces duplicated interfaces.
Approved by: Albert Astals Cid

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <QtTest>
32
32
#include <QDBusInterface>
33
33
#include <QDBusReply>
 
34
#include <QDBusMetaType>
34
35
#include <QDomDocument>
35
36
 
36
37
// This is a mock, specifically to test the LauncherModel
136
137
 
137
138
    QList<QVariantMap> getASConfig() {
138
139
        AccountsServiceDBusAdaptor *as = launcherModel->m_asAdapter->m_accounts;
139
 
        return as->getUserProperty("", "", "LauncherItems").value<QList<QVariantMap>>();
 
140
        QDBusReply<QVariant> reply = as->getUserPropertyAsync(QString(qgetenv("USER")),
 
141
                                                              "com.canonical.unity.AccountsService",
 
142
                                                              "LauncherItems");
 
143
        return qdbus_cast<QList<QVariantMap>>(reply.value().value<QDBusArgument>());
140
144
    }
141
145
 
142
146
private Q_SLOTS:
143
147
 
144
148
    void initTestCase() {
 
149
        qDBusRegisterMetaType<QList<QVariantMap>>();
 
150
 
145
151
        launcherModel = new LauncherModel(this);
146
152
        QCoreApplication::processEvents(); // to let the model register on DBus
147
153
        QCOMPARE(launcherModel->rowCount(QModelIndex()), 0);
152
158
 
153
159
    // Adding 2 apps to the mock appmanager. Both should appear in the launcher.
154
160
    void init() {
 
161
        QDBusInterface accountsInterface(QStringLiteral("org.freedesktop.Accounts"),
 
162
                                         QStringLiteral("/org/freedesktop/Accounts"),
 
163
                                         QStringLiteral("org.freedesktop.Accounts"));
 
164
        QDBusReply<bool> addReply = accountsInterface.call(QStringLiteral("AddUser"),
 
165
                                                           QString(qgetenv("USER")));
 
166
        QVERIFY(addReply.isValid());
 
167
        QCOMPARE(addReply.value(), true);
 
168
 
155
169
        appManager->addApplication(new MockApp("abs-icon"));
156
170
        QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
157
171
 
169
183
        while (launcherModel->rowCount(QModelIndex()) > 0) {
170
184
            launcherModel->requestRemove(launcherModel->get(0)->appId());
171
185
        }
 
186
 
 
187
        QDBusInterface accountsInterface(QStringLiteral("org.freedesktop.Accounts"),
 
188
                                         QStringLiteral("/org/freedesktop/Accounts"),
 
189
                                         QStringLiteral("org.freedesktop.Accounts"));
 
190
        QDBusReply<bool> removeReply = accountsInterface.call(QStringLiteral("RemoveUser"),
 
191
                                                              QString(qgetenv("USER")));
 
192
        QVERIFY(removeReply.isValid());
 
193
        QCOMPARE(removeReply.value(), true);
172
194
    }
173
195
 
174
196
    void testMove() {